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

Dialog Pages

  • Like
Reactions: QuantumMatter
  • Create a dialog with automatic pages
  • Optionally show an index page
  • Automatic Next/Previous/Back/Cancel buttons
API:
JASS:
//  *   NOTES:
//          - dialogId refers to handle id
//          - buttonId and pageId refer to zero-indexed id
//
boolean DialogPDisplay(player plr, integer dialogId, boolean display)
//          - Display/Hide dialog
//          - If displayed when dialog is already displayed, it will be updated
//          - Returns false if the dialog wasn't found
//
integer DialogPCreate(string message, boolean showIndex)
//          - Create a new dialog
//          - Returns dialog handle id (dialogId)
//
boolean DialogPDestroy(integer dialogId)
//          - Destroy dialog
//          - Returns false if the dialog wasn't found
//
boolean DialogPSetPage(integer dialogId, integer pageId)
//          - Set dialog page
//          - Set to 0 if pageId < 0 or to maximum pageId if pageId > maximum pageId
//          - Returns false if the dialog wasn't found
//
boolean DialogPSetMessage  (integer dialogId, string message)
boolean DialogPSetButtonsPP(integer dialogId, integer buttonsPP)
//          - Set dialog message/buttons per page
//          - Returns false if the dialog wasn't found
//
boolean DialogPSetButtonsText  (integer dialogId, string  next, string  previous, string  back, string  cancel)
boolean DialogPSetButtonsHotkey(integer dialogId, integer next, integer previous, integer back, integer cancel)
boolean DialogPDisplayButtons  (integer dialogId, boolean next, boolean previous, boolean back, boolean cancel)
//          - Set browse buttons text/hotkey/visibility
//          - Returns false if the dialog wasn't found
//
dialog DialogPGetHandle(integer dialogId)
//          - Get dialog handle
//          - Returns null if the dialog wasn't found
//
trigger DialogPGetTrigger(integer dialogId)
//          - Get dialog trigger
//          - Executed/Evaluated when the dialog is clicked
//          - Execution of actions prevented when Next, Previous, Back, Cancel and index page buttons are clicked
//          - Returns null if the dialog wasn't found
//
integer DialogPGetClickedId(integer dialogId)
//          - Get dialog last clicked buttonId
//          - Returns DP_BROWSED for Next, Previous, Back and index page buttons
//          - Returns DP_CANCELED for Cancel button
//          - Returns DP_NONE if no button has been clicked yet
//          - Returns DP_NOT_FOUND if the dialog wasn't found
//
//      * BUTTONS *
//      -----------
integer DialogPAddButton    (integer dialogId, string text, integer hotkey)
integer DialogPAddQuitButton(integer dialogId, boolean doScoreScreen, string text, integer hotkey)
//          - Add (quit) button to dialog
//          - Returns buttonId (not a handle id)
//          - Returns DP_NOT_FOUND if the dialog wasn't found
//
boolean DialogPSetButton    (integer dialogId, integer buttonId, string text, integer hotkey)
boolean DialogPSetQuitButton(integer dialogId, integer buttonId, boolean doScoreScreen, string text, integer hotkey)
//          - Set (quit) button (doScoreScreen), text and hotkey
//          - Can both be used on regular and quit buttons
//          -- Using SetQuitButton on a regular button will turn it into a quit button
//          - Returns false if the dialog or button wasn't found
//
string DialogPGetButtonText(integer dialogId, integer buttonId)
//          - Get button text
//          - Returns null if the dialog or button wasn't found
//
//      * INDEX *
//      ---------
boolean DialogPEnableIndex(integer diagId, boolean enable)
//          - Enable/Disable index and set page to 0
//          - If enabled, also opens index
//          - Index is only shown when number of buttons > buttons per page
//          - Returns false if the dialog wasn't found
//
boolean DialogPSetIndexPage(integer dialogId, integer pageId)
//          - Set dialog index page
//          - Set to 0 if pageId < 0 or to maximum pageId if pageId > maximum pageId
//          - Returns false if the dialog wasn't found
//
//      * INDEX BUTTONS *
//      -----------------
boolean DialogPSetIndexButton(integer dialogId, integer pageId, string text, integer hotkey)
//          - Set index button text and hotkey
//          - Text and hotkey will be saved even if page doesn't (yet) exist
//          - Returns false if the dialog wasn't found
//
//      * CONFIG VARIABLES *
//      --------------------
integer DP_btnsPP
//          - Default number of buttons to show per page
//          - Does not include Next, Previous, Back or Cancel buttons
//          - Default: 5
//
string  DP_strNext,  DP_strPrev,  DP_strBack,  DP_strCancel
integer DP_hkNext,   DP_hkPrev,   DP_hkBack,   DP_hkCancel
boolean DP_showNext, DP_showPrev, DP_showBack, DP_showCancel
//          - Default settings for Next, Previous, Back and Cancel buttons
//          - Text: "Next >", "< Previous", "< Back", "Cancel"
//          - Hotkeys: 0 (all)
//          - Visibility: true (all)
//          -- When index is enabled, Next and Previous buttons are on index pages, Back button is on normal pages
//          -- When there are 2 pages, Previous button on first page and Next button on second page are always hidden
//          -- When there are less than 2 pages, Next and Previous buttons are always hidden
Contents

