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

Author Topic: changing Keybinds basic  (Read 2707 times)

Thazager

  • General Accounts
  • *
  • Posts: 1160
  • Never stop learning
    • View Profile
changing Keybinds basic
« on: Jun 30, 14, 05:46:00 PM »

Semi Advanced Tutorial

This tutorial displays a key bind list in a scrollable client window that can be added to the Option Window tutorial, with some coding work. It also works without the options window. It uses the basic key binds set up in the base E_ scripts, and adds the esc menu tutorial window. The list at top in the script is a data list, easily modifiable. Most of the movement keys have 2 key binds for them, while the commands have 1 key bind. It is setup as a window like the chat window, and to toggle it you will need to add your code.

In the DOM, create 4 new fields
tmp_KeyChoice    type = string
tmp_KeyCommand      type =string
tmp_KeysList      type = list of string
tmp_KeyText      type = string
_____________________________________________________________________________________

In the DOM, create 2 new classes
TMP_OptionKeyboard
archtype = guicontrol

add a parent, _GUIBaseWindow
add the 4 fields above to this class
_____________________________________________________________________________________

TMP_button
archtype = guicontrol

add a parent,  _GUIButton
_____________________________________________________________________________________

Create new xml file  TMP_button

Code: [Select]
<createControlType class='TMP_button' type='TMP_button' description='' treePath='' name="TMP_button" texture="\GUI\aaron_test_textures.dds" textureFilter="false">
  <size x="100" y="20"/>
  <minimumSize x="60" y="20"/>
  <maximumSize x="200" y="20"/>
  <defaultStatePresentation>
    <position x="175" y="123"/>
    <size x="98" y="24"/>
  </defaultStatePresentation>
  <hoverStatePresentation>
    <color r="0.5" g="0.800000012"/>
    <position x="175" y="123"/>
    <size x="98" y="24"/>
  </hoverStatePresentation>
  <selectedHoverStatePresentation>
    <color r="0" g="0" b="0" a="0"/>
    <size x="0" y="0"/>
  </selectedHoverStatePresentation>
  <_label name="text" dockMode="FILL" text="name" justification="CENTER">
    <defaultStatePresentation>
      <color r="0" g="1" b="0"/>
    </defaultStatePresentation>
    <hoverStatePresentation>
      <color g="0" b="0"/>
    </hoverStatePresentation>
  </_label>
</createControlType>
_____________________________________________________________________________________

Create new xml file  TMP_OptionKeyboard

Code: [Select]
<createControlType class='TMP_OptionKeyboard' type='TMP_OptionKeyboard' description='' treePath='' name="TMP_OptionKeyboard" textureFilter="false" layer="game" resizeable="ALL" scrollable="VERTICAL">
  <size x="400" y="400"/>
  <maximumSize x="2048" y="2048"/>
  <defaultStatePresentation>
    <color r="0" g="0" b="0" a="0.5"/>
  </defaultStatePresentation>
  <hoverStatePresentation>
    <color r="0" g="0" b="0" a="0.5"/>
  </hoverStatePresentation>
  <selectedHoverStatePresentation>
    <color r="0" g="0" b="0" a="0"/>
    <size x="0" y="0"/>
  </selectedHoverStatePresentation>
  <_scrollableParent name="scrollable">
    <set name="TMP_OptionKeyboard.scrollable.clientarea">
      <defaultStatePresentation>
        <color r="1" g="1" b="1" a="0"/>
      </defaultStatePresentation>
    </set>
  </_scrollableParent>
</createControlType>
_____________________________________________________________________________________

Create new xml file  TMP_KeyWindow

Code: [Select]
<createControlType inheritFrom='_panel' type='TMP_KeyWindow' description='' treePath='CleanEngine' name="TMP_KeyWindow">
  <size x="160" y="60"/>
  <defaultStatePresentation>
    <color r="0" g="0" b="0" a="0.5"/>
  </defaultStatePresentation>
  <_label name="text" dockMode="FILL" text="Replace">
    <size x="160" y="60"/>
    <defaultStatePresentation>
      <color r="0" g="1" b="0"/>
    </defaultStatePresentation>
  </_label>
</createControlType>
_____________________________________________________________________________________

Create new xml file  TMP_KeyBindPanel

Code: [Select]
<createControlType inheritFrom='_panel' type='TMP_KeyBindPanel' description='' treePath='CleanEngine' name="TMP_KeyBindPanel">
  <size x="360" y="20"/>
  <defaultStatePresentation>
    <color a="0"/>
  </defaultStatePresentation>
  <_label name="command" text="name" dropShadowAlpha="1" justification="CENTER">
    <defaultStatePresentation>
      <color r="0" g="1" b="0"/>
    </defaultStatePresentation>
  </_label>
  <TMP_button name="button1">
    <position x="120"/>
    <set name='TMP_KeyBindPanel.button1.text' attribute='dropShadowAlpha' value="1"/>
  </TMP_button>
  <TMP_button name="button2">
    <position x="240"/>
    <set name='TMP_KeyBindPanel.button2.text' attribute='dropShadowAlpha' value="1"/>
  </TMP_button>
</createControlType>
_____________________________________________________________________________________

In client side script E_PlayerAccountClassMethods

under the code for the chat window add:

        TMP_OptionKeyboardClassMethods:Start()  // can add a toggle where you have other windows toggling

_____________________________________________________________________________________

In client side script E_CharacterCreationWindowClassMethods

in method _OnButtonMouseClick , under the last line of
    is "finished"

add :

      TMP_OptionKeyboardClassMethods:CreateNewKindBindList()    // create new keybind list for new character

« Last Edit: Jun 30, 14, 05:51:45 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

Thazager

  • General Accounts
  • *
  • Posts: 1160
  • Never stop learning
    • View Profile
Re: changing Keybinds basic
« Reply #1 on: Jun 30, 14, 05:47:15 PM »

Create new client side script TMP_OptionKeyboardClassMethods

Code: [Select]

// titles for each section
// title /  amount of groups
// uses / for separator
function getTitleForBinds() as List of String
  dataList as List of String

  data as String = "Movement/10/"
  data = data + "Chat/2/"
  data = data + "Targeting/2/"
  data = data + "Windows/1/"
  data = data + "Hotkeys/5/"

  SplitBy(data,"/",dataList)           // make it an array
  return dataList
.

// amount of titles for keybinds
function getAmountOfTitles() as Integer
  data as Integer = 5 * 2
  return data
.

// amt is the total amount of groups from getNewKeyBinds
function getAmountOfBinds() as Integer
  data as Integer = 20 * 4
  return data
.

// keys and their binds - list
// CMD, key1, key2, layer
// (20 groups of 4)
// uses ; for separator
function getNewKeyBinds() as List of String
  dataList as List of String

// movement - (10 grps of 4)
  data as String = "Forward;W;UP;Movement;"
  data = data + "Backward;S;DOWN;Movement;"
  data = data + "Left;A;LEFT;Movement;"
  data = data + "Right;D;RIGHT;Movement;"
  data = data + "Up;R;HOME;Movement;"
  data = data + "Down;F;END;Movement;"
  data = data + "Rotate Left;Q;__;Movement;"
  data = data + "Rotate Right;E;__;Movement;"
  data = data + "Jump;SPACE;none;Movement;"
  data = data + "AutoForward;BACKSPACE;none;Movement;"

// chat - (2 grps of 4)
  data = data + "Chatting;ENTER;none;Command;"
  data = data + "SlashChat;/;none;Command;"

// enemy target - (2 grps of 4)
  data = data + "Clear Target;ESC;none;Command;"
  data = data + "Nearest Enemy;Tab;none;Command;"

// windows - (1 grps of 4)
  data = data + "exit Menu;ESC;none;Command;" // from tutorial

// hotkeys main bar - (5 grps of 4)
  data = data + "HotKey1;1;none;Command;"
  data = data + "HotKey2;2;none;Command;"
  data = data + "HotKey3;3;none;Command;"
  data = data + "HotKey4;4;none;Command;"
  data = data + "HotKey5;5;none;Command;"

  SplitBy(data,";",dataList)           // make it an array
  return dataList
