Semi-transparant dialog gui's [Solved]

Started by arj0n, Thu 09/06/2011 20:14:13

Previous topic - Next topic

arj0n

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)

ThreeOhFour

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)
Code: ags

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:


Code: ags

 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

monkey0506

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.

arj0n


ThreeOhFour

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.

abstauber

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.
Code: ags
CDG.bg_img_transparency = 70;




@Ben: No bananas = no success or the other way round?

ThreeOhFour

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.

monkey0506

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.

ThreeOhFour

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?

monkey0506

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).

ThreeOhFour

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.

abstauber

#11
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)



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 ;)

monkey0506

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.

abstauber

#13
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 :)

ThreeOhFour

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  :=

abstauber

#15
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.

monkey0506

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. :=

SMF spam blocked by CleanTalk