Magentix
if (OP.statement == false) postCount++;
- Reaction score
- 107
jBoard
Combines the power of jQuery (webdesign) into vJASS multiboards.
The manual is quite clear, give it a look:
You can copy this into a map to try it out:
Changelog:
Combines the power of jQuery (webdesign) into vJASS multiboards.
The manual is quite clear, give it a look:
JASS:
//==============================================================================
// jBoard -- ADVANCED MULTIBOARD SYSTEM BY MAGENTIX -- v1.2
//==============================================================================
//==============================================================================
// Quick manual:
//==============================================================================
//
// Implement by adding "requires jBoardLib" behind your library/scope names
//
// ----------------------------------------------------------------------
// What is jBoard?
// ----------------------------------------------------------------------
//
// jBoard is an enhanced multiboard management system, inspired by the
// jQuery library that is available to webdesigners. That javascript library
// allows for a cool functionality called "chaining".
//
// Because WC3 multiboards often require a huge amount of function calls,
// I came up with jBoard to allow you to make your multiboard code shorter,
// smoother and overall more easy to use.
//
//
// ----------------------------------------------------------------------
// What is chaining and how to use it?
// ----------------------------------------------------------------------
//
// An example says a thousand words, assume this is your 10x5 multiboard setup
// and you want to set all fields to "0" and the first field to "1":
//
// - local multiboard MB = CreateMultiboard()
// local multiboarditem MBI
// call MultiboardSetTitleText(MB,"My Multiboard")
// call MultiboardDisplay(MB,true)
// call MultiboardSetRowCount(MB,10)
// call MultiboardSetColumnCount(MB,5)
// call MultiboardSetItemsValue(MB,"0")
// call MultiboardSetItemsStyle(MB,true,false)
// set MBI = MultiboardGetItem(MB,0,0)
// call MultiboardSetItemValue(MBI,"1")
//
// Now take a look at jBoard:
// - //! runtextmacro jBoardCreate("MyBoard","10","5")
// local MyBoard MB = MyBoard.create("My Multiboard").field(0,0).setValue("1")
// That's all you need to type!
//
// Remember: the textmacro also only has to be called ONCE to create a
// multiboard with the wanted dimensions. So actually that line wouldn't be
// there, but at the top of your script.
//
// Did you also notice how every method call returned an object that you
// could then call another method on? That is the beauty of chaining.
//
// !! EVERY FUNCTION CALL RETURNS A jBoard OBJECT UNLESS STATED OTHERWISE !!
//
//
// ----------------------------------------------------------------------
// I noticed a textmacro there, what gives?
// ----------------------------------------------------------------------
//
// Since you need to create structs that represent your multiboard, jBoard
// needs to know the dimensions of your multiboard to ensure the structs
// don't take up more space than they need to.
//
// For every multiboard variation you plan to use, simply call this once at
// the top of your script:
// //! runtextmacro jBoardCreate("StructName","RowAmount","ColAmount")
//
// Example for an 8 row, 4 col board:
// //! runtextmacro jBoardCreate("My8x4Board","8","4")
// Which you can then instanciate in your script as
// My8x4Board.create("BoardTitle")
//
//
// ----------------------------------------------------------------------
// Defaults
// ----------------------------------------------------------------------
//
// Somtimes we don't want our board cells to be empty by default, but show
// 0 for example. This is easy to achieve by setting a default. Take a look
// at the jBoard struct further down this info block and edit the defaults
// you like to see changed. Every jBoard that gets created after a change
// will take those defaults into account.
//
// Note that you can hardcode defaults below and still change them on the fly!
// set jBoard.defaultItemValue = "1" -- Valid syntax!
//
// Edit your defaults here:
//! textmacro jBoardDefaults
static string defaultItemValue = ""
static string defaultIconPath = "UI\\Widgets\\EscMenu\\Human\\observer-icon.blp"
static boolean defaultShowValue = true
static boolean defaultShowIcon = false
static boolean defaultShowBoard = true
static real defaultItemWidth = 0.03
//! endtextmacro
//
//==============================================================================
//==============================================================================
// Tip: Commenting out newlines
//==============================================================================
//
// Sometimes when chaining methods, a command can get quite lengthy. jQuery
// doesn't suffer from this visually, because javascript allows people to write
// code over multiple lines until they end it with a semicolon (<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite2" alt=";)" title="Wink ;)" loading="lazy" data-shortname=";)" />
//
// JASS, however, doesn't allow that directly. Fortunately you can call jBoard
// commands just as easily on multiple lines. Remember: Until you call .reset(),
// your selection will be saved to the next line!
//
// Example:
// local MyBoard MB = MyBoard.create("funkyboard").setplayerrow(0,2).setcolour("ff0000").reset().setplayerrow(1,3).setcolour("0000ff").reset().etc...
//
// Could become:
// local MyBoard MB = MyBoard.create("funkyboard")
// call MB.setplayerrow(0,2).setcolour("ff0000").reset()
// call MB.setplayerrow(1,3)
// call MB.setcolour("0000ff").reset() <-- Previous row selection was saved to this line
//
// In the end it all boils down to which type of coding you prefer, of course.
//
//==============================================================================
//==============================================================================
// Tip: -R Functions
//==============================================================================
//
// When chaining several commands onto a set of fields, one could easily say:
// "There, now let me reset my selection and continue chaining methods"
//
// However, when chaining that way, a string of jBoard commands could easily
// contain the call .reset() a dozen times.
//
// To save coding space and safeguard readability, I introduced the -R functions:
// Basically, any non-selector function that returns a jBoard object can be called
// with a capital "R" behind the name and the jBoard system will automatically
// call a .reset() for you.
//
// The above example of commenting out newlines would then become:
// local MyBoard MB = MyBoard.create("funkyboard").setPlayerRow(0,2).setColourR("ff0000").setPlayerRow(1,3).setColourR("0000ff").etc...
//
// As you can see, this makes the chaining process yet again a little smoother
// Once again: this functionality does not work on selectors/"getters"!
//
//==============================================================================
//==============================================================================
// Function index:
//==============================================================================
//
// ----------------------------------------------------------------------
// Standard Functions - Creating, showing, etc...
// ----------------------------------------------------------------------
//
// Main functionality you'd expect from any multiboard. May be used within
// a local player block. Can be used on any jBoard object (boad, row, col,
// field(s)) and returns the selection you called the function on.
//
// .create("MultiboardName")
// .show()
// .hide()
// .clear() -- SHOULD NEVER BE CALLED, just here for completion
// .fold()
// .unfold()
// .setName()
// .getName() -- Returns the multiboard name as a string, not a jBoard object
// .setNameColour("rgb value")
// Colour syntax: rrggbb (in hexadecimal)
// .getNameColour()
// .destroy()
//
//
// ----------------------------------------------------------------------
// Selection Functions - Adds rows, cols or fields to the selection
// ----------------------------------------------------------------------
//
// Selectors can be used on any jBoard object (boad, row, col, field(s))
// They always return the collection of all the objects you selected from
// the last .reset() up to that point.
//
// VERY IMPORTANT!
// .reset()
// Resets the current selection to the board
//
// MAIN SELECTORS
// .row(integer start, integer end)
// .col(integer start, integer end)
// Selects a row, a columns or multiple of any
// - .row(0,0) returns the row object of row 0
// - .row(0,1) returns the combined fields of row 0 and row 1
// - ONLY WHEN HAVING -ONE- ROW/COL SELECTED will you be able
// to use row/col only functionality
// (it won't give errors or bugs if you try, though)
//
// SINGLE SELECTOR
// .field(integer row, integer col)
// Adds one field to the selection or (if selection is empty)
// returns one field to use field-level manipulations on
// .getPlayerRowField(integer player, integer column)
// .getPlayerColField(integer player, integer row)
// The above two return just ONE field of a player's row.
// Since the player selectors return an entire row and a deep
// selector inside that row would clear the selection first,
// it would otherwise be impossible to select multiple fields
// from player rows or columns...
// You should use this over .getPlayerRow(0).getField(3) unless
// you want only that field of course.
//
// DEEP SELECTOR
// .getField(integer which)
// Returns just ONE field, selected from your previous selection
//
// Quick list of what it does when used on a:
// - Board: Returns the field in position X of the board,
// reading from top left to bottom right
// - Row: Returns the field in column X of that row
// - Column: Returns the field in row X of that column
// - Fields: Returns the field in position X of the selection,
// reading from top left to bottom right
// - Field: Does nothing (returns same field)
//
//
// ----------------------------------------------------------------------
// Player Selectors
// ----------------------------------------------------------------------
//
// Simple functions that allow you to save a row/col to a player.
//
// Both the setters and the getters add the row/col you just set
// to the current selection. Hence, this is both valid syntax:
// - MB.setPlayerRow(0,1).setcolour("ff0000")
// - MB.setPlayerRow(0,1)
// MB.getPlayerRow(0,1).setcolour("ff0000")
//
// The player "setters" have -R functionality, but the "getters" don't!
//
// .setPlayerRow(integer player, integer row)
// .setPlayerCol(integer player, integer col)
// .getPlayerRow(integer player)
// .getPlayerCol(integer player)
//
//
// ----------------------------------------------------------------------
// Manipulation Functions - Also referred to as "setters"
// ----------------------------------------------------------------------
//
// Setters can be used on any jBoard object (boad, row, col, field(s))
// They always return the object that was just manipulated
//
// ABOUT PREFIXES AND SUFFIXES:
// Imagine you want a row with user experience values, by setting a suffix
// "XP", you could still use .add(value) to a field, because the content
// can still be handled by S2I(). Example:
// - .field(1,2) has content "2" and suffix " xp", the field shows "2 xp"
// A user calls .field(1,2).add(4), the field now show "6 xp", without
// having to worry about the " xp" bit!
//
// VALUE SETTERS
// .setValue("value")
// .setColour("rgb value")
// Colour syntax: rrggbb (in hexadecimal)
// .setPrefix("value")
// .setSuffix("value")
// .setIconPath("path")
// .setWidth(real width)
//
// VALUE MANIPULATORS
// .add(integer value)
// Only works if field contents are numerical strings, value can be negative
//
//
// ----------------------------------------------------------------------
// Retrieval Functions - Also referred to as "getters"
// ----------------------------------------------------------------------
//
// Getters can be used on any jBoard object (boad, row, col, field(s))
// !! EVERY GETTER RETURNS A STRING !!
//
// HERE'S WHY:
// When using a getter on anything but a single field, a string is returned
// with all values in it, separated by a pipe (|).
// Future versions may support smart retrieval of a row's/col's properties
// should they all have the same colour for example...
//
// Naturally, the fact that these methods return a string instead of a
// jBoard object means that calling any of these methods is in fact
// "The end of the line" for that chaining process...
//
// .getValue()
// .getColour()
// .getPrefix()
// .getSuffix()
// .getIconPath() -- CAREFUL USE on many fields! (might blow up in your face)
// .getWidth()
//
//
// ----------------------------------------------------------------------
// Extra Functions - Various
// ----------------------------------------------------------------------
//
// .showIcon()
// .hideIcon()
// .showValue()
// .hideValue()
//
//==============================================================================
//==============================================================================
// Credits:
//==============================================================================
//
// John Resig for coming up with jQuery and its chaining
// Vexorian for vJass and JassHelper, making jBoard possible
//
//==============================================================================
//==============================================================================
// Open letter to Vexorian:
//==============================================================================
//
// Take a look at the setter/getter methods and the -R functions. If that isn't
// a reason why textmacroes should be allowed to be nested, I don't know what
// is :x (They're all the same bar the function name...)
//
// Protip: Yes, this is a request to you to get nested textmacroes working <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite1" alt=":)" title="Smile :)" loading="lazy" data-shortname=":)" />
//
//==============================================================================
//==============================================================================
// Macro function core -- No touchy from here on out!
//==============================================================================
//! textmacro jBoardCreate takes NAME, ROWS, COLS
globals
private constant integer $NAME$SIZE = $ROWS$*$COLS$
private constant integer $NAME$ROWS = $ROWS$
private constant integer $NAME$COLS = $COLS$
endglobals
private struct $NAME$FIELD
$NAME$ parent
integer realRow
integer realCol
multiboarditem mbi
real width = jBoard.defaultItemWidth
string iconpath = jBoard.defaultIconPath
string colour = "ffffff"
string prefix = ""
string content = jBoard.defaultItemValue
string suffix = ""
boolean showV = jBoard.defaultShowValue
boolean showI = jBoard.defaultShowIcon
static method create takes $NAME$ parent, integer row, integer col returns thistype
local thistype f = thistype.allocate()
set f.parent = parent
set f.realRow = row
set f.realCol = col
set f.mbi = MultiboardGetItem(f.parent.MB,f.realRow,f.realCol)
return f
endmethod
method onDestroy takes nothing returns nothing
call MultiboardReleaseItem(.mbi)
endmethod
private method updateField takes nothing returns nothing
call MultiboardSetItemValue(.mbi,"|cff"+.colour+.prefix+.content+.suffix+"|r")
endmethod
method add takes integer i returns nothing
set .content = I2S(S2I(.content) + i)
call .updateField()
endmethod
method setValue takes string s returns nothing
set .content = s
call .updateField()
endmethod
method setPrefix takes string s returns nothing
set .prefix = s
call .updateField()
endmethod
method setSuffix takes string s returns nothing
set .suffix = s
call .updateField()
endmethod
method setColour takes string rgb returns nothing
set .colour = rgb
call .updateField()
endmethod
method setWidth takes real w returns nothing
set .width = w
call MultiboardSetItemWidth(.mbi,w)
endmethod
method showIcon takes nothing returns nothing
set .showI = true
call MultiboardSetItemStyle(.mbi,.showV,.showI)
endmethod
method hideIcon takes nothing returns nothing
set .showI = false
call MultiboardSetItemStyle(.mbi,.showV,.showI)
endmethod
method showValue takes nothing returns nothing
set .showV = true
call MultiboardSetItemStyle(.mbi,.showV,.showI)
endmethod
method hideValue takes nothing returns nothing
set .showV = false
call MultiboardSetItemStyle(.mbi,.showV,.showI)
endmethod
method setIconPath takes string s returns nothing
set .iconpath = s
endmethod
method getValue takes nothing returns string
return .content
endmethod
method getPrefix takes nothing returns string
return .prefix
endmethod
method getSuffix takes nothing returns string
return .suffix
endmethod
method getColour takes nothing returns string
return .colour
endmethod
method getWidth takes nothing returns string
return R2S(.width)
endmethod
method getIconPath takes nothing returns string
return .iconpath
endmethod
endstruct
private interface $NAME$FIELDCOLLECTION
$NAME$ parent
method getField takes integer i returns $NAME$FIELD
endinterface
private struct $NAME$UTILITY extends $NAME$FIELDCOLLECTION
stub method getField takes integer i returns $NAME$FIELD
return 0
endmethod
endstruct
private struct $NAME$ROW extends $NAME$UTILITY
$NAME$FIELD array fields[$COLS$]
integer realPos
integer fromPlayer = -1
static method create takes $NAME$ parent, integer pos returns thistype
local thistype row = thistype.allocate()
local integer i = 0
set row.parent = parent
set row.realPos = pos
loop
exitwhen i == $NAME$COLS
set row.fields<i> = $NAME$FIELD.create(parent,pos,i)
set i = i + 1
endloop
return row
endmethod
method getField takes integer i returns $NAME$FIELD
return .fields<i>
endmethod
endstruct
private struct $NAME$COL extends $NAME$UTILITY
$NAME$FIELD array fields[$ROWS$]
integer realPos
integer fromPlayer = -1
static method create takes $NAME$ parent, integer pos returns thistype
local thistype col = thistype.allocate()
local integer i = 0
set col.parent = parent
set col.realPos = pos
loop
exitwhen i == $NAME$ROWS
set col.fields<i> = col.parent.rows<i>.fields[pos]
set i = i + 1
endloop
return col
endmethod
method getField takes integer i returns $NAME$FIELD
return .fields<i>
endmethod
endstruct
private struct $NAME$FLD extends $NAME$UTILITY
$NAME$FIELD array fields[$NAME$SIZE]
static method create takes $NAME$ parent returns thistype
local thistype fld = thistype.allocate()
set fld.parent = parent
return fld
endmethod
private method hasField takes $NAME$FIELD f returns boolean
local integer i = 0
loop
exitwhen i == .parent.selectionAmount
if (.fields<i> == f) then
return true
endif
set i = i + 1
endloop
return false
endmethod
method addFields takes $NAME$FIELDCOLLECTION f, integer amount returns nothing
local integer i = 0
loop
exitwhen i == amount
if not(.hasField(f.getField(i))) then
set .fields[.parent.selectionAmount] = f.getField(i)
set .parent.selectionAmount = .parent.selectionAmount + 1
endif
set i = i + 1
endloop
endmethod
method getField takes integer i returns $NAME$FIELD
return .fields<i>
endmethod
endstruct
struct $NAME$ extends jBoard
$NAME$ROW array rows[$ROWS$]
$NAME$COL array cols[$COLS$]
$NAME$FLD selection
static method create takes string boardName returns thistype
local thistype board = thistype.allocate(boardName)
local integer i = 0
call MultiboardSetRowCount(board.MB,$NAME$ROWS)
call MultiboardSetColumnCount(board.MB,$NAME$COLS)
set board.selection = $NAME$FLD.create(board)
loop
exitwhen i == $NAME$ROWS
set board.rows<i> = $NAME$ROW.create(board,i)
set i = i + 1
endloop
set i = 0
loop
exitwhen i == $NAME$COLS
set board.cols<i> = $NAME$COL.create(board,i)
set i = i + 1
endloop
call board.initBoard()
return board
endmethod
private method transfer takes $NAME$FIELDCOLLECTION f, integer ftype, integer amount returns nothing
set .selectionLevel = IntegerTertiaryOp(.selectionLevel == jBoard_SELECTION_LVL_BOARD,ftype,jBoard_SELECTION_LVL_FIELDS)
call .selection.addFields(f,amount)
endmethod
method reset takes nothing returns thistype
set .selectionLevel = jBoard_SELECTION_LVL_BOARD
set .selectionAmount = 0
return this
endmethod
method field takes integer row, integer col returns thistype
set .selection.fields[0] = .rows[row].fields[col]
set .selectionLevel = jBoard_SELECTION_LVL_FLD
return this
endmethod
method getField takes integer which returns thistype
if .selectionLevel == jBoard_SELECTION_LVL_ROW then
set .selection.fields[0] = .rows[.selectionSpecial].fields[which]
elseif .selectionLevel == jBoard_SELECTION_LVL_COL then
set .selection.fields[0] = .cols[.selectionSpecial].fields[which]
elseif .selectionLevel == jBoard_SELECTION_LVL_FIELDS then
set .selection.fields[0] = .selection.fields[which]
elseif .selectionLevel == jBoard_SELECTION_LVL_BOARD then
set .selection.fields[0] = .rows[which/$NAME$COLS].fields[ModuloInteger(which,$NAME$COLS)]
endif
set .selectionLevel = jBoard_SELECTION_LVL_FLD
return this
endmethod
method row takes integer start, integer end returns thistype
local integer i = IntegerTertiaryOp(start<end,start,end)
local integer j = IntegerTertiaryOp(start<end,end,start)
if start == end then
set .selectionSpecial = start
call .transfer(.rows[start],jBoard_SELECTION_LVL_ROW,$NAME$COLS)
else
loop
exitwhen i > j
call .transfer(.rows<i>,jBoard_SELECTION_LVL_ROW,$NAME$COLS)
set i = i + 1
endloop
endif
return this
endmethod
method col takes integer start, integer end returns thistype
local integer i = IntegerTertiaryOp(start<end,start,end)
local integer j = IntegerTertiaryOp(start<end,end,start)
if start == end then
set .selectionSpecial = start
call .transfer(.cols[start],jBoard_SELECTION_LVL_COL,$NAME$ROWS)
else
loop
exitwhen i > j
call .transfer(.cols<i>,jBoard_SELECTION_LVL_COL,$NAME$ROWS)
set i = i + 1
endloop
endif
return this
endmethod
method setPlayerRow takes integer p, integer row returns thistype
set .playerRow[p] = row
set .rows[row].fromPlayer = p
return .row(row,row)
endmethod
method getPlayerRow takes integer p returns thistype
return .row(.playerRow[p],.playerRow[p])
endmethod
method getPlayerRowField takes integer p, integer i returns thistype
return .field(.playerRow[p],i)
endmethod
method setPlayerCol takes integer p, integer col returns thistype
set .playerCol[p] = col
set .cols[col].fromPlayer = p
return .col(col,col)
endmethod
method getPlayerCol takes integer p returns thistype
return .col(.playerCol[p],.playerCol[p])
endmethod
method getPlayerColField takes integer p, integer i returns thistype
return .field(i,.playerCol[p])
endmethod
method setColour takes string rgb returns thistype
local integer i = 0
if (.selectionLevel == jBoard_SELECTION_LVL_BOARD) then
loop
exitwhen i == $NAME$ROWS
call .reset().row(i,i).setColour(rgb)
set i = i + 1
endloop
set .selectionLevel = jBoard_SELECTION_LVL_BOARD
elseif (.selectionLevel == jBoard_SELECTION_LVL_FIELDS) then
loop
exitwhen i == .selectionAmount
call .selection.fields<i>.setColour(rgb)
set i = i + 1
endloop
elseif (.selectionLevel == jBoard_SELECTION_LVL_ROW) then
loop
exitwhen i == $NAME$COLS
call .rows[.selectionSpecial].fields<i>.setColour(rgb)
set i = i + 1
endloop
elseif (.selectionLevel == jBoard_SELECTION_LVL_COL) then
loop
exitwhen i == $NAME$ROWS
call .cols[.selectionSpecial].fields<i>.setColour(rgb)
set i = i + 1
endloop
elseif (.selectionLevel == jBoard_SELECTION_LVL_FLD) then
call .selection.fields[0].setColour(rgb)
endif
return this
endmethod
method setWidth takes real w returns thistype
local integer i = 0
if (.selectionLevel == jBoard_SELECTION_LVL_BOARD) then
loop
exitwhen i == $NAME$ROWS
call .reset().row(i,i).setWidth(w)
set i = i + 1
endloop
set .selectionLevel = jBoard_SELECTION_LVL_BOARD
elseif (.selectionLevel == jBoard_SELECTION_LVL_FIELDS) then
loop
exitwhen i == .selectionAmount
call .selection.fields<i>.setWidth(w)
set i = i + 1
endloop
elseif (.selectionLevel == jBoard_SELECTION_LVL_ROW) then
loop
exitwhen i == $NAME$COLS
call .rows[.selectionSpecial].fields<i>.setWidth(w)
set i = i + 1
endloop
elseif (.selectionLevel == jBoard_SELECTION_LVL_COL) then
loop
exitwhen i == $NAME$ROWS
call .cols[.selectionSpecial].fields<i>.setWidth(w)
set i = i + 1
endloop
elseif (.selectionLevel == jBoard_SELECTION_LVL_FLD) then
call .selection.fields[0].setWidth(w)
endif
return this
endmethod
method setPrefix takes string val returns thistype
local integer i = 0
if (.selectionLevel == jBoard_SELECTION_LVL_BOARD) then
loop
exitwhen i == $NAME$ROWS
call .reset().row(i,i).setPrefix(val)
set i = i + 1
endloop
set .selectionLevel = jBoard_SELECTION_LVL_BOARD
elseif (.selectionLevel == jBoard_SELECTION_LVL_FIELDS) then
loop
exitwhen i == .selectionAmount
call .selection.fields<i>.setPrefix(val)
set i = i + 1
endloop
elseif (.selectionLevel == jBoard_SELECTION_LVL_ROW) then
loop
exitwhen i == $NAME$COLS
call .rows[.selectionSpecial].fields<i>.setPrefix(val)
set i = i + 1
endloop
elseif (.selectionLevel == jBoard_SELECTION_LVL_COL) then
loop
exitwhen i == $NAME$ROWS
call .cols[.selectionSpecial].fields<i>.setPrefix(val)
set i = i + 1
endloop
elseif (.selectionLevel == jBoard_SELECTION_LVL_FLD) then
call .selection.fields[0].setPrefix(val)
endif
return this
endmethod
method setSuffix takes string val returns thistype
local integer i = 0
if (.selectionLevel == jBoard_SELECTION_LVL_BOARD) then
loop
exitwhen i == $NAME$ROWS
call .reset().row(i,i).setSuffix(val)
set i = i + 1
endloop
set .selectionLevel = jBoard_SELECTION_LVL_BOARD
elseif (.selectionLevel == jBoard_SELECTION_LVL_FIELDS) then
loop
exitwhen i == .selectionAmount
call .selection.fields<i>.setSuffix(val)
set i = i + 1
endloop
elseif (.selectionLevel == jBoard_SELECTION_LVL_ROW) then
loop
exitwhen i == $NAME$COLS
call .rows[.selectionSpecial].fields<i>.setSuffix(val)
set i = i + 1
endloop
elseif (.selectionLevel == jBoard_SELECTION_LVL_COL) then
loop
exitwhen i == $NAME$ROWS
call .cols[.selectionSpecial].fields<i>.setSuffix(val)
set i = i + 1
endloop
elseif (.selectionLevel == jBoard_SELECTION_LVL_FLD) then
call .selection.fields[0].setSuffix(val)
endif
return this
endmethod
method setIconPath takes string val returns thistype
local integer i = 0
if (.selectionLevel == jBoard_SELECTION_LVL_BOARD) then
loop
exitwhen i == $NAME$ROWS
call .reset().row(i,i).setIconPath(val)
set i = i + 1
endloop
set .selectionLevel = jBoard_SELECTION_LVL_BOARD
elseif (.selectionLevel == jBoard_SELECTION_LVL_FIELDS) then
loop
exitwhen i == .selectionAmount
call .selection.fields<i>.setIconPath(val)
set i = i + 1
endloop
elseif (.selectionLevel == jBoard_SELECTION_LVL_ROW) then
loop
exitwhen i == $NAME$COLS
call .rows[.selectionSpecial].fields<i>.setIconPath(val)
set i = i + 1
endloop
elseif (.selectionLevel == jBoard_SELECTION_LVL_COL) then
loop
exitwhen i == $NAME$ROWS
call .cols[.selectionSpecial].fields<i>.setIconPath(val)
set i = i + 1
endloop
elseif (.selectionLevel == jBoard_SELECTION_LVL_FLD) then
call .selection.fields[0].setIconPath(val)
endif
return this
endmethod
method showIcon takes nothing returns thistype
local integer i = 0
if (.selectionLevel == jBoard_SELECTION_LVL_BOARD) then
loop
exitwhen i == $NAME$ROWS
call .reset().row(i,i).showIcon()
set i = i + 1
endloop
set .selectionLevel = jBoard_SELECTION_LVL_BOARD
elseif (.selectionLevel == jBoard_SELECTION_LVL_FIELDS) then
loop
exitwhen i == .selectionAmount
call .selection.fields<i>.showIcon()
set i = i + 1
endloop
elseif (.selectionLevel == jBoard_SELECTION_LVL_ROW) then
loop
exitwhen i == $NAME$COLS
call .rows[.selectionSpecial].fields<i>.showIcon()
set i = i + 1
endloop
elseif (.selectionLevel == jBoard_SELECTION_LVL_COL) then
loop
exitwhen i == $NAME$ROWS
call .cols[.selectionSpecial].fields<i>.showIcon()
set i = i + 1
endloop
elseif (.selectionLevel == jBoard_SELECTION_LVL_FLD) then
call .selection.fields[0].showIcon()
endif
return this
endmethod
method hideIcon takes nothing returns thistype
local integer i = 0
if (.selectionLevel == jBoard_SELECTION_LVL_BOARD) then
loop
exitwhen i == $NAME$ROWS
call .reset().row(i,i).hideIcon()
set i = i + 1
endloop
set .selectionLevel = jBoard_SELECTION_LVL_BOARD
elseif (.selectionLevel == jBoard_SELECTION_LVL_FIELDS) then
loop
exitwhen i == .selectionAmount
call .selection.fields<i>.hideIcon()
set i = i + 1
endloop
elseif (.selectionLevel == jBoard_SELECTION_LVL_ROW) then
loop
exitwhen i == $NAME$COLS
call .rows[.selectionSpecial].fields<i>.hideIcon()
set i = i + 1
endloop
elseif (.selectionLevel == jBoard_SELECTION_LVL_COL) then
loop
exitwhen i == $NAME$ROWS
call .cols[.selectionSpecial].fields<i>.hideIcon()
set i = i + 1
endloop
elseif (.selectionLevel == jBoard_SELECTION_LVL_FLD) then
call .selection.fields[0].hideIcon()
endif
return this
endmethod
method showValue takes nothing returns thistype
local integer i = 0
if (.selectionLevel == jBoard_SELECTION_LVL_BOARD) then
loop
exitwhen i == $NAME$ROWS
call .reset().row(i,i).showValue()
set i = i + 1
endloop
set .selectionLevel = jBoard_SELECTION_LVL_BOARD
elseif (.selectionLevel == jBoard_SELECTION_LVL_FIELDS) then
loop
exitwhen i == .selectionAmount
call .selection.fields<i>.showValue()
set i = i + 1
endloop
elseif (.selectionLevel == jBoard_SELECTION_LVL_ROW) then
loop
exitwhen i == $NAME$COLS
call .rows[.selectionSpecial].fields<i>.showValue()
set i = i + 1
endloop
elseif (.selectionLevel == jBoard_SELECTION_LVL_COL) then
loop
exitwhen i == $NAME$ROWS
call .cols[.selectionSpecial].fields<i>.showValue()
set i = i + 1
endloop
elseif (.selectionLevel == jBoard_SELECTION_LVL_FLD) then
call .selection.fields[0].showValue()
endif
return this
endmethod
method hideValue takes nothing returns thistype
local integer i = 0
if (.selectionLevel == jBoard_SELECTION_LVL_BOARD) then
loop
exitwhen i == $NAME$ROWS
call .reset().row(i,i).hideValue()
set i = i + 1
endloop
set .selectionLevel = jBoard_SELECTION_LVL_BOARD
elseif (.selectionLevel == jBoard_SELECTION_LVL_FIELDS) then
loop
exitwhen i == .selectionAmount
call .selection.fields<i>.hideValue()
set i = i + 1
endloop
elseif (.selectionLevel == jBoard_SELECTION_LVL_ROW) then
loop
exitwhen i == $NAME$COLS
call .rows[.selectionSpecial].fields<i>.hideValue()
set i = i + 1
endloop
elseif (.selectionLevel == jBoard_SELECTION_LVL_COL) then
loop
exitwhen i == $NAME$ROWS
call .cols[.selectionSpecial].fields<i>.hideValue()
set i = i + 1
endloop
elseif (.selectionLevel == jBoard_SELECTION_LVL_FLD) then
call .selection.fields[0].hideValue()
endif
return this
endmethod
method setValue takes string val returns thistype
local integer i = 0
if (.selectionLevel == jBoard_SELECTION_LVL_BOARD) then
loop
exitwhen i == $NAME$ROWS
call .reset().row(i,i).setValue(val)
set i = i + 1
endloop
set .selectionLevel = jBoard_SELECTION_LVL_BOARD
elseif (.selectionLevel == jBoard_SELECTION_LVL_FIELDS) then
loop
exitwhen i == .selectionAmount
call .selection.fields<i>.setValue(val)
set i = i + 1
endloop
elseif (.selectionLevel == jBoard_SELECTION_LVL_ROW) then
loop
exitwhen i == $NAME$COLS
call .rows[.selectionSpecial].fields<i>.setValue(val)
set i = i + 1
endloop
elseif (.selectionLevel == jBoard_SELECTION_LVL_COL) then
loop
exitwhen i == $NAME$ROWS
call .cols[.selectionSpecial].fields<i>.setValue(val)
set i = i + 1
endloop
elseif (.selectionLevel == jBoard_SELECTION_LVL_FLD) then
call .selection.fields[0].setValue(val)
endif
return this
endmethod
method add takes integer val returns thistype
local integer i = 0
if (.selectionLevel == jBoard_SELECTION_LVL_BOARD) then
loop
exitwhen i == $NAME$ROWS
call .reset().row(i,i).add(val)
set i = i + 1
endloop
set .selectionLevel = jBoard_SELECTION_LVL_BOARD
elseif (.selectionLevel == jBoard_SELECTION_LVL_FIELDS) then
loop
exitwhen i == .selectionAmount
call .selection.fields<i>.add(val)
set i = i + 1
endloop
elseif (.selectionLevel == jBoard_SELECTION_LVL_ROW) then
loop
exitwhen i == $NAME$COLS
call .rows[.selectionSpecial].fields<i>.add(val)
set i = i + 1
endloop
elseif (.selectionLevel == jBoard_SELECTION_LVL_COL) then
loop
exitwhen i == $NAME$ROWS
call .cols[.selectionSpecial].fields<i>.add(val)
set i = i + 1
endloop
elseif (.selectionLevel == jBoard_SELECTION_LVL_FLD) then
call .selection.fields[0].add(val)
endif
return this
endmethod
method getValue takes nothing returns string
local integer i = 0
local string s = ""
if (.selectionLevel == jBoard_SELECTION_LVL_FLD) then
set s = .selection.fields[0].getValue()
else
loop
exitwhen i == .selectionAmount
set s = s + .selection.fields<i>.getValue()
set i = i + 1
exitwhen i == .selectionAmount
set s = s + "|"
endloop
endif
call .reset()
return s
endmethod
method getPrefix takes nothing returns string
local integer i = 0
local string s = ""
if (.selectionLevel == jBoard_SELECTION_LVL_FLD) then
set s = .selection.fields[0].getPrefix()
else
loop
exitwhen i == .selectionAmount
set s = s + .selection.fields<i>.getPrefix()
set i = i + 1
exitwhen i == .selectionAmount
set s = s + "|"
endloop
endif
call .reset()
return s
endmethod
method getSuffix takes nothing returns string
local integer i = 0
local string s = ""
if (.selectionLevel == jBoard_SELECTION_LVL_FLD) then
set s = .selection.fields[0].getSuffix()
else
loop
exitwhen i == .selectionAmount
set s = s + .selection.fields<i>.getSuffix()
set i = i + 1
exitwhen i == .selectionAmount
set s = s + "|"
endloop
endif
call .reset()
return s
endmethod
method getWidth takes nothing returns string
local integer i = 0
local string s = ""
if (.selectionLevel == jBoard_SELECTION_LVL_FLD) then
set s = .selection.fields[0].getWidth()
else
loop
exitwhen i == .selectionAmount
set s = s + .selection.fields<i>.getWidth()
set i = i + 1
exitwhen i == .selectionAmount
set s = s + "|"
endloop
endif
call .reset()
return s
endmethod
method getColour takes nothing returns string
local integer i = 0
local string s = ""
if (.selectionLevel == jBoard_SELECTION_LVL_FLD) then
set s = .selection.fields[0].getColour()
else
loop
exitwhen i == .selectionAmount
set s = s + .selection.fields<i>.getColour()
set i = i + 1
exitwhen i == .selectionAmount
set s = s + "|"
endloop
endif
call .reset()
return s
endmethod
method getIconPath takes nothing returns string
local integer i = 0
local string s = ""
if (.selectionLevel == jBoard_SELECTION_LVL_FLD) then
set s = .selection.fields[0].getIconPath()
else
loop
exitwhen i == .selectionAmount
set s = s + .selection.fields<i>.getIconPath()
set i = i + 1
exitwhen i == .selectionAmount
set s = s + "|"
endloop
endif
call .reset()
return s
endmethod
method setName takes string s returns thistype
set .boardName = s
call MultiboardSetTitleText(.MB,"|cff"+.boardNameColour+.boardName+"|r")
return this
endmethod
method getName takes nothing returns string
call .reset()
return .boardName
endmethod
method setNameColour takes string s returns thistype
set .boardNameColour = s
call MultiboardSetTitleText(.MB,"|cff"+.boardNameColour+.boardName+"|r")
return this
endmethod
method getNameColour takes nothing returns string
call .reset()
return .boardNameColour
endmethod
method show takes nothing returns thistype
call MultiboardDisplay(.MB,true)
return this
endmethod
method hide takes nothing returns thistype
call MultiboardDisplay(.MB,false)
return this
endmethod
method clear takes nothing returns thistype
call MultiboardClear(.MB)
return this
endmethod
method fold takes nothing returns thistype
call MultiboardMinimize(.MB,true)
return this
endmethod
method unfold takes nothing returns thistype
call MultiboardMinimize(.MB,false)
return this
endmethod
method setValueR takes string val returns thistype
call .setValue(val)
call .reset()
return this
endmethod
method setColourR takes string rgb returns thistype
call .setColour(rgb)
call .reset()
return this
endmethod
method setPrefixR takes string val returns thistype
call .setPrefix(val)
call .reset()
return this
endmethod
method setSuffixR takes string val returns thistype
call .setSuffix(val)
call .reset()
return this
endmethod
method setIconPathR takes string val returns thistype
call .setIconPath(val)
call .reset()
return this
endmethod
method setWidthR takes real w returns thistype
call .setWidth(w)
call .reset()
return this
endmethod
method addR takes integer val returns thistype
call .add(val)
call .reset()
return this
endmethod
method setPlayerRowR takes integer p, integer col returns thistype
call .setPlayerRow(p,row)
call .reset()
return this
endmethod
method setPlayerColR takes integer p, integer col returns thistype
call .setPlayerCol(p,col)
call .reset()
return this
endmethod
method setNameR takes string s returns thistype
call .setName(s)
call .reset()
return this
endmethod
method setNameColourR takes string s returns thistype
call .setNameColour(s)
call .reset()
return this
endmethod
method showR takes nothing returns thistype
call .show()
call .reset()
return this
endmethod
method showIconR takes nothing returns thistype
call .showIcon()
call .reset()
return this
endmethod
method hideIconR takes nothing returns thistype
call .hideIcon()
call .reset()
return this
endmethod
method showValueR takes nothing returns thistype
call .showValue()
call .reset()
return this
endmethod
method hideValueR takes nothing returns thistype
call .hideValue()
call .reset()
return this
endmethod
method hideR takes nothing returns thistype
call .hide()
call .reset()
return this
endmethod
method clearR takes nothing returns thistype
call .clear()
call .reset()
return this
endmethod
method foldR takes nothing returns thistype
call .fold()
call .reset()
return this
endmethod
method unfoldR takes nothing returns thistype
call .unfold()
call .reset()
return this
endmethod
method destroy takes nothing returns nothing
local integer i = 0
local integer j = 0
loop
exitwhen i == $NAME$ROWS
loop
exitwhen j == $NAME$COLS
call rows<i>.fields[j].destroy()
set j = j + 1
endloop
set i = i + 1
endloop
call DestroyMultiboard(.MB)
call .deallocate()
endmethod
endstruct
//! endtextmacro
//==============================================================================
// ACTUAL LIBRARY
//==============================================================================
library jBoardLib
globals
constant integer jBoard_SELECTION_LVL_BOARD = 0
constant integer jBoard_SELECTION_LVL_ROW = 1
constant integer jBoard_SELECTION_LVL_COL = 2
constant integer jBoard_SELECTION_LVL_FLD = 3
constant integer jBoard_SELECTION_LVL_FIELDS = 4
endglobals
struct jBoard
//! runtextmacro jBoardDefaults()
multiboard MB
string boardName
string boardNameColour = "ffffcc"
integer selectionLevel = 0
integer selectionSpecial = 0
integer selectionAmount = 0
integer array playerRow[12]
integer array playerCol[12]
static method create takes string boardName returns jBoard
local jBoard j = thistype.allocate()
local integer i = 0
set j.MB = CreateMultiboard()
set j.boardName = boardName
call MultiboardSetTitleText(j.MB,boardName)
call MultiboardDisplay(j.MB,false)
return j
endmethod
method initBoard takes nothing returns nothing
call MultiboardSetItemsValue(.MB,.defaultItemValue)
call MultiboardSetItemsIcon(.MB,.defaultIconPath)
call MultiboardSetItemsStyle(.MB,.defaultShowValue,.defaultShowIcon)
call MultiboardSetItemsWidth(.MB,.defaultItemWidth)
call MultiboardDisplay(.MB,.defaultShowBoard)
endmethod
endstruct
endlibrary
//==============================================================================
// END OF jBoard ADVANCED MULTIBOARD SYSTEM
//==============================================================================
</i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i>
You can copy this into a map to try it out:
JASS:
library test initializer Init requires jBoardLib
//! runtextmacro jBoardCreate("MyBoard","4","4")
private function Actions takes nothing returns nothing
local MyBoard mb = MyBoard.create("Some jBoard")
call mb.setPlayerRow(0,0).setValue("1").setColourR("ff0000")
call mb.setPlayerRow(1,1).setValue("2").setColourR("00ff00")
call mb.setPlayerRow(2,2).setValue("3").setColourR("ffff00")
call mb.setPlayerRow(3,3).setValue("4").setColourR("ff00ff")
call mb.getField(3).setValueR("Sup").getField(14).setValueR("Dawg?")
endfunction
private function Init takes nothing returns nothing
local trigger T = CreateTrigger()
call TriggerRegisterTimerEvent(T,1.,false)
call TriggerAddAction(T,function Actions)
endfunction
endlibrary
Changelog:
Code:
v1.2 - Fixed unwanted behaviour of "getters" not resetting your selection
Deleted support for commenting out newlines, added multi-line call hint instead
Added two new functions: getPlayerRowField and getPlayerColField
Now you can get just one field belonging to a player and add it to
your selection instead of being bound to adding the entire row
v1.1 - Followed method naming convention
Added a defaultShowBoard value