• 🏆 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!

[PROTOTYPE] myBoard

Status
Not open for further replies.
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:
  • 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:
Level 31
Joined
Jul 10, 2007
Messages
6,306
These aren't really necessary

JASS:
    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

Should use [][] and operators for these

JASS:
    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
    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

operators
JASS:
    method setColCount takes integer cols returns nothing
    method setRowCount takes integer rows returns nothing

another operator

method display takes boolean doDisplay returns nothing

API needs some work

Please compare and contrast to http://www.hiveworkshop.com/forums/jass-resources-412/snippet-multiboard-210232/ to show why this is better/different
 

Cokemonkey11

Spell Reviewer
Level 29
Joined
May 9, 2006
Messages
3,534
These aren't really necessary

......

API needs some work

Please compare and contrast to http://www.hiveworkshop.com/forums/jass-resources-412/snippet-multiboard-210232/ to show why this is better/different

your_opinion.jpg
 

Cokemonkey11

Spell Reviewer
Level 29
Joined
May 9, 2006
Messages
3,534
There is a reason why general coding, including JASS, uses i[5] = 6 instead of setArrayValue(i, 5, 6) =)

In c#, getters/setters look like fields, not methods ;p

ehm, I'm not going to go into an argument about this -.-

There's also a reason why Haskell supports first class functions, why python dynamically types its variables, why x86 includes a multiplication instruction, what's your point?

That's why it's called *subjective thinking* and it doesn't belong here.

Take a look at the second reply here - http://stackoverflow.com/questions/77718/why-doesnt-java-offer-operator-overloading
 

Cokemonkey11

Spell Reviewer
Level 29
Joined
May 9, 2006
Messages
3,534
When the language supports operators, you use operators.

No. If you bothered to read the link I posted you would understand how that's not true.

when the language doesn't support operators, you don't.

Obviously you don't have the choice.

vJASS supports operators, so we use operators, not getters/setters

vJass also supports local shadowing and the : operator, but we don't all use them or encourage them do we?

Java does not, so they use getters/setters

Nice little ninja edit you did there, guess you realized you sounded pretty stupid eh?
 
The point of using operator overloading is to make short, concise and readable code.

You can do set_array_element_value(arr, index, value) or you can do arr[index] = value

The former tells you exactly what's going on, but the latter is nicer to look at.

If you want to imagine a board as a matrix, using operator overloading would be appropriate. I know I would.

In this case, it would actually benefit you. You could decompose the entire resource into 2 main components: A BoardElement, and a Board, which is a matrix of BoardElement. BoardElement contains code to handle one BoardElement. Board uses BoardElement to aggregate everything into a multiboard.

This also lets you put the implementation detail of having a fake 2D array in just two methods: operator [] and operator []=.
This way, the 2D array math is localized to one spot.
 

Cokemonkey11

Spell Reviewer
Level 29
Joined
May 9, 2006
Messages
3,534
The point of using operator overloading is to make short, concise and readable code.

You can do set_array_element_value(arr, index, value) or you can do arr[index] = value

The former tells you exactly what's going on, but the latter is nicer to look at.

If you want to imagine a board as a matrix, using operator overloading would be appropriate. I know I would.

In this case, it would actually benefit you. You could decompose the entire resource into 2 main components: A BoardElement, and a Board, which is a matrix of BoardElement. BoardElement contains code to handle one BoardElement. Board uses BoardElement to aggregate everything into a multiboard.

This also lets you put the implementation detail of having a fake 2D array in just two methods: operator [] and operator []=.
This way, the 2D array math is localized to one spot.

Yes, I agree overloading the operators in this case could be an equally good design decision since it has some clear advantages, but to suggest he refactor the the library just so you can have [] is absurd.

This'll end up becoming more or less a clone of Multiboard in the JASS Section, which is why I asked for a comparison to show how it's different.

Well, this doesn't use Table. Looks like a clear advantage to me. I bet it will perform overwhelmingly better in benchmarks.
 
The system concept is good, API is okay, code could be improved a little. I'm not very fond of struct arrayed-members because the implementation underneath is a bit ugly and it is a bit limiting to the coder.

This'll end up becoming more or less a clone of Multiboard in the JASS Section, which is why I asked for a comparison to show how it's different.

This has getters. Although, I agree that if it switches API, most of it will be a clone of Multiboard. There is a different way to go about things internally, though, to optimize it around featuring getters. Yours isn't optimized around that (naturally, since it doesn't have those features), which may be enough to warrant a separate system (since there are many people who do not need getters).

multiboard resources don't need to be fast. Also, as a result of not using table, it's much more limited in its information capacity.

eh, you can't make a blanket statement like that. I agree that Table would be nice--it would reduce the limitations. I'm assuming you mean that multiboard resources shouldn't compromise capacity in favor of speed, which I can agree with. :)

-----

I've tried this before, and yours looks good so far. You just have to make it as awesome as possible (get a good balance of clean API and code). For starters, I don't like the name "myBoard". I don't know if it is just me, or whether it is the fact that it is camelCase, but I recommend looking into a different name. I might be alone though, so wait until someone else comments on the name before changing. :p

If you get the getters and general API to look really good, it will be really easy to make awesome extensions such as row/column rearranging, sorting, inserting paragraphs in multiboards, etc! Good luck!
 
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:
  • 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.

New version ;p
 
Status
Not open for further replies.
Top