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

Author Topic: Basic Exit game window  (Read 5536 times)

Thazager

  • General Accounts
  • *
  • Posts: 1160
  • Never stop learning
    • View Profile
Basic Exit game window
« on: Oct 05, 13, 07:33:59 PM »

This will pop a window exiting options when the escape key is pressed. It has 2 buttons - (exit game) and (log to select screen) on the menu. It makes a basic button. It adds a line to the keybindings.ini  file in the repository.

Download the GameKeyBindings.ini file from the repository.
below
      [Command] = Input_Command
add
      exitMenu = ESC

make sure no other command is using the ESC key.  If it is, change 1 of the keys to another value. (only the last command set to ESC will use that key)
Upload the GameKeyBindings.ini file to the repository, in the same place you found it. (the main HE directory)

__________________________________________________________________
From the basic window tutorial
Make basic window here. This is a base window and will be used in many of my Tutorials. It uses the GUI pics from textures that all engines have. This can be skipped if you have the basic window already from another tutorial.

Make basic button here. This will also be used in many of my tutorials.

_________________________________________________________________________
In the DOM, create a new (client side) class
name = tmp_exitWarning
archtype = guicontrol
add a parent to the class, TMP_Window

click open script

In new (client side) script tmp_exitWarning

Code: [Select]
// make window for warning
shared function Start()
  var win = getExitWarningClass()
  if win <> None
    DestroyNode( win )
  .
  win = CreateNodeFromPrototype("tmp_exitWarning")
  win.build = true
  MiscUtils:centerWindow(win)
.

// which button chosen
method onMouseClick(args references Class GUIMouseEvent)
  target as NodeRef of Class GUIControl = args.source
  when target.name
    is "YesButton"
      $BASECLIENT._Exit()
    .
    is "NoButton"
      var win = getLogoutClass()
      win.closeLogoutWindow()
    .
  .
.

//=========================================================================================================
// classes needed by this script
//=========================================================================================================
// get class window - this
function getExitWarningClass() as NodeRef of Class tmp_exitWarning
  return FindGUIControlByName(None, "game.tmp_exitWarning")
.

// get class window - main
function getLogoutClass() as NodeRef of Class tmp_logoutWindow
  return FindGUIControlByName(None, "game.tmp_logoutWindow")
.

_________________________________________________________________________
In new (XML) script tmp_exitWarning

Code: [Select]
<createControlType inheritFrom='TMP_Window' class='tmp_exitWarning' type='tmp_exitWarning' description='' treePath='' name="tmp_exitWarning">
  <size x="300" y="100"/>
  <defaultStatePresentation>
    <color r="0" g="0" b="0"/>
  </defaultStatePresentation>
  <set name="tmp_exitWarning.BGpanel">
    <size x="292" y="92"/>
  </set>
  <_label name="warning" text="Do you want to quit?" displayfont="LARGETEXT" justification="CENTER">
    <position y="20"/>
    <size x="300" y="30"/>
    <defaultStatePresentation>
      <color r="0" g="1" b="0"/>
    </defaultStatePresentation>
  </_label>
  <tmp_button name="YesButton">
    <position x="60" y="60"/>
    <size x="60"/>
    <set name='tmp_exitWarning.YesButton.text' attribute='text' value="Exit"/>
  </tmp_button>
  <tmp_button name="NoButton">
    <position x="160" y="60"/>
    <size x="60"/>
    <set name='tmp_exitWarning.NoButton.text' attribute='text' value="Cancel"/>
  </tmp_button>
</createControlType>

_________________________________________________________________________
In the DOM, create a new (client side) class
name = tmp_logWarning
archtype = guicontrol
add a parent to the class, TMP_Window

click open script

In new (client side) script tmp_logWarning

Code: [Select]
// make window for warning
shared function Start()
  var win = getLogWarningClass()
  if win <> None
    DestroyNode( win )
  .
  win = CreateNodeFromPrototype("TMP_logWarning")
  win.build = true
  MiscUtils:centerWindow(win)
.

// which button chosen
method onMouseClick(args references Class GUIMouseEvent)
  target as NodeRef of Class GUIControl = args.source
  when target.name
    is "YesButton"
      var win = getLogoutClass()
      win.gotoSelectionScreen()
    .
    is "NoButton"
      var win = getLogoutClass()
      win.closeLogoutWindow()
    .
  .
.
 
