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

[Snippet] Multiboard Group

Level 18
Joined
Oct 20, 2007
Messages
353
This system allows you creating, showing/hiding, deleting multiboard groups.
You can switch multiboards ("tabs") from group by clicking "minimize" button.

On the following screenshot you can see group with 3 multiboards in all possible four states (each multiboard and minimized state):
127362d1373215422-snippet-needs-work-multiboard-group-mbg.jpg


Multiboard Group library:

JASS:
library MultiboardGroupLibrary initializer Init // by D.O.G. version 2.1
    
    // Settings
    globals
        // Default color of selected tab's name (active multiboard's name)
        private string DEFAULT_ACTIVE_COLOR   = "|cFFFFCC00"
        // Default color of unselected tabs' names
        private string DEFAULT_INACTIVE_COLOR = "|cFFC0C0C0"
        private string SPACING_COLOR  = "|cFF707070" // Color of text before, between and after tabs' names
        private string SPACING_LEFT   = "["          // Text before tabs' names
        private string SPACING_CENTER = "]  ["       // Text between tabs' names
        private string SPACING_RIGHT  = "]"          // Text after tabs' names
        private constant real CHECK_PERIOD = 0.01    // Time interval in which multiboard state is checked
    endglobals
    
    // Do not edit
    globals
        private integer ActiveGroup = -1
        private integer LastGroup = -1
        private hashtable Hash = InitHashtable()
    endglobals
    
    ////////////////////////
    function GetMultiboardCountInGroup takes integer mgroup returns integer
        return LoadInteger(Hash, mgroup, -2)
    endfunction
    private function SetMultiboardCountInGroup takes integer mgroup, integer count returns nothing
        call SaveInteger(Hash, mgroup, -2, count)
    endfunction
    ////////////////////////
    function GetMultiboardNameInGroup takes integer mgroup, integer index returns string
        return LoadStr(Hash, mgroup, index)
    endfunction
    function SetMultiboardNameInGroup takes integer mgroup, integer index, string name returns nothing
        call SaveStr(Hash, mgroup, index, name)
    endfunction
    ///////////////////////////
    function GetActiveMultiboardInGroup takes integer mgroup returns integer
        return LoadInteger(Hash, mgroup, -3)
    endfunction
    function SetActiveMultiboardInGroup takes integer mgroup, integer index returns nothing
        call SaveInteger(Hash, mgroup, -3, index)
    endfunction
    ///////////////////////
    function GetMultiboardNameColorInGroup takes integer mgroup, integer index returns string
        return LoadStr(Hash, mgroup, index + 256)
    endfunction
    function SetMultiboardNameColorInGroup takes integer mgroup, integer index, string color returns nothing
        call SaveStr(Hash, mgroup, index + 256, color)
    endfunction
    ///////////////////////
    function GetMultiboardNameInactiveColorInGroup takes integer mgroup, integer index returns string
        return LoadStr(Hash, mgroup, index + 512)
    endfunction
    function SetMultiboardNameInactiveColorInGroup takes integer mgroup, integer index, string color returns nothing
        call SaveStr(Hash, mgroup, index + 512, color)
    endfunction
    ///////////////////////
    function GetMultiboardFromGroup takes integer mgroup, integer mindex returns multiboard
        return LoadMultiboardHandle(Hash, mgroup, mindex)
    endfunction
    private function SetMultiboardToGroup takes integer mgroup, integer mindex, multiboard mb returns nothing
        call SaveMultiboardHandle(Hash, mgroup, mindex, mb)
    endfunction
    ///////////////////////
    
    function AddMultiboardToGroupC takes integer mgroup, multiboard mb, string activecolor, string inactivecolor returns nothing
        //local multiboard mb0
        local integer mcount = GetMultiboardCountInGroup(mgroup)
        /*if mcount == 0 then
            set mb0 = CreateMultiboard()
            call SetMultiboardToGroup(mgroup, 0, mb0)
            set mcount = 1
            set mb0 = null
        endif*/
        call SetMultiboardToGroup(mgroup, mcount, mb)
        call SetMultiboardNameInGroup(mgroup, mcount, MultiboardGetTitleText(mb))
        call SetMultiboardNameColorInGroup(mgroup, mcount, activecolor)
        call SetMultiboardNameInactiveColorInGroup(mgroup, mcount, inactivecolor)
        call SetMultiboardCountInGroup(mgroup, mcount + 1)
    endfunction
    
    function AddMultiboardToGroup takes integer mgroup, multiboard mb returns nothing
        call AddMultiboardToGroupC(mgroup, mb, DEFAULT_ACTIVE_COLOR, DEFAULT_INACTIVE_COLOR)
    endfunction
    
    function NewMultiboardGroup takes nothing returns integer
        set LastGroup = LastGroup + 1
        call SetMultiboardToGroup(LastGroup, 0, CreateMultiboard())
        call SetMultiboardCountInGroup(LastGroup, 1)
        return LastGroup
    endfunction
    
    function UpdateMultiboardNamesInGroup takes integer mgroup returns nothing
        local integer mlast = GetMultiboardCountInGroup(mgroup) - 1
        local string array n
        local string array t
        local integer i = 1
        local integer j
        set n[0] = SPACING_COLOR + SPACING_LEFT + "|r" 
        loop
            exitwhen i >= mlast
            set n[i] = GetMultiboardNameInGroup(mgroup, i) + "|r" + SPACING_COLOR + SPACING_CENTER + "|r" 
            set i = i + 1
        endloop
        set n[mlast] = GetMultiboardNameInGroup(mgroup, i) + "|r" + SPACING_COLOR + SPACING_RIGHT + "|r" 
        set i = 0
        loop
            exitwhen i > mlast
            set j = 0
            loop
                exitwhen j > mlast
                if i == j then
                    set t[i] = t[i] + GetMultiboardNameColorInGroup(mgroup, j) + n[j]
                else
                    set t[i] = t[i] + GetMultiboardNameInactiveColorInGroup(mgroup, j) + n[j]
                endif
                set j = j + 1
            endloop
            set i = i + 1
        endloop
        set i = 0
        loop
            exitwhen i > mlast
            call MultiboardSetTitleText(GetMultiboardFromGroup(mgroup, i), t[i])
            set i = i + 1
        endloop
    endfunction
    
    function ShowMultiboardGroup takes integer mgroup returns nothing
        local integer i = GetActiveMultiboardInGroup(mgroup)
        local multiboard t = GetMultiboardFromGroup(mgroup, i)
        set ActiveGroup = mgroup
        call MultiboardDisplay(t, true)
        call MultiboardMinimize(t, i == 0)
        set t = null
    endfunction
    
    function ShowMultiboardGroupToPlayer takes integer mgroup, player p returns nothing
        if p == GetLocalPlayer() then
            call ShowMultiboardGroup(mgroup)
        endif
    endfunction
    
    function HideCurrentMultiboardGroup takes nothing returns nothing
        call MultiboardDisplay(GetMultiboardFromGroup(ActiveGroup, GetActiveMultiboardInGroup(ActiveGroup)), false)
        set ActiveGroup = -1
    endfunction
    
    function HideCurrentMultiboardGroupForPlayer takes player p returns nothing
        if p == GetLocalPlayer() then
            call HideCurrentMultiboardGroup()
        endif
    endfunction
    
    function RemoveMultiboardGroup takes integer mgroup returns nothing
        if mgroup == ActiveGroup then
            call HideCurrentMultiboardGroup()
        endif
        call FlushChildHashtable(Hash, mgroup)
    endfunction
    
    private function Mod takes integer a, integer b returns integer
        if (a >= 0) and (a < b) then
            return a
        endif
        return 0
    endfunction
    
    private function Handler takes nothing returns nothing
        local integer act
        local multiboard mb
        if ActiveGroup != -1 then
            set act = GetActiveMultiboardInGroup(ActiveGroup)
            if (act != 0) == IsMultiboardMinimized(GetMultiboardFromGroup(ActiveGroup, act)) then
                set act = Mod(act + 1, GetMultiboardCountInGroup(ActiveGroup))
                call SetActiveMultiboardInGroup(ActiveGroup, act)
                set mb = GetMultiboardFromGroup(ActiveGroup, act)
                call MultiboardDisplay(mb, true)
                call MultiboardMinimize(mb, act == 0)
            endif
        endif
        set mb = null
    endfunction
    
    private function Init takes nothing returns nothing
        call TimerStart(CreateTimer(), CHECK_PERIOD, true, function Handler)
    endfunction
    
