Alternative to Properties for UI elements

Started by Babar, Sun 02/09/2018 20:44:55

Previous topic - Next topic

Babar

Hey! I'm trying to come up with an optimal verbcoin (you can see the background in this thread here), but I've run into some hiccups, so I figured I'd get some help here. It's not exactly scripting help questions as much as procedure advice :D. Keep in mind, I'm trying to create a generalised solution that at most requires users need to add some of their own text or properties at a later time if they want to make changes to the verbs, but don't have to go into adjusting hardcoded numbers each time.

Code: ags
function bLook_OnClick(GUIControl *control, MouseButton button)
{
  gVerbCoin.Visible=false;
  if (button==eMouseLeft) Room.ProcessClick(verbCoinX, verbCoinY, eModeLookat);
  
}

That's the code for the OnClick of one of the buttons that pop up on my verbcoin UI. Every button's function is very similar, the only difference is the eMode... at the end. I could make a single function that just changed the last line of each, but I can't think of a generalised way to handle this. The function itself has the GUIControl as a parameter, so I can identify which verbcoin button was pressed, but there doesn't seem to be a useful way to use that. I had initially thought that everything (including UI elements) had Properties, so I would have used those, but apparently they do not.
As a related problem, I wanted to add action texts connected to each verb. So if the player moves the mouse over a blue cup, the text "Blue Cup" would appear at the bottom. When the player clicks the blue cup, this opens the verbcoin, and what I'd like is that when mousing over the LOOK button, "Look at" would be added to the text to change it to "Look at Blue Cup". I was assuming each text would be connected somehow to the verb.

So what I can think of right now for all this is to either use GUIControl.ID and/or create enums and strings for all the different possible verbs, but that really isn't a generalised solution, and would require a user in the future to add to it/remove from it themselves themselves if they ever wanted to make some changes. Is there a better, more generalised way?
The ultimate Professional Amateur

Now, with his very own game: Alien Time Zone

artium

#1
Regarding the first question.

The connection between the button and the mode is established when you register the verb. It is stored inside VerbCoin.

Therefore, you can add a lookup function to the VerbCoin and call that function from bLook_OnClick.

Assuming you base your work on the template coin verb:

Code: ags

static function VerbCoin::GetModeByControl(GUIControl* control) {
  
  if (control.OwningGUI == interface && control.Visible) {
   
    return modemap[control.ID];
  
  } else {
  
    return eModePointer
  
  }
  
}

Babar

Quote from: artium on Mon 03/09/2018 20:51:05
Regarding the first question.

The connection between the button and the mode is established when you register the verb. It is stored inside VerbCoin.

Therefore, you can add a lookup function to the VerbCoin and call that function from bLook_OnClick.

Assuming you base your work on the template coin verb:
I was very confused until I saw your edit :grin:. But no, I'm not using the template verbcoin. I'll look it up to see how it handles the issue, though.
The ultimate Professional Amateur

Now, with his very own game: Alien Time Zone


SMF spam blocked by CleanTalk