jass基礎(chǔ)-倉(cāng)庫(kù)UI

#include "../../jass/BlizzardAPI.j"
library demo initializer test
???// 倉(cāng)庫(kù)UI
???globals
???????Storage sto
???endglobals
???struct Storage
???????integer parentUI?// 父UI
???????integer backUI??// 背景圖
???????integer array cellArr[100]?// 格子
???????real cellSize?// 格子的大小(長(zhǎng)寬)
???????real borderSize // 邊框大小
???????integer row?// 橫向格子數(shù)
???????integer col?// 縱向格子數(shù)
???????string backStr = ""?// 背景圖路徑
???????string cellStr = "ReplaceableTextures\\PassiveButtons\\PASBTNStatUp.blp" // 格子圖路徑
???????public static method create takes integer row, integer col, real cellSize, real borderSize returns thistype
???????????local Storage this = Storage.allocate()
???????????set this.row = row
???????????set this.col = col
???????????set this.cellSize = cellSize
???????????set this.borderSize = borderSize
???????????return this
???????endmethod
???endstruct
???function storageInit takes nothing returns nothing
???????local integer i = 0
???????local integer j = 0
???????local integer index
???????set sto = Storage.create(10, 6, 0.03, 0.01)
???????set sto.parentUI = DzCreateFrameByTagName("FRAME", "", DzGetGameUI(), "", 0)
???????call DzFrameSetAbsolutePoint(sto.parentUI, 6, 0.2, 0.2)
???????call DzFrameSetSize(sto.parentUI, 2 * sto.borderSize + sto.row * sto.cellSize, 2 * sto.borderSize + sto.col * sto.cellSize)
???????set sto.backUI = DzCreateFrameByTagName("BACKDROP", "", sto.parentUI, "", 0)
???????call DzFrameSetPoint(sto.backUI, 6, sto.parentUI, 6, 0, 0)
???????call DzFrameSetSize(sto.backUI, 2 * sto.borderSize + sto.row * sto.cellSize, 2 * sto.borderSize + sto.col * sto.cellSize)
???????call DzFrameSetTexture(sto.backUI, sto.backStr, 0)
???????loop
???????????exitwhen i >= sto.col
???????????loop
???????????????exitwhen j >= sto.row
???????????????set index = j + i * sto.row
???????????????set sto.cellArr[index] = DzCreateFrameByTagName("BACKDROP", "", sto.backUI, "", 0)
???????????????call DzFrameSetPoint(sto.cellArr[index], 6, sto.backUI, 6, sto.borderSize + j * sto.cellSize, sto.borderSize + i * sto.cellSize)
???????????????call DzFrameSetSize(sto.cellArr[index], sto.cellSize, sto.cellSize)
???????????????call DzFrameSetTexture(sto.cellArr[index], sto.cellStr, 0)
???????????????set j = j + 1
???????????endloop
???????????set j = 0
???????????set i = i + 1
???????endloop
???endfunction
???function doSomething takes nothing returns nothing
???????call storageInit()
???endfunction
???function triggerInit takes nothing returns nothing
???????local trigger t = CreateTrigger()
???????call TriggerRegisterPlayerChatEvent(t, Player(0), "1", true)
???????call TriggerAddAction(t, function doSomething)
???????set t = null
???endfunction
???function gameInit takes nothing returns nothing
???????local unit u = CreateUnit(Player(0), 'hfoo', 0, 0, 0)
???????local unit u2 = CreateUnit(Player(0), 'hrif', 100, 100, 0)
???????call FogEnable(false)
???????call FogMaskEnable(false)
???endfunction
???function test takes nothing returns nothing
???????call gameInit()
???????call triggerInit()
???endfunction
endlibrary