Dialog Pages (Map)

Reviews
MyPad
Code Review: Suggestions: The Dialog Page System should be struct-based. This is based on the structure of the functions themselves, which appear to be functionality-based, yet support OOP-syntax. The function API can be kept as wrappers to the...
Wrda
In part, I have to say this looks like is simulating OOP syntax, and probably could benefit the NewTable or whatever the resource is called now. Looks like a mistake. Dividing twice by btnsPP. Perhaps DialogPDisplayButtonsProps would be better...

Code Review:


Suggestions:
The Dialog Page System should be struct-based. This is based on the structure of the functions themselves, which appear to be functionality-based, yet support OOP-syntax. The function API can be kept as wrappers to the methods in the Dialog Page struct.

The system suffers a bit from having to use up dynamically instantiated hashtables (due to the maximum limit of 255 hashtables per map), though that is going to be a very rare scenario from the user's end.​
 
@MyPad Any chance this could be approved? Just logged in for the first time in a few years, looking at my old resources. I remember this one working quite well. I'm not planning on working on it anymore though, so I'm not gonna make it struct-based.

Anyway, sorry to bother, hope you're well!
 

Wrda

Spell Reviewer
Level 26
Joined
Nov 18, 2012
Messages
1,889
In part, I have to say this looks like is simulating OOP syntax, and probably could benefit the NewTable or whatever the resource is called now.

JASS:
//==== Set Index Page ====
    function DialogPSetIndexPage takes integer diagId, integer pageId returns boolean
        local integer pageIdMax
        local integer btnsPP
        if HaveSavedInteger(htbDialogs, diagId, INDEX_PAGE_ID) then
            if pageId < 0 then
                set pageId = 0
            elseif pageId > 0 then
                set btnsPP = LoadInteger(htbDialogs, diagId, BTNS_PP)
                set pageIdMax = ((LoadInteger(htbDialogs, diagId, BTN_CNT)-1)/btnsPP)/btnsPP
                if pageId > pageIdMax then
                    set pageId = pageIdMax
                endif
            endif
            call SaveInteger(htbDialogs, diagId, INDEX_PAGE_ID, pageId)
            return true
        endif
        return false // dialog not found
    endfunction   
set pageIdMax = ((LoadInteger(htbDialogs, diagId, BTN_CNT)-1)/btnsPP)/btnsPP
Looks like a mistake. Dividing twice by btnsPP.

JASS:
//==== Display Browse Buttons ====
    function DialogPDisplayButtons takes integer diagId, boolean next, boolean prev, boolean back, boolean cancel returns boolean
        local hashtable htbBtns = null
  
        if HaveSavedHandle(htbDialogs, diagId, BTN_HTB) then
            set htbBtns = LoadHashtableHandle(htbDialogs, diagId, BTN_HTB)
      
            call SaveBoolean(htbBtns, BTN_SHOW, BTN_NEXT,   next)
            call SaveBoolean(htbBtns, BTN_SHOW, BTN_PREV,   prev)
            call SaveBoolean(htbBtns, BTN_SHOW, BTN_BACK,   back)
            call SaveBoolean(htbBtns, BTN_SHOW, BTN_CANCEL, cancel)
      
            set htbBtns = null
            return true
        endif
  
        return false // dialog not found
    endfunction
    //========
Perhaps DialogPDisplayButtonsProps would be better. Right now the name looks like it is actually going to show/hide these buttons, kind of misleading.

All in all, the resource works wells, and the demo is pretty decent.

Approved
 
Top