- Joined
- Jul 20, 2009
- Messages
- 835
JASS:
//================================================================================
struct myBoard
//
// :: F E A T U R E S ::
//
// - Gives full control of the values inside the multiboard.
// - Allows to change the values for only one concrete player.
// - Leakless, safe and easy control of any parameter.
// - Counts the letter amount that can fit in this item[col;row].
//
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// == H O W T O U S E ==
//
// I will give the method explanations below.
//
static method create takes integer cols, integer rows, string title returns thistype
// This method creates the multiboard. Usage:
// myBoard.create(columnCount,rowCount,"This is my title")
// It will create the multiboard with a title 'This is my title'.
//
method setColCount takes integer cols returns nothing
method setRowCount takes integer rows returns nothing
// Those methods allow you to adjust column and row amounts.
// Usage example: mainBoard.setColCount(8)
// mainBoard.setRowCount(4)
// where mainBoard is the variable of type myBoard.
//
method display takes boolean doDisplay returns nothing
method minimize takes boolean doMinimize returns nothing
// Toggles display and minimization of the multiboard.
// Usage examples: mainBoard.display(true)
// mainBoard.minimize(true)
// where mainBoard is the variable of type myBoard.
method displayIcon takes integer col, integer row, boolean doDisplay returns nothing
method displayValue takes integer col, integer row, boolean doDisplay returns nothing
method setIcon takes integer col, integer row, string newIcon returns nothing
method setValue takes integer col, integer row, string newValue returns nothing
method setWidth takes integer col, integer row, real width returns nothing
// Those methods are able to change the settings of the given multiboard.
// displayIcon : This determines if the icon in the selected item[column;row] will be displayed.
// true is 'enable', false is 'disable' icon displaying.
// displayValue : This determines if the text value in the selected item[column;row] will be displayed.
// true is 'enable', false is 'disable' value displaying.
// setIcon : This sets the new icon path for the selected item[column;row].
// setValue : This sets the new text value for the selected item[column;row].
// setWidth : This sets the new width for the selected item[column;row].
// Please note that the width is the percent from the current screen width!
// For example, if you need 14% width then set it as 0.14.
method displayLocalIcon takes player whichPlayer, integer col , integer row, boolean doDisplay returns nothing
method displayLocalValue takes player whichPlayer, integer col , integer row, boolean doDisplay returns nothing
method setLocalIcon takes player whichPlayer, integer col , integer row, string newIcon returns nothing
method setLocalValue takes player whichPlayer, integer col , integer row, string newValue returns nothing
method setLocalWidth takes player whichPlayer, integer col , integer row, real width returns nothing
method setLocalTitleText takes player whichPlayer, string newTitle returns nothing
// Same as above, but they set these parameters only for one concrete player.
// This also works with title text.
// GET API works correct with these functions and always will return exact value.
method getCharCount takes integer col, integer row returns integer
method getWidth takes integer col, integer row returns real
method getIconPath takes integer col, integer row returns string
method getValue takes integer col, integer row returns string
method getItem takes integer col, integer row returns multiboarditem
method isValueShown takes integer col, integer row returns boolean
method isIconShown takes integer col, integer row returns boolean
// This is the GET API of myBoard. It allows to get any value you want easily.
// getCharCount returns the maximal amount of characters that can be placed in this multiboard's item[column;row].
//
// Examples of usage: mainBoard.getCharCount(8,4)
// mainBoard.getWidth(8,4)
// mainBoard.getIconPath(8,4)
// mainBoard.getValue(8,4)
// mainBoard.getItem(8,4)
// mainBoard.isValueShown(8,4)
// mainBoard.isIconShown(8,4)
// where mainBoard is the variable of type myBoard.
//
// To get the multiboard, use : mainBoard.board
// where mainBoard is the variable of type myBoard.
// Note that this variable cannot be reassigned.
//
// This system also features some operators for the user to control everything easier.
// Dedicated to lazy typers. :)
method operator title takes nothing returns string
method operator columns takes nothing returns integer
method operator rows takes nothing returns integer
method operator show takes nothing returns boolean
method operator suppress takes nothing returns boolean
// These ones are used easily. See by yourself!
// To get the current title of the multiboard, use : mainBoard.title
// To get the current column count of the multiboard, use : mainBoard.columns
// To get the current row count of the multiboard, use : mainBoard.rows
// To discover if the board is shown or hidden, use : mainBoard.show
// To discover if the board is minimized or not, use : mainBoard.suppress
//
// To set the current title of the multiboard, use : set mainBoard.title = "My awesome title!"
// To set the current column count of the multiboard, use : set mainBoard.columns = myColumnCount
// To set the current row count of the multiboard, use : set mainBoard.rows = myColumnCount
// To show or hide the multiboard, use : set mainBoard.show = trueOrFalse
// To minimize or maximize the multiboard, use : set mainBoard.suppress = trueOrFalse
//
// where mainBoard is the variable of type myBoard.
//
// Please credit bowser499 aka [DUOS] for the system.
// Thank you!
//================================================================================
JASS:
library MyBoardSystem
globals
private boolean DEBUG_MODE = false
private constant integer MAX_ROW_COUNT = 100
private constant integer MAX_COLUMN_COUNT = 30
private constant integer MAX_ARRAY_SIZE = MAX_ROW_COUNT*MAX_COLUMN_COUNT
private constant real AVERAGE_LETTER_WIDTH = .01484375
endglobals
struct myBoard
readonly multiboard board = null
private integer colCount = 0
private integer rowCount = 0
private boolean isMinimized = false
private boolean isShown = false
private string titleText = ""
private integer array charCnt [MAX_ARRAY_SIZE]
private real array width [MAX_ARRAY_SIZE]
private boolean array showVal [MAX_ARRAY_SIZE]
private boolean array showIcon[MAX_ARRAY_SIZE]
private string array curIcon [MAX_ARRAY_SIZE]
private string array curValue[MAX_ARRAY_SIZE]
private multiboarditem array brdItem [MAX_ARRAY_SIZE]
// Getting the correct values from arrays.
method getCharCount takes integer col, integer row returns integer
return .charCnt[MAX_COLUMN_COUNT*col + row]
endmethod
method getWidth takes integer col, integer row returns real
return .width[MAX_COLUMN_COUNT*col + row]
endmethod
method getIconPath takes integer col, integer row returns string
return .curIcon[MAX_COLUMN_COUNT*col + row]
endmethod
method getValue takes integer col, integer row returns string
return .curValue[MAX_COLUMN_COUNT*col + row]
endmethod
method getItem takes integer col, integer row returns multiboarditem
return .brdItem[MAX_COLUMN_COUNT*col + row]
endmethod
method isValueShown takes integer col, integer row returns boolean
return showVal[MAX_COLUMN_COUNT*col + row]
endmethod
method isIconShown takes integer col, integer row returns boolean
return showIcon[MAX_COLUMN_COUNT*col + row]
endmethod
// Local parameter changes.
method displayLocalIcon takes player whichPlayer, integer col, integer row, boolean doDisplay returns nothing
local integer arrIndex = MAX_COLUMN_COUNT*col + row
if GetLocalPlayer() == whichPlayer then
set .showIcon[arrIndex] = doDisplay
endif
call MultiboardSetItemStyle(.brdItem[arrIndex],.showVal[arrIndex],.showIcon[arrIndex])
endmethod
method displayLocalValue takes player whichPlayer, integer col, integer row, boolean doDisplay returns nothing
local integer arrIndex = MAX_COLUMN_COUNT*col + row
if GetLocalPlayer() == whichPlayer then
set .showVal[arrIndex] = doDisplay
endif
call MultiboardSetItemStyle(.brdItem[arrIndex],.showVal[arrIndex],.showIcon[arrIndex])
endmethod
method setLocalIcon takes player whichPlayer, integer col, integer row, string newIcon returns nothing
local integer arrIndex = MAX_COLUMN_COUNT*col + row
if GetLocalPlayer() == whichPlayer then
set .curIcon[arrIndex] = newIcon
endif
call MultiboardSetItemIcon(.brdItem[arrIndex],.curIcon[arrIndex])
endmethod
method setLocalValue takes player whichPlayer, integer col, integer row, string newValue returns nothing
local integer arrIndex = MAX_COLUMN_COUNT*col + row
if GetLocalPlayer() == whichPlayer then
set .curValue[arrIndex] = newValue
endif
call MultiboardSetItemValue(.brdItem[arrIndex],.curValue[arrIndex])
endmethod
method setLocalWidth takes player whichPlayer, integer col, integer row, real width returns nothing
local integer arrIndex = MAX_COLUMN_COUNT*col + row
if GetLocalPlayer() == whichPlayer then
set .width[arrIndex] = width
set .charCnt[arrIndex] = R2I(width/AVERAGE_LETTER_WIDTH)
endif
call MultiboardSetItemWidth(.brdItem[arrIndex],.width[arrIndex])
endmethod
method setLocalTitleText takes player whichPlayer, string newTitle returns nothing
if GetLocalPlayer() == whichPlayer then
set .titleText = newTitle
endif
call MultiboardSetTitleText(.board,.titleText)
endmethod
// Global parameter changes.
method displayIcon takes integer col, integer row, boolean doDisplay returns nothing
call .displayLocalIcon(GetLocalPlayer(),col,row,doDisplay)
endmethod
method displayValue takes integer col, integer row, boolean doDisplay returns nothing
call .displayLocalValue(GetLocalPlayer(),col,row,doDisplay)
endmethod
method setIcon takes integer col, integer row, string newIcon returns nothing
call .setLocalIcon(GetLocalPlayer(),col,row,newIcon)
endmethod
method setValue takes integer col, integer row, string newValue returns nothing
call .setLocalValue(GetLocalPlayer(),col,row,newValue)
endmethod
method setWidth takes integer col, integer row, real width returns nothing
call .setLocalWidth(GetLocalPlayer(),col,row,width)
endmethod
// General stuff.
method minimize takes boolean doMinimize returns nothing
if .isShown then
call MultiboardMinimize(.board,doMinimize)
endif
set .isMinimized = doMinimize
endmethod
method display takes boolean doDisplay returns nothing
set .isShown = doDisplay
call MultiboardDisplay(.board,doDisplay)
if doDisplay then
// Unbug the minimization - known issue.
call .minimize(not .isMinimized)
call .minimize(not .isMinimized)
call .minimize(not .isMinimized)
call .minimize(not .isMinimized)
endif
endmethod
method setRowCount takes integer rows returns nothing
local integer colLoop = 0
local integer rowLoop = 0
local integer arrIndex = 0
// No actions if it's same.
if rows != .rowCount then
// Here's the anti-lag snippet: remove unneeded multiboard items from memory.
// (or add new!)
if rows < .rowCount then
set rowLoop = rows
loop
exitwhen rowLoop > .rowCount
set colLoop = 0
loop
exitwhen colLoop > .colCount
set arrIndex = MAX_COLUMN_COUNT*colLoop + rowLoop
call MultiboardReleaseItem(.brdItem[arrIndex])
set .brdItem[arrIndex] = null
set colLoop = colLoop + 1
endloop
set rowLoop = rowLoop + 1
endloop
else
set rowLoop = .rowCount
loop
exitwhen rowLoop > rows
set colLoop = 0
loop
exitwhen colLoop > .colCount
set arrIndex = MAX_COLUMN_COUNT*colLoop + rowLoop
set brdItem [arrIndex] = MultiboardGetItem(.board,rowLoop,colLoop)
set width [arrIndex] = .01
set showVal [arrIndex] = true
set showIcon[arrIndex] = true
set curValue[arrIndex] = ""
set curIcon [arrIndex] = ""
set colLoop = colLoop + 1
endloop
set rowLoop = rowLoop + 1
endloop
endif
set .rowCount = rows
call MultiboardSetRowCount(.board,.rowCount)
endif
endmethod
method setColCount takes integer cols returns nothing
local integer colLoop = 0
local integer rowLoop = 0
local integer arrIndex = 0
// No actions if it's same.
if cols != .colCount then
// Here's the anti-lag snippet: remove unneeded multiboard items from memory.
// (or add new!)
if cols < .colCount then
set colLoop = cols
loop
exitwhen colLoop > .colCount
set rowLoop = 0
loop
exitwhen rowLoop > .rowCount
set arrIndex = MAX_COLUMN_COUNT*colLoop + rowLoop
call MultiboardReleaseItem(.brdItem[arrIndex])
set .brdItem[arrIndex] = null
set rowLoop = rowLoop + 1
endloop
set colLoop = colLoop + 1
endloop
else
set colLoop = .colCount
loop
exitwhen colLoop > cols
set rowLoop = 0
loop
exitwhen rowLoop > .rowCount
set arrIndex = MAX_COLUMN_COUNT*colLoop + rowLoop
set brdItem [arrIndex] = MultiboardGetItem(.board,rowLoop,colLoop)
set width [arrIndex] = .01
set showVal [arrIndex] = true
set showIcon[arrIndex] = true
set curValue[arrIndex] = ""
set curIcon [arrIndex] = ""
set rowLoop = rowLoop + 1
endloop
set colLoop = colLoop + 1
endloop
endif
set .colCount = cols
call MultiboardSetColumnCount(.board,.colCount)
endif
endmethod
method setTitleText takes string newTitle returns nothing
set .titleText = newTitle
call MultiboardSetTitleText(.board,.titleText)
endmethod
// Operator API.
method operator title takes nothing returns string
return .titleText
endmethod
method operator title= takes string newTitle returns nothing
call .setTitleText(newTitle)
endmethod
method operator columns takes nothing returns integer
return .colCount
endmethod
method operator columns= takes integer cols returns nothing
call .setColCount(cols)
endmethod
method operator rows takes nothing returns integer
return .rowCount
endmethod
method operator rows= takes integer cols returns nothing
call .setRowCount(cols)
endmethod
method operator show takes nothing returns boolean
return .isShown
endmethod
method operator show= takes boolean doDisplay returns nothing
call .display(doDisplay)
endmethod
method operator suppress takes nothing returns boolean
return .isMinimized
endmethod
method operator suppress= takes boolean doMinimize returns nothing
call .minimize(doMinimize)
endmethod
// Initializer.
static method create takes integer cols, integer rows, string title returns thistype
local thistype this = thistype.allocate()
local integer colLoop = 0
local integer rowLoop = 0
local integer arrIndex = 0
set .board = CreateMultiboard()
set .colCount = cols
set .rowCount = rows
set .isMinimized = false
set .isShown = false
set .titleText = title
call MultiboardSetColumnCount(.board,cols)
call MultiboardSetRowCount(.board,rows)
call MultiboardSetTitleText(.board,title)
// Pre-initializing board items.
// This is needed to drastically reduce function calls afterwards.
loop
exitwhen colLoop > cols
set rowLoop = 0
loop
exitwhen rowLoop > rows
set arrIndex = MAX_COLUMN_COUNT*colLoop + rowLoop
set .brdItem [arrIndex] = MultiboardGetItem(.board,rowLoop,colLoop)
set .width [arrIndex] = .01
set .charCnt [arrIndex] = 4
set .showVal [arrIndex] = true
set .showIcon[arrIndex] = true
set .curValue[arrIndex] = ""
set .curIcon [arrIndex] = ""
set rowLoop = rowLoop + 1
endloop
set colLoop = colLoop + 1
endloop
return this
endmethod
endstruct
endlibrary
Version 1.1:
Version 1.0:
- The struct members are now protected from editing outside of the struct.
- Added minimize method for adjusting the minimization.
- Added setLocalTitleText method for setting the title locally.
- Added operators:
- title (for getting/setting multiboard's title)
- columns (for getting/setting multiboard's column count)
- rows (for getting/setting multiboard's row count)
- show (for getting/setting multiboard's visibility)
- suppress (for getting/setting multiboard's suppression)
Version 1.0:
- First public version.
This is the system that allows full featured control of multiboard. It is simple to use even for GUI lovers and it's possible for it to extend their possibilities.
Tell me your opinions please.
Last edited: