Highlight buttons text and display/hide arrows in dialog GUI

Started by Giacomo, Wed 01/03/2023 10:01:52

Previous topic - Next topic

Giacomo

Hello everybody.

I'd like to ask you a couple of questions about labels and arrows buttons.

I searched a lot in the forum and in the manual to find out a solution but I'm still
having my first experience in scripting and I need your help before I compromise my code.

I saw two interesting posts in which eri0o and Khris talked about the matter.

https://www.adventuregamestudio.co.uk/forums/beginners-technical-questions/changing-number-dialog-options-in-general-settings-doesn-t-make-any-change/msg636653127/#msg636653127

https://www.adventuregamestudio.co.uk/forums/beginners-technical-questions/about-dialog-options-and-templates/msg636637797/#msg636637797

Thanks for these answer, they helped me a lot despite I'm not able to resolve these problems yet!

What'd I like to do is the following:

1)once you open Menu GUI, passing cursor over buttons should highlight their text

To accomplish this I thought to create an empty sprite, assign this sprite to every MouseOverImage button functions in the GUI, then create a Dynamic Sprite and Surface from the button graphic and text.
I wonder if I can use button text and background together to create a Dynamic Sprite.

2)I need an upload function to display correctly the dialogs GUI, as everytime I switch off an option state, a blank space
remains in the dialog windows, as if the option was still active; same goes for arrows, as they should appear and disappear
only when needed. This works fine for inventory window, but I'm not able to export the function over dialogs.


I also have a question about characters animation on standing frame, which is not in the title. I read about similar problems
but I'm not able to create a fine function. Please let me know if I can expand the post and put the question here, or should I
put the issue in a new post?

A character walks randomly in a certain area. He stops and after a little time he starts walking again.
I created a function with two timer calling each other everytime one of them is expired.
Character is carrying a ballon, so when he's standing the baloon should float.
I tried to split the animation, making of the baloon an object following character, but I don't find this is a good solution.
The function works fine except when the character stop moving, as he changes view but no animation starts.

Please let me know if I can put some code regarding this matter in this post!

Thank you all in advance,
Giacomo
https://ko-fi.com/giacomo97557 To support Falco's adventures

Khris

Re 1:
You can create a copy of the button's background sprite, then draw the text on top:

Code: ags
DynamicSprite* CreateButtonSprite(int bg_slot, String text, bool highlight) {
  int font = Game.NormalFont; // set font
  DynamicSprite* r = DynamicSprite.CreateFromExistingSprite(bg_slot);
  DrawingSurface* ds = r.GetDrawingSurface();
  ds.DrawingColor = !highlight * 12345 + highlight * 23456; // AGS color values for text / highlighted text
  int y = (r.Height - GetFontHeight(font)) / 2;
  ds.DrawStringWrapped(0, y, r.Width, font, eAlignCentre, text);
  ds.Release();
  return r;
}

DynamicSprite* menuButtonSprite[5], menuButtonHSprite[5];

function PrepareButton(int index, Button* button, int bg_slot, String text) {
  menuButtonSprite[index] = CreateButtonSprite(bg_slot, text, false);
  menuButtonHSprite[index] = CreateButtonSprite(bg_slot, text, true);
  button.NormalGraphic = menuButtonSprite[index].Graphic;
  button.MouseOverGraphic = menuButtonHSprite[index].Graphic;
}

// call this in game_start (or put the lines in there instead)
function PrepareMenu() {
  PrepareButton(0, btnStartGame, 123, "Start Game");
  PrepareButton(1, btnLoadGame, 124, "Load Game");
}

Khris

Re 2:
My guess is when you draw the options you need to iterate over the options and only increment the y coordinate if it's on, similarly to what I do in the code you linked where I do the keypress detection.

Which template/module/dialog code are you using?

As for the balloon character, assigning an Idle View should work here. It can be used to animate the balloon whenever the character is standing still.

Giacomo

Thank you Khris!

I'm using BASS template.

About the baloon animation, I still have to try to assign it an idle animation and set the shortest timer possible
between one animation and the other; I wonder if doing so reduce the waiting to zero, letting the animation run
continually... If this works, I could delete the baloon object and merge its sprite to the character sprite, setting idle
to -1 everytime he starts walking and resetting it to right view once he stops.

I'm gonna try your code later in the day!

Thank you again,
Giacomo
https://ko-fi.com/giacomo97557 To support Falco's adventures

Giacomo

Khris, let me ask you just one more thing.

I have an issue about character walk function.

I'd like him to walk automatically to hotspots, chars and objcets, but I don't want
to set eBlock in params, despite I'd like to block following functions and let them run
only once he reached the target.

I saw some options about this but my game is not working as I'd like, and I don't like to always use eBlock
to prevent next functions to run. About this matter and eBlock param I'd have a couple of more questions to ask...
I would open a post to make all these specific questions about it, but if you tell me that there are older posts that
can help me, I will take a deeper look in the forum!

Sorry if I'm fullfilling you with these stupid questions, but my first game is almost done and I spent several days
looking for an answer to these problems!
https://ko-fi.com/giacomo97557 To support Falco's adventures

Khris

Hey Giacomo,

don't worry, finding something in the manuals or tutorials can be really hard, and the forum search is not exactly great to find specific solutions either.

Try my module:
https://www.adventuregamestudio.co.uk/forums/beginners-technical-questions/graphicalfunctional-questions-for-cmi-style-guiinventorymenus/msg636639852/#msg636639852