endlibrary

Testing trigger:
This trigger creates multiboard group from screenshot.
JASS:
library MultiboardGroupTest initializer Init requires MultiboardGroupLibrary
    
    private function CreateMultiboard1x1 takes string title, string text returns multiboard
        local multiboard mb = CreateMultiboard()
        local multiboarditem mbi
        call MultiboardSetRowCount(mb, 1)
        call MultiboardSetColumnCount(mb, 1)
        call MultiboardSetTitleText(mb, title)
        set mbi = MultiboardGetItem(mb, 0, 0)
        call MultiboardSetItemValue(mbi, text)
        call MultiboardSetItemStyle(mbi, true, false)
        call MultiboardReleaseItem(mbi)
        set mbi = null
        return mb
    endfunction

    
    private function Actions takes nothing returns nothing
        local integer g = NewMultiboardGroup()
        
        call AddMultiboardToGroup(g, CreateMultiboard1x1("123", "abc"))
        call AddMultiboardToGroupC(g, CreateMultiboard1x1("456", "def"), "|cFFFF0000", "|cFFBB4444")
        call AddMultiboardToGroupC(g, CreateMultiboard1x1("789", "ghi"), "|cFF00FF00", "|cFF44BB44")
        
        call UpdateMultiboardNamesInGroup(g)
        call ShowMultiboardGroup(g)
        
        call DestroyTimer(GetExpiredTimer())
    endfunction
    
    private function Init takes nothing returns nothing
        call TimerStart(CreateTimer(), 0.1, false, function Actions)
    endfunction
    
