- Joined
- Jun 21, 2012
- Messages
- 431
Hashtable version:
Newtable version:
JASS:
library MultiboardTools/*
*******************************************************************************************************
*
* MultiboardTools (hashtable version)
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
* v2.0.1.1
* by Thelordmarshall
*
*
* Manage your Multiboard without limits.
*
* set myBoard = Multiboard.create("my board title", rowCount, columnCount)
* set myBoard[0][1].text = GetPlayerName(somePlayer)
* set myBoard[0][1].icon = "some\\path\\icon.blp"
* set myBoard.display = GetLocalPlayer()==somePlayer
*
* API:
* ¯¯¯
* struct Icon extends array
*
* static method operator []= takes integer rawCode, string file returns nothing
* static method fromUnit takes unit u returns string
* static method fromItem takes item i returns string
*
* struct Multiboard extends array
*
* static method create takes string title, integer rows, integer cols returns Multiboard
* method destroy takes nothing returns nothing
*
* method operator [] takes integer id returns thistype
* - used for row and column
*
* method operator width= takes real width returns nothing
* method operator text= takes string text returns nothing
* method operator icon= takes string icon returns nothing
* method operator title takes nothing returns string
* method operator title= takes string s returns nothing
* method operator display takes nothing returns boolean
* method operator display= takes boolean b returns nothing
* method operator rows takes nothing returns integer
* method operator rows= takes integer i returns nothing
* method operator columns takes nothing returns integer
* method operator columns= takes integer i returns nothing
* method operator minimize takes nothing returns boolean
* method operator minimize= takes boolean b returns nothing
*
* method clear takes nothing returns nothing
* method setStyle takes boolean showValue, boolean showIcon returns nothing
*
* Credits:
* ¯¯¯¯¯¯¯
* - Bribe: for suggest me to add Icon API into this library
* - PurgeandFire: notice me of Multiboard row glitch
*
*******************************************************************************************************/
//CONFIGURATION
//=================================================================================
globals
private constant integer MAX_RESOLUTION_X = 60 //Multiboard max columns count
private constant integer MAX_RESOLUTION_Y = 60 //Multiboard max rows count
endglobals
//=================================================================================
globals
private integer keySize=0
private integer instance=0
private integer rowIndex=0
private integer colIndex=0
private integer loopSize=0
private integer resolution=0
private boolean getCache=false
private boolean boardShowValue=false
private boolean boardShowIcon=false
private boolean columnIndexer=false
private boolean configBoardStyle=false
private integer array list
private hashtable cache=InitHashtable()
endglobals
private module Init
static method onInit takes nothing returns nothing
set list[0]=1
endmethod
endmodule
private struct a extends array
implement Init
endstruct
struct Icon extends array
/*
multiboard default icon
*/
readonly static string DEFAULT = "UI\\Widgets\\Console\\Undead\\undead-inventory-slotfiller.blp"
static method operator []= takes integer rawCode, string file returns nothing
if(not HaveSavedString(cache,rawCode,0))then
call SaveStr(cache,rawCode,0,file)
endif
endmethod
//! textmacro MULTIBOARD_ICON takes METHOD,ARGUMENT,FUNC
static method $METHOD$ takes $ARGUMENT$ returns string
local integer id=$FUNC$
if(HaveSavedString(cache,id,0))then
return LoadStr(cache,id,0)
endif
return DEFAULT
endmethod
//! endtextmacro
//! runtextmacro MULTIBOARD_ICON("fromUnit","unit u","GetUnitTypeId(u)")
//! runtextmacro MULTIBOARD_ICON("fromItem","item i","GetItemTypeId(i)")
endstruct
//================================================================================
struct Multiboard extends array
private static integer m_row=0
private static integer m_col=0
debug private static string s=""
private multiboard board
private integer row
private integer col
method operator [] takes integer id returns thistype
set keySize=keySize+1
debug set s=s+"["+I2S(id)+"]"
if(1==keySize)then
set m_row=id
elseif(2==keySize)then
set m_col=id
endif
return this
endmethod
private static method key takes integer r, integer c returns integer
return StringHash(I2S(r)+","+I2S(c))
endmethod
private method valid takes string m returns boolean
local boolean unvalid=0<keySize and 2<keySize
debug if(unvalid)then
debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"[MultiboardTools] error: unable to set "+m+" on row/column: "+s)
debug endif
set keySize=0
debug set s=""
return not unvalid and 0!=this
endmethod
//! textmacro Mb_cacheLoopIndex takes a,b,c
if(0==$a$)then
set $a$=$c$
set $b$=$b$-1
endif
set $a$=$a$-1
//! endtextmacro
private static method antiCrashLoop takes nothing returns nothing
loop
exitwhen(0>resolution)
if(not configBoardStyle)then
if(getCache)then
call SaveMultiboardItemHandle(cache,instance,key(rowIndex,colIndex),MultiboardGetItem(Multiboard(instance).board,rowIndex,colIndex))
else
call MultiboardReleaseItem(LoadMultiboardItemHandle(cache,instance,key(rowIndex,colIndex)))
endif
else
call MultiboardSetItemStyle(LoadMultiboardItemHandle(cache,instance,key(rowIndex,colIndex)),boardShowValue,boardShowIcon)
endif
if(columnIndexer)then
//! runtextmacro Mb_cacheLoopIndex("rowIndex","colIndex","Multiboard(instance).row")
else
//! runtextmacro Mb_cacheLoopIndex("colIndex","rowIndex","Multiboard(instance).col")
endif
set loopSize=loopSize+1
set resolution=resolution-1
if(/*anti crash size:*/400==loopSize)then
if(0<resolution)then
set loopSize=0
call ExecuteFunc("s__Multiboard_antiCrashLoop")
return
endif
endif
endloop
endmethod
private method configResolution takes integer resSize, boolean getBoardCache, boolean isColIndex, boolean configStyle returns nothing
if(MAX_RESOLUTION_X*MAX_RESOLUTION_X<.row*.col)then
debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"[MultiboardTools] error: resolution has reached the limit ("+I2S(.col)+"x"+I2S(.row)+" Max --> "+I2S(MAX_RESOLUTION_X)+"x"+I2S(MAX_RESOLUTION_Y)+")")
return
endif
set instance=this
set rowIndex=.row
set colIndex=.col
set loopSize=0
set resolution=resSize
set getCache=getBoardCache
set columnIndexer=isColIndex
set configBoardStyle=configStyle
call ExecuteFunc("s__Multiboard_antiCrashLoop")
endmethod
//! textmacro Mb_debug takes STRING
if(not .valid("$STRING$"))then
return
endif
//! endtextmacro
//! textmacro Mb_operator takes METHOD,ARGUMENT,RETURN,ACTION1,ACTION2
method $METHOD$ takes $ARGUMENT$ returns $RETURN$
$ACTION1$
$ACTION2$
endmethod
//! endtextmacro
//! runtextmacro Mb_operator("operator title","nothing","string","return MultiboardGetTitleText(.board)","")
//! runtextmacro Mb_operator("operator title=","string s","nothing","call MultiboardSetTitleText(.board,s)","")
//! runtextmacro Mb_operator("operator display","nothing","boolean","return IsMultiboardDisplayed(.board)","")
//! runtextmacro Mb_operator("operator display=","boolean b","nothing","call MultiboardDisplay(.board,b)","")
//! runtextmacro Mb_operator("operator rows","nothing","integer","return .row","")
//! runtextmacro Mb_operator("operator columns","nothing","integer","return .col","")
//! runtextmacro Mb_operator("operator minimize","nothing","boolean","return IsMultiboardMinimized(.board)","")
//! runtextmacro Mb_operator("operator minimize=","boolean b","nothing","call MultiboardMinimize(.board,b)","")
//! runtextmacro Mb_operator("clear","nothing","nothing","call MultiboardClear(.board)","")
method operator rows= takes integer rows returns nothing
local integer r=IAbsBJ(.row-rows)*.col
if(rows>.row)then
set .row=rows
call MultiboardSetRowCount(.board,.row)
call .configResolution(r,true,false,false)
elseif(rows<.rows)then
call .configResolution(r-1,false,false,false)
loop
exitwhen(.row==rows)
set .row=.row-1
call MultiboardSetRowCount(.board,.row)
endloop
endif
endmethod
method operator columns= takes integer cols returns nothing
local integer r=IAbsBJ(.col-cols)*.col
if(cols>.col)then
set .col=cols
call .configResolution(r,true,true,false)
elseif(cols<.col)then
call .configResolution(r-1,false,true,false)
endif
set .col=cols
call MultiboardSetColumnCount(.board,.col)
endmethod
method operator width= takes real width returns nothing
local integer r=.row
//! runtextmacro Mb_debug("width")
if(0==m_row)then
loop
call MultiboardSetItemWidth(LoadMultiboardItemHandle(cache,this,key(r,m_col)),width/100)
exitwhen(0==r)
set r=r-1
endloop
elseif(m_row>0)then
call MultiboardSetItemWidth(LoadMultiboardItemHandle(cache,this,key(m_row,m_col)),width/100)
endif
endmethod
method operator text= takes string text returns nothing
//! runtextmacro Mb_debug("text")
call MultiboardSetItemValue(LoadMultiboardItemHandle(cache,this,key(m_row,m_col)),text)
endmethod
method operator icon= takes string icon returns nothing
local multiboarditem i=LoadMultiboardItemHandle(cache,this,key(m_row,m_col))//.cache[m_row][m_col].multiboarditem
//! runtextmacro Mb_debug("icon")
call MultiboardSetItemIcon(i,icon)
call MultiboardSetItemStyle(i,true,true)
set i=null
endmethod
method setStyle takes boolean showValue, boolean showIcon returns nothing
local integer r=.row
local integer c=.col
//! runtextmacro Mb_debug("style")
if(0==m_col and 0==m_row)then
set boardShowValue=showValue
set boardShowIcon=showIcon
call .configResolution((.row*.col)+.col,false,false,true)
elseif(m_col>0 or m_row>0)then
call MultiboardSetItemStyle(LoadMultiboardItemHandle(cache,this,key(m_row,m_col)),showValue,showIcon)
endif
endmethod
static method create takes string title, integer rows, integer cols returns Multiboard
local thistype this=list[0]
if(0==list[this])then
set list[0]=this+1
else
set list[0]=list[this]
endif
set .row=rows
set .col=cols
set .board=CreateMultiboard()
call MultiboardSetTitleText(.board,title)
call MultiboardSetRowCount(.board,rows)
call MultiboardSetColumnCount(.board,cols)
call .configResolution((.row*.col)+.col,true,false,false)
return this
endmethod
method destroy takes nothing returns nothing
set list[this]=list[0]
set list[0]=this
call .configResolution((.row*.col)+.col,false,false,false)
call FlushChildHashtable(cache,this)
call DestroyMultiboard(.board)
set .board=null
endmethod
endstruct
endlibrary
Newtable version:
JASS:
library MultiboardTools/*
*******************************************************************************************************
*
* ***************************************************************************************************
*
* */ uses /*
* */ Table /* hiveworkshop.com/forums/jass-functions-413/snippet-new-table-188084/
*
* ***************************************************************************************************
*
* MultiboardTools (newtable version)
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
* v2.0.1.1
* by Thelordmarshall
*
*
* Manage your Multiboard without limits.
*
* set myBoard = Multiboard.create("my board title", rowCount, columnCount)
* set myBoard[0][1].text = GetPlayerName(somePlayer)
* set myBoard[0][1].icon = "some\\path\\icon.blp"
* set myBoard.display = GetLocalPlayer()==somePlayer
*
* API:
* ¯¯¯
* struct Icon extends array
*
* static method operator []= takes integer rawCode, string file returns nothing
* static method fromUnit takes unit u returns string
* static method fromItem takes item i returns string
*
* struct Multiboard extends array
*
* static method create takes string title, integer rows, integer cols returns Multiboard
* method destroy takes nothing returns nothing
*
* method operator [] takes integer id returns thistype
* - used for row and column
*
* method operator width= takes real width returns nothing
* method operator text= takes string text returns nothing
* method operator icon= takes string icon returns nothing
* method operator title takes nothing returns string
* method operator title= takes string s returns nothing
* method operator display takes nothing returns boolean
* method operator display= takes boolean b returns nothing
* method operator rows takes nothing returns integer
* method operator rows= takes integer i returns nothing
* method operator columns takes nothing returns integer
* method operator columns= takes integer i returns nothing
* method operator minimize takes nothing returns boolean
* method operator minimize= takes boolean b returns nothing
*
* method clear takes nothing returns nothing
* method setStyle takes boolean showValue, boolean showIcon returns nothing
*
* Credits:
* ¯¯¯¯¯¯¯
* - Bribe: for suggest me to add Icon API into this library
* - PurgeandFire: notice me of Multiboard row glitch
*
*******************************************************************************************************/
//CONFIGURATION
//=================================================================================
globals
private constant integer MAX_RESOLUTION_X = 60 //Multiboard max columns count
private constant integer MAX_RESOLUTION_Y = 60 //Multiboard max rows count
endglobals
//=================================================================================
globals
private integer keySize=0
private integer instance=0
private integer rowIndex=0
private integer colIndex=0
private integer loopSize=0
private integer resolution=0
private boolean getCache=false
private boolean boardShowValue=false
private boolean boardShowIcon=false
private boolean columnIndexer=false
private boolean configBoardStyle=false
private integer array list
endglobals
private module Init
static method onInit takes nothing returns nothing
set list[0]=1
set icon=Table.create()
endmethod
endmodule
struct Icon extends array
/*
multiboard default icon
*/
readonly static string DEFAULT = "UI\\Widgets\\Console\\Undead\\undead-inventory-slotfiller.blp"
private static Table icon=0
implement Init
static method operator []= takes integer rawCode, string file returns nothing
if(not icon.string.has(rawCode))then
set icon.string[rawCode]=file
endif
endmethod
//! textmacro MULTIBOARD_ICON takes METHOD,ARGUMENT,FUNC
static method $METHOD$ takes $ARGUMENT$ returns string
local integer id=$FUNC$
if(icon.string.has(id))then
return icon.string[id]
endif
return DEFAULT
endmethod
//! endtextmacro
//! runtextmacro MULTIBOARD_ICON("fromUnit","unit u","GetUnitTypeId(u)")
//! runtextmacro MULTIBOARD_ICON("fromItem","item i","GetItemTypeId(i)")
endstruct
//================================================================================
struct Multiboard extends array
private static integer m_row=0
private static integer m_col=0
debug private static string s=""
private multiboard board
private integer row
private integer col
private HashTable cache
method operator [] takes integer id returns thistype
set keySize=keySize+1
debug set s=s+"["+I2S(id)+"]"
if(1==keySize)then
set m_row=id
elseif(2==keySize)then
set m_col=id
endif
return this
endmethod
private method valid takes string m returns boolean
local boolean unvalid=0<keySize and 2<keySize
debug if(unvalid)then
debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"[MultiboardTools] error: unable to set "+m+" on row/column: "+s)
debug endif
set keySize=0
debug set s=""
return not unvalid and 0!=this
endmethod
//! textmacro Mb_cacheLoopIndex takes a,b,c
if(0==$a$)then
set $a$=$c$
set $b$=$b$-1
endif
set $a$=$a$-1
//! endtextmacro
private static method antiCrashLoop takes nothing returns nothing
loop
exitwhen(0>resolution)
if(not configBoardStyle)then
if(getCache)then
set Multiboard(instance).cache[rowIndex].multiboarditem[colIndex]=MultiboardGetItem(Multiboard(instance).board,rowIndex,colIndex)
else
call MultiboardReleaseItem(Multiboard(instance).cache[rowIndex].multiboarditem[colIndex])
endif
else
call MultiboardSetItemStyle(Multiboard(instance).cache[rowIndex].multiboarditem[colIndex],boardShowValue,boardShowIcon)
endif
if(columnIndexer)then
//! runtextmacro Mb_cacheLoopIndex("rowIndex","colIndex","Multiboard(instance).row")
else
//! runtextmacro Mb_cacheLoopIndex("colIndex","rowIndex","Multiboard(instance).col")
endif
set loopSize=loopSize+1
set resolution=resolution-1
if(/*anti crash size:*/400==loopSize)then
if(0<resolution)then
set loopSize=0
call ExecuteFunc("s__Multiboard_antiCrashLoop")
return
endif
endif
endloop
endmethod
private method configResolution takes integer resSize, boolean getBoardCache, boolean isColIndex, boolean configStyle returns nothing
if(MAX_RESOLUTION_X*MAX_RESOLUTION_X<.row*.col)then
debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"[MultiboardTools] error: resolution has reached the limit ("+I2S(.col)+"x"+I2S(.row)+" Max --> "+I2S(MAX_RESOLUTION_X)+"x"+I2S(MAX_RESOLUTION_Y)+")")
return
endif
set instance=this
set rowIndex=.row
set colIndex=.col
set loopSize=0
set resolution=resSize
set getCache=getBoardCache
set columnIndexer=isColIndex
set configBoardStyle=configStyle
call ExecuteFunc("s__Multiboard_antiCrashLoop")
endmethod
//! textmacro Mb_debug takes STRING
if(not .valid("$STRING$"))then
return
endif
//! endtextmacro
//! textmacro Mb_operator takes METHOD,ARGUMENT,RETURN,ACTION1,ACTION2
method $METHOD$ takes $ARGUMENT$ returns $RETURN$
$ACTION1$
$ACTION2$
endmethod
//! endtextmacro
//! runtextmacro Mb_operator("operator title","nothing","string","return MultiboardGetTitleText(.board)","")
//! runtextmacro Mb_operator("operator title=","string s","nothing","call MultiboardSetTitleText(.board,s)","")
//! runtextmacro Mb_operator("operator display","nothing","boolean","return IsMultiboardDisplayed(.board)","")
//! runtextmacro Mb_operator("operator display=","boolean b","nothing","call MultiboardDisplay(.board,b)","")
//! runtextmacro Mb_operator("operator rows","nothing","integer","return .row","")
//! runtextmacro Mb_operator("operator columns","nothing","integer","return .col","")
//! runtextmacro Mb_operator("operator minimize","nothing","boolean","return IsMultiboardMinimized(.board)","")
//! runtextmacro Mb_operator("operator minimize=","boolean b","nothing","call MultiboardMinimize(.board,b)","")
//! runtextmacro Mb_operator("clear","nothing","nothing","call MultiboardClear(.board)","")
method operator rows= takes integer rows returns nothing
local integer r=IAbsBJ(.row-rows)*.col
if(rows>.row)then
set .row=rows
call MultiboardSetRowCount(.board,.row)
call .configResolution(r,true,false,false)
elseif(rows<.rows)then
call .configResolution(r-1,false,false,false)
loop
exitwhen(.row==rows)
set .row=.row-1
call MultiboardSetRowCount(.board,.row)
endloop
endif
endmethod
method operator columns= takes integer cols returns nothing
local integer r=IAbsBJ(.col-cols)*.col
if(cols>.col)then
set .col=cols
call .configResolution(r,true,true,false)
elseif(cols<.col)then
call .configResolution(r-1,false,true,false)
endif
set .col=cols
call MultiboardSetColumnCount(.board,.col)
endmethod
method operator width= takes real width returns nothing
local integer r=.row
//! runtextmacro Mb_debug("width")
if(0==m_row)then
loop
call MultiboardSetItemWidth(.cache[r].multiboarditem[m_col],width/100)
exitwhen(0==r)
set r=r-1
endloop
elseif(m_row>0)then
call MultiboardSetItemWidth(.cache[m_row].multiboarditem[m_col],width/100)
endif
endmethod
method operator text= takes string text returns nothing
//! runtextmacro Mb_debug("text")
call MultiboardSetItemValue(.cache[m_row].multiboarditem[m_col],text)
endmethod
method operator icon= takes string icon returns nothing
local multiboarditem i=.cache[m_row].multiboarditem[m_col]
//! runtextmacro Mb_debug("icon")
call MultiboardSetItemIcon(i,icon)
call MultiboardSetItemStyle(i,true,true)
set i=null
endmethod
method setStyle takes boolean showValue, boolean showIcon returns nothing
local integer r=.row
local integer c=.col
//! runtextmacro Mb_debug("style")
if(0==m_col and 0==m_row)then
set boardShowValue=showValue
set boardShowIcon=showIcon
call .configResolution((.row*.col)+.col,false,false,true)
elseif(m_col>0 or m_row>0)then
call MultiboardSetItemStyle(.cache[m_row].multiboarditem[m_col],showValue,showIcon)
endif
endmethod
static method create takes string title, integer rows, integer cols returns Multiboard
local thistype this=list[0]
if(0==list[this])then
set list[0]=this+1
else
set list[0]=list[this]
endif
set .cache=HashTable.create()
set .row=rows
set .col=cols
set .board=CreateMultiboard()
call MultiboardSetTitleText(.board,title)
call MultiboardSetRowCount(.board,rows)
call MultiboardSetColumnCount(.board,cols)
call .configResolution((.row*.col)+.col,true,false,false)
return this
endmethod
method destroy takes nothing returns nothing
set list[this]=list[0]
set list[0]=this
call .configResolution((.row*.col)+.col,false,false,false)
call .cache.destroy()
call DestroyMultiboard(.board)
set .board=null
endmethod
endstruct
endlibrary
Last edited: