HeroEngine Forums
Welcome, Guest. Please login or Register for HeroCloud Account.
Pages: [1] 2 3 4

Author Topic: Press "I" to open a gui window  (Read 19097 times)

Jrome90

  • General Accounts
  • *
  • Posts: 330
    • View Profile
Press "I" to open a gui window
« on: Feb 07, 12, 12:06:06 AM »

This is a simple tutorial to show how to open a window after pressing the "I" key.
I assume that you are using the default GameKeyBindings.ini file. If not, that is ok.

Editing the GameKeyBindings file

First we need to open up the GameKeyBindings.ini file. To do that open up the Repository broswer and go to the root folder "HE". Right-click on "GameKeyBindings.ini", and choose open. Save the file to your desktop

Open the file up with notepad, or your preferred text editor.

Under " = Input_Command"
add the following: OpenInventory = I

Save the file, and drag it from the desktop onto the one in the repository browser. Overwrite it.

Next, Create the following GUI XML files:

To Create each GUI XML file, open up the script editor then go to:
File>New>GUI XML
After pasting the following compile, and submit.

TestInvPanel.XML
Code: (xml) [Select]
<createControlType inheritFrom='_panel' type='TestInvPanel' description='Just a temporary inv panel' treePath='CleanEngine' name="TestInvPanel" texture="\GUI\inventory_v3.dds">
  <position x="162.500015259" y="225.000030518"/>
  <size x="63.750007629" y="63.750007629"/>
  <defaultStatePresentation>
    <position x="512.129821777" y="910.518493652"/>
    <size x="99.410667419" y="102.589332581"/>
  </defaultStatePresentation>
</createControlType>

PopUp.XML
Code: (xml) [Select]
<createControlType inheritFrom='_window' class='PopUp' type='PopUp' description='' treePath='CleanEngine' name="PopUp" resizeable="NONE" toggleIPopUp="0">
  <position x="355" y="406"/>
  <size x="213" y="307"/>
  <minimumSize x="213" y="307"/>
  <anchor bottom="true" left="false" right="true"/>
  <set name="PopUp.resizeTop">
    <size x="213" y="7"/>
    <resize top="false"/>
  </set>
  <set name="PopUp.resizeTop.topLeft">
    <size x="7" y="7"/>
  </set>
  <set name="PopUp.resizeTop.topRight">
    <size x="7" y="7"/>
  </set>
  <set name="PopUp.resizeBottom">
    <size x="213" y="7"/>
    <resize bottom="false"/>
  </set>
  <set name="PopUp.resizeBottom.bottomLeft">
    <size x="7" y="7"/>
  </set>
  <set name="PopUp.resizeBottom.bottomRight">
    <size x="7" y="7"/>
  </set>
  <set name="PopUp.resizeLeft">
    <size x="7" y="293"/>
    <resize left="false"/>
  </set>
  <set name="PopUp.resizeRight">
    <size x="7" y="293"/>
    <resize right="false"/>
  </set>
  <set name="PopUp.titlebar">
    <size x="199" y="22"/>
  </set>
  <set name="PopUp.titlebar.borderBottom">
    <size x="199" y="7"/>
  </set>
  <set name='PopUp.titlebar.title' attribute='text' value="PopUp Test"/>
  <set name='PopUp.titlebar.closeButton' attribute='visible' value="false"/>
  <set name='PopUp.titlebar.closeButton' attribute='enabled' value="false"/>
  <set name='PopUp.titlebar.closeButton.buttonImage' attribute='visible' value="false"/>
  <set name='PopUp.titlebar.closeButton.buttonImage' attribute='enabled' value="false"/>
  <set name="PopUp.scrollable.clientarea">
    <_flowLayoutContainer name="_flowLayoutContainer" dockMode="FILL" HGap="3" VGap="3"/>
  </set>
</createControlType>
Next create a field on the client side named "toggleIPopUp"

Name: toggleIPopUp
Description: Toggle the window
Type: noderef
Everything else is default

On the client side, create the Class "IPopUp"
ArcheType: data
Add the field "toggleIPopUp" to the newly created class.

For the ClassMethods Script
Type the following:
Code: (hsl) [Select]
Method IOpen()
  if me.toggleIPopUp = None
      popUp as NodeRef of Class  GUIControl = CreateNodeFromPrototype("PopUp")
      popUp.build = true
      me.toggleIPopUp = popUp
    else
      DestroyNode(me.toggleIPopUp)
      me.toggleIPopUp = None
     .
.


Next, create a new class named "PopUp"
ArcheType: guicontrol
Add the Parent Class: _GUIBaseWindow

Create the ClassMethods script
Type the following:
Code: (hsl) [Select]
method OnControlBuild()
 viewPort as Vector3 = GetViewPortSize()
  me.position.x = viewPort.x - 216
  me.position.y = viewPort.y / 2
  flow as NodeRef of Class GUIFlowLayoutContainer = me.Flow()
   
  flow.TopMargin = 0
  flow.BottomMargin = 0
  flow.HorzNearMargin = 0
  flow.HorzFarMargin = 0
  flow.VGap = 3
  flow.HGap = 3
  flow.ReverseRows = false
  flow.AutoLayout = true
  flow.AutoHeight = true
 

  me.CharacterInventory_InitializeSlots()
