How to "activate a textbox"?

Started by TheMagician, Sun 13/11/2005 13:01:10

Previous topic - Next topic

TheMagician

Hi everybody!

Well, I couldn't find anything in the manual about this so I'm going to ask.

If you create a new textbox for your GUI you can set some options in the little floating window in the editor, such as "Font Color" and "Background Color".
The last item in that list is called "Activate" and you can specify a function which should be run when "the textbox is activated".

Can you please tell me when or how this function gets run? What does the user have to do to trigger the "activation of the textbox"?
A simple click on the textbox doesn't seem to work.

Thanks in advance,
Stefan

Pumaman

Pressing Return will activate it.

TheMagician

#2
Thanks for the answer CJ!

===Possible bug report===

I think I found a little bug with this feature.
When it asked for the name of the function I put in:

txtSaveGameDescription_Activate

However, this seemed to be too long so when I opened the window again it had cropped it to

txtSaveGameDescription_Activat

Well, so I called my section in the global script accordingly:

#sectionstart txtSaveGameDescription_Activat 
function txtSaveGameDescription_Activat(GUIControl *control) {
  gSave.Visible = false;
}
#sectionend txtSaveGameDescription_Activat 

However, the function doesn't get run. Or did I do something wrong?
===============

And one more question:

I want to close the GUI when the player clicks on the textbox.
Here is the code in my module:

function on_mouse_click(MouseButton button) { 
   if (button == eMouseLeft) {   
      GUIControl *savecontrol = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
      if (savecontrol == txtSaveGameDescription) {  // if the cursor is over the textbox
         gSave.Visible = false;
      }
   }
}

Well, it doesn't work.
Perhaps you could help me again?

monkey0506

on_mouse_click isn't called when you click on a GUI.  You have to define the GUI_Click function for that (or use the deprecated interface_click).  I think it describes it in the manual, but I don't have time ATM to look it up.

TheMagician

#4
Thanks for the information, monkey!

The old interface_click function can only register clicks on buttons.
And I don't find any information about the GUI_Click function in the manual.

So I still don't know how to trigger a function when the player clicks on a textbox  :'(

Ashen

#5
GUI_Click is like the individual control functions, but works for a whole GUI. However, I don't think it's called when a control on the GUI is clicked, so it probably isn't what you need.

You could try using on_event, and eEventGUIMouseUp/Down. E.g.:

Code: ags

function on_event(EventType event, int data) {
  if (event == eEventGUIMouseUp) {// react when button is released.
    if (GUIControl.GetAtScreenXY(mouse.x, mouse.y) == txtBox) Display("You clicked a textbox!"); // where 'txtBox' is the script name of your textbox
  }
}


You could also, if you want/need to, add a check to make it only work if the left button was used.
I know what you're thinking ... Don't think that.

Pumaman

Woops you're right, there's a truncation bug in the editor.

It looks like it's truncated to 30 characters ("txtSaveGameDescription_Activat") but actually when you save the game it truncates it to 29 ("txtSaveGameDescription_Activa") so the handler becomes un-linked.

Sorry about that. Go into your global script and remove the "t" from the end of the function name, and you should find it starts working.

I'll get it fixed.

TheMagician

@Ashen:
Now it works perfectly. Thanks a lot!

@Pumaman:
Glad I could help  ;)

SMF spam blocked by CleanTalk