HeroEngine Forums
Welcome, Guest. Please login or Register for HeroCloud Account.

Author Topic: [Resolved] gui, class script vs normal script  (Read 3146 times)

Gothrek

  • General Accounts
  • *
  • Posts: 92
    • View Profile
[Resolved] gui, class script vs normal script
« on: Dec 22, 11, 06:37:45 AM »

Hi,
i m a bit confused about this:

i do a new gui window (skillsmanagerwindow)
i do a script (normal) with a public function for open this window
Code: [Select]
public function makeSkillsManagerWindow()
  mySkillsManagerWindow as NodeRef of Class GUIControl = createNodeFromPrototype("RoC_SkillsManagerWindow")
  // Make the new window renderable in the screen
  mySkillsManagerWindow.build = true
  // Configure the window's position in the viewport
  screen as Vector3 = getViewPortSize()
  mySkillsManagerWindow.position.x = (screen.x - mySkillsManagerWindow.size.x) / 2
  mySkillsManagerWindow.position.y = (screen.y - mySkillsManagerWindow.size.y) / 2

i change the keybind file for use CTRL-S in the input_Command script and call the public function
Code: [Select]
function onCmdStop(cmd as String) as Boolean
  when cmd
    is "PlayMode"
      $PLAYMODE._togglePlayModeState()
    .
    is "SkillsManager"
     RoC_SkillsManagerWindow:makeSkillsManagerWindow()
its all ok and when i push CTRL-S i can see the window

now the q,
if i try to use the class methods like onbuttonmouseclick etc i have the error that i cannot use this methods if the script is not a class script.

also i create a class script calle RoC_skillsManagerWindow but how can i use it when i open my skillmanagerwindow with CTRL-S?

tks for explain 
« Last Edit: Nov 01, 12, 02:40:38 PM by HE-Cooper »
Logged

FI-ScottZ

  • General Accounts
  • *
  • Posts: 1407
    • View Profile
    • Forever Interactive, Inc.
Re: gui, class script vs normal script
« Reply #1 on: Dec 22, 11, 06:56:04 PM »

Right, you will need a class methods script to handle things like onbuttonmouseclick.  There are a variety of ways to go about it.

One thing about gui control classes is that they must be of archetype "guicontrol" or it will not be compatible with gui controls.  That is something I sometimes forget when in a hurry and it can only be set when the class is created and cannot be changed afterwards.  So if a class was not created as the right archetype, it will need to be deleted and recreated.  

I'd recommend starting by looking at the script _GUIButtonClassMethods.  The OnMouseClick method is called from the engine to various gui controls.  In that you can see that it allows for different ways to pass it on:

1. If the button class has a HE_onButtonClick method, that is all that is called.  That method could be added via inheritance or glomming.

2. If that HE method was not found, it checks the parent and all ancestors upward for the method _onButtonMouseClick().  Those methods can set source == None to stop the call from going farther up.  This approach means a button click can be handled by a parent control, such as the window it is in.

3. Failing that, if the button has a script set and that script defines the shared function onButtonClick(), that gets called.

So, it comes down to either having the button class itself handle the event, or else a parent control can take it, or else a script on the button.  Different strokes for different folks, and some approaches can be better than others for different situations.  Sometimes you might want a parent window to handle the button clicks for all of the buttons that are contained in it.

Setting classes:
When a gui prototype is defined, it must have a class.  That can be inherited from another prototype or defined explicitly.  Even when inheriting from another prototype (which might be done to get the structure of child controls), you can still change the class that will be used.

So, to handle on the button itself, either declare a class that inherits from _GUIButton which will be the class of the prototype, or a standalone class to glom onto a button prototype.  In the case of the glomming class, you could only define the HE_ method (since glommed classes cannot override inherited methods), while for the inheriting class you can define either the HE_ one, or OnMouseClick which would complete replace the one in _GUIButton.  The easiest way to glom onto a control is via the gui editor: select the control and in the glomClass property type the name of the class.

Alternatively, your class could derive from the same parent class as _GUIButton, but then you would probably want to provide definitions for all of the different methods that _GUIButton defines.

For a parent class to handle it, you will need a class for that parent control whose methods script will define _onButtonMouseClick.  That can come from glomming or inheritance.

Or create a script with shared function onButtonClick() in it (the script can be ClassMethods or not) and set that script to the control's script field, also easiest through the gui editor properties panel.

Other gui event callbacks work in similar ways.
« Last Edit: Dec 22, 11, 07:04:46 PM by ScottZarnke »
Logged
Scott Zarnke
Lead Programmer, Visions of Zosimos
CTO, Forever Interactive, Inc.

Gothrek

  • General Accounts
  • *
  • Posts: 92
    • View Profile
Re: gui, class script vs normal script
« Reply #2 on: Dec 22, 11, 11:31:13 PM »

uuuuuhhh, very complete answer, tks a lot.

but maybe i have a newbie Q,

its ok, i have a function in a "normal" script for open my skillsManagerWindow, but the real prob is:
how can associate this window to the skillsManagerWindowClass script?

i need to create a new system node or what? or its a class field when i create a gui prototype...i dont understand

when i create a new PG, the system node "say to me" that these window is "opened" by RoC_characterCreationSystemClass that open the window and "managed" by RoC_characterCreationWindowClass (Why? or better where i can see this?)

i want to do the same with my skillManager window, opened by a script and managed by other class script.
This is my situation:
RoC_skillsManagerWindow (my GUI xml)
RoC_skillsManagerWindow (my system client script for open(create by node) the window)
RoC_skillsManagerWindowClassMethods (my client class for manage the window)

Tks for help.
« Last Edit: Dec 23, 11, 01:14:32 AM by Gothrek »
Logged

TGSRofar

  • General Accounts
  • *
  • Posts: 153
    • View Profile
Re: gui, class script vs normal script
« Reply #3 on: Dec 24, 11, 07:06:28 AM »

The class to use for a GUI is specified in the GUI XML. So the XML should look something like this for your RoC_skillsManagerWindow...

Code: [Select]
<createControlType class='RoC_skillsManagerWindow' type='RoC_skillsManagerWindow' description='' treePath='' name="RoC_skillsManagerWindow"...
Logged
Ron Farrell
Lead Programmer
Triad Game Studios

Gothrek

  • General Accounts
  • *
  • Posts: 92
    • View Profile
Re: gui, class script vs normal script
« Reply #4 on: Dec 27, 11, 12:38:06 AM »

there isnt class part
Code: [Select]
<createControlType inheritFrom='_movePanel' type='RoC_skillsManagerWindow' description='finestra di gestione delle skill' treePath='CleanEngine' name="RoC_skillsManagerWindow" owner="0">
also i can add it manually?
Logged

Gothrek

  • General Accounts
  • *
  • Posts: 92
    • View Profile
Re: gui, class script vs normal script
« Reply #5 on: Dec 27, 11, 12:43:27 AM »

i delete the inherit and the owner and now work


tks a lot now i understand something more.

tks again.
Logged