System Bars

Sevion

The DIY Ninja
Reaction score
413
Bars
1.0.0.2
By Sevion

4+ Builders in Construction Mode is broken atm.
Uses StringColors and T32xs.
Update 1.0.0.3 will add more security to the construction detection.

Docs
  • What Bars does:
    Bars creates an easy method to create custom bars for almost ANY purpose!
  • How Bars was made:
    Basically, I got bored. And with StringColors created, I wanted to do something using that system.

  • Creating a Bar at a Location:

    • [ljass]local Bar myBar = Bar.createOnLocation(loc, TRACK_TYPE_CUSTOM1, Color.create(200,50,50), Color.create(10,10,10), 100)[/ljass]
  • Creating a Bar on a Unit:

    • [ljass]local Bar myBar = Bar.createOnUnit(Unit, TRACK_TYPE_HEALTH, Color.create(0,255,0), Color.create(10,10,10), 0)[/ljass]
  • Creating a Bar on an Item:

    • [ljass]local Bar myBar = Bar.createOnItem(Item, TRACK_TYPE_CUSTOM1, Color.create(200,50,50), Color.create(10,10,10), 100)[/ljass]
  • Creating a Bar on a Destructable:

    • [ljass]local Bar myBar = Bar.createOnDestructable(Destructable, TRACK_TYPE_HEALTH, Color.create(0,255,0), Color.create(10,10,10), 0)[/ljass]
  • Setting the maximum for a Custom Bar:

    • [ljass]set myBar.maximum = 100[/ljass]

JASS:
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~ Bars ~~ By Sevion ~~ Version 1.0.0.2 ~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//  What is Bars?
//          -An easy way to create floating status bars for almost anything
//           without removing any advanced features and power.
//
// Configurables:
    //! textmacro Bar__CONFIGURABLE_GLOBALS
        private constant string BAR_CHAR = "'"
        private constant integer NUM_CHARS = 30
        private constant integer NUM_CHARS_CONSTRUCTION = 80
        private constant real BAR_SIZE = 11.00
        private constant real X_OFFSET = -35.00
        private constant real Y_OFFSET = -40.00
        private constant real Y_OFFSET_MANA = -14.00
        private constant real X_OFFSET_CONSTRUCTION = -65.00
        private constant real Y_OFFSET_CONSTRUCTION = -40.00
        private constant real X_OFFSET_CUSTOM1 = -35.00
        private constant real Y_OFFSET_CUSTOM1 = -40.00
        private constant real X_OFFSET_CUSTOM2 = -35.00
        private constant real Y_OFFSET_CUSTOM2 = -40.00
        private constant real X_OFFSET_CUSTOM3 = -35.00
        private constant real Y_OFFSET_CUSTOM3 = -40.00
        private constant integer BACKGROUND_RED = 10
        private constant integer BACKGROUND_GREEN = 10
        private constant integer BACKGROUND_BLUE = 10
    //! endtextmacro
    
    //! textmacro Bar__GetCustomData1
        set i = GetUnitUserData(this.unit)
    //! endtextmacro
    //! textmacro Bar__Custom1EndCondition
        set b = this.max - 1 < T32_PERIOD
    //! endtextmacro
    //! textmacro Bar__GetCustomData2
        set i = GetUnitUserData(this.unit)
    //! endtextmacro
    //! textmacro Bar__Custom2EndCondition
        set b = this.max - 1 < T32_PERIOD
    //! endtextmacro
    //! textmacro Bar__GetCustomData3
        set i = GetUnitUserData(this.unit)
    //! endtextmacro
    //! textmacro Bar__Custom3EndCondition
        set b = this.max - 1 < T32_PERIOD
    //! endtextmacro
//
//  API:
//          -globals
//              -constant integer TRACK_TYPE_HEALTH = 0
//                  TrackType to pass for health tracking.
//
//              -constant integer TRACK_TYPE_MANA = 1
//                  TrackType to pass for mana tracking.
//
//              -constant integer TRACK_TYPE_CONSTRUCTION = 2
//                  TrackType to pass for construction tracking.
//
//              -constant integer TRACK_TYPE_CUSTOM1 = 3
//                  TrackType to pass for custom 1 tracking.
//
//              -constant integer TRACK_TYPE_CUSTOM2 = 4
//                  TrackType to pass for custom 2tracking.
//
//              -constant integer TRACK_TYPE_CUSTOM3 = 5
//                  TrackType to pass for custom 3 tracking.
//
//          -struct Bar extends array
//              -location location
//                  Location of the bar (in location mode).
//
//              -unit unit
//                  Unit of the bar (in unit mode).
//
//              -item item
//                  Item of the bar (in item mode).
//
//              -destructable destructable
//                  Destructable of the bar (in destructable mode).
//
//              -integer maximum
//                  Maximum value of the bar (in custom mode).
//
//              -static method createOnLocation takes location whichLocation, integer trackType, Color Color1, Color Color2, integer maximum returns thistype
//                  Creates a bar at a location with a tracktype, colors, and a maximum (in the case of custom).
//
//              -static method createOnUnit takes unit whichUnit, integer trackType, Color Color1, Color Color2, integer maximum returns thistype
//                  Creates a bar on a unit with a tracktype, colors, and a maximum (in the case of custom).
//
//              -static method createOnItem takes item whichItem, integer trackType, Color Color1, Color Color2, integer maximum returns thistype
//                  Creates a bar on an item with a tracktype, colors, and a maximum (only custom tracking).
//
//              -static method createOnDestructable takes destructable whichDestructable, integer trackType, Color Color1, Color Color2, integer maximum returns thistype
//                  Creates a bar on a destructable with a tracktype, colors, and a maximum (in the case of custom).
//
//              -method destroy takes nothing returns nothing
//                  Destroys the bar and cleans out leaks. Note: This does not autodestroy colors!
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
native GetUnitBuildTime     takes integer unitid                        returns integer
native UnitAlive            takes unit unitid                           returns boolean
library Bars uses StringColors, T32
    globals
        constant integer TRACK_TYPE_HEALTH = 0
        constant integer TRACK_TYPE_MANA = 1
        constant integer TRACK_TYPE_CONSTRUCTION = 2
        constant integer TRACK_TYPE_CUSTOM1 = 3
        constant integer TRACK_TYPE_CUSTOM2 = 4
        constant integer TRACK_TYPE_CUSTOM3 = 5
        //! runtextmacro Bar__CONFIGURABLE_GLOBALS()
        private string array Text
    endglobals
    
    private struct ValueType extends array
        public static constant integer HEALTH = 0
        public static constant integer MANA = 1
        public static constant integer CONSTRUCTION = 2
        public static constant integer CUSTOM1 = 3
        public static constant integer CUSTOM2 = 4
        public static constant integer CUSTOM3 = 5
    endstruct
    
    private struct DataType extends array
        public static constant integer LOCATION = 0
        public static constant integer UNIT = 1
        public static constant integer ITEM = 2
        public static constant integer DESTRUCTABLE = 3
    endstruct
    
    struct Bar extends array
        private static integer instanceCount = 0
        private static integer array recycle
        private static integer recycleCount = 0
        private static hashtable hash
        private static Color background
        private Color Mixed
        private integer max
        private DataType type
        private texttag tag
        private string string
        private ValueType track
        private integer tracked
        private Color Color1
        private Color Color2
        private boolean autoDestroy
        public location location
        public unit unit
        public item item
        public destructable destructable
        
        private method periodic takes nothing returns nothing
            local integer id = GetHandleId(this.unit)
            local real tick
            local integer count
            local integer i = 0
            local integer m = 0
            local boolean b
            local real ratio = 0
            if ( this.type == DataType.LOCATION ) then
                call SetTextTagVisibility(this.tag, IsLocationVisibleToPlayer(this.location, GetLocalPlayer()))
                call SetTextTagPos(this.tag, GetLocationX(this.location) + X_OFFSET, GetLocationY(this.location) + Y_OFFSET, 200)
            elseif ( this.type == DataType.UNIT ) then
                call SetTextTagVisibility(this.tag, IsUnitVisible(this.unit, GetLocalPlayer()))
                if ( this.track == ValueType.HEALTH or this.track == ValueType.CUSTOM1 or this.track == ValueType.CUSTOM2 or this.track == ValueType.CUSTOM3 ) then
                    call SetTextTagPos(this.tag, GetUnitX(this.unit) + X_OFFSET, GetUnitY(this.unit) + Y_OFFSET, 200)
                elseif ( this.track == ValueType.MANA ) then
                    call SetTextTagPos(this.tag, GetUnitX(this.unit) + X_OFFSET, GetUnitY(this.unit) + Y_OFFSET + Y_OFFSET_MANA, 200)
                elseif ( this.track == ValueType.CONSTRUCTION ) then
                    call SetTextTagPos(this.tag, GetUnitX(this.unit) + X_OFFSET + X_OFFSET_CONSTRUCTION, GetUnitY(this.unit) + Y_OFFSET_CONSTRUCTION, 200)
                endif
            elseif ( this.type == DataType.ITEM ) then
                call SetTextTagVisibility(this.tag, IsVisibleToPlayer(GetItemX(this.item), GetItemY(this.item), GetLocalPlayer()))
                call SetTextTagPos(this.tag, GetItemX(this.item) + X_OFFSET, GetItemY(this.item) + Y_OFFSET, 200)
            elseif ( this.type == DataType.DESTRUCTABLE ) then
                call SetTextTagVisibility(this.tag, IsVisibleToPlayer(GetDestructableX(this.destructable), GetDestructableY(this.destructable), GetLocalPlayer()))
                call SetTextTagPos(this.tag, GetDestructableX(this.destructable) + X_OFFSET, GetDestructableY(this.destructable) + Y_OFFSET, 200)
            endif
            if ( this.track == ValueType.HEALTH ) then
                if ( this.type == DataType.UNIT ) then
                    set ratio = GetUnitState(this.unit, UNIT_STATE_LIFE) / GetUnitState(this.unit, UNIT_STATE_MAX_LIFE)
                    set i = R2I(NUM_CHARS * ratio + 0.5)
                elseif ( this.type == DataType.DESTRUCTABLE ) then
                    set ratio = GetDestructableLife(this.destructable) / GetDestructableMaxLife(this.destructable)
                    set i = R2I(NUM_CHARS * GetDestructableLife(this.destructable) / GetDestructableMaxLife(this.destructable) + 0.5)
                endif
            elseif ( this.track == ValueType.MANA ) then
                set ratio = GetUnitState(this.unit, UNIT_STATE_MANA) / GetUnitState(this.unit, UNIT_STATE_MAX_MANA)
                set i = R2I(NUM_CHARS * ratio + 0.5)
            elseif ( this.track == ValueType.CONSTRUCTION ) then
                set tick = LoadReal(thistype.hash, id, 0)
                if ( GetUnitBuildTime(GetUnitTypeId(this.unit)) - tick < T32_PERIOD or this.unit == null or not UnitAlive(this.unit) ) then
                    set this.autoDestroy = true
                    set i = 0
                else
                    set count = LoadInteger(thistype.hash, id, 1)
                    if ( count == 1 ) then
                        call SaveReal(thistype.hash, id, 0, tick + T32_PERIOD)
                    elseif ( count == 2 ) then
                        call SaveReal(thistype.hash, id, 0, tick + T32_PERIOD * 1.592859695 )
                    elseif ( count == 3 ) then
                        call SaveReal(thistype.hash, id, 0, tick + T32_PERIOD * 2.185)
                    endif
                    set ratio = LoadReal(thistype.hash, id, 0) / GetUnitBuildTime(GetUnitTypeId(this.unit))
                    set i = R2I(NUM_CHARS_CONSTRUCTION * ratio + 0.5)
                endif
            elseif ( this.track == ValueType.CUSTOM1 ) then
                call SetTextTagPos(this.tag, GetLocationX(this.location) + X_OFFSET_CUSTOM1, GetLocationY(this.location) + Y_OFFSET_CUSTOM1, 200)
                //! runtextmacro Bar__GetCustomData1()
                set ratio = i / this.max
                set i = R2I(NUM_CHARS * ratio + 0.5)
                //! runtextmacro Bar__Custom1EndCondition()
                if ( b ) then
                    set this.autoDestroy = true
                endif
            elseif ( this.track == ValueType.CUSTOM2 ) then
                call SetTextTagPos(this.tag, GetLocationX(this.location) + X_OFFSET_CUSTOM2, GetLocationY(this.location) + Y_OFFSET_CUSTOM2, 200)
                //! runtextmacro Bar__GetCustomData2()
                set ratio = i / this.max
                set i = R2I(NUM_CHARS * ratio + 0.5)
                //! runtextmacro Bar__Custom2EndCondition()
                if ( b ) then
                    set this.autoDestroy = true
                endif
            elseif ( this.track == ValueType.CUSTOM3 ) then
                call SetTextTagPos(this.tag, GetLocationX(this.location) + X_OFFSET_CUSTOM3, GetLocationY(this.location) + Y_OFFSET_CUSTOM3, 200)
                //! runtextmacro Bar__GetCustomData3()
                set ratio = i / this.max
                set i = R2I(NUM_CHARS * ratio + 0.5)
                //! runtextmacro Bar__Custom3EndCondition()
                if ( b ) then
                    set this.autoDestroy = true
                endif
            endif
            if ( this.track == ValueType.CONSTRUCTION ) then
                set m = NUM_CHARS_CONSTRUCTION - i
            else
                set m = NUM_CHARS - i
            endif
            if ( this.Mixed == 0 ) then
                set this.Mixed = Color.create(0,0,0)
            endif
            if ( this.Color1 != 0 ) then
                set this.Mixed.red = R2I(RAbsBJ(this.Color1.red*(1-ratio)-this.Color2.red*ratio)+.5)
                set this.Mixed.green = R2I(RAbsBJ(this.Color1.green*(1-ratio)-this.Color2.green*ratio)+.5)
                set this.Mixed.blue = R2I(RAbsBJ(this.Color1.blue*(1-ratio)-this.Color2.blue*ratio)+.5)
            else
                set this.Mixed = this.Color2
            endif
            call SetTextTagText(this.tag, this.Mixed.apply(Text<i>) + thistype.background.apply(Text[m]), BAR_SIZE * 0.023 / 10)
            if ( this.autoDestroy ) then
                call this.stopPeriodic()
                call this.destroy()
            endif
        endmethod
        
        implement T32xs
        
        public method operator maximum takes nothing returns integer
            debug if ( this.trackType != ValueType.CUSTOM1 and this.trackType != ValueType.CUSTOM2 and this.trackType != ValueType.CUSTOM3 ) then
                debug call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, &quot;Error (Bar): Cannot geta maximum for a non-custom tracking type!&quot;)
                debug return 0
            debug endif
            return this.maximum
        endmethod
        
        public method operator maximum= takes integer maximum returns nothing
            debug if ( this.trackType != ValueType.CUSTOM1 and this.trackType != ValueType.CUSTOM2 and this.trackType != ValueType.CUSTOM3 ) then
                debug call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, &quot;Error (Bar): Cannot set a maximum for a non-custom tracking type!&quot;)
                debug return
            debug endif
            set this.max = maximum
        endmethod
        
        public static method createOnLocation takes location whichLocation, integer trackType, Color Color1, Color Color2, integer maximum returns thistype
            local thistype this
            
            debug if ( trackType != ValueType.Custom1 and trackType != ValueType.Custom2 and trackType != ValueType.Custom3 ) then
                debug call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, &quot;Error (Bar): Cannot track Health/Mana/Construction of a location!&quot;)
                return 0
            debug endif
           
            if (recycleCount != 0) then
                set recycleCount = recycleCount - 1
                set this = recycle[recycleCount]
            else
                set instanceCount = instanceCount + 1
                set this = instanceCount
            endif
            
            set this.tag = CreateTextTag()
            call SetTextTagPos(this.tag, GetLocationX(whichLocation) + X_OFFSET, GetLocationY(whichLocation) + Y_OFFSET, 200)
            call SetTextTagPermanent(this.tag, true)
            call SetTextTagVisibility(this.tag, IsLocationVisibleToPlayer(whichLocation, GetLocalPlayer()))
            
            set this.Color1 = Color1
            set this.Color2 = Color2
            
            if ( trackType == ValueType.CUSTOM1 or trackType == ValueType.CUSTOM2 or trackType == ValueType.CUSTOM3 ) then
                set this.max = maximum
            endif
            
            //call SaveInteger(thistype.hash, GetHandleId(whichLocation), 0, this)
            
            set this.location = whichLocation
            set this.type = DataType.LOCATION
            set this.track = trackType
            
            call this.startPeriodic()
            
            call RemoveLocation(whichLocation)
            set whichLocation = null
            
            return this
        endmethod
        
        public static method createOnUnit takes unit whichUnit, integer trackType, Color Color1, Color Color2, integer maximum returns thistype
            local thistype this
            
            debug if ( trackType == ValueType.MANA and GetUnitState(whichUnit, UNIT_STATE_MAX_MANA) == 0 ) then
                debug call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, &quot;Error (Bar): Cannot track Mana of a non-mana unit!&quot;)
                debug return 0
            debug endif
           
            if (recycleCount != 0) then
                set recycleCount = recycleCount - 1
                set this = recycle[recycleCount]
            else
                set instanceCount = instanceCount + 1
                set this = instanceCount
            endif
            
            if ( trackType == ValueType.CONSTRUCTION ) then
                call SaveReal(thistype.hash, GetHandleId(whichUnit), 0, 0)
            endif
            
            set this.tag = CreateTextTag()
            call SetTextTagPos(this.tag, GetUnitX(whichUnit) + X_OFFSET, GetUnitY(whichUnit) + Y_OFFSET, 200)
            call SetTextTagPermanent(this.tag, true)
            call SetTextTagVisibility(this.tag, IsUnitVisible(whichUnit, GetLocalPlayer()))
            
            set this.Color1 = Color1
            set this.Color2 = Color2
            
            if ( trackType == ValueType.CUSTOM1 or trackType == ValueType.CUSTOM2 or trackType == ValueType.CUSTOM3 ) then
                set this.max = maximum
            endif
            
            call SaveInteger(thistype.hash, GetHandleId(whichUnit), 0, this)
            
            set this.unit = whichUnit
            set this.type = DataType.UNIT
            set this.track = trackType
            
            call this.startPeriodic()
            
            return this
        endmethod
        
        public static method createOnItem takes item whichItem, integer trackType, Color Color1, Color Color2, integer maximum returns thistype
            local thistype this
            
            debug if ( trackType != ValueType.CUSTOM1 and trackType != ValueType.CUSTOM2 and trackType != ValueType.CUSTOM3 ) then
                debug call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, &quot;Error (Bar): Cannot track Health/Mana/Construction of an item!&quot;)
                debug return 0
            debug endif
           
            if (recycleCount != 0) then
                set recycleCount = recycleCount - 1
                set this = recycle[recycleCount]
            else
                set instanceCount = instanceCount + 1
                set this = instanceCount
            endif
            
            set this.tag = CreateTextTag()
            call SetTextTagPos(this.tag, GetItemX(whichItem) + X_OFFSET, GetItemY(whichItem) + Y_OFFSET, 200)
            call SetTextTagPermanent(this.tag, true)
            call SetTextTagVisibility(this.tag, IsVisibleToPlayer(GetItemX(whichItem), GetItemY(whichItem), GetLocalPlayer()))
            
            set this.Color1 = Color1
            set this.Color2 = Color2
            
            if ( trackType == ValueType.CUSTOM1 or trackType == ValueType.CUSTOM2 or trackType == ValueType.CUSTOM3 ) then
                set this.max = maximum
            endif
            
            call SaveInteger(thistype.hash, GetHandleId(whichItem), 0, this)
            
            set this.item = whichItem
            set this.type = DataType.ITEM
            set this.track = trackType
            
            call this.startPeriodic()
            
            return this
        endmethod
        
        public static method createOnDestructable takes destructable whichDestructable, integer trackType, Color Color1, Color Color2, integer maximum returns thistype
            local thistype this
            
            debug if ( trackType == ValueType.MANA or trackType == ValueType.CONSTRUCTION ) then
                debug call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, &quot;Error (Bar): Cannot track Mana/Construction of a destructable!&quot;)
                debug return 0
            debug endif
           
            if (recycleCount != 0) then
                set recycleCount = recycleCount - 1
                set this = recycle[recycleCount]
            else
                set instanceCount = instanceCount + 1
                set this = instanceCount
            endif
            
            set this.tag = CreateTextTag()
            call SetTextTagPos(this.tag, GetDestructableX(whichDestructable) + X_OFFSET, GetDestructableY(whichDestructable) + Y_OFFSET, 200)
            call SetTextTagPermanent(this.tag, true)
            call SetTextTagVisibility(this.tag, IsVisibleToPlayer(GetDestructableX(whichDestructable), GetDestructableY(whichDestructable), GetLocalPlayer()))
            
            set this.Color1 = Color1
            set this.Color2 = Color2
            
            if ( trackType == ValueType.CUSTOM1 or trackType == ValueType.CUSTOM2 or trackType == ValueType.CUSTOM3 ) then
                set this.max = maximum
            endif
            
            //call SaveInteger(thistype.hash, GetHandleId(whichDestructable), 0, this)
            
            set this.destructable = whichDestructable
            set this.type = DataType.DESTRUCTABLE
            set this.track = trackType
            
            call this.startPeriodic()
            
            return this
        endmethod
       
        public method destroy takes nothing returns nothing
            call DestroyTextTag(this.tag)
            set this.tag = null
            if ( this.location != null ) then
                call RemoveLocation(this.location)
                set this.location = null
            endif
            set this.unit = null
            set this.item = null
            set recycle[recycleCount] = this
            set recycleCount = recycleCount + 1
        endmethod
    
        // Item Management
        private static trigger itemDrop = CreateTrigger()
        private static trigger itemPickUp = CreateTrigger()
           
        private static method itemDropC takes nothing returns boolean
            local thistype this = LoadInteger(thistype.hash, GetHandleId(GetManipulatedItem()), 0)
            set this.type = DataType.ITEM
            set this.unit = null
            return false
        endmethod
           
        private static method itemPickUpC takes nothing returns boolean
            local thistype this = LoadInteger(thistype.hash, GetHandleId(GetManipulatedItem()), 0)
            set this.type = DataType.UNIT
            set this.unit = GetTriggerUnit()
            return false
        endmethod
        
        // Construction Management
        private static trigger stopBuild = CreateTrigger()
        private static trigger startBuild = CreateTrigger()
        
        private static method stopBuildC takes nothing returns boolean
            local integer tid = GetHandleId(GetTriggerUnit())
            local thistype this = LoadInteger(thistype.hash, tid, 2)
            local integer uid = GetHandleId(this.unit)
            if ( this.unit == GetOrderTargetUnit() ) then
                return false
            endif
            call SaveInteger(thistype.hash, uid, 1, LoadInteger(thistype.hash, uid, 1) - 1)
            if ( LoadInteger(thistype.hash, uid, 1) == 0 ) then
                call this.stopPeriodic()
            endif
            call SaveInteger(thistype.hash, tid, 2, 0)
            return false
        endmethod
        
        private static method startBuildC takes nothing returns boolean
            local thistype this = LoadInteger(thistype.hash, GetHandleId(GetOrderTargetUnit()), 0)
            local integer id = GetHandleId(this.unit)
            if ( not HaveSavedInteger(thistype.hash, id, 1) ) then
                call SaveInteger(thistype.hash, id, 1, 0)
            endif
            call SaveInteger(thistype.hash, id, 1, LoadInteger(thistype.hash, id, 1) + 1)
            call this.startPeriodic()
            call SaveInteger(thistype.hash, GetHandleId(GetTriggerUnit()), 2, this)
            return false
        endmethod
           
        private static method onInit takes nothing returns nothing
            local integer i = 16
            local integer n
               
            loop
                set i = i -1
                call TriggerRegisterPlayerUnitEvent(thistype.itemDrop, Player(i), EVENT_PLAYER_UNIT_DROP_ITEM, null)
                call TriggerRegisterPlayerUnitEvent(thistype.itemPickUp, Player(i), EVENT_PLAYER_UNIT_PICKUP_ITEM, null)
                call TriggerRegisterPlayerUnitEvent(thistype.stopBuild, Player(i), EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER, null)
                call TriggerRegisterPlayerUnitEvent(thistype.startBuild, Player(i), EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER, null)
                call TriggerRegisterPlayerUnitEvent(thistype.stopBuild, Player(i), EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER, null)
                exitwhen i == 0
            endloop
               
            call TriggerAddCondition(thistype.itemDrop, Condition(function thistype.itemDropC))
            call TriggerAddCondition(thistype.itemPickUp, Condition(function thistype.itemPickUpC))
               
            call TriggerAddCondition(thistype.stopBuild, Condition(function thistype.stopBuildC))
            call TriggerAddCondition(thistype.startBuild, Condition(function thistype.startBuildC))
            
            set i = NUM_CHARS_CONSTRUCTION
            
            loop
                exitwhen i == 0
                set n = i
                loop
                    exitwhen n == 0
                    set Text<i> = Text<i> + BAR_CHAR
                    set n = n -1
                endloop
                set i = i - 1
            endloop
            
            set thistype.background = Color.create(BACKGROUND_RED, BACKGROUND_GREEN, BACKGROUND_BLUE)
            
            set thistype.hash = InitHashtable()
        endmethod
    endstruct
