Name | Type | is_array | initial_value |
library TasAbilityChargeBox requires optional FrameLoader
// TasAbilityChargeBox V1 by Tasyen
//Adds a custom ChargeBox over Command Buttons to display a Number
//requires loading a fdf/toc containing "TasAbilityChargeBox"
//incorrect display when commandbutton Positions colide or in Group selection
//function TasAbilityChargeBox.SetValue(unit, spellCode, value)
//enforce a wanted Value for that spellCode for unit
//function TasAbilityChargeBox.GetValue(unit, spellCode)
//function TasAbilityChargeBox.Clear(unit)
//function TasAbilityChargeBox.Init()
globals
public unit array Unit
public real UpdateIntervale = 0.2
public hashtable Hash
public string TocPath ="war3mapImported/TasAbilityChargeBox.toc"
endglobals
public function GetUnitSpellCodeKey takes integer unitId, integer spellCode returns integer
local integer count = LoadInteger(Hash, unitId, 0)
local integer loopA = 0
loop
set loopA = loopA + 1
exitwhen loopA > count
if LoadInteger(Hash, unitId, loopA) == spellCode then
return loopA
endif
endloop
set count = count + 1
call SaveInteger(Hash, unitId, 0, count)
call SaveInteger(Hash, unitId, count, spellCode)
return count
endfunction
public function SetValue takes unit u, integer spellCode, string value returns nothing
local integer unitId = GetHandleId(u)
call GetUnitSpellCodeKey(unitId, spellCode)
call SaveStr(Hash, unitId, spellCode, value)
endfunction
public function GetValue takes unit u, integer spellCode returns string
return LoadStr(Hash, GetHandleId(u), spellCode)
endfunction
public function Clear takes unit u returns nothing
call FlushChildHashtable(Hash, GetHandleId(u))
endfunction
public function Update takes nothing returns nothing
local unit u = Unit[GetPlayerId(GetLocalPlayer())]
local integer unitId = GetHandleId(u)
local integer i = 0
local integer pos
local integer spellCode
loop
exitwhen i > 11
call BlzFrameSetVisible(BlzGetFrameByName("TasAbilityChargeBox", i), false)
set i = i + 1
endloop
// One wants to display something specific?
set i = LoadInteger(Hash, unitId, 0)
loop
exitwhen i <= 0
set spellCode = LoadInteger(Hash, unitId, i)
set pos = BlzGetAbilityPosX(spellCode)+ BlzGetAbilityPosY(spellCode)*4
call BlzFrameSetVisible(BlzGetFrameByName("TasAbilityChargeBox", pos), true)
call BlzFrameSetText(BlzGetFrameByName("TasAbilityChargeBoxText", pos), LoadStr(Hash, unitId, spellCode))
set i = i - 1
endloop
set u = null
endfunction
private function Create takes nothing returns nothing
local framehandle frame
local integer i = 0
call BlzLoadTOCFile(TocPath)
loop
exitwhen i > 11
set frame = BlzCreateSimpleFrame("TasAbilityChargeBox", BlzGetOriginFrame(ORIGIN_FRAME_COMMAND_BUTTON, i), i)
// reserve HandleId, used Async later
call BlzGetFrameByName("TasAbilityChargeBoxText", i)
call BlzFrameSetVisible(frame, false)
set i = i + 1
endloop
if GetHandleId(frame) == 0 then
call BJDebugMsg("TasAbilityChargeBox - Error Creating Frames")
endif
endfunction
public function Select takes nothing returns nothing
set Unit[GetPlayerId(GetTriggerPlayer())] = GetTriggerUnit()
endfunction
public function Init takes nothing returns nothing
local trigger trig
call TimerStart(CreateTimer(), UpdateIntervale, true, function Update)
call Create()
static if LIBRARY_FrameLoader then
call FrameLoaderAdd(function Create)
endif
set trig = CreateTrigger()
call TriggerAddAction(trig, function Select)
call TriggerRegisterAnyUnitEventBJ(trig, EVENT_PLAYER_UNIT_SELECTED)
set Hash = InitHashtable()
endfunction
endlibrary