//=========================================================================================================
// classes needed by this script
//=========================================================================================================
// get class window - this
function getLogWarningClass() as NodeRef of Class tmp_logWarning
  return FindGUIControlByName(None, "game.tmp_logWarning")
.

// get class window - main
function getLogoutClass() as NodeRef of Class tmp_logoutWindow
  return FindGUIControlByName(None, "game.tmp_logoutWindow")
.

_________________________________________________________________________
In new (XML) script tmp_logWarning

Code: [Select]
<createControlType inheritFrom='TMP_Window' class='tmp_logWarning' type='tmp_logWarning' description='' treePath='' name="tmp_logWarning">
  <size x="300" y="100"/>
  <defaultStatePresentation>
    <color r="0" g="0" b="0"/>
  </defaultStatePresentation>
  <set name="tmp_logWarning.BGpanel">
    <size x="292" y="92"/>
  </set>
  <_label name="warning" text="Logging out so soon?" displayfont="LARGETEXT" justification="CENTER">
    <position y="20"/>
    <size x="300" y="30"/>
    <defaultStatePresentation>
      <color r="0" g="1" b="0"/>
    </defaultStatePresentation>
  </_label>
  <tmp_button name="YesButton">
    <position x="60" y="60"/>
    <size x="60"/>
    <set name='tmp_logWarning.YesButton.text' attribute='text' value="Log out"/>
  </tmp_button>
  <tmp_button name="NoButton">
    <position x="180" y="60"/>
    <size x="60"/>
    <set name='tmp_logWarning.NoButton.text' attribute='text' value="Cancel"/>
  </tmp_button>
</createControlType>

__________________________________________________________________
In the DOM, create a new (client side) class
name = tmp_logoutWindow
archtype = guicontrol
add a parent to the class, TMP_Window

click open script

In new (client side) script tmp_logoutWindow
// compile this script after above 2

Code: [Select]
// toggle exit window
shared function Start()
  var win = getLogoutClass()
  if win <> None
    DestroyNode(win)
  .
  win = CreateNodeFromPrototype( "tmp_logoutWindow" )
  win.build = true
  MiscUtils:centerWindow(win)
.

// toggle window on and off
public function ToggleLogoutWindow()
  var win = getLogoutClass()
  if win <> None
    destroynode(win)       // remove it
  else
    start()
  .
.

// remove the logout window
method closeLogoutWindow()
  var win = getLogoutClass()
  if win <> None
    DestroyNode(win)
  .
  var log = getLogWarningClass()
  if log <> None
    DestroyNode(log)
  .
  var exit = getExitWarningClass()
  if exit <> None
    DestroyNode(exit)
  .
.

// which button chosen
method onMouseClick(args references Class GUIMouseEvent)
  target as NodeRef of Class GUIControl = args.source
  when target.name
    is "exitButton"
      tmp_exitWarningClassMethods:Start()
    .
    is "logoutButton"
      tmp_logWarningClassMethods:Start()
    .
  .
.

// go back to selection area
method gotoSelectionScreen()
  out as Class RemoteCallServerOut
  out.toScript = "_TravelDataClassMethods"
  out.toFunction = "UntrustedChangeAreaRequest"
  out.args["area"] = 1
  out.args["instance"] = 1
  RemoteCallServer(out)
.

//=========================================================================================================
// classes needed by this script
//=========================================================================================================
// get class window - this main
function getLogoutClass() as NodeRef of Class tmp_logoutWindow
  return FindGUIControlByName(None, "game.tmp_logoutWindow")
.

// get class window - logout
function getLogWarningClass() as NodeRef of Class tmp_logWarning
  return FindGUIControlByName(None, "game.tmp_logWarning")
.

// get class window - exit
function getExitWarningClass() as NodeRef of Class tmp_exitWarning
  return FindGUIControlByName(None, "game.tmp_exitWarning")
.

In new (XML) script tmp_logoutWindow