.

method CharacterInventory_InitializeSlots()
  slots as Integer = 12
  var container = me.Flow()
  clear container.children destroy
 
  slot as NodeRef of Class GUIControl
  loop i from 1 to slots
    slot = me.CharacterInventory_CreateSlot(i)
    add back slot to container.children
  .
.

method CharacterInventory_CreateSlot(slotNumber as Integer) as NodeRef of Class GUIPanel
  slot as NodeRef of Class GUIControl
  slot = CreateNodeFromPrototype("TestInvPanel")
  slot.build = true
  slot.name = "slot" + slotNumber
  return slot
.

method Flow() as NodeRef of Class GUIFlowLayoutContainer
  var flow = FindGUIControlByName(me.getClientarea(),"_flowLayoutContainer")
  return flow
.
Now we need to create a prototype on the client side.

Creating the protoype on the client side

In the console type the following:
Code: [Select]
|CPFC "IPopUp", "Test"*You can name the prototype anything. I named mine Test. Why? I don't know..
Finally, Open up the "Input_Command" script
Under the function onCmdStop(), add:
Code: (hsl) [Select]
is "OpenInventory"
      $Test.IOpen()
    .

Now when you press "I" a window should open, and when you press it again, it should close. (Hopefully it works)
 *The above is only for learning purposes only
« Last Edit: Aug 12, 12, 07:40:20 PM by Jrome90 »
Logged

XCalPro

  • General Accounts
  • *
  • Posts: 105
  • 3D Artist & HSL Coder
    • View Profile
    • Excalibur Productions
Re: Press "I" to open a gui window
« Reply #1 on: Feb 08, 12, 03:31:42 PM »

Worked great thanks.
Logged
Tony Oliveira aka XCalPro
HeroEngine Projects: Traveller 6 Online - www.traveller6.com/forum/
Portfolio: www.xcalpro.com/art

runningbird

  • General Accounts
  • *
  • Posts: 37
    • View Profile
    • Runningbird Studios
Re: Press "I" to open a gui window
« Reply #2 on: Feb 09, 12, 08:20:21 PM »

hmm I've done everything and I get this error in the console

System:SCRIPT[_Input_Command]:Unknown command (OpenInventory) in the COMMAND LAYER

Any ideas?
Logged

XCalPro

  • General Accounts
  • *
  • Posts: 105
  • 3D Artist & HSL Coder
    • View Profile
    • Excalibur Productions
Re: Press "I" to open a gui window
« Reply #3 on: Feb 09, 12, 10:51:34 PM »

Did you add "OpenInventory = I" to you GameKeyBindings.ini file in the right place?
Logged
Tony Oliveira aka XCalPro
HeroEngine Projects: Traveller 6 Online - www.traveller6.com/forum/
Portfolio: www.xcalpro.com/art

runningbird

  • General Accounts
  • *
  • Posts: 37
    • View Profile
    • Runningbird Studios
Re: Press "I" to open a gui window
« Reply #4 on: Feb 10, 12, 04:47:05 PM »

Yes I added it to the right place when I get home I'll past a copy of my GameKeyBindings.ini
EDIT:

[Command] = Input_Command
  PlayMode = CTRL+G
  HotKey1 = 1
  HotKey2 = 2
  HotKey3 = 3
  HotKey4 = 4
  HotKey5 = 5
  Chat = ENTER
  SlashChat = /
  ClearTarget = ESC
  NearestTarget = TAB
  OpenInventory = I
« Last Edit: Feb 10, 12, 11:25:33 PM by runningbird »
Logged

runningbird

  • General Accounts
  • *
  • Posts: 37
    • View Profile
    • Runningbird Studios
Re: Press "I" to open a gui window
« Reply #5 on: Feb 11, 12, 01:57:28 AM »

For some reason I didn't have a E_InputHandler class so I deleted it from my System nodes and just added the command to the _input_command script.

I don't recommend people do this since it's an engine script.
But it works like expected now.

Thanks I just made my news window pop up as well  ;)
Logged

GFG_Ulfrpsion

  • General Accounts
  • *
  • Posts: 40
    • View Profile
Re: Press "I" to open a gui window
« Reply #6 on: Feb 11, 12, 09:39:22 PM »

Has anyone had success with the method in adding a script to the created GUI?