.

//=============================================================================================================
// get the data that was saved
function LoadKeyBindOptionsFromRepository()
  println( "Making request for options." )
  var reqID3 = LoadLocalRepositoryData( "/keybindoptions/", SYSTEM.EXEC.THISSCRIPT )
  println( "Made keybind request: " + reqID3 + "." )
.

// receive callback from external functions
function RepositoryDataDownloaded( name as String, reqID as ID, successful as Boolean, data as String ) as Boolean
  println( "Got request: " + reqID + "." )
  SetKeyBind( data )
  return false  // indicates that we don't care about future changes to the data
.

// set the value from keys load
// called after window open
function SetKeyBind( data as String )
  var win = getOptionKeyboardClass()
  dataType as List of String
  SplitBy(data, ";", dataType)

  println("loaded data "+data)
  win.tmp_KeysList = dataType
  DisplayKeybinds()
.

// save data in a string
public function SaveKeyBindOptions()
  var win = getOptionKeyboardClass()
  keyVal as List of String = win.tmp_KeysList     // current values for keys

  data as String
  amt as Integer = getAmountOfBinds()

  // save values of list
  loop i from 1 to amt
    data = data + keyVal[i] +";"
  .
//  println("saved data "+data)

  if not( SaveLocalRepositoryData( "/keybindoptions/", SYSTEM.EXEC.THISSCRIPT, data ) )
    ScriptError( "Attempted to save KeyBind options to local repository, but return code was FALSE." )
  . 
.

//=============================================================================================================
// create new list when character is made
public function CreateNewKindBindList()
  Init as List of String = getNewKeyBinds()     // Init the list to our list
  data as String
  amt as Integer = getAmountOfBinds()

  // save values of list
  loop i from 1 to amt
    data = data + Init[i] +";"
  .

  //save data in repo
  if not( SaveLocalRepositoryData( "/keybindoptions/", SYSTEM.EXEC.THISSCRIPT, data ) )
    ScriptError( "Attempted to save KeyBind options to local repository, but return code was FALSE." )
  . 
.

// init all options
public function Start()
  var win = getOptionKeyboardClass()
  if win != None
    DestroyNode( win )
  .
  screen as Vector3 = GetViewPortSize()
  win = CreateNodeFromPrototype( "TMP_OptionKeyboard" )
  win.build = true
  win.owner = 0
  win.position.x = ((screen.x - win.size.x) / 2)  // start centered
  win.position.y = ((screen.y - win.size.y) / 2)

  CaptureKeyInput( None )
  InitKeyBindValues()
.

// called when window created
// loads player saved data
public function InitKeyBindValues()
  var win = getOptionKeyboardClass()
  Init as List of String = getNewKeyBinds()
  win.tmp_KeysList = Init

  // load data
  LoadKeyBindOptionsFromRepository()    // load data when we open window
.

// show current values on screen
function DisplayKeybinds()
  var main = getKeyClientArea()
  posY as Integer = 10

  // clear old values in window
  foreach child in main.children
    destroynode(child)
  .

  setColor as Class rgba = SetKeyTextColor()

  lbl as NodeRef of Class GUILabel
  lbl = createNodeFromPrototype("_label")     // section title
  lbl.build = true
  lbl.name = "title"
  lbl.text = "Key Binds"
  lbl.size.x = 240
  lbl.size.y = 25
  lbl.scale = 1.8
  lbl.position.y = 0
  lbl.dropShadowAlpha = 1
  lbl.displayfont = LARGETEXT
  lbl.justification = BOTTOMCENTER
  lbl.autoCenter.horizontal = true
  lbl.defaultStatePresentation.color = setColor
  add back lbl to main.children
  posY = posY + 40

  but as NodeRef of Class TMP_button = createNodeFromPrototype("TMP_Button")     // default button
  but.build = true
  but.name = "setDefault"
  but.position.y = posY
  but.autoCenter.horizontal = true

  lbl = FindGuiControlByName(but, "text")
  lbl.text = "Set Default"
  lbl.defaultStatePresentation.color = setColor
  add back but to main.children
  posY = posY + 10

  start as Integer = 1
  end as Integer

  var win = getOptionKeyboardClass()
  keyVal as List of String = win.tmp_KeysList         // get our current list
  titles as List of String = getTitleForBinds()       // titles
  Val as Integer = getAmountOfTitles()

  // run arrays through the loop - display
  loop i from 1 to Val by 2
    posY = setupKeyTitle(main, titles[i], posY)     // section titles
    end = stoi(titles[i+1]) * 4 + start-1

    loop j from start to end by 4
      cmd as String = keyVal[j]
      key1 as String = keyVal[j+1]
      key2 as String = keyVal[j+2]
      layer as String = keyVal[j+3]
      posY = setupKeyBindButton(main, cmd, key1, key2, layer, posY)  // print CMD, key1, key2
    .
    start = start + stoi(titles[i+1]) * 4
  .