Code: [Select]
<createControlType inheritFrom='TMP_Window' class='tmp_logoutWindow' type='tmp_logoutWindow' description='' treePath='' name="tmp_logoutWindow">
  <size x="200" y="200"/>
  <defaultStatePresentation>
    <color r="0" g="0" b="0"/>
  </defaultStatePresentation>
  <set name="tmp_logoutWindow.BGpanel">
    <size x="192" y="192"/>
  </set>
  <_label name="title" dockMode="TOP" text="Main Menu" displayfont="LARGETEXT" dropShadowAlpha="1" justification="CENTER">
    <size x="160" y="30"/>
    <defaultStatePresentation>
      <color r="1" g="0" b="0"/>
    </defaultStatePresentation>
  </_label>
  <tmp_button name="logoutButton">
    <position x="20" y="110"/>
    <size x="160" y="35"/>
    <set name='tmp_logoutWindow.logoutButton.text' attribute='text' value="Log Out"/>
    <set name='tmp_logoutWindow.logoutButton.text' attribute='displayfont' value="LARGETEXT"/>
  </tmp_button>
  <tmp_button name="exitButton">
    <position x="20" y="150"/>
    <size x="160" y="35"/>
    <set name='tmp_logoutWindow.exitButton.text' attribute='text' value="Exit"/>
    <set name='tmp_logoutWindow.exitButton.text' attribute='displayfont' value="LARGETEXT"/>
  </tmp_button>
</createControlType>

_________________________________________________________________________
In the (client side) script Input_Command  in

            function onCmdStop(cmd as String) as Boolean

under

         when cmd

add

Code: [Select]
    is "exitMenu"
      tmp_logoutWindowClassMethods:ToggleLogoutWindow()
    .
« Last Edit: May 31, 15, 01:12:03 AM by Thazager »
Logged
Lead scripter for EO, Repop helper.
HSL Video tutorials:
https://community.heroengine.com/forums/index.php/topic,1719.msg36858.html#msg3685

AlderonGames

  • World Owners
  • ****
  • Posts: 20
    • View Profile
Re: Basic Exit game window
« Reply #1 on: Oct 25, 13, 06:17:56 AM »

Thanks for this tutorial, works perfectly.  :)
Logged

HistoriaOnline

  • World Owners
  • ****
  • Posts: 26
  • Aspiring MMO Creator
    • View Profile
Re: Basic Exit game window
« Reply #2 on: Nov 09, 13, 09:55:51 AM »

Guys how come I cant compile the classes? he cant find the functions from the XML file.
I did write down the xml files, compiled and submitted them, but the according classes dont compile, what am i missing?

Thanks in advance.
Logged

Thazager

  • General Accounts
  • *
  • Posts: 1160
  • Never stop learning
    • View Profile
Re: Basic Exit game window
« Reply #3 on: Nov 09, 13, 05:51:18 PM »

Clarifying some terms.

Classes are created/defined in the DOM, and are a group of fields that work together.  http://hewiki.heroengine.com/wiki/Classes
Scripts are the files we open, read through and modify, which can also use copy/paste.

Briefly, to make this work:

Need to change the keybindings file.
Create 3 new client side classes, 3 new scripts for them, and 3 new XML files.
     TMP_LogoutWindow
     TMP_exitWarning
     TMP_logWarning

Then link them in the client side Input_Command script.
« Last Edit: May 31, 15, 01:13:06 AM by Thazager »
Logged
Lead scripter for EO, Repop helper.
HSL Video tutorials:
https://community.heroengine.com/forums/index.php/topic,1719.msg36858.html#msg3685

HistoriaOnline

  • World Owners
  • ****
  • Posts: 26
  • Aspiring MMO Creator
    • View Profile
Re: Basic Exit game window
« Reply #4 on: Nov 10, 13, 05:11:11 AM »

I understand that, I did make the DOM classes and the fields accordingly, on top of that I did make the XML scripts.
But for example, the TMP_logoutWindow class method "makeExitWindow" attempts to use class type "TMP_exitWarning" but the compiler cant find it.
I see that TMP_exitWarning is defined in the XML file, but the compiler is still blind to it, I get these errors:

(TMP_exitWarning) "Class not found in DataBase" 
(FindGUIControlByName)  "Cannot copy that type - yet"
Logged

Thazager

  • General Accounts
  • *
  • Posts: 1160
  • Never stop learning
    • View Profile
Re: Basic Exit game window
« Reply #5 on: Nov 10, 13, 05:02:49 PM »

fixed.
« Last Edit: May 31, 15, 01:13:54 AM by Thazager »
Logged
Lead scripter for EO, Repop helper.
HSL Video tutorials:
https://community.heroengine.com/forums/index.php/topic,1719.msg36858.html#msg3685

PN-Dwight

  • General Accounts
  • *
  • Posts: 465
    • View Profile
    • Pirates' Nest
