• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

How can i create Buttons Next to stats on a hero? {Warcraft III hero attributes}

Status
Not open for further replies.
Level 4
Joined
Jan 14, 2005
Messages
73
Im wondering how to create a button "[+]" that looks like that next to a heros stats and also how to make thier stats show up to the left of thier portrait?

so
----------
STR [+] |Portrait|
INT [+] |Portrait|
AGI [+] |Portrait|
----------
Somthing like that?

I have been reading a bit about dialog buttons but im not sure how the position on them works yet, Do i have to specify the ui as the object to have the button? Or is it the screen position? (I havent actually attempted to do this myself but i want to understand that im using the correct functions in the triggers to place the buttons where i want them before I start "Trial and Error"-ing the positions).

If someone could tell me which Functions i should use (exact name please) to draw a dialog box on the ui id appreciate it.
 
Level 11
Joined
Jul 20, 2004
Messages
2,760
(Finally a question directly related on the subject of my StarCraft II current research)

While it is possible to modify the UI via specific XML files as to allow insertion of additional elements into the actual interface mechanics, my solution is pure script (well, trigger) based.

1) Setting up the dialog at Map Initialization - first thing's first: we need the actual dialog containing the requested elements - imagine the dialog being a container, and the items inside it being the user-interface objects (like text labels, buttons etc.). The development steps are as follows:

  • Create and place a dialog at the designated position. Because the dialog container should in-fact be part of the UI, it is relative to the screen itself. Dialogs are by default rendered above any element of the screen (though it is possible to alter this behavior). After doing a bit of experiments, I have determined that the following parameters work:
    • Dialog - Create a Modal dialog of size (260, 140) at (300, 50) relative to Bottom of screen
    • Variable - Set Dialog_HeroStats = (Last created dialog)
    You may notice that I also store the dialog in a variable for later use (though you can use the same dialog for all players - values can be modified selectively for the (Player Group) composed of the (Triggering Player) alone.
  • Add the dialog items. The items belong to the dialog, so their position will be relative to it (not the screen). This greatly simplifies placement and position-related tweaking. We need 3 categories of items (per each stat) more specifically:
    • Text Label that describes the stat (Intelligence, Agility, Strength)
    • Text Label that reads the current amount of the stat for a specific unit (generally 1 to 3 digits should suffice - we don't want heroes with 3567 Intelligence points now, do we?)
    • Button that enables selective increasing of stats (you can set them visible/invisible depending on when and how you want players to be able to increase the afferent stats).
    Again, after a bit of experimenting we end up with this placement:
    • Dialog - Create a label for dialog (Last created dialog) with the dimensions (200, 25) anchored to Top Left with an offset of (40, 40) with the text "Strength" color set to White text writeout set to False with a writeout duration of 2.0
    • Dialog - Create a label for dialog (Last created dialog) with the dimensions (200, 25) anchored to Top Left with an offset of (40, 65) with the text "Agility" color set to White text writeout set to False with a writeout duration of 2.0
    • Dialog - Create a label for dialog (Last created dialog) with the dimensions (200, 25) anchored to Top Left with an offset of (40, 90) with the text "Intelligence" color set to White text writeout set to False with a writeout duration of 2.0
    • ------- Store these into afferent variables so they can be later accessed.
    • ------- Buttons need to generate trigger events.
    • Dialog - Create a button for dialog (Last created dialog) with the dimensions (25, 25) anchored to Top Right with an offset of (35, 35) setting the tooltip to "" with button text "+" and the hover image set to ""
    • Dialog - Create a button for dialog (Last created dialog) with the dimensions (25, 25) anchored to Top Right with an offset of (35, 60) setting the tooltip to "" with button text "+" and the hover image set to ""
    • Dialog - Create a button for dialog (Last created dialog) with the dimensions (25, 25) anchored to Top Right with an offset of (35, 85) setting the tooltip to "" with button text "+" and the hover image set to ""
    • ------- Labels will be modified whenever another hero is selected, or stats are modified.
    • Dialog - Create a label for dialog (Last created dialog) with the dimensions (50, 25) anchored to Top Right with an offset of (60, 40) with the text "8" color set to White text writeout set to False with a writeout duration of 2.0
    • Dialog - Create a label for dialog (Last created dialog) with the dimensions (50, 25) anchored to Top Right with an offset of (60, 65) with the text "66" color set to White text writeout set to False with a writeout duration of 2.0
    • Dialog - Create a label for dialog (Last created dialog) with the dimensions (50, 25) anchored to Top Right with an offset of (60, 90) with the text "109" color set to White text writeout set to False with a writeout duration of 2.0
    Due to the incompleteness of this response, the dialog items are not stored into separate variables. You ought to do this yourself - again, you can use global variables safely, as labels' text can be altered individually/player.

2) Display the dialog whenever a hero unit alone is selected. For demonstrative purposes, I consider all (and only) Archons as being hero units. The trigger is described as follows:

  • Responsiveness to selection events. Deselection itself is relevant in case 2 or more units are selected, and then one unit alone from that selection is clicked, for instance. In that case the selection event will not trigger.
    • Events
      • Unit Selection - Any Unit is Selected by player Any Player
      • Unit Selection - Any Unit is Deselected by player Any Player
  • We recover the first unit of the selection into a local variable.
    • Local Variables
      • selUnit = (Unit 1 from (Selected units for player (Triggering player))) <Unit>
  • Finally we need to decide if we want to display the dialog (or hide it!). There are three conditions that need to be taken into consideration:
    • Only one unit is selected by the player!
    • The selected unit is a hero (in our case an Archon)
    • The selected unit belongs to the (Triggering Player) (unless you want to allow anyone to see the stats of the hero - case in which you should still deactivate the buttons - remember the dialog is global for all players).
    • General - If (Conditions) then do (Actions) else do (Actions)
      • If
        • (Number of Any units in (Selected units for player (Triggering player))) == 1
        • (Owner of selUnit) == (Triggering player)
        • (Unit type of selUnit) == Archon
      • Then
        • Dialog - Show Dialog_HeroStats for (Player group((Triggering player)))
      • Else
        • Dialog - Hide Dialog_HeroStats for (Player group((Triggering player)))
    Note: Remember if you show the dialog to also tweak the values of the stats. Modify the labels according to the stats of the selected unit (stored in the local variable). It might be useful to use the Unit - Custom Value array for this purpose (for example indexes 1, 2 and 3 for Strength, Agility, Intelligence).

3) Button manipulation - I will leave this part to you to try. A simple trigger that responds to the Button Dialog Items being clicked should be quite easy to implement. Keep in mind to limit the number of "upgrades" or else people might indefinitely keep upgrading their stats.


And I end the reply with a small "preview" of the system (hopefully something you're looking for). For the + thing of the button, either increase the size of the buttons (it failed to show me the text and I was too lazy to play with them more) or add a label on top of them.

~Daelin
 

Attachments

  • TestDialog.jpg
    TestDialog.jpg
    68.5 KB · Views: 440

Rui

Rui

Level 41
Joined
Jan 7, 2005
Messages
7,550
I figured they'd allow you to do this with triggers, though I wonder if it's possible with the Data Editor (probably is).

This looks nice, though, Daelin, just a few lines and its setup? How far have you experimented with dialogs? If you know more about them, could you clarify what is: «White Text writeout»; «writeout duration»; Modal dialog size and «relative to Bottom of screen»?
Thank you in advance!
 
Level 11
Joined
Jul 20, 2004
Messages
2,760
I figured they'd allow you to do this with triggers, though I wonder if it's possible with the Data Editor (probably is).
I doubt actual buttons can be added to the UI via the Data Editor alone, but then again, I have yet to experiment a great deal with it.

This looks nice, though, Daelin, just a few lines and its setup? How far have you experimented with dialogs? If you know more about them, could you clarify what is: «White Text writeout»; «writeout duration»; Modal dialog size and «relative to Bottom of screen»?

White refers to the actual color of the text inside the label. You can also apply styles to the text too, but I haven't experimented much with that aspect.

Text Writeout feature makes the system print the text letter by letter, typewriter style. This seems to activate first time the dialog is set to visible. If the dialog is hidden and then revealed again, the writeout does not reactivate (even if overwritten to true via the specific action Dialog - Set <Item> Text Writeout to True).

Modal dialogs are not yet implemented by Blizzard. All dialogs are treated as non-modal, regardless of the selected option. It is indeed recommended that people make non-modal dialogs for the time being. A modal dialog is expected to set focus on the dialog alone, locking the user from interacting with any other UI component (Main Menu dialog for instance is modal).

Relativity refers to the point from which offset is calculated. There are 9 anchor points from which offset can be taken into consideration (the eight cardinal direction - E, SE, S, SV, V, NV, N, NE + Center). Offsets are calculated as relative to the anchor point (of a given item - whether it is the screen, a dialog, or a dialog item such as panel).

Positive offset values 'move' the item towards the center, while negative values work in the direction opposite to that towards the center. I can be more explicit about this if necessary. But at the moment, "Bottom of the screen" means that the dialog's offset coordinates (X=300, Y=50) are computed relative to the middle of the bottom of the screen.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,202
Unit Selection - Any Unit is Selected by player Any Player
Unit Selection - Any Unit is Deselected by player Any Player
The responses to these events are generated with lag. This is due to having to syncronize the unit selections. This will mean the dialogs will appear noticably after you have selected the unit.

Be aware that hidden (and I think even disabled) dialog items are able to be pressed by eithor lag (push responses delayed from before the item wsa hidden) or by hacks (sending fake packages containing dialog item orders). For logical reasons when responding to a dialog item event in a trigger you should always check if the press response was valid in the first place (the button is in a state it can actually be pressed).

It is very common in multiplayer maps that you can break them by quickly double pressing a dialog item (period of presses less than period of lag) and thus triggering a button which is meant to dissapear after 1 press twice.

This was present in WarCraft III's dialog system as well (you could use a hack to trigger dialog event responses for a dialog that is never shown to a player) but the UI prevented double clicking (as dialogs automaticly hid asyncrniously when a player pressed a button).
 
Level 11
Joined
Jul 20, 2004
Messages
2,760
The Dialog background can be hidden. That way it will look like the labels/icons/whatever elements you have inside it are not part of a dialog but part of the UI. I noticed the small icons to the left of the hero in the map you mentioned (never played it myself). I assume those icons are inserted into a dialog, but the background of the dialog is not visible.
 
Level 4
Joined
Jan 14, 2005
Messages
73
Thanks for the nice answer Daelin. Il try it out, Seems pretty straight forward (It will probably take me some trial and error to get the buttons in the right place but at least now i know how i need to set it up)

So again Thank you

PS: I found a great Map Called Dialog Creator (Search Dialog in custom maps and it will show up) So far it appears to work great for designing dialog Menus. I have not yet implemented them into my map and the save function doesnt work, however if you want to make a super quality stats menu or inventory or somthing of the sort it appears to be able to do the layout almost perfect. Im posting because i wanted to know if anyone could tell me how to implement this code? the Dialog Creator is in a different Language so i cant read what it tells me to do.
 
Last edited:
  • Like
Reactions: Rui
Status
Not open for further replies.
Top