.

// set default values for key binds
// checks current list and Init list
// reset the values of current to Init
public function SetDefaults()
  var win = getOptionKeyboardClass()
  current as List of String = win.tmp_KeysList  // current
  Init as List of String = getNewKeyBinds()     // Init
  amt as Integer = getAmountOfBinds()

  key1 as String
  key2 as String

  loop i from 1 to amt by 4
    com as String = Init[i]
    layer as String = Init[i+3]

    if current[i+1] <> Init[i+1]          // if new and old are diff
      key1 = current[i+1]                 // remove old
      RemoveThisKey(com, key1, layer)
      key1 = Init[i+1]                    // set new
      AddThisKey(com, key1, layer)
    .
    if current[i+2] <> Init[i+2]          // if new and old are diff
      key2 = current[i+2]                 // remove old
      RemoveThisKey(com, key2, layer)
      key2 = Init[i+2]                    // set new
      if key2 <> "none"
        AddThisKey(com, key2, layer)
      .
    .
  .

  win.tmp_KeysList = Init    // set to new list

  SaveKeyBindOptions()  // save reset to default
  DisplayKeybinds()     // show them
.

// look for the key that matches
// set newkey to add in
function findMatchingKey(com as String, oldkey as String) as String
  myKeys as List of Class keybinding = GetKeyBindings()   // get data stored by Hero engine
  newkey as String

  foreach key in myKeys
    if FindString(key.layer, "HE_") <> 1      // skip HE_ key list
      if com = key.command
        if oldkey <> key.key          // skip 1st key
          newkey = key.key
          break
        .
      .
    .
  .
  return newkey
.

// key not found - add it in
function AddThisKey(com as String, key as String, lay as String)
  newKey as Class keybinding
  newKey.command = com
  newKey.key = key
  if lay = "Movement"         // all movement keys need to accept 2 key inputs
    newKey.key = "ANY+"+key
  .
  newKey.layer = lay
  if newKey.key <> "ANY+__"             // skip "none"
    if SetKeyBinding(newKey)            // add in new
      println("key added "+newKey.key)
    .
  .
.

// key should not be here - remove it
function RemoveThisKey(com as String, key as String, lay as String)
  oldKey as Class keybinding
  oldKey.command = com
  oldKey.key = key
  oldKey.layer = lay
  if ClearKeyBinding(oldKey)                      // remove it
    println("key removed "+oldKey.key)
  .
.

Logged
Lead scripter for EO, Repop helper.
HSL Video tutorials:
https://community.heroengine.com/forums/index.php/topic,1719.msg36858.html#msg3685

Thazager

  • General Accounts
  • *
  • Posts: 1160
  • Never stop learning
    • View Profile
Re: changing Keybinds basic
« Reply #2 on: Jun 30, 14, 05:48:25 PM »

Continued from above (same script)

Code: [Select]

//=============================================================================================================
// check and set current button
method _OnButtonMouseClick(button as NodeRef of Class _GUIButton, args references Class GUIMouseEvent)

  if args.leftButton
    when button.name
      is "setDefault"
        SetDefaults()
        return
      .
    .

    // for keybind section