If I follow a method of creating the GUI like so (taken from the way GUI's are created in the E_PlayerAccount script):

Code: [Select]
Method IOpen()
  if me.toggleIPopUp = None
      popUp as NodeRef of Class  E_PopUp = CreateNodeFromPrototype("PopUp")
      popUp.build = true
      me.toggleIPopUp = popUp
    else
      DestroyNode(me.toggleIPopUp)
      me.toggleIPopUp = None
     .
.



Where my class E_PopUp is a class containing the methods of the PopUp, I end up calling a series of errors.

Are there alternatives to this method? I feel like this method would not be good for multiple GUIs as you'll be creating a ton of root nodes for each GUI and registering lightweight methods on every build just so it can catch events from the player? Perhaps I am not understanding this, but I feel like a better alternative is to store the GUIs with the other Game-specific GUI's in E_PlayerAccountClassMethods, I am just not sure how you'd go about?

I'm guessing rather than create a root node for the GUI, you will want to build the GUI in the player account methods and place it on it's own layer and call $GUI with some method to toggle the layer the GUI is on when the command is pressed.
Logged

elchettoloco

  • General Accounts
  • *
  • Posts: 21
    • View Profile
Re: Press "I" to open a gui window
« Reply #7 on: Feb 17, 12, 08:35:10 PM »

Excellent.  Worked perfectly! 

Thanks Jrome!  ;D
Logged

Jrome90

  • General Accounts
  • *
  • Posts: 330
    • View Profile
Re: Press "I" to open a gui window
« Reply #8 on: Feb 17, 12, 11:12:49 PM »

Excellent.  Worked perfectly! 

Thanks Jrome!

Glad you got it working.
Logged

mixxit

  • General Accounts
  • *
  • Posts: 25
    • View Profile
Re: Press "I" to open a gui window
« Reply #9 on: Mar 07, 12, 11:19:05 AM »

What do you mean add xml file? Do you mean in GUI XML in organizer?

found it, guixml folder in the repository!
« Last Edit: Mar 07, 12, 11:43:23 AM by mixxit »
Logged

mixxit

  • General Accounts
  • *
  • Posts: 25
    • View Profile
Re: Press "I" to open a gui window
« Reply #10 on: Mar 07, 12, 04:22:50 PM »

Code: [Select]
22:21:35: !ERROR!HeroScript::HeroMachine::ScriptError:Exception DefinitionNotFoundException in function 'createNodeFromPrototype' definition not found: PopUp
22:21:35: !ERROR!System:SCRIPT ERROR: Exception DefinitionNotFoundException in function 'createNodeFromPrototype' definition not found: PopUp
03/07/2012 22:21:28
Call trace:
  Script InvPopUpClassMethods line 3 me[id=1000000278 class=InvPopUp]
  Script Input_Command line 8 me[9223372055763131540]
starting method/function ONCMDSTOP
starting me[id=9223372055763131540 class=E_playerAccount,HBNode,CharacterNode,_ACCControllerOwner]

For some reason it can't find the popup - i think it's looking for a prototype but I can't see this guide creating a PopUp prototype

Any ideas?
Logged

mixxit

  • General Accounts
  • *
  • Posts: 25
    • View Profile
Re: Press "I" to open a gui window
« Reply #11 on: Mar 07, 12, 04:26:14 PM »

I created a prototype PopUp from the class PopUp but the error is still there about no defined prototype

Code: [Select]
|CPFC "PopUp", "PopUp"
Logged

mixxit

  • General Accounts
  • *
  • Posts: 25
    • View Profile
Re: Press "I" to open a gui window
« Reply #12 on: Mar 07, 12, 04:28:35 PM »

Looks like that error has gone away now that I see this has happened in the console

Quote
22:25:30: SYSTEM:System:GOM updated from repository

Guess I was impatient
Logged

mixxit

  • General Accounts
  • *
  • Posts: 25
    • View Profile
Re: Press "I" to open a gui window
« Reply #13 on: Mar 07, 12, 04:31:34 PM »

Now I have a new error

Code: [Select]
22:27:34: SYSTEM:System:{NONE} ERROR 0 : "Parser Error: unknown command"
22:27:39: !ERROR!HeroScript::HeroMachine::ScriptError:GOM::getVariableReferenceFromNode (10757): requested node ID (0) not found
22:27:39: !ERROR!System:SCRIPT ERROR: GOM::getVariableReferenceFromNode (10757): requested node ID (0) not found
03/07/2012 22:27:32
Call trace:
  Script PopUpClassMethods line 7 me[1000000303]
starting method/function ONCONTROLBUILD
starting me[id=1000000303 class=PopUp]
22:27:49: Refreshing clientScriptOrganizer.
22:30:17: Refreshing guiXMLOrganizer.
22:30:17: Adding missing GUIXML controls to organizer
22:30:17: Finished adding missing GUIXML controls to organizer

Line 7 is

Code: [Select]
  flow.TopMargin = 0
Would that mean that flow has no TopMargin? I don't understand why this is so complicated
Logged

mixxit

  • General Accounts
  • *
  • Posts: 25
    • View Profile
Re: Press "I" to open a gui window
« Reply #14 on: Mar 07, 12, 04:47:01 PM »

Ok I think i figured out what happened, because I just dragged the XML files into the repository it didn't seem to create a prototype so I didn't need to actually use cpfc to make the PopUp prootype as the guixml panel should do that for me

To fix this I deleted the xml files, and recreated them using the GUI XML panel and that seemed to make the necessary prototypes that the other code was searching for

Maybe you could edit this tutorial a bit and explain the process for your tutorial line:

Quote
Next, Create the following GUI XML files
« Last Edit: Mar 07, 12, 04:48:43 PM by mixxit »
Logged
Pages: [1] 2 3 4