Giacomo

Thank you, Khris, point 1 is accomplished!

I just had to empty button text because it seems to be in front of the drawn sprite, but it's fine so!
I guess there's no problem for transaltion till I'm creating new strings..

I'm still having a hard time in achieving point 2 but it's because my skills are still too low(and maybe my IQ too).

I have followed eriOo's instructions and made a new script in which i pasted all the lines he wrote. I'm trying to put the
function inside there and do some useful imports in global but nothing good is happening. Anyway, I'm not sure about how
key press function works, but since I am using mouse only maybe I should modify on mouse click func and insert the iteration here
Code: ags
function dialog_options_mouse_click(DialogOptionsRenderingInfo *info, MouseButton button)
{
  int d_x = info.X;
  int d_y = info.Y;
  if(button == eMouseLeft) {
    if(IsMouveOverScrollUp(d_x, d_y)) 
    {
      ScrollUp();
      info.Update();
    }
    
    if(IsMouseOverScrollDown(d_x, d_y)) 
    {
      ScrollDown(info.DialogToRender.OptionCount);
      info.Update();
    }
    
    if (info.ActiveOptionID > 0) {
      info.RunActiveOption();
    }
  }
}

Thanks eriOo, this module is very helpful for my learning!
https://ko-fi.com/giacomo97557 To support Falco's adventures

eri0o

Oh man, I didn't notice I never answered the rest of Chomba questions at the time.

I don't have a computer right now, but I see you haven't shared how you are tackling your custom dialog rendering.

One suggestion though, there is a module from abstauber that is pretty good, it's called Custom Dialog GUI.

https://www.adventuregamestudio.co.uk/forums/index.php?topic=36313.0

Not sure if you have looked into it or not. This module has a demo game, I recommend testing it's demo and experimenting with it before, just to see if the module does what you want.

Giacomo

https://ko-fi.com/giacomo97557 To support Falco's adventures

Khris

Regarding the scrolling dialogs I wrote a module:

https://drive.google.com/file/d/19uyh4VBjeMkhg-oNX2RC-STsw7IGG9Bl/view?usp=share_link

Here's example setup code, however each line is optional:

Code: ags
  Dialogs.SetFont(eFontFont0);
  Dialogs.SetTextColors(11, 12); // normal text, hovered text, optionally: chosen text and hovered chosen text
  Dialogs.SetPadding(4, 4); // padding inside the GUI, first x then y
  Dialogs.SetVisibleOptions(4); // only show 4 options max, enable mouse scrolling (pass 0 to always show all)
  Dialogs.SetScrollArrowSlots(2170, 2171); // slots for the scroll arrows
  Dialogs.SetShowNumbers(true); // show line numbers

Preview:

Giacomo

That's great, Khris. I am gonna work on it soon.
I hope to issue my first game in he early summer!

Anyway, the many times I ask or look for answers I find out
you give solutions that seem to be simpler and more efficient
than many function in AGS editor...It's getting more interesting
and I'm enjoying scripting the game always more, thanks again!
https://ko-fi.com/giacomo97557 To support Falco's adventures

Khris

You're welcome :)

But the real work is done by the people maintaining the engine, primarily Crimson Wizard. I'm just using the tools they provide :)

Giacomo

Sure, I wanted to write "you" as you all.

This to say that the editor is cool because it's "easy" to use for
newbies like me, but things get more interesting when you dive deeper
into script...and you all help me see better into it..

PS:I'm a fan of adventure games since I was 5 yo and MI left me the most visible mark ever in my life.
I'm having a lot of fun making a stupid game and you can't tell how much this community made my life funnier!
https://ko-fi.com/giacomo97557 To support Falco's adventures

Giacomo

Good morning everybody,
I'd like to post a question about buttons enlightement in the module of Khris.

First of all, thank you Khris because the module works perfectly;
what I'd like to ask you is a little customization to enlight arrows' buttons.

I don't use a background color in dialogs GUI and I noticed that when arrows are not enlighted,
they are partially coloured of magenta, which should be the colour for transparency in AGS.

What I'd like to do is substitute the sprites of arrows with a character, or eventually with two sprites for each arrow(an enlighted one an a normal one), to avoid seeing the magenta colour.

Using other Khris' function, like PrepareMenu and PrepareButton, I set some buttons in my inventory GUI with special charcaters instead of loading a sprite.
This is useful to enlight the buttons in a easy way(always thanks to khris as well!), and, in my case, I set some symbols like arrows and music off/on button with some special characters in order to easy enlight them.

I wonder if it is possible to do something similar in Scrolling Dialogs mod: to set arrows button like characters and enlight them the same way you enlight texts.

I studied a bit the module, but I'm afraid to put my hands on it and I wonder if it can be stable after a modify like this.
Either way, loading two sprites for each arrow button would be ok to me, and maybe it is even easier.

Any help is appreciated,
thank you,
Giacomo
https://ko-fi.com/giacomo97557 To support Falco's adventures

Khris

@Giacomo
Hi Giacomo,

I have updated the module accordingly. You can use a line like
Code: ags
  Dialogs.SetScrollArrowSlots(2172, 2173, 2170, 2171); // up, down, up highlighted, down highlighted
to set four sprites.

Giacomo

https://ko-fi.com/giacomo97557 To support Falco's adventures

SMF spam blocked by CleanTalk