//    Over as NodeRef of Class GUIControl = button.parent.parent.parent.parent  // used for options windows tabs
//    if Over.name = "keyboard"

      var main = getKeyClientArea()
      var win = getOptionKeyboardClass()

      command as String = ReplaceString(button.name, "but1", "")    //remove but names
      command = ReplaceString(command, "but2", "")

      keyValue as NodeRef of Class GUILabel = FindGUIControlByName(main, command+"keyPanel."+button.name+".text")
      win.tmp_KeyText = keyValue.text    // get current key value
      win.tmp_KeyCommand = command
      win.tmp_KeyChoice = button.name

      setupPlayerChoice(button)
//    .
  .
.

//-------------------------------------
// Allow mouse wheel scrolling of items
//-------------------------------------
method onMouseWheel(args references Class GUIMouseEvent)
  c as NodeRef of Class GUIScrollablePanel = getKeyClientArea()
  if c = None
    return
  .

  where c is kindof GUIScrollablePanel
    if args.wheelDelta > 0
      var newOffset = c.offset.y - 60
      if newOffset < 0
        newOffset = 0
      .
      if newOffset > (c.area.y - c.size.y)
        newOffset = c.area.y - c.size.y
      .
      c.offset.y = newOffset
    else
      var newOffset = c.offset.y + 60
      if newOffset < 0
        newOffset = 0
      .
      if newOffset > (c.area.y - c.size.y)
        newOffset = c.area.y - c.size.y
      .
      c.offset.y = newOffset
    .
  .
.

// get which key was pressed
function OnCaptureKeyDown(keyName as String) as Boolean
  if keyName = "CTRL" or keyName = "ALT" or keyName = "SHIFT"
    return false
  .
  CheckNewKey(keyName)
  return true
.

// process the keypress
public function CheckNewKey(WhichKey as String)
  CaptureKeyInput( None )   // turn off key checks

  // set player choice in window text
  var main = getKeyClientArea()
  lbl as NodeRef of Class GUILabel = FindGuiControlByName(main, "KeyChoiceWin.text")
  lbl.text = lbl.text +" "+ WhichKey

  // find which button
  var win = getOptionKeyboardClass()
  lbl = FindGuiControlByName(main, win.tmp_KeyCommand+"keyPanel."+win.tmp_KeyChoice+".text")
  Com as String = ReplaceString(win.tmp_KeyCommand, " ", "")  // clear spaces
  but as Integer = ReplaceString(win.tmp_KeyChoice, Com+"but", "")    // get which button 1 or 2

  newKey as Class keybinding
  offset as Integer = FindCommandOffset(Com)

  dataType as List of String = win.tmp_KeysList     // get our current list
  newkey.command = Com                              // set current values
  newkey.layer = dataType[offset+3]

  when newkey.layer
    is "Movement"                     // movement has ANY+
      checkRemoveDuplicateKey("ANY+"+WhichKey, but)  // check for dups of our new key
      newKey.key = "ANY+"+WhichKey                   // set new key
    .
    default
      checkRemoveDuplicateKey(WhichKey, but)         // check for dups of our new key
      newKey.key = WhichKey                          // set new key
    .
  .

  RemoveOldKey(offset, but, newkey.layer)
  SetKeyBinding(newKey)                            // add in new
  lbl.text = WhichKey                              // show on screen
  dataType[offset+but] = WhichKey       // set new key in list

  // rebuild list
  amt as Integer = getAmountOfBinds()
  data as List of String

  loop i from 1 to amt
    add back dataType[i] to data
  .
  win.tmp_KeysList = data    // save new list
  SaveKeyBindOptions()       // save in repo

  Keywin as NodeRef of Class GUIControl = FindGuiControlByName(main, "KeyChoiceWin")
  DestroyNode(Keywin)     // remove little pop up window
.