Re: Basic Exit game window
« Reply #6 on: Nov 25, 13, 12:58:31 PM »

Reading through the class methods, Tazagar still left a few errors in there...

For example:

Code: [Select]
win as NodeRef of Class TMP_exitWarning = FindGUIControlByName(None, "game.TMP_exitWarning")

should be:

Code: [Select]
win as NodeRef of Class TMP_exitWindow = FindGUIControlByName(None, "game.TMP_exitWarning")

You cannot reference TMP_exitWarning as it is not a class. Fixing that fixes your issues, I believe :)

Thazager

  • General Accounts
  • *
  • Posts: 1160
  • Never stop learning
    • View Profile
Re: Basic Exit game window
« Reply #7 on: Nov 25, 13, 06:14:40 PM »

Quote
TMP_exitWarning as it is not a class.

Thanks. I added the corrections in.

It should be TMP_exitWarning and TMP_logWarning rather then "Window"
« Last Edit: Aug 27, 14, 06:48:30 PM by Thazager »
Logged
Lead scripter for EO, Repop helper.
HSL Video tutorials:
https://community.heroengine.com/forums/index.php/topic,1719.msg36858.html#msg3685

xSystems

  • World Owners
  • ****
  • Posts: 18
    • View Profile
Re: Basic Exit game window
« Reply #8 on: Mar 20, 14, 04:05:03 PM »

When i press ESC aigain there is a new Window.... and again again .... then i have 10 Win open.

And the Buttons in the Win after click logout isnt correct... what can i do?
Logged

Thazager

  • General Accounts
  • *
  • Posts: 1160
  • Never stop learning
    • View Profile
Re: Basic Exit game window
« Reply #9 on: Mar 20, 14, 06:38:32 PM »

I modified the GUI code to match the Script code.
« Last Edit: Jun 01, 15, 03:07:10 PM by Thazager »
Logged
Lead scripter for EO, Repop helper.
HSL Video tutorials:
https://community.heroengine.com/forums/index.php/topic,1719.msg36858.html#msg3685

xSystems

  • World Owners
  • ****
  • Posts: 18
    • View Profile
Re: Basic Exit game window
« Reply #10 on: Mar 21, 14, 05:30:12 AM »

No its there, thats why i dont understand :/

Ok i found the error....

When i use this:
Code: [Select]
win as NodeRef of Class TMP_LogoutWindow = FindGUIControlByName(None, "game.TMP_LogoutWindow" )
it doesnt work... i have to use this:
Code: [Select]
  win as NodeRef of Class TMP_LogoutWindow = FindGUIControlByName(None, "TMP_LogoutWindow" )
« Last Edit: Mar 21, 14, 06:01:24 AM by xSystems »
Logged

Thazager

  • General Accounts
  • *
  • Posts: 1160
  • Never stop learning
    • View Profile
Re: Basic Exit game window
« Reply #11 on: Mar 21, 14, 11:44:34 AM »

The difference is that game is not set for your layer property on the main GUI. If you like, you can add it. This will allow the window to fade with the rest of the HUD GUIs, when you push control g. Control g is a built in toggle that removes the screen GUIs, if they are on the game layer.
Logged
Lead scripter for EO, Repop helper.
HSL Video tutorials:
https://community.heroengine.com/forums/index.php/topic,1719.msg36858.html#msg3685

xSystems

  • World Owners
  • ****
  • Posts: 18
    • View Profile
Re: Basic Exit game window
« Reply #12 on: Mar 21, 14, 11:57:02 AM »

But when i use it with "game." then i cant close when i press ESC again, i become a new Window...
Logged

Thazager

  • General Accounts
  • *
  • Posts: 1160
  • Never stop learning
    • View Profile
Re: Basic Exit game window
« Reply #13 on: Mar 21, 14, 07:13:12 PM »

There are 2 things that need to be set, if you want to use the "game" part. The 1st is in code, the 2nd is in the actual GUI. To set the GUI part, right after opening the GUI in the editor, the main part will be the one name you can see in the GUI editor on the top line. Its the parent of the whole GUI, TMP_LogoutWindow. In the properties panel, there is a field called layer. Setting that to "game", will link it with the code, if you use it.
Logged
Lead scripter for EO, Repop helper.
HSL Video tutorials:
https://community.heroengine.com/forums/index.php/topic,1719.msg36858.html#msg3685