endlibrary</i></i></i>


Change Log
1.0.0.2 said:
Removed an O(n) generation that I missed.
1.0.0.1 said:
Fixed textmacro bug when AdicParser is disabled, removed multibuilder boolean
1.0.0.0 said:
Initial Release

Demo
JASS:
scope Tests initializer initTest
    private function construct takes nothing returns nothing
        call Bar.createOnUnit(GetConstructingStructure(), TRACK_TYPE_CONSTRUCTION, Color.create(255,0,0), Color.create(0,255,0), 0)
    endfunction
    private function enter takes nothing returns nothing
        if ( IsUnitType(GetTriggerUnit(), UNIT_TYPE_STRUCTURE) ) then
            return
        endif
        call Bar.createOnUnit(GetTriggerUnit(), TRACK_TYPE_HEALTH, 0, Color.create(0,255,0), 0)
        if ( IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO ) ) then
            call Bar.createOnUnit(GetTriggerUnit(), TRACK_TYPE_MANA, 0, Color.create(0,0,255), 0)
        endif
    endfunction
    
    private function initTest takes nothing returns nothing
        local trigger t = CreateTrigger()
        local region world = CreateRegion()
        call RegionAddRect(world, GetWorldBounds())
        call TriggerRegisterEnterRegion(t, world, null)
        call TriggerAddAction(t, function enter)
        set t = CreateTrigger()
        call TriggerRegisterPlayerUnitEvent(t, Player(0), EVENT_PLAYER_UNIT_CONSTRUCT_START, null)
        call TriggerAddAction(t, function construct)
        call Cheat(&quot;greedisgood 9999999&quot;)
        call CreateUnit(Player(0), &#039;Hpal&#039;, 0, 0, 0)
        call CreateUnit(Player(0), &#039;hpea&#039;, 0, 0, 0)
        call CreateUnit(Player(0), &#039;hpea&#039;, 0, 0, 0)
        call CreateUnit(Player(0), &#039;hpea&#039;, 0, 0, 0)
        call BJDebugMsg(&quot;Warning: Warpten Cheat Breaks Construction ATM!&quot;)
    endfunction
endscope
 

Attachments

  • Bars Demo.w3m
    35.4 KB · Views: 312

Romek

Super Moderator
Reaction score
963
Post a demo map, and post demo code in separate JASS tags.
 

Sevion

The DIY Ninja
Reaction score
413
List T32 requirement, also. :)
(Always nice to see it in there...)

Bleh. I always forget to do that. Will do after work.

I'm starting to forget because I usually hard code it now >_<

Will post demo after work. In like 4 hours.

Version 1.0.0.1 Posted!

Demo Map Added with Demo Code!

Change Log Implemented Into Post!
 

Sevion

The DIY Ninja
Reaction score
413
1) I don't like the way it looks and it only allows locking to units.
2) Once again, you only allow locking to units and you force the user to have to manually work the system.
3) It's in Zinc (apparently It's in X is a valid argument now-a-days.)
 

