Autor Thema: Switching to a custom GUI when selecting a certain character  (Gelesen 2920 mal)

lizhustedt

  • Tentakelschleim
  • *
  • Beiträge: 6
    • Profil anzeigen
    • E-Mail
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:
  • For the beginning of the game, I have one character, and she uses the mainGui
  • Later, a new character is introduced, a playable cat
  • I want to be able to switch to a custom GUI (catGui, shown below) when you switch to the cat, and switch back to the mainGui when the primary character is in use



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



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.



Additionally, it'd be great to add documentation to the Starter Park 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.

alphawolf300

  • Teenie Tentakel
  • ****
  • Beiträge: 301
    • Profil anzeigen
    • E-Mail
Re: Switching to a custom GUI when selecting a certain character
« Antwort #1 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.
« Letzte Änderung: 22. Januar 2023, 19:36:31 von alphawolf300 »

lizhustedt

  • Tentakelschleim
  • *
  • Beiträge: 6
    • Profil anzeigen
    • E-Mail
Re: Switching to a custom GUI when selecting a certain character
« Antwort #2 am: 22. Januar 2023, 20:14:43 »


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

alphawolf300

  • Teenie Tentakel
  • ****
  • Beiträge: 301
    • Profil anzeigen
    • E-Mail
Re: Switching to a custom GUI when selecting a certain character
« Antwort #3 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.
« Letzte Änderung: 23. Januar 2023, 07:03:49 von alphawolf300 »

lizhustedt

  • Tentakelschleim
  • *
  • Beiträge: 6
    • Profil anzeigen
    • E-Mail
Re: Switching to a custom GUI when selecting a certain character
« Antwort #4 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:
  • The Z order of the main GUI is 1, and the Z order of the cat GUI is also 1.
  • I experimented with setting the main GUI Z order to 0, and that didn't have any effect.
  • I tried resetting the buttons using the UpdateButtons() method. I checked that the cc1 and cc2 variables were populated with the right data from the cc_char array. Sure enough, cc1 is populated with my main character's correct ID, and .Visible is marked as "true."
  • Calling UpdateButtons(cc1) had no effect on finding my seemingly missing switch character button
  • I thought maybe I needed to remove the button and then call it again -- i played around with calling UpdateButtons(null) before calling UpdateButtons(cc1), and still no dice.




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!!!

alphawolf300

  • Teenie Tentakel
  • ****
  • Beiträge: 301
    • Profil anzeigen
    • E-Mail
Re: Switching to a custom GUI when selecting a certain character
« Antwort #5 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.

lizhustedt

  • Tentakelschleim
  • *
  • Beiträge: 6
    • Profil anzeigen
    • E-Mail
Re: Switching to a custom GUI when selecting a certain character
« Antwort #6 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:



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!

lizhustedt

  • Tentakelschleim
  • *
  • Beiträge: 6
    • Profil anzeigen
    • E-Mail
Re: Switching to a custom GUI when selecting a certain character
« Antwort #7 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:



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.

lizhustedt

  • Tentakelschleim
  • *
  • Beiträge: 6
    • Profil anzeigen
    • E-Mail
Re: Switching to a custom GUI when selecting a certain character
« Antwort #8 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!



Time to clean up my code, but again, thanks for your help!

alphawolf300

  • Teenie Tentakel
  • ****
  • Beiträge: 301
    • Profil anzeigen
    • E-Mail
Re: Switching to a custom GUI when selecting a certain character
« Antwort #9 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.