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

Author Topic: [Question] - How Do I Update Labels In A GUI  (Read 3336 times)

Jarvis

  • World Owners
  • ****
  • Posts: 16
    • View Profile
[Question] - How Do I Update Labels In A GUI
« on: Aug 19, 14, 01:25:04 PM »

Hello all, I am just starting out in making GUIs.

I made stats and skills that I wish to update in a skills menu. Currently I press K and it opens up this menu.

This menu has Stat labels, and skill labels. Currently they just read out like "Constitution: " and "Forestry: " etc.

My question is, after I have created this GUI (Called SkillsGUI), how to I update it to the player values I have?

I wish for something along the lines of _statConstitution.text = "Constitution: " && STA_CONSTITUTION.

I just don't know how to code it. Thanks in advance.
Logged

Thazager

  • General Accounts
  • *
  • Posts: 1160
  • Never stop learning
    • View Profile
Re: [Question] - How Do I Update Labels In A GUI
« Reply #1 on: Aug 19, 14, 07:33:30 PM »

The next step would be loading in values. You could start with some values hard coded, but that would be just for testing. Next would be to load them in from a saved location. If players will start with a base value and be able to add to it, the hard value could be saved on the server.

Once that part is working, next would be saving values on the character on server side. As you probably have seen, hitpoints and experience are saved on the character. When they are sent to the server side they auto save. There are a few ways of doing this. One of the easier ways is making a stat value for each similar to the hitpoints.

A step up from that would be making them into a string and putting a few values together in the same string. Another way would be making a new class called Stats, and adding in the values to that class, then add that class to the character. Either through glomming, or by making it a parent of the E_playerCharacter (this is the way I use).
Logged
Lead scripter for EO, Repop helper.
HSL Video tutorials:
https://community.heroengine.com/forums/index.php/topic,1719.msg36858.html#msg3685

Jarvis

  • World Owners
  • ****
  • Posts: 16
    • View Profile
Re: [Question] - How Do I Update Labels In A GUI
« Reply #2 on: Aug 19, 14, 07:37:41 PM »

Sorry, that is not what I meant to ask. I have already taken care of the stats. I just mean how do I update the "labels" on the GUI with those variables that are saved on the character. Meaning what do I add to TMP_SkillsGUIClassMethods to update the GUI with the player's stats.

In this situation just putting in HP in the GUI I could learn from/modify if you could provide that example.
Logged

Thazager

  • General Accounts
  • *
  • Posts: 1160
  • Never stop learning
    • View Profile
Re: [Question] - How Do I Update Labels In A GUI
« Reply #3 on: Aug 19, 14, 07:44:04 PM »

To add a value to a label:

      lbl as Noderef of class GUILabel = findguicontrolbyname(mainGuiname, "labelname")
      lbl.text = statValue

for adding/changing color of it

      lbl.defaultpresentation.color = MiscUtils:setColor(1,1,1,1)    // where the 1s are RGBA values

might be diff function name n MiscUtils
Logged
Lead scripter for EO, Repop helper.
HSL Video tutorials:
https://community.heroengine.com/forums/index.php/topic,1719.msg36858.html#msg3685

Jarvis

  • World Owners
  • ****
  • Posts: 16
    • View Profile
Re: [Question] - How Do I Update Labels In A GUI
« Reply #4 on: Aug 19, 14, 08:31:06 PM »

Starting to wonder if HE is for me. I was working on getting this working when I am repeatedly being disconnected from HeroBlade. Besides that: our trees keep appearing above the terrain every time the server reloads, there are always white seams on the terrain, time warps happen, CTRL+Z sometimes completely mangles the terrain, and so on.

Ah well. Anyways this is what I got so far:

Code: [Select]
method UpdateSkillGUI()
  labelStatConst as NodeRef of Class GUILabel = FindGUIControlByName(SkillsGUI, "_statConstitution")
  labelStatConst.text = me.STAT_CONSTITUTION
.

labelStatConst.text gives an error (which in this case is expected) about labelStatConst not having a text or whatever it was. Which I believe is because currently SkillsGUI does not exist (or rather, not sure how to put it in there).  You said mainGuiname, which in this case the Skills menu gui is SkillsGUI.
Logged

Thazager

  • General Accounts
  • *
  • Posts: 1160
  • Never stop learning
    • View Profile
Re: [Question] - How Do I Update Labels In A GUI
« Reply #5 on: Aug 20, 14, 12:15:07 AM »

FindGUIControlByName(SkillsGUI, "_statConstitution")

This needs to point at the label in the  GUI tree. There are a few ways to do it. One way is following the tree in the editor as you type the tree path in.

FindGUIControlByName(SkillsGUI, "panel.labelholder._statConstitution")

Where panel and labelholder might be the names of the parts in the tree to reach the label. Add a . between parts inside the quotes.

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

Jrome90

  • General Accounts
  • *
  • Posts: 330
    • View Profile
Re: [Question] - How Do I Update Labels In A GUI
« Reply #6 on: Aug 20, 14, 06:09:48 AM »

To update a GUI when you open it:
Code: [Select]
//Called when the control is built
method OnControlBuild()
  me.PopulateSkillGUI()
.

method PopulateSkillGUI()
  account as NodeRef of Class E_playerAccount = GetAccountID()
  player as NodeRef of Class E_playerCharacter = account.GetMyCharacter()
  statConstitution as String = player.STAT_CONSTITUTION // Prefer to use a Get method
 
  labelStatConst as NodeRef of Class GUILabel = FindGUIControlByName(me.getClientarea(), "_statConstitution")
  labelStatConst.text = statConstitution
.

The following assumptions are made:
  • Still using the default "E_playerAccount" Class
  • The STAT_CONSTITUTION value is used with the "E_playerCharacter"Class
  • The Skill GUI is a window with the "_statConstitution" as a child of the clientarea

An issue with just updating the values when the skill GUI is opened is that it won't update while the window is open. To address this problem, you can use a listener to update the gui. http://hewiki.heroengine.com/wiki/Observer_pattern

One way you can do this is to use the same method as the "E_playerAccount" class uses for upating the experience bar,status bar, level, and health values:

Where statusBar and expBar are the Nodes created using "CreateNodeFromPrototype()"
Code: [Select]
$LightweightEvents.addLightweightEventListener(addedNode, "xpUpdated", expbar)
        $LightweightEvents.addLightweightEventListener(addedNode, "nameUpdated", statusBar)
        $LightweightEvents.addLightweightEventListener(addedNode, "hpUpdated", statusBar)
        $LightweightEvents.addLightweightEventListener(addedNode, "levelUpdated", statusBar)

The method "lightweightEventRaised(subject as ID, eventType as String, data as NodeRef)" is called on the class for the GUI

Example is the status bar GUI :
Code: [Select]
method lightweightEventRaised(subject as ID, eventType as String, data as NodeRef)
  when eventType
    is "nameUpdated"
      char as NodeRef of Class E_CommonCharacter = subject
      if char != None
        me.SetName(char.name)
      .     
    .
    is "hpUpdated"
      char as NodeRef of Class E_CommonCharacter = subject
      if char != None
        me.SetHP(char.E_hitPoints)
      . 
    .
   is "levelUpdated"
//     char as NodeRef of Class E_playerCharacter = subject
     char as NodeRef of Class RO_playerCharacter = subject

      me.Level(char.E_level)
      //only for quick testing (isnt working)
      //me.ItemEquip(char.E_level)
    .
  .
.
You would then need to use replication to update the values of the field to the client. Just like "E_hitPoints" ect
If the skills are only for players, put the field in the E_PlayerCharacter Class, not the E_CommonCharacter

Because the LightweightEvents requires a node  you would need to create the Skill GUI but not make it visible.
The upshot to using this method is that you no longer have to update the GUI when the GUI is opened, and it will always be updated. The Downside is that you have more nodes in memory, but since this is on the client side it shouldn't be an issue.

If you look at my Inventory Popup window Tutorial you can use similar code to just toggle the visibilty:

Code: [Select]
Method IOpen()
  if me.toggleIPopUp = None
      popUp as NodeRef of Class GUIControl = CreateNodeFromPrototype("PopUp")
      popUp.build = true
      me.toggleIPopUp = popUp
    else
      SkillGUI as NodeRef of Class _GUIBaseWindow = me.toggleIPopUp //<-PopUp
      if SkillGUI .visible // If it is visible
        SkillGUI .visible = false
      else
        SkillGUI .visible = true
      .
     .
.

This code is untested, but should work. And there are still some holes to fill in.

P.S.
HeroEngine is for anybody willing to put forth the effort to learn. I did it, so can you :)
« Last Edit: Aug 20, 14, 06:12:59 AM by Jrome90 »
Logged

Thazager

  • General Accounts
  • *
  • Posts: 1160
  • Never stop learning
    • View Profile
Re: [Question] - How Do I Update Labels In A GUI
« Reply #7 on: Aug 20, 14, 07:24:25 PM »

Yes, that tutorial goes more in depth of how things are put together, where mine are more of how to put this type of idea into code.

When the window is open, adding a value to the label.text area will update what the screen is showing. A listener is good if you are updating through another means, like changing data and the value is auto updated on screen.
Logged
Lead scripter for EO, Repop helper.
HSL Video tutorials:
https://community.heroengine.com/forums/index.php/topic,1719.msg36858.html#msg3685