Deaod

Member
Reaction score
6
1.) You didnt look at all of them.
2.) At least the various libraries allow working with them to that extent.
3.) You didnt look at all of them.

Its not like redundancy is the only problem of this library.
This library is less than optimal efficiency-wise (generation of the bar is O(n), instead of O(1)).
 

Deaod

Member
Reaction score
6
JASS:
private method periodic takes nothing returns nothing
// ...
            loop
                exitwhen i == 0
                set s1 = s1 + BAR_CHAR
                set i = i - 1
            endloop
            loop
                exitwhen m == 0
                set s2 = s2 + BAR_CHAR
                set m = m - 1
            endloop
// ...
        endmethod
 

Romek

Super Moderator
Reaction score
963
> Demo Map Added with Demo Code!
Requires a username and password to download... Attach it to the post, instead of using an external site.
 

Sevion

The DIY Ninja
Reaction score
413
Fixed.

Edit:

Huh. That's weird. My FTP never required an account before... w/e. Uploading to post.
 

Deaod

Member
Reaction score
6
Now make the Bar length, the basic char of the bar and the offsets of the bar adjustable during run-time, and you almost have a decent copy of an already existing library. Except that you bundled stuff with your version that shouldnt be bundled with it. Sure, it may be convenient under certain conditions, but it adds fluff to the library and makes maintaining (even reading) its code a horror.

