Maniac Mansion Mania Forum

MMM-Werkzeugkiste => Technik => Thema gestartet von: lizhustedt am 22. Januar 2023, 18:49:05

Titel: Switching to a custom GUI when selecting a certain character
Beitrag von: lizhustedt am 22. Januar 2023, 18:49:05
Friends! Folks! Coders!

I need some help on a game I'm working on, and having difficulty tracing the stack of calls around updating GUI buttons and actions on-screen. It would be awesome if someone understood the high-level flow of the GUI code and could talk through it.

Here's the scenario:

(https://i.imgur.com/YRWeLc7.png)

I have been able to change the text overlay on the button when switching characters, as shown below. For example, when you click "Pick up," the label shows "Hiss at." (I have some code in SetActionButtons() that implements this, as well as some other foundational code in other methods.)

(https://i.imgur.com/zRM4LDA.png)

I have not been able to find the appropriate place in the code to switch GUIs. I'd like to add a code block somewhere that would relay something like the following pseudo-code:

if char == cCat
gMaingui.Visible = false
gCatgui.Visible = true

And, likewise, I'd like to add a code block that would switch back to the main GUI when the cat is not selected.

I'm also not sure when I should use the method
SetAlternativeAction(), so if anyone has insight into that, that'd be helpful. I think I need to add some calls to CheckDefaultAction(), but I'm still playing around there, and have some commented-out code.

(https://i.imgur.com/cf8uMVy.png)

Additionally, it'd be great to add documentation to the Starter Park wiki (https://github.com/ManiacMansionMania/Bernard-SP/wiki (https://github.com/ManiacMansionMania/Bernard-SP/wiki)) and document some of these high-level flows or niche problem areas for others. I'd be happy to contribute in any way I can, and thanks in advance for any help.
Titel: Re: Switching to a custom GUI when selecting a certain character
Beitrag von: alphawolf300 am 22. Januar 2023, 19:34:15
Hi Liz,

I hope I can help you with my semi-good coding performance.

Try to find the SetPlayer function. At the end of it call a function

CheckCharacter()
The CheckCharacter function has to look like this:
function CheckCharacter()
{
  if (player == cCat)
  {
    gMaingui.Visible = false
    gCatgui.Visible = true
  }
  else
  {
    gMaingui.Visible = true
    gCatgui.Visible = false
  }
}

This is completely untested. I hope it works or will help or at least that it will help you.
Feel free to post if there are any further problems.
Titel: Re: Switching to a custom GUI when selecting a certain character
Beitrag von: lizhustedt am 22. Januar 2023, 20:14:43
(https://i.imgur.com/rjpSOKz.png)

Oh, this is super helpful -- THANK YOU.

We are SO CLOSE! This almost fixes the issue. I added the custom CheckCharater() code to the end of SetPlayer(), like you had suggested. The GUI overlay changes to the cat GUI, as shown above, but now the main character's button disappears in the character selection portion of the GUI, and I don't have a way of switching back to the main character. Hmm....
Titel: Re: Switching to a custom GUI when selecting a certain character
Beitrag von: alphawolf300 am 22. Januar 2023, 21:54:56
ls the character's button part of the main gui?
If so, add a character's button to the cat's gui as well.

Edit: 2nd guess: look for the z-order of your guis. Maybe your cat's gui has a different value. Use the same value as the main gui.
Titel: Re: Switching to a custom GUI when selecting a certain character
Beitrag von: lizhustedt am 25. Januar 2023, 05:22:36
Hah, you read my mind about the Z order of the GUIs.

Okay, so that was my first thought: maybe something is obscured by the Z-order, or they're conflicting with each other somehow?

Things I tried:


(https://i.imgur.com/LhtHSRN.png)

During my last trial, the code did hit the logic block on line 30, and played the sound effect and everything, but the button still didn't show up or blink. I feel like I'm missing something obvious or need to think laterally. Any ideas on what to try next?


Thank you!!!
Titel: Re: Switching to a custom GUI when selecting a certain character
Beitrag von: alphawolf300 am 25. Januar 2023, 06:39:31
As far as I understand, the button you want to show is part of the main gui? If you hide the main gui, the button gets hidden as well and there is no chance to show it as far its part of it.

Try one of these suggestions:
1. add the button to your cat's gui as well
2. create an additional gui and move the button over there.

I hope this will fix your issue.
Titel: Re: Switching to a custom GUI when selecting a certain character
Beitrag von: lizhustedt am 26. Januar 2023, 04:46:50
Ahh, thank you again for your reply!

So, I should have clarified -- the button is not part of the main GUI.


The character button is dynamically added via the code when a new character becomes available to switch to, and the new button appears on the right side of the GUI. The main GUI design is shown here:

(https://i.imgur.com/L9aEcUW.png)

In that code snippet I showed above, it passes in the variable "nb," which is a pointer to the newly created button. I tried calling this method with the cc1 variable, but it didn't work.

Wait a minute. I wonder if it's dynamically adding it to the mainGUI instead of the catGUI when I call this code.... I think I know what I need to look into!
Titel: Re: Switching to a custom GUI when selecting a certain character
Beitrag von: lizhustedt am 26. Januar 2023, 05:36:00
Yep, sure enough, the UpdateButtons() only changes the visibility of the buttons in the main GUI (starting on line 14 in my screenshot above).

I grabbed some of that code for a first pass and put it into the CheckCharacter() function. I'll make this more modular once I get the solution complete:

(https://i.imgur.com/g2kWWuK.png)

On line 92, I make sure it's looking at the cat GUI, not the main GUI. That change made the character's picture appear, but it wasn't clickable.

I also had to change the cat GUI inventory window width to 125 pixels, instead of the standard 165. This change made the button clickable.


My last challenge: I need to add the "Switch to" label to this button on the cat's GUI. I wish I could make the cat GUI inherit a button from the other GUI, but meh, I'll see how sticky this is.
Titel: Re: Switching to a custom GUI when selecting a certain character
Beitrag von: lizhustedt am 26. Januar 2023, 05:49:22
Okay, another update! The label was being added in the GlobalCondition() code, but again, another spot where only the main GUI was checked.

I added a condition to see if the cat GUI was active, and that fixed adding the label!

(https://i.imgur.com/TDr9ld1.png)

Time to clean up my code, but again, thanks for your help!
Titel: Re: Switching to a custom GUI when selecting a certain character
Beitrag von: alphawolf300 am 26. Januar 2023, 12:05:09
Happy to hear your GUI issue is fixed. Have fun while creating your game. I am really excited about the outcome and looking forward to playing your game someday.