// if key already assigned, remove that assignment
// update the list, show on screen
function checkRemoveDuplicateKey(dupkey as String, button as Integer)
  var main = getKeyClientArea()
  oldList as List of Class keybinding = GetKeyBindings()   // get data stored by Hero engine
  oldKey as Class keybinding

  foreach key in oldList
    if FindString(key.layer, "HE_") <> 1        // skip HE_ key list
      if key.key = dupkey                       // same key we want to add?
        cmd as String = ReplaceString(key.command, " ", "")  // clear spaces
        oldKey.command = cmd
        oldKey.key = dupkey
        oldKey.layer = key.layer

        if ClearKeyBinding(oldKey)              // remove duplicate keys
          offset as Integer = FindCommandOffset(cmd)    // find in list
          num as Integer = getWhichButton(dupkey, offset, button)
          println(" clearing Dup "+dupkey+" at cmd "+cmd+" but "+num)

          lbl as NodeRef of Class GUILabel = FindGuiControlByName(main, cmd+"keyPanel."+cmd+"but"+num+".text")
          lbl.text = "__"                               // clear it on screen
          break
        .
      .
    .
  .
.

// find offset of command
function FindCommandOffset(Com as String) as Integer
  var win = getOptionKeyboardClass()
  command as List of String = win.tmp_KeysList     // get our current list

  amt as Integer = getAmountOfBinds()
  offset as Integer

  // search our current list
  loop i from 1 to amt by 4
    if Com = ReplaceString(command[i], " ", "")  // clear spaces
      offset = i
      break
    .
  .
  return offset
.

// get which button our dup key is in 1st or 2nd
function getWhichButton(dupkey as String, offset as Integer, clickbut as Integer) as Integer
  var win = getOptionKeyboardClass()
  command as List of String = win.tmp_KeysList     // get our current list
  copyKey as String = ReplaceString(dupkey, "ANY+", "")      // clear extra for movement layer

  key1 as String = command[offset+1]
  key2 as String = command[offset+2]
  but as Integer

  if copyKey = key1    // place dup key was?
    but = 1
  .
  if copyKey = key2    // place dup key was?
    but = 2
  .

  return but
.

// remove the current value of this key from keybinding list
function RemoveOldKey(offset as Integer, but as Integer, layer as String)
  var win = getOptionKeyboardClass()
  dataType as List of String = win.tmp_KeysList     // get our current list

  oldkey as String = dataType[offset+but]
  if layer = "Movement"
    oldkey = "ANY+"+oldkey
  .

  newList as List of Class keybinding = GetKeyBindings()
  aKey as Class keybinding

  foreach key in newList
    if FindString(key.layer, "HE_") <> 1      // skip hero engine keylist
      if key.key = oldkey                     // this key?
        aKey.layer = key.layer
        aKey.command = key.command
        aKey.key = oldkey

        if ClearKeyBinding(aKey)        // remove key in this spot
          println(" clearing Old "+akey.key)
          break
        .
      .
    .
  .
.

//=============================================================================================================
// get client area where key panel is placed
function getKeyClientArea() as NodeRef of Class GUIControl
  client as String = "game.TMP_OptionKeyboard.scrollable.clientarea"
  main as NodeRef of Class GUIControl = FindGuiControlByName(None, client)
  return main
.

// get Option keyboard class for variables
function getOptionKeyboardClass() as NodeRef of Class TMP_OptionKeyboard
  win as NodeRef of Class TMP_OptionKeyboard = FindGuiControlByName(None,"game.TMP_OptionKeyboard")
  return win
.

// set color for our text
function SetKeyTextColor() as Class rgba
  data as Class rgba = MiscUtils:MakeRGBA( 0, 1, 0, 1 )
  return data
.

// set up the window for player input
public function setupPlayerChoice(button as NodeRef of Class _GUIButton)
  var main = getKeyClientArea()

  window as NodeRef of Class GUIControl = FindGuiControlByName(main, "KeyChoiceWin")
  if window <> None
    DestroyNode( window )
  .
  window = createNodeFromPrototype("TMP_KeyWindow")
  window.build = true
  window.name = "KeyChoiceWin"
  window.position.x = button.parent.position.x
  window.position.y = button.parent.position.y
  add back window to main.children

  var win = getOptionKeyboardClass()
  setColor as Class rgba = SetKeyTextColor()

  lbl as NodeRef of Class GUILabel = FindGuiControlByName(window, "text")
  lbl.text = win.tmp_KeyCommand+",  Replace "+win.tmp_KeyText+" with..."
  lbl.defaultStatePresentation.color = setColor

  SetKeyboardFocus(window)     // ready to get user input
  CaptureKeyInput(TMP_OptionKeyboardClassMethods)