Seriously, why are so many people trying to recreate something thats already existing? Do it for learning purposes, but dont freaking publish it. Youre only going to create confusion and harm the process of standardization.
If youre really trying to do a better job than anyone before you, watch what they did and HOW. At least be about on par with every other competitor, but make sure you surpass them in certain (important) aspects.

"Don't fix what ain't broken."
 

Sevion

The DIY Ninja
Reaction score
413
Adjustable bar character during run-time? That's pointless..... and useless. You can't sit there and seriously tell me anyone would ever do that.

Bar length, perhaps. It's easy anyhow.

Create confusion and harm the process of standardization?

Are you trying to snuff out creativity?

And I really don't understand what you mean by confusion. That just doesn't make sense.
 

Deaod

Member
Reaction score
6
Not exactly adjusting at run-time (ie. some time after creating the bar), but when creating the bar (other people might want to use other characters for a bar like "|").

Are you trying to snuff out creativity?
No. If you go into more detail as to what made you think that, i may be able to give an explanation.

And I really don't understand what you mean by confusion.
Confusion over which library (of the many) to use.
 

Sevion

The DIY Ninja
Reaction score
413
1) Why would anyone ever want to use more than 1 character for each bar. Consistency looks better aesthetically.

2) "Standardization". You're basically saying you want one system for each thing. Meaning others won't even think about making systems for things even when they can make it better. Thus, snuffing out creativity.