endlibrary

Test map: View attachment MultiboardGroup.w3x
 

Attachments

  • mbg.jpg
    mbg.jpg
    110.7 KB · Views: 273
Last edited:
Level 17
Joined
Apr 27, 2008
Messages
2,455
You came to late to the party for comments about a new jass resource.

If you see no comments it could mean that there is nothing wrong.
(Or no one care about it).

Quite irrevelant comment :

You don't need to write 9 numbers under the decimal for a real if the last ones are 0.
I've forced Mag to make countless of tests about it.
More, if i believe my old memory, the timer period was even screwed with 9 numbers under the decimal, and was fine with 8 numbers (needs to be tested again).
 
Actually, with 9 numbers it's fine, but with 10 it doesn't work :eek:

For some odd reason, it could work with a number of decimal places higher than 10 ;l
I know this because I have this test map made by D4RK_G4ND4LF in which he defines Pi to God knows how many digits and it works perfectly.

I don't know if this is only for timers though.
I'll test later with 8 - 20 digits and see what happens.
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
without explicitly stating the 0s in the decimal places, the number wc3 gets isn't exact.

.03125 != exact .03125, it's like .0312500002 or something

putting the 0s in makes it exactly .03125

Last time i checked this, that was wrong.
So make a better test.

Now ofc my test could be wrong, but that woudn't be the first time you said something wrong.
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
Little suggestion, make two color codes for inactive and stripe them (so you know which titles are which)
 
Level 18
Joined
Oct 20, 2007
Messages
353
System updated from 2.0 to 2.1.
Added more interface options: spacing left and right strings, colors of tab names, timer period, some new functions.

So why this isn't good enought to be approved? This is unique resource anyway)
It works in multiplayer and supports many groups.

I'll keep this updating from time to time as some efficiency improvements can be done and some functions are not made yet.
 
Top