Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: arj0n on Thu 09/06/2011 20:14:13

Title: Semi-transparant dialog gui's [Solved]
Post by: arj0n on Thu 09/06/2011 20:14:13
Are semi-transparant dialog gui's (where you can choose an option to say to a NPC) for a 32-bit true color game supported for the current AGS version?

(it's 32bit alpha channel)
Title: Re: Semi-transparant dialog gui's
Post by: ThreeOhFour on Thu 09/06/2011 22:36:37
Yeah, it's possible, but it's a mega pain to do! I have alpha channels in the one for ~airwave~ :).

To do it, I have a seperate gui that just holds the background image sitting behind the dialogue gui, because the actual gui background itself does not support alpha channels (not in 3.1.2 which is what I'm currently using, anyway). I then adjust this gui's position to match the height of the dialogue gui. Seeing as I couldn't manage to get the game to tell me what the actual height of the gui was, and I couldn't seem to get it working with repeatedly_execute_always, that means I calculate it of the number of active dialogue options available.

This means all my dialogue choices have to be one line long only, and that i have to keep manually positioning the gui every time I add or remove an option, as well as manually turning it off for every option you click then back on again when the option has finished.

The code is a little like this:

(in globalscript)

function GuiSetter()
{
  int MaxOptions = dialog[DNum].OptionCount;
  int OptionsIndex = 1;
  int TotalOptions = 0;
  while (OptionsIndex <= MaxOptions)
  {
    if (dialog[DNum].GetOptionState(OptionsIndex) == eOptionOn)
    {
      TotalOptions++;
      OptionsIndex++;
    }
    else
    {
      OptionsIndex++;
    }
  }
  gDialogOptions.Y = 238 - (TotalOptions * 10);
  gDialogBG.Y = gDialogOptions.Y - 14;
}

function StartDialog(int DialogNumber)
{
  DNum = DialogNumber;
  GuiSetter();
  dialog[DialogNumber].Start();
  gDialogBG.Visible = true;
  gDialogOptions.Clickable = true;
}

function dialog_request(int request)
{
  if (request == 1) //call this whenever adding/removing dialogue options
  {
    GuiSetter();
  }
  else if (request == 2) //call this whenever quitting a dialogue
  {
    gDialogBG.Visible = false;
    gDialogOptions.Clickable = false;
  }
}




Here you can see how I turn everything on and off in the actual dialogue script:



gDialogBG.Visible = false; //otherwise the options will disappear and the background will remain, which looks horrid
Cedilla: A 'Neuro app'?
cDural.Loop = 3;
Dural: You've never heard of a neuro app?
Cedilla: Nope, never. I don't think anyone has back home in Navil.
cDural.Loop = 1;
Dural: Neuro apps are pieces of software designed to integrate with your brain and body.
Dural: Like installing a program on your electrical devices, except on yourself.
Cedilla: Isn't that dangerous?
Dural: Only for the beta testers.
Dural: As the eloquent poet Hutley wrote in his epic piece Shimmering: 'It ain't gonna happen, right, if sometimes things don't go a bit wrong at first, I guess...'
option-off 2
run-script 1 // the option-off command means we need to reset the size of the gui background, or it won't synchronise
gDialogBG.Visible = true; // we need to turn the gui background back on before we get back to the dialogue options, because we turned it off manually
return



Like I said, it's a big pain... but I wanted alpha transparencies on my guis, and this was seemingly the only way to achieve it. You may not consider it worth the effort - personally I'll do whatever it takes to make my game look how I want it to :P
Title: Re: Semi-transparant dialog gui's
Post by: monkey0506 on Fri 10/06/2011 00:38:49
Well another option would be to use the same method I used to get a fully transparent dialog option background that works with AA fonts, which is basically to redraw the portion of the screen behind the GUI yourself..it's not the simplest thing, but actually works nicer than one might think..I used it in my game and abstauber implemented the same thing into his module.

In fact, the CDG module might allow this directly. If not then I'll try and scrounge up the code when I get home and show you how I've done it..with the additional step of semi-transparently drawing your background image.
Title: Re: Semi-transparant dialog gui's
Post by: arj0n on Fri 10/06/2011 10:39:10
Thanx guys  :)
Title: Re: Semi-transparant dialog gui's [Solved]
Post by: ThreeOhFour on Fri 10/06/2011 11:27:47
Pretty sure I tried Dirk's module and no bananas. I'd love to see a more organic method than the one I've been relying on.
Title: Re: Semi-transparant dialog gui's [Solved]
Post by: abstauber on Fri 10/06/2011 11:44:31
As long as you're not working with tints, the CDG module can help you out. You just need a background image, it does not work with plain colors.
CDG.bg_img_transparency = 70;

(http://shatten.sonores.de/wp-content/uploads/2011/06/CDG_Transparent.png)

@Ben: No bananas = no success or the other way round?
Title: Re: Semi-transparant dialog gui's [Solved]
Post by: ThreeOhFour on Fri 10/06/2011 20:16:14
Haha bananas always equals success!  :D

Therefore no bananas = no success. My gui relies on the actual use of a sprite containing its own alpha channel, for I have done fancy and pretty fading things that nobody notices :=. That background transparency look nice, but for my purposes I need the actual image to keep its alpha channel, rather than being able to rely on setting a transparency over the whole thing within the game.
Title: Re: Semi-transparant dialog gui's [Solved]
Post by: monkey0506 on Fri 10/06/2011 20:39:08
DrawingSurface.DrawImage works fine with alpha channeled sprites!! The only limitations are that the alpha channel is lost in the resultant image, and if you draw anything semitransparent on a fully transparent portion of the surface you get a pink haze because AGS still relies on "magic pink" for its transparency deductions.

In short, abstauber's module should work even with alpha channeled backgrounds, because there can't be a transparent area behind the dialog, and while the alpha channel is applied, the resultant image can safely be flattened for the same reason.
Title: Re: Semi-transparant dialog gui's [Solved]
Post by: ThreeOhFour on Fri 10/06/2011 20:55:22
Yep, I am aware that DrawImage works fine with alpha channeled sprites, and have been using it with them a bit lately.

However, the last time I tried Dirk's module to try and do this, it didn't make any difference at all. This was nearly a year ago that I wrote that code, mind you, so perhaps it has changed since then, or perhaps there was a stage I missed?
Title: Re: Semi-transparant dialog gui's [Solved]
Post by: monkey0506 on Fri 10/06/2011 21:22:26
Ah, well come to think of it..yeah he's probably trying to be clever if the bg_img_transparency isn't set which could mean it wouldn't be playing nicely with your sprites.

Well, I didn't write the module so I claim absolutely no responsibility for how he's doing things (regardless of what I may have, implicitly or explicitly, said, implied, or otherwise indicated would or should work :P).
Title: Re: Semi-transparant dialog gui's [Solved]
Post by: ThreeOhFour on Fri 10/06/2011 22:32:31
lol @ disclaimer :P

To be honest, I've actually grown quite used to doing dialogues this way now as I've been using this system for around a year (perhaps a bit less). Still I'd not object if there was an easier way - while this way works and I've released stuff using it, it is a little clunky and I can sometimes forget to add in a command accidentally now and then.
Title: Re: Semi-transparant dialog gui's [Solved]
Post by: abstauber on Sat 11/06/2011 10:50:16
QuoteHaha bananas always equals success!
How could I now know, for my next trip to Australia, I'll be finally safe ;D

Anyway, there's a bug in the GUI module, which eats alpha channels for lunch.

Without this bug, the GUI looks like this (in other words: fixed)
(http://shatten.sonores.de/wp-content/uploads/2011/06/alpha_gui.png)


Now I just need to find the motivation to build new packages :P


edit:
QuoteWell, I didn't write the module so I claim absolutely no responsibility for how he's doing things
Hehe, but you're the inventor of the semi transparent background workaround ;)
Title: Re: Semi-transparant dialog gui's [Solved]
Post by: monkey0506 on Sat 11/06/2011 11:13:01
It's the same as the semitransparent code, you just draw the alpha channeled image with DrawingSurface.DrawImage as normal. I'm pretty sure that the transparency parameter still works even if the image has an alpha channel, doesn't it?

What I'm guessing is that you're trying to optimize it so that if the bg_img_transparency isn't set then you're not using the semitransparent code at all, right? That would explain why your code is asploding the alpha channels. Unfortunately there's not a way to check via the script whether a given sprite has an alpha channel, but you could perhaps allow the user to set bg_img_transparency to, say, -1, which would mean, don't apply any additional transparency, but still use the semitransparent code because the background has an alpha channel. Could work nicely. Saves the optimization factor if using totally opaque backgrounds, but lets you use alpha channeled sprites without having to really make too many changes to the code.
Title: Re: Semi-transparant dialog gui's [Solved]
Post by: abstauber on Sat 11/06/2011 13:44:12
QuoteI'm pretty sure that the transparency parameter still works even if the image has an alpha channel, doesn't it?

That's the point, as soon as you pass the transparency parameter to DrawImage, the sprite's alpha channel is being ignored. Currently I've done it with another parameter.
But setting bg_img_transparency to -1 in order to preserve the alpha channel sounds reasonable too :)
Title: Re: Semi-transparant dialog gui's [Solved]
Post by: ThreeOhFour on Sat 11/06/2011 14:31:24
The ability to use the module with alpha channel containing images would be a big thing! Like I said, before I invented my workaround I had hoped that I could use the module to get the effect I wanted, and was pretty heartbroken when I couldn't  :=
Title: Re: Semi-transparant dialog gui's [Solved]
Post by: abstauber on Sat 11/06/2011 17:16:37
Just updated the module, please try to set CDG.bg_img_transparency to -1. I hope this will lead to lots of bananas :)

@Arj0n: Sorry that we've hi-jacked your thread ;) But thanks to you the CDG module now can do this.
Title: Re: Semi-transparant dialog gui's [Solved]
Post by: monkey0506 on Sat 11/06/2011 19:36:28
Quote from: abstaubE3 on Sat 11/06/2011 13:44:12That's the point, as soon as you pass the transparency parameter to DrawImage, the sprite's alpha channel is being ignored.

Ah, I thought it would work more like GUIs which now allow you to set the Transparency even if the BackgroundGraphic has an alpha channel. Well, at least you implemented yet another of my suggestions! :P

And yes, I suppose this is enough hijackage and we can let this thread die in peace now. :=