3) People will just use the library that they 1) trust, 2) have used before, 3) are recommended to, 4) like, or 5) read through and understand is the best for their purposes.
 

Deaod

Member
Reaction score
6
1.) different chars for different bars.
2.) I want everyone to use what is best (ideally there should only be one library). I dont want to discourge people from thinking of better ways to do something. I dont want people NOT thinking about improving it. If you can improve it, go ahead, maybe start a discussion, maybe write your own library from scratch.
But let me stress this again: This library is not creative. Its worse than whats already available.
3.) If you have a few mediocre libraries and only one state-of-the-art library, the decision should be obvious, regarless of how you like it. If you have two (or more) equally good libraries, go with whichever you like more. Ideally, thats the decision process. The less libraries users will have to compare the less confusion will there be. Not every user is an expert or has enough knowledge to give an accurate account of which library is better. Also, not many will spend their time comparing all libraries themselves.
 

Sevion

The DIY Ninja
Reaction score
413
1) Again, why..... You haven't answered why anyone would ever do that.

2) So basically you want every library's advantages to be mixed into one big "uber"-library.

3) So you're saying every other library is mediocre except for this one state-of-the-art library. Which is that one?

I'm curious, why are you making this campaign to destroy all uploads here by trying to compare them to other systems on Hive?

Wouldn't it be better to give constructive criticism than to just keep saying "x system is better, why are you making this?"? (No I'm not trying to ignore your few suggestions that you did post here. For those I am thankful. The rest, I am not.)

Anyhow, anyone have any comments on this?
 

Rushhour

New Member
Reaction score
46
Looks nice :)
I noticed a "bug": Your construction bar grows even tough the builders are not actually constructing it. Just sent them to a point a little offset from the constructed building and right click the building. The time they walk towards it (in order to finish construction) is regarded as if they actually use their hammers ;)
 

Deaod

Member
Reaction score
6
1.) Do you want to write a library other people are going to use and build upon, or do you not? If you want to allow others to build upon your work, it would make sense to include the option of different basic chars. Not every bar has to look the same.
2.) No.
3.) No.

Why im making this campaign? Because i feel the libraries i comment on truly are redundant (and bad in some cases).

No, giving constructive criticism would be a waste of time. Tell me about one important feature this for example has, but NO OTHER library to date has.
 

Sevion

The DIY Ninja
Reaction score
413
@Rushhour, I know >_< The construction is tricky. You can't actually get a unit's construction progress. Only set it.

1) Perhaps they don't, but does anyone really want multiple bars that look different?
2 and 3) Then what can the best be described as?

One feature? It has construction. (Albiet it's broken in some places. It's still being fixed).
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top