.

// switches used in keyboard area title name
function setupKeyTitle(ca references NodeRef of Class GUIControl, title as String, posY copies Integer) as Integer
  posY = posY + 20
  name as NodeRef of Class GUILabel

  name = createNodeFromPrototype("_label")
  name.build = true
  name.name = title
  name.text = title
  name.size.x = 160
  name.position.x = 25
  name.position.y = posY
  name.displayfont = JUMBO
  name.dropShadowAlpha = 1
  name.defaultStatePresentation.color = MiscUtils:MakeRGBA( 1, 1, 1, 1 )
  add back name to ca.children

  posY = posY + 20
  return posY
.

// switches used in keyboard area
function setupKeyBindButton(ca references NodeRef of Class GUIControl, CMD as String, Key1 as String, Key2 as String, layer as String, posY copies Integer) as Integer
  setColor as Class rgba = SetKeyTextColor()
  tmp as String = replaceString(CMD, " ", "")   //remove spaces for names

  panel as NodeRef of Class GUIControl = createNodeFromPrototype("TMP_KeyBindPanel")
  panel.build = true
  panel.name = tmp+"keyPanel"
  panel.position.y = posY
  add back panel to ca.children

  lbl as NodeRef of Class GUILabel = FindGuiControlByName(panel, "command")
  lbl.text = replaceString(CMD, "Open ", "")   //remove "Open "
  lbl.defaultStatePresentation.color = setColor

  button as NodeRef of Class _GUIButton = FindGuiControlByName(panel, "button1")
  button.name = tmp+"but1"
  lbl = FindGuiControlByName(button, "text")
  lbl.text = ReplaceString(key1, "ANY+", "")   // remove "ANY+"
  lbl.defaultStatePresentation.color = setColor

  button = FindGuiControlByName(panel, "button2")
  if key2 <> "none"
    button.name = tmp+"but2"
    lbl = FindGuiControlByName(button, "text")
    lbl.text = ReplaceString(key2, "ANY+", "")   // remove "ANY+"
    lbl.defaultStatePresentation.color = setColor
  else
    button.visible = false    // remove it
  .

  posY = posY + 20
  return posY
.

Logged
Lead scripter for EO, Repop helper.
HSL Video tutorials:
https://community.heroengine.com/forums/index.php/topic,1719.msg36858.html#msg3685

ToY-Krun

  • General Accounts
  • *
  • Posts: 677
  • Support Volunteer
    • View Profile
Re: changing Keybinds basic
« Reply #3 on: Dec 30, 15, 01:42:37 PM »

Not trying to take over Thaz' topic,  But I'm gonna bump it since this is what I'm setting up currently.

One issue I've found is this:

Using SaveLocalRepositoryData() to save the file, and LoadLocalRepositoryData() to retrieve it works great IN THE BLADE.
This however does not work in the player client.

Added a chat message to see if the Save was working and obviously it is.  So its just not loading it for some reason.

Aha!  Okay I've discovered the cause..

using "/" preceding and after the filename works for blade but not for playerclient...
removing them works for player client but not for blade...

Looking into that, may just have to check for bladeUser.

Edit #3
Okay resolution is as follows:

fqn as string
if IsHeroBlade()
  fqn = "/keybindoptions/" //works in the blade
else
  fqn = "keybindoptions" //works in the player Client
.
then use fqn in the Save/Load functions.
This would probably lead to two separate files and so what is set in the blade for an account would not be the same as in the playerClient...
I'll test that out, and if you have any other suggestions.....
« Last Edit: Dec 30, 15, 01:55:03 PM by ToY-Krun »
Logged