Darthfett
Aerospace/Cybersecurity Software Engineer
- Reaction score
- 615
Multiboard
Created By: Darthfett
vJASS
Leakless
What is Multiboard?
The Multiboard wrapper system is simply an easier way to work with Multiboards. It keeps track of all the multiboarditems and provides a few useful functions, as well as all of the original multiboard functions (many will inline, or cost little more than a function call and a few comparisons).
Why Use Multiboard?
To understand why you might use Multiboard, you should first look at the problems with native multiboard use:
- Forced to use multiboarditems
- Ugly, sometimes inefficient BJ functions
- multiboarditems leak if they are not released.
This is what the vJASS Multiboard gives to you:
- Removes the need to work with multiboarditems individually.
- Has an improved algorithm when modifying multiple rows or columns.
- Will automatically recycle multiboarditems and remove them when no longer needed
- Simplistic O.O. syntax.
How do I Use Multiboard?
Using the Multiboard wrapper is relatively simple. Methods are named according to what they replace. For example, to create a multiboard, simply do this:
JASS:
local Multiboard mb = Multiboard.create(COLUMN_COUNT,ROW_COUNT)
Or, to set an item (or items) value, simply use the setItemValue method. See the following tips when working with the "setItem___" methods:
- Columns always come before Rows
- Columns and Rows start at 0
- Use -1 to refer to all columns or rows
All functions which are not documented are equivalent to the function they call inside. They will also inline.
functions that modify a multiboarditem, such as setItemValue, replace the singular MultiboardSetItemValue, the MultiboardSetItemsValue, as well as the MultiboardSetItemValueBJ function.
Function list:
JASS:
static method create takes integer columnCount, integer rowCount returns Multiboard
//Creates a new Multiboard and sets up the columns and rows.
method destroy takes nothing returns nothing
//Cleans up the Multiboard and related items
method clear takes nothing returns nothing
//Clears the multiboard
//======================================================================================
//======================================================================================
method display takes boolean flag returns nothing
//Displays the multiboard to all players
method displayToPlayer takes player whichPlayer, boolean flag returns nothing
//Displays the multiboard to a specified player.
method minimize takes boolean flag returns nothing
//Minimizes the multiboard for all players
method minimizeForPlayer takes player whichPlayer, boolean flag returns nothing
//Minimizes the multiboard for a specified player
static method suppress takes boolean flag returns nothing
//Suppresses all multiboards for all players
static method suppressForPlayer takes player p, boolean flag returns nothing
//Suppresses all multiboards for a specified player
//======================================================================================
method setColumnCount takes integer count returns nothing
//Changes the specified amount of columns. Does not need to be run on Multiboard Init.
//If the amount is less than the previous amount, it will clean up leaks
method getColumnCount takes nothing returns integer
//Number of columns in the multiboard
method setRowCount takes integer count returns nothing
//Changes the specified amount of rows. Does not need to be run on Multiboard Init.
//If the amount is less than the previous amount, it will clean up leaks
method getRowCount takes nothing returns integer
//Number of rows in the multiboard
//======================================================================================
method setTitleText takes string label returns nothing
//Sets the title's text
method setTitleTextColor takes integer red, integer green, integer blue, integer alpha returns nothing
//Sets the title's text color
method setItemValue takes integer column, integer row, string val returns nothing
//sets the specified item's value. If -1 is used for column or row, it will set all of them.
//Using a Column or Row higher than the current max will result in the function not doing anything.
method setItemColor takes integer column, integer row, integer red, integer green, integer blue, integer alpha returns nothing
//sets the specified item's color. If -1 is used for column or row, it will set all of them.
//Using a Column or Row higher than the current max will result in the function not doing anything.
method setItemWidth takes integer column, integer row, real width returns nothing
//sets the specified item's width. If -1 is used for column or row, it will set all of them.
//Using a Column or Row higher than the current max will result in the function not doing anything.
method setItemIcon takes integer column, integer row, string iconFileName returns nothing
//sets the specified item's icon. If -1 is used for column or row, it will set all of them.
//Using a Column or Row higher than the current max will result in the function not doing anything.
method setItemStyle takes integer column, integer row, boolean showValue, boolean showIcon returns nothing
//sets the specified item's style. If -1 is used for column or row, it will set all of them.
//Using a Column or Row higher than the current max will result in the function not doing anything.
//======================================================================================
//======================================================================================
//======================================================================================
method isDisplayed takes nothing returns boolean
//returns whether the multiboard is being displayed
//Beware when using this with displayToPlayer, it can cause desyncs.
method isMinimized takes nothing returns boolean
//returns whether "this" is minimized
//Beware when using this with minimizeForPlayer, it can cause desyncs.
Now for the System:
JASS:
library Multiboard
//Configurables:
globals
private constant integer MAX_COLUMN_COUNT = 16
private constant integer MAX_ROW_COUNT = 16
endglobals
//======================================================================================
globals
private constant integer MAX_COUNT = MAX_COLUMN_COUNT * MAX_ROW_COUNT //Don't Touch
endglobals
struct Multiboard
private multiboard which
private multiboarditem array MBIZ[MAX_COUNT] //MultiBoardItemZ (Z stands for Array)
private integer columnCount
private integer rowCount
//======================================================================================
//======================================================================================
static method create takes integer columnCount, integer rowCount returns Multiboard
//Creates a new Multiboard and sets up the columns and rows.
local Multiboard this = Multiboard.allocate()
local integer i = 0
local integer j = 0
set .which = CreateMultiboard()
set .columnCount = columnCount
set .rowCount = rowCount
call MultiboardSetColumnCount(.which,columnCount)
call MultiboardSetRowCount(.which,rowCount)
loop
exitwhen i > .columnCount
loop
exitwhen j > .rowCount
set .MBIZ[i * MAX_ROW_COUNT + j] = MultiboardGetItem(.which,j,i)
set j = j + 1
endloop
set j = 0
set i = i + 1
endloop
return this
endmethod
private method onDestroy takes nothing returns nothing
//Cleans up the Multiboard and related items
local integer i = 0
local integer j
loop
exitwhen i > .columnCount
set j = 0
loop
exitwhen j > .rowCount
call MultiboardReleaseItem(.MBIZ[i * MAX_ROW_COUNT + j])
set j = j + 1
endloop
set i = i + 1
endloop
call MultiboardClear(.which)
call DestroyMultiboard(.which)
endmethod
method clear takes nothing returns nothing
call MultiboardClear(.which)
endmethod
//======================================================================================
//======================================================================================
method display takes boolean flag returns nothing
call MultiboardDisplay(.which,flag)
endmethod
method displayToPlayer takes player whichPlayer, boolean flag returns nothing
//Displays the multiboard to a specified player.
call MultiboardDisplay(.which,(GetLocalPlayer() == whichPlayer) and flag)
endmethod
method minimize takes boolean flag returns nothing
call MultiboardMinimize(.which,flag)
endmethod
method minimizeForPlayer takes player whichPlayer, boolean flag returns nothing
//Minimizes the multiboard for a specified player.
call MultiboardMinimize(.which,(GetLocalPlayer() == whichPlayer) and flag)
endmethod
static method suppress takes boolean flag returns nothing
call MultiboardSuppressDisplay(flag)
endmethod
static method suppressForPlayer takes player p, boolean flag returns nothing
//Suppresses all multiboards for a specified player
call MultiboardSuppressDisplay((GetLocalPlayer() == p) and flag)
endmethod
//======================================================================================
method setColumnCount takes integer count returns nothing
//Changes the specified amount of columns. Does not need to be run on Multiboard Init.
//If the amount is less than the previous amount, it will clean up leaks
local integer i
local integer j = 0
if count > MAX_COLUMN_COUNT then
set count = MAX_COLUMN_COUNT
endif
call MultiboardSetColumnCount(.which,count)
if count < .columnCount then
loop
exitwhen j > .rowCount
set i = count
loop
exitwhen i > .columnCount
call MultiboardReleaseItem(.MBIZ[i * MAX_ROW_COUNT + j])
set i = i + 1
endloop
set j = j + 1
endloop
endif
set .columnCount = count
endmethod
method getColumnCount takes nothing returns integer
return .columnCount
endmethod
method setRowCount takes integer count returns nothing
//Changes the specified amount of rows. Does not need to be run on Multiboard Init.
//If the amount is less than the previous amount, it will clean up leaks
local integer i = 0
local integer j
if count > MAX_ROW_COUNT then
set count = MAX_ROW_COUNT
endif
call MultiboardSetRowCount(.which,count)
if count < .rowCount then
loop
exitwhen i > .columnCount
set j = count
loop
exitwhen j > .rowCount
call MultiboardReleaseItem(.MBIZ[i * MAX_ROW_COUNT + j])
set j = j + 1
endloop
set i = i + 1
endloop
endif
set .rowCount = count
endmethod
method getRowCount takes nothing returns integer
return .rowCount
endmethod
//======================================================================================
method setTitleText takes string label returns nothing
call MultiboardSetTitleText(.which,label)
endmethod
method setTitleTextColor takes integer red, integer green, integer blue, integer alpha returns nothing
call MultiboardSetTitleTextColor(.which,red,green,blue,alpha)
endmethod
method setItemValue takes integer column, integer row, string val returns nothing
//Works similar to the MultiboardSetItem* functions.
//However, a value of 0 refers to the first column/row, -1 refers to all columns/rows
//Using a Column or Row higher than the current max will result in the function not doing anything.
local integer curCol = 0
local integer curRow = 0
if column > .columnCount or row > .rowCount then
return
endif
if column == -1 or row == -1 then
if column == -1 and row == -1 then
call MultiboardSetItemsValue(.which,val)
return
elseif column == -1 then
loop
exitwhen curCol > .columnCount
call MultiboardSetItemValue(.MBIZ[curCol * MAX_ROW_COUNT + row],val)
set curCol = curCol + 1
endloop
return
else
loop
exitwhen curRow > .rowCount
call MultiboardSetItemValue(.MBIZ[column * MAX_ROW_COUNT + curRow],val)
set curRow = curRow + 1
endloop
return
endif
endif
call MultiboardSetItemValue(.MBIZ[column * MAX_ROW_COUNT + row],val)
endmethod
method setItemColor takes integer column, integer row, integer red, integer green, integer blue, integer alpha returns nothing
//Works similar to the MultiboardSetItem* functions.
//However, a value of 0 refers to the first column/row, -1 refers to all columns/rows
//Using a Column or Row higher than the current max will result in the function not doing anything.
local integer curCol = 0
local integer curRow = 0
if column > .columnCount or row > .rowCount then
return
endif
if column == -1 or row == -1 then
if column == -1 and row == -1 then
call MultiboardSetItemsValueColor(.which,red,green,blue,alpha)
return
elseif column == -1 then
loop
exitwhen curCol > .columnCount
call MultiboardSetItemValueColor(.MBIZ[curCol * MAX_ROW_COUNT + row],red,green,blue,alpha)
set curCol = curCol + 1
endloop
return
else
loop
exitwhen curRow > .rowCount
call MultiboardSetItemValueColor(.MBIZ[column * MAX_ROW_COUNT + curRow],red,green,blue,alpha)
set curRow = curRow + 1
endloop
return
endif
endif
call MultiboardSetItemValueColor(.MBIZ[column * MAX_ROW_COUNT + row],red,green,blue,alpha)
endmethod
method setItemWidth takes integer column, integer row, real width returns nothing
//Works similar to the MultiboardSetItem* functions.
//However, a value of 0 refers to the first column/row, -1 refers to all columns/rows
//Using a Column or Row higher than the current max will result in the function not doing anything.
local integer curCol = 0
local integer curRow = 0
if column > .columnCount or row > .rowCount then
return
endif
if column == -1 or row == -1 then
if column == -1 and row == -1 then
call MultiboardSetItemsWidth(.which,width)
return
elseif column == -1 then
loop
exitwhen curCol > .columnCount
call MultiboardSetItemWidth(.MBIZ[curCol * MAX_ROW_COUNT + row],width)
set curCol = curCol + 1
endloop
return
else
loop
exitwhen curRow > .rowCount
call MultiboardSetItemWidth(.MBIZ[column * MAX_ROW_COUNT + curRow],width)
set curRow = curRow + 1
endloop
return
endif
endif
call MultiboardSetItemWidth(.MBIZ[column * MAX_ROW_COUNT + row],width)
endmethod
method setItemIcon takes integer column, integer row, string iconFileName returns nothing
//Works similar to the MultiboardSetItem* functions.
//However, a value of 0 refers to the first column/row, -1 refers to all columns/rows
//Using a Column or Row higher than the current max will result in the function not doing anything.
local integer curCol = 0
local integer curRow = 0
if column > .columnCount or row > .rowCount then
return
endif
if column == -1 or row == -1 then
if column == -1 and row == -1 then
call MultiboardSetItemsIcon(.which,iconFileName)
return
elseif column == -1 then
loop
exitwhen curCol > .columnCount
call MultiboardSetItemIcon(.MBIZ[curCol * MAX_ROW_COUNT + row],iconFileName)
set curCol = curCol + 1
endloop
return
else
loop
exitwhen curRow > .rowCount
call MultiboardSetItemIcon(.MBIZ[column * MAX_ROW_COUNT + curRow],iconFileName)
set curRow = curRow + 1
endloop
return
endif
endif
call MultiboardSetItemIcon(.MBIZ[column * MAX_ROW_COUNT + row],iconFileName)
endmethod
method setItemStyle takes integer column, integer row, boolean showValue, boolean showIcon returns nothing
//Works similar to the MultiboardSetItem* functions.
//However, a value of 0 refers to the first column/row, -1 refers to all columns/rows
//Using a Column or Row higher than the current max will result in the function not doing anything.
local integer curCol = 0
local integer curRow = 0
if column > .columnCount or row > .rowCount then
return
endif
if column == -1 or row == -1 then
if column == -1 and row == -1 then
call MultiboardSetItemsStyle(.which,showValue,showIcon)
return
elseif column == -1 then
loop
exitwhen curCol > .columnCount
call MultiboardSetItemStyle(.MBIZ[curCol * MAX_ROW_COUNT + row],showValue,showIcon)
set curCol = curCol + 1
endloop
return
else
loop
exitwhen curRow > .rowCount
call MultiboardSetItemStyle(.MBIZ[column * MAX_ROW_COUNT + curRow],showValue,showIcon)
set curRow = curRow + 1
endloop
return
endif
endif
call MultiboardSetItemStyle(.MBIZ[column * MAX_ROW_COUNT + row],showValue,showIcon)
endmethod
//======================================================================================
//======================================================================================
//======================================================================================
method isDisplayed takes nothing returns boolean
return IsMultiboardDisplayed(.which)
endmethod
method isMinimized takes nothing returns boolean
return IsMultiboardMinimized(.which)
endmethod
endstruct
endlibrary
Comments and Reviews are always appreciated! Happy Mapping.