• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[vJASS] [Snippet] MultiboardTools

Level 9
Joined
Jun 21, 2012
Messages
432
Hashtable 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:
That is a pretty clever hack for implementing the [] operators. It isn't super efficient and it makes the implementation convoluted, but at least it is pretty. :p

For setStyle, why can't you just use MultiboardSetItemsStyle?

As for row=, you may want to consider stepping them by one to avoid this bug:
http://www.hiveworkshop.com/forums/lab-715/multiboard-glitches-250775/

Otherwise, this seems like a decent wrapper.
 
Level 9
Joined
Jun 21, 2012
Messages
432
For setStyle, why can't you just use MultiboardSetItemsStyle?
.

Remember, when creates Multiboard this is returned in instance integer xd

As for row=, you may want to consider stepping them by one to avoid this bug:
http://www.hiveworkshop.com/forums/submissions-414/snipet-multiboardtools-263709/l...itches-250775/

I'll take it into account for next version

Thanks for the review LoL.

@pred1980: Yes I know of the nestharus one, but mine uses less code and fewer resources.
 
Last edited:

Kazeon

Hosted Project: EC
Level 33
Joined
Oct 12, 2011
Messages
3,449
JASS:
        method operator [] takes integer i returns thistype
            if(n==0)then
                set .r=i
                set n=1
            elseif(n==1)then
                set .c=i
                set n=0
            endif
            return this
        endmethod
It has no safety factor. It accepts any dimensions: [0] or [0][1][2] will be accepted nonetheless and it's going to be bugged.

I recommend to display icon/value automatically on this method:
JASS:
        method operator text= takes string text returns nothing
            local multiboarditem e=MultiboardGetItem(.m,.r,.c)
            call MultiboardSetItemValue(e,text)
            call MultiboardReleaseItem(e)
            set e=null
        endmethod
        
        method operator icon= takes string icon returns nothing
            local multiboarditem e=MultiboardGetItem(.m,.r,.c)
            call MultiboardSetItemIcon(e,icon)
            call MultiboardSetItemStyle(e,true,true)
            call MultiboardReleaseItem(e)
            set e=null
        endmethod
If the icon is null or "", set the item style to hide icon. If the text (value) is "", set the item style to hide value.

However, this wrapper isn't really applicable in any map. In a lot of cases, multiboard would be updated locally. Using those two methods above would result in desync:
JASS:
if GetLocalPlayer() == p then
    set SomeMB[0][1].text = "123"
else
    set SomeMB[0][1].text = "456"
endif
is going to be desync-ed here:
JASS:
            local multiboarditem e=MultiboardGetItem(.m,.r,.c)
It's going to create handle/agent locally. However, without this wrapper, that desync could be avoided:
JASS:
local multiboarditem e=MultiboardGetItem(.m,0,1)

if GetLocalPlayer() == p then
    call MultiboardSetItemValue(e,"123")
else
    call MultiboardSetItemValue(e,"456")
endif
call MultiboardReleaseItem(e)
set e=null

@pnf:
Greetings. Glad you are around. :)
 
Level 9
Joined
Jun 21, 2012
Messages
432
@PurgeandFire: Excuse me, which he not understood was me; I not use only MultiboardSetItemsStyle because if used with row and column 0 the icons and values will be configured for all Multiboard, this prevents users from using a loop to set all rows and columns manually, it would be tedious, I think... :)

- It has no safety factor. It accepts any dimensions: [0] or [0][1][2] will be accepted nonetheless and it's going to be bugged.

- However, this wrapper isn't really applicable in any map. In a lot of cases, multiboard would be updated locally. Using those two methods above would result in desync:

- Yeah, I was thinking about it, and I have partially solved.

- you're right, I'll fix it.
 
@PurgeandFire: Excuse me, which he not understood was me; I not use only MultiboardSetItemsStyle because if used with row and column 0 the icons and values will be configured for all Multiboard, this prevents users from using a loop to set all rows and columns manually, it would be tedious, I think... :)

I meant, what is the difference between this (yours):
JASS:
        method setStyle takes boolean showValue, boolean showIcon returns nothing
            local integer rowCount=MultiboardGetRowCount(.m)
            local integer columnCount=MultiboardGetColumnCount(.m)
            local integer i=0
            local integer h=0
            //! runtextmacro Mb_debug("style")
            if(.r==0 and .c==0)then
                loop
                    exitwhen(i==rowCount)
                    loop
                        exitwhen(h==columnCount)
                        set e=MultiboardGetItem(.m,i,h)
                        call MultiboardSetItemStyle(e,showValue,showIcon)
                        call MultiboardReleaseItem(e)
                        set h=h+1
                    endloop
                    set h=0
                    set i=i+1
                endloop
            elseif(.r>0 or .c>0)then
                set e=MultiboardGetItem(.m,.r,.c)
                call MultiboardSetItemStyle(e,showValue,showIcon)
                call MultiboardReleaseItem(e)
            endif
            set e=null
        endmethod

And this?
JASS:
        method setStyle takes boolean showValue, boolean showIcon returns nothing
            local integer rowCount=MultiboardGetRowCount(.m)
            local integer columnCount=MultiboardGetColumnCount(.m)
            local integer i=0
            local integer h=0
            //! runtextmacro Mb_debug("style")
            if(.r==0 and .c==0)then
                call MultiboardSetItemsStyle(.m, showValue, showIcon)
            elseif(.r>0 or .c>0)then
                set e=MultiboardGetItem(.m,.r,.c)
                call MultiboardSetItemStyle(e,showValue,showIcon)
                call MultiboardReleaseItem(e)
            endif
            set e=null
        endmethod
 

Kazeon

Hosted Project: EC
Level 33
Joined
Oct 12, 2011
Messages
3,449
@TS:
Actuallly, I would prefer to preserve all multiboard items inside the declared multiboard, using Table. So we don't need to get and release all the time.

So when create method is called:
JASS:
set this = allocate()
set .mb = CreateMultiboard()
set .multitem = TableArray[rowParameter]
set .rowCount = rowParameter // row and column count should be stored as well to avoid repeated fc
set .columnCount = columnParameter
loop
    i = row
    j = collumn
    set .multitem[i].multiboarditem[j] = MultiboardGetItem(.mb, i, j)
endloop

Now you can avoid desync on text= and icon= method :thumbs_up:

I wrote it manually here, hope you understand :p

EDIT:
* - method operator show= takes boolean b returns nothing
I will add "which player" as parameter if I were you :p It will do the action locally for that player automatically. Will ease users all the time.
 
Level 14
Joined
Dec 12, 2012
Messages
1,007
It would be good if you explain a bit why this resource should be prefered over Nestharus Multiboard library.

You mention that yours uses less resources, but Nestharus one just uses table as a requirement, so thats not really a big dependency tree. What advantages does this system offer to the user, that would be interesting.

About the coding, I have to say I don't like the way of putting every three-liner inside a textmacro, that really makes the code harder to read (especially since you use code itself as macro arguments). And having operator[] returning thistype and then checking if the index is within the allowed range is not good. It allows semantically ill-formed constructs like mb[1][2][3][4] etc. Use a proxy class instead, that one provides compile-time safety.
 
Top