1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. We have recently started the 16th edition of the Mini Mapping Contest. The theme is mini RPG. Do check it out and have fun.
    Dismiss Notice
  4. Dismiss Notice
  5. Choose your ride to damnation in the 5th Special Effect Contest Poll.
    Dismiss Notice
  6. The winners of the 13th Techtree Contest have been announced!
    Dismiss Notice
  7. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[PROTOTYPE] myBoard

Discussion in 'The Lab' started by bowser499, Dec 1, 2013.

  1. bowser499

    bowser499

    Joined:
    Jul 20, 2009
    Messages:
    782
    Resources:
    7
    Tools:
    1
    Maps:
    3
    Spells:
    3
    Resources:
    7
    Documentation
    Code (vJASS):
    //================================================================================
        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!
    //================================================================================


    System Code
    Code (vJASS):
    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


    Changelog
    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: Dec 4, 2013
  2. Cokemonkey11

    Cokemonkey11

    Wurst Reviewer

    Joined:
    May 9, 2006
    Messages:
    3,237
    Resources:
    18
    Tools:
    1
    Maps:
    5
    Spells:
    3
    Tutorials:
    2
    JASS:
    7
    Resources:
    18
    API looks really nice. Haven't checked the code but I doubt there's much to worry about :)
     
  3. Rheiko

    Rheiko

    Joined:
    Aug 27, 2013
    Messages:
    2,948
    Resources:
    7
    Icons:
    2
    Spells:
    3
    Tutorials:
    2
    Resources:
    7
    agree with cokemonkey, API looks nice
     
  4. Nestharus

    Nestharus

    Joined:
    Jul 10, 2007
    Messages:
    6,146
    Resources:
    8
    Spells:
    3
    Tutorials:
    4
    JASS:
    1
    Resources:
    8
    These aren't really necessary

    Code (vJASS):

        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

    Code (vJASS):

        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
    Code (vJASS):

        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
     
  5. Cokemonkey11

    Cokemonkey11

    Wurst Reviewer

    Joined:
    May 9, 2006
    Messages:
    3,237
    Resources:
    18
    Tools:
    1
    Maps:
    5
    Spells:
    3
    Tutorials:
    2
    JASS:
    7
    Resources:
    18
  6. Nestharus

    Nestharus

    Joined:
    Jul 10, 2007
    Messages:
    6,146
    Resources:
    8
    Spells:
    3
    Tutorials:
    4
    JASS:
    1
    Resources:
    8
    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 -.-
     
  7. chobibo

    chobibo

    Joined:
    Sep 24, 2005
    Messages:
    2,702
    Resources:
    0
    Resources:
    0
    Operators would be easier to work with though (in my opinion).
     
  8. Cokemonkey11

    Cokemonkey11

    Wurst Reviewer

    Joined:
    May 9, 2006
    Messages:
    3,237
    Resources:
    18
    Tools:
    1
    Maps:
    5
    Spells:
    3
    Tutorials:
    2
    JASS:
    7
    Resources:
    18
    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
     
  9. Nestharus

    Nestharus

    Joined:
    Jul 10, 2007
    Messages:
    6,146
    Resources:
    8
    Spells:
    3
    Tutorials:
    4
    JASS:
    1
    Resources:
    8
    When the language supports operators, you use operators.

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

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

    Java does not, so they use getters/setters


    cokemonkey, your point is?
     
  10. TriggerHappy

    TriggerHappy

    Code Moderator

    Joined:
    Jun 23, 2007
    Messages:
    3,694
    Resources:
    22
    Spells:
    11
    Tutorials:
    2
    JASS:
    9
    Resources:
    22
    @bowser499 Show an example?
     
  11. Cokemonkey11

    Cokemonkey11

    Wurst Reviewer

    Joined:
    May 9, 2006
    Messages:
    3,237
    Resources:
    18
    Tools:
    1
    Maps:
    5
    Spells:
    3
    Tutorials:
    2
    JASS:
    7
    Resources:
    18
    No. If you bothered to read the link I posted you would understand how that's not true.

    Obviously you don't have the choice.

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

    Nice little ninja edit you did there, guess you realized you sounded pretty stupid eh?
     
  12. Nestharus

    Nestharus

    Joined:
    Jul 10, 2007
    Messages:
    6,146
    Resources:
    8
    Spells:
    3
    Tutorials:
    4
    JASS:
    1
    Resources:
    8
    I thought about operator overloading in c++ >.>. I was only thinking about getters/setters when I initially wrote that.
     
  13. Magtheridon96

    Magtheridon96

    Joined:
    Dec 12, 2008
    Messages:
    6,006
    Resources:
    26
    Maps:
    1
    Spells:
    8
    Tutorials:
    7
    JASS:
    10
    Resources:
    26
    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.
     
  14. Nestharus

    Nestharus

    Joined:
    Jul 10, 2007
    Messages:
    6,146
    Resources:
    8
    Spells:
    3
    Tutorials:
    4
    JASS:
    1
    Resources:
    8
    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.
     
  15. Cokemonkey11

    Cokemonkey11

    Wurst Reviewer

    Joined:
    May 9, 2006
    Messages:
    3,237
    Resources:
    18
    Tools:
    1
    Maps:
    5
    Spells:
    3
    Tutorials:
    2
    JASS:
    7
    Resources:
    18
    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.

    Well, this doesn't use Table. Looks like a clear advantage to me. I bet it will perform overwhelmingly better in benchmarks.
     
  16. Nestharus

    Nestharus

    Joined:
    Jul 10, 2007
    Messages:
    6,146
    Resources:
    8
    Spells:
    3
    Tutorials:
    4
    JASS:
    1
    Resources:
    8
    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.
     
  17. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,426
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
    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 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).

    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!
     
  18. Cokemonkey11

    Cokemonkey11

    Wurst Reviewer

    Joined:
    May 9, 2006
    Messages:
    3,237
    Resources:
    18
    Tools:
    1
    Maps:
    5
    Spells:
    3
    Tutorials:
    2
    JASS:
    7
    Resources:
    18
    This is the best public wc3 multiboard library I've seen yet, and the only one I would consider using if I planned to use a multiboard anytime soon.

    That's all I have to say, 'bout that
     
  19. bowser499

    bowser499

    Joined:
    Jul 20, 2009
    Messages:
    782
    Resources:
    7
    Tools:
    1
    Maps:
    3
    Spells:
    3
    Resources:
    7
    Documentation
    Code (vJASS):
    //================================================================================
        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!
    //================================================================================


    System Code
    Code (vJASS):
    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


    Changelog
    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
     
  20. Grey Nightmare

    Grey Nightmare

    Joined:
    Feb 24, 2009
    Messages:
    2,853
    Resources:
    0
    Resources:
    0
    Hah! :D
    Fantastic.