[Snippet In Progress] Loading/Casting Bar

skyblader

You're living only because it's illegal killing.
Reaction score
159
I made a loading/casting bar since I haven't found a proper GUI one, and another is in JASS. (Also made it sometime back, just didn't submit because of a few glitches) It's meant for users that have trouble getting NewGen, and for others that do not want to learn JASS. It would be much easier for them. At the moment, it's almost functional except for a few glitches here and there which I have not managed to solve. I would be really grateful if you would take some time to browse through my triggers and see if you can find anything wrong, or more ways to make it more efficient. Once it's fully functional, I'll post it in the tutorial and resources section. And do inform me if I missed out anything required for submission, and thanks in advance! :)

Current Problems:
-The bar jumps slightly at the start
-Doesn't work properly with other smoothness values


Loading/Casting Bar
In GUI
V 1.1​

Features:

-Very customizable
-Can fit into almost every use (building, spell casting, attack cool down)
-Simple to implement and use (Made it as simple as I could)


Images:

loadingbarpic1.png
LoadingBarPic2.png
loadingbarpic3.png


Triggers:
Trigger:
  • LB Load
    • Events
    • Conditions
    • Actions
      • Unit Group - Pick every unit in LBUnitGroup and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • CheckAliveBool Equal to True
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ((Picked unit) is alive) Equal to False
                • Then - Actions
                  • Unit Group - Remove (Picked unit) from LBUnitGroup
                  • Hashtable - Clear all child hashtables of child (Key (Picked unit)) in LBHash
                • Else - Actions
            • Else - Actions
              • Set LBTotalLength = (Load (Key LBTotalLength) of (Key (Picked unit)) from LBHash)
              • Set LBTotalLengthInt = ((Integer(LBTotalLength)) x ((Integer(LBMultiplier)) + 2))
              • Set LBLength = (Load (Key LBLength) of (Key (Picked unit)) from LBHash)
              • Set LBLengthRemaining = (Load (Key LBLengthRemaining) of (Key (Picked unit)) from LBHash)
              • Set LB = LBColour
              • Set LBIntegerAReal = (LBLength x LBMultiplier)
              • Set LBIntegerAInteger = (Integer(LBIntegerAReal))
              • For each (Integer A) from 3 to LBTotalLengthInt, do (Actions)
                • Loop - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • LBIntegerAReal Equal to (Real((Integer A)))
                    • Then - Actions
                      • Set LBIntegerAInteger = (Integer A)
                    • Else - Actions
              • For each (Integer A) from 0 to LBIntegerAInteger, do (Actions)
                • Loop - Actions
                  • Set LB = (LB + LBPiece)
              • Set LB = (LB + |r)
              • Set LBIntegerAReal = (LBLengthRemaining x LBMultiplier)
              • Set LBIntegerAInteger = (Integer(LBIntegerAReal))
              • For each (Integer A) from 0 to LBIntegerAInteger, do (Actions)
                • Loop - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • LBLengthRemaining Greater than 0.00
                    • Then - Actions
                      • Set LB = (LB + LBPiece)
                    • Else - Actions
              • Floating Text - Create floating text that reads LB above (Picked unit) with Z offset 0.00, using font size 10.00, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
              • Floating Text - Change (Last created floating text): Disable permanence
              • Floating Text - Change the lifespan of (Last created floating text) to (LBSmooth + 0.05) seconds
              • Floating Text - Change the fading age of (Last created floating text) to (LBSmooth + 0.05) seconds
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • LBLength Equal to LBTotalLength
                • Then - Actions
                  • Unit Group - Remove (Picked unit) from LBUnitGroup
                  • Hashtable - Clear all child hashtables of child (Key (Picked unit)) in LBHash
                • Else - Actions
                  • Hashtable - Save (LBLength + LBSmooth) as (Key LBLength) of (Key (Picked unit)) in LBHash
                  • Hashtable - Save (LBLengthRemaining - LBSmooth) as (Key LBLengthRemaining) of (Key (Picked unit)) in LBHash

Trigger:
  • LB Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- Set to true if you want the casting bar to be removed if the unit dies --------
      • Set CheckAliveBool = False
      • -------- Set colour of loading bar --------
      • -------- Colour code starts with |c like in the example below. --------
      • -------- It follows with the first two 00, which is transparency and can be ignored. --------
      • -------- Next two 00, represents red. --------
      • -------- Next two 00, represents green. --------
      • -------- Next two 00, represents blue. --------
      • -------- For example, |c00ff00ff would be a mixture of red and blue. --------
      • -------- The default is black. --------
      • Set LBColour = |c00000000
      • -------- Set size of loading bar. Recommended 1. --------
      • Set LBSize = 1
      • -------- Set smoothness of Loading bar. Lower value = smoother. Recommended 0.20. Too smooth, loading bar will be too long. --------
      • -------- Note: Might not work properly if smoothness is set to anything other than 0.20. --------
      • Set LBSmooth = 0.20
      • -------- Do not touch below unless you know what you're doing. --------
      • -------- If you want to use your own hashtable, set LBHash to your hashtable and remove the action "Hashtable - Create a hashtable" --------
      • Hashtable - Create a hashtable
      • Set LBHash = (Last created hashtable)
      • For each (Integer A) from 1 to LBSize, do (Actions)
        • Loop - Actions
          • Set LBPiece = (LBPiece + ')
      • Set LBMultiplier = (1.00 / LBSmooth)
      • Trigger - Add to LB Load <gen> the event (Time - Every LBSmooth seconds of game time)

This trigger is for adding in to wherever you're using the loading bar.
Trigger:
  • LB Setup
    • Events
    • Conditions
    • Actions
      • -------- Edit LBTotalLength to how long you want the loading bar to last. For example 10, if your unit takes 10 seconds to build a building. --------
      • Set LBTotalLength = 10.00
      • Set LBTotalLength = (LBTotalLength - LBSmooth)
      • Set LBLength = 0.00
      • Set LBLengthRemaining = LBTotalLength
      • -------- Repalce triggering unit with your units. E.g. Attacking unit/constructing unit/picked unit --------
      • Unit Group - Add (Triggering unit) to LBUnitGroup
      • Hashtable - Save LBTotalLength as (Key LBTotalLength) of (Key (Triggering unit)) in LBHash
      • Hashtable - Save LBLength as (Key LBLength) of (Key (Triggering unit)) in LBHash
      • Hashtable - Save LBLengthRemaining as (Key LBLengthRemaining) of (Key (Triggering unit)) in LBHash

Changelog:
Code:
V 1.0
-Release

V 1.1
-Changed handles saved to texts instead of integers
-Added comment to use own hashtable
-Improved testing triggers

Do feel free to tell me, if there are things I can improve on. I'm looking to make it as efficient as possible in GUI. Thanks. :)
Download for testmap:View attachment Loading Bar in GUI.w3x
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
you should add the option to use their own hashtable so they dont use up a space for this and instead of using integers as the key change it to text, IE: (Key LBLength)
overall looks like a pretty solid gui system, im thinking about make a GUI friendly version with jass
 

skyblader

You're living only because it's illegal killing.
Reaction score
159
Hmmm, I believe to use your own hashtable, all you have to do is delete the "Hashtable - Create a hashtable" action, and set LBHash = YourHash. That works right? I added in the comments stating so.

As for the integers and key text, what's the difference? I find it easier to track with integers.
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
The integers arent random rediculously high numbers so they arent MI (multi-instanceable) whereas if you use a string it wont interfere with other gui systems that use hashtables
 

skyblader

You're living only because it's illegal killing.
Reaction score
159
Hmmm. Okay. I tried making the change, but I wouldn't know how to call it out in future. If I set it to key LBLength of key triggering unit, I won't be able to load it because LBLength won't be the same anymore. Other ways to do so?
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
if you used the text LBLength and did not reference the variable that would not change
 

skyblader

You're living only because it's illegal killing.
Reaction score
159
It would change if let's say, used together. For example, the first casting bar started, and while it's in progress, another casting bar starts, the LBLength would change. And that would screw up...
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
No, because its not the value of the variable that you are using to save it, its the name of the variable, basically its saved as this

12557634 (unit handle of the caster) of 4263134 (the handle of the text string you chose, as every letter has a number value) (i chose a random number)

it should not say
Trigger:
  • Hashtable - Save Something as (Key Casting unit) of LBLength in LBHashtable


it should say
Trigger:
  • Hashtable - Save Something as (Key Casting unit) of (Key LBLength) in LBHashtable
 

skyblader

You're living only because it's illegal killing.
Reaction score
159
Oh you mean the word itself, and not the value of the variable. In other words, I'll have to use different words for each value I'm saving?
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
yes, that way you would just be saving the information under your words, no1 else would use them, so if another hashtable was used it would be MUI and not overlap with any numbers they used, if they happened to use 0/1
 

skyblader

You're living only because it's illegal killing.
Reaction score
159
Alright, made the changes and made some minor improvements. Updated the triggers and map and included the change log in my post.
 

KaerfNomekop

Swim, fishies. Swim through the veil of steel.
Reaction score
612
1). The interval between changes is too long - if the unit is moving, the bar's movement is super bumpy.
2). I don't think buildings need a loading bar, since they already have one.
3). Every unit can only have one loading bar at the same time - new instances will overwrite the old ones.
More as I think of 'em. I could list plenty of changes to apply, but I don't think I should hijack your project.
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
you could do what pkmfrk was suggesting via a linked list
ie:
Variables Needed:
Integer array Next
Integer array Previous
Integer array RecycleList
Integer LastRecycled
Integer ListSize
Integer RecycleCount
Integer Allocated_Index
Whatever Variables You use

Getting the variable Indexes
Trigger:
  • Allocation
    • Events
    • Conditions
    • Actions
      • Set Allocated_Index = RecycleList[0]
      • If then else
        • If
          • Allocated_Index = 0
        • Then
          • Set ListSize = ListSize + 1
          • Set Allocated_Index = ListSize
        • Else
          • Set RecycleList[0] = RecycleList[Allocated_Index]
          • Set RecycleList[Allocated_Index] = 0
      • Set Previous[Allocated_Index] = Previous[0]
      • Set Next[Allocated_Index] = 0
      • Set Next[Previous[0]] = Allocated_Index
      • Set Previous[0] = Allocated_Index
      • Set ListCount = ListCount + 1

Getting a variable index and using it
Trigger:
  • Actions
    • Trigger - Run Allocation <gen>
    • Set Variable[Allocated_Index] = Whatever you save it to

Going through the list and doing actions
Trigger:
  • Actions
    • Set Temp_Integer[1] = Previous[0]
    • For Each Integer A from 1 to ListCount do actions
      • Loop - Actions
        • If Then Else
          • If
            • Temp_Integer[1] Does not equal 0
          • Then
            • Do your Actions for the castbar useing Temp_Integer[1] as the index for the variables <--------
          • Else
        • Set Temp_Integer[2] = Temp_Integer[1]
        • Set Temp_Integer = Previous[Temp_Integer[1]]
        • If Then Else
          • If
            • Your Variables, using the Temp_Integer[2] Index, Meet your removal criteria (castbar finished or they stop/are interupted)
          • Then
            • Trigger - Run Deallocation
          • Else

Deleting the information (removing a link in the list)
Trigger:
  • Deallocation
    • Events
    • Conditions
    • Actions
      • Set Previous[Next[Temp_Integer[2]]] = Previous[Temp_Integer[2]]
      • Set Next[Previous[Temp_Integer[2]]] = Next[Temp_Integer[2]]
      • Set RecycleList[LastRecycled] = Temp_Integer[2]
      • Set LastRecycled = Temp_Integer[2]
      • Set ListCount = ListCount - 1

Thats basically how a linked list is used
Next Points to the next integer in the list
previous points to the previous

Its like a Unit Group that can store any information you want and can have multiple copies of one unit in the unit group
 

skyblader

You're living only because it's illegal killing.
Reaction score
159
1). The interval between changes is too long - if the unit is moving, the bar's movement is super bumpy.
2). I don't think buildings need a loading bar, since they already have one.
3). Every unit can only have one loading bar at the same time - new instances will overwrite the old ones.
More as I think of 'em. I could list plenty of changes to apply, but I don't think I should hijack your project.

1) I tried making it faster, but the bar becomes too long and it glitches a little. Maybe you can shine some light here?
2) It's just an option, the testing was given just in case people wanted to use it for buildings, for whatever reason. (And it shows the true building time, even if units are hitting it while it's building)
3) I'm working on it at the moment, getting help from GFreak as to how to do it. Will edit this post when I'm done, or bump if its 24 hours from now.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top