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

[Solved] Dialog

Status
Not open for further replies.
Level 17
Joined
Mar 21, 2011
Messages
1,597
At the start of my game, i want to create a dialog window for player 1 to select settings like game length and item spawn rate etc.
I made this in GUI and want to make the same thing in vJass now, but i fail horribly xD

How it works:

There is a main dialog window that shows all options with the current setting behind it in "[]"

--------TITLE_SETTINGS-------------

--------TIME [2 minutes]-------------

--------ITEMS [40 seconds]----------

When you click on TIME for example, it will show a new dialog with the different minutes to set.

--------TITLE_TIME-------------

--------2 minutes---------------

--------4 minutes--------------

If you select one of those, you will return back to the Setting dialog with the new setting inside the bracket
example:
TIME [2 minutes] ---> TIME [4 minutes]

because the subsettings dialogbuttons are constant in their name (they do never change), i create all of those dialogs at the beginning of the game and show/hide them on klick. However, the main dialog always changes because of the data in the brackets "[]". So i create and destroy this one.

Until now, when i click on a button, no sub dialog disappears and i cannot click on sth else on the map. seems like it is there but not visible? i dunno.


JASS:
        /* ---------------Dialog Settings--------------- */
        set DialogItemBoxText[0] = "|cffffffffOften|r"
        set DialogItemBoxText[1] = "|cffffffffMedium|r"
        set DialogItemBoxText[2] = "|cffffffffLow|r"
        set DialogItemBoxText[3] = "|cffffffffOff|r"
        set DialogItemBoxValue[0] = 25
        set DialogItemBoxValue[1] = 50
        set DialogItemBoxValue[2] = 75
        set DialogItemBoxValue[3] = 0
        set DialogItemBoxSetting = 1
        
        set DialogTimeText[0] = "|cffffffff10 minutes|r"
        set DialogTimeText[1] = "|cffffffff15 minutes|r"
        set DialogTimeText[2] = "|cffffffff20 minutes|r"
        set DialogTimeValue[0] = 600
        set DialogTimeValue[1] = 900
        set DialogTimeValue[2] = 1200
        set DialogTimeSetting = 0
        
        set DialogEventText[0] = "|cffffffff120 seconds|r"
        set DialogEventText[1] = "|cffffffff160 seconds|r"
        set DialogEventText[2] = "|cffffffff200 seconds|r"
        set DialogEventText[3] = "|cffffffffOff|r"
        set DialogEventValue[0] = 120
        set DialogEventValue[1] = 160
        set DialogEventValue[2] = 200
        set DialogEventValue[3] = 0
        set DialogEventSetting = 1
        
        set DialogAreaText[0] = "|cffffffffBloomfield|r"
        set DialogAreaText[1] = "|cffffffffIslands|r"
        set DialogAreaValue[0] = 0
        set DialogAreaValue[1] = 1
        set DialogAreaSetting = 0
        
        set DialogVehicleText[0] = "|cffffffffOften|r"
        set DialogVehicleText[1] = "|cffffffffMedium|r"
        set DialogVehicleText[2] = "|cffffffffLow|r"
        set DialogVehicleText[3] = "|cffffffffOff|r"
        set DialogVehicleValue[0] = 170
        set DialogVehicleValue[1] = 215
        set DialogVehicleValue[2] = 260
        set DialogVehicleValue[3] = 0
        set DialogVehicleSetting = 1
        /* --------------------------------------------- */

JASS:
library Dialog /* v.1.1.0.0
**************************************************
*
*   A struct wrapper for easy dialog creation.
*
**************************************************
*
*/  requires Table  /* [url]http://www.hiveworkshop.com/forums/jass-resources-412/snippet-new-table-188084/[/url]
* 
**************************************************
*
*   struct Dialog 
*
*       static method create() returns thistype
*           
*           Creates a new dialog and returns its instance.
*
*       method operator title= takes string s
*
*           Sets the title message for the dialog.
*
*       method addButton( string text, integer hotkey ) returns button
*
*           Adds a button to the dialog that reads <text>.
*           The hotkey serves as a shortcut to press a dialog 
*           button. Example input: 'a', 'b', 512 (esc).
*
*       method display( player p, boolean flag )
*           
*           Shows/hides a dialog for a particular player. 
*
*       method displayAll( boolean flag )
*
*           Shows/hides a dialog for all players. 
*
*       method clear()
*   
*           Clears a dialog of its message and buttons.
*
*       method destroy()
*
*           Destroys a dialog and its instance.
*
*   -- Event API --
*
*       method registerClickEvent( boolexpr b )
*
*           Registers when a dialog button is clicked.
*
*       static method getClickedDialog() returns Dialog
*       static method getClickedButton() returns button
*       static method getPlayer() returns player
*
*            Event responses.
*
**************************************************
*
*   Constants - Credits to DysfunctionaI for the list!
*/
    globals
        constant integer KEY_SPACEBAR          = 32
        
        /* Number Pad */
        constant integer KEY_NUMPAD_0          = 257
        constant integer KEY_NUMPAD_1          = 258
        constant integer KEY_NUMPAD_2          = 259
        constant integer KEY_NUMPAD_3          = 260
        constant integer KEY_NUMPAD_4          = 261
        constant integer KEY_NUMPAD_5          = 262
        constant integer KEY_NUMPAD_6          = 263
        constant integer KEY_NUMPAD_7          = 264
        constant integer KEY_NUMPAD_8          = 265
        constant integer KEY_NUMPAD_9          = 266
        constant integer KEY_NUMPAD_PLUS       = 267
        constant integer KEY_NUMPAD_MINUS      = 268
        constant integer KEY_NUMPAD_ASTERISK   = 269 
        constant integer KEY_NUMPAD_SLASH      = 270
        constant integer KEY_NUMPAD_PERIOD     = 271
        
        constant integer KEY_EQUALS            = 272
        constant integer KEY_MINUS             = 273
        constant integer KEY_LEFT_BRACKET      = 274
        constant integer KEY_RIGHT_BRACKET     = 275
        constant integer KEY_BACKSLASH         = 276
        constant integer KEY_SEMICOLON         = 277
        constant integer KEY_APOSTROPHE        = 278
        constant integer KEY_COMMA             = 279
        constant integer KEY_PERIOD            = 280   
        constant integer KEY_SLASH             = 281
        constant integer KEY_ESCAPE            = 512
        constant integer KEY_BACKSPACE         = 514
        
        /* Arrows */
        constant integer KEY_LEFT_ARROW        = 516
        constant integer KEY_UP_ARROW          = 517
        constant integer KEY_RIGHT_ARROW       = 518
        constant integer KEY_DOWN_ARROW        = 519
        
        constant integer KEY_INSERT            = 520
        constant integer KEY_DELETE            = 521
        constant integer KEY_HOME              = 522
        constant integer KEY_END               = 523
        constant integer KEY_PAGE_UP           = 524
        constant integer KEY_PAGE_DOWN         = 525
        constant integer KEY_CAPS_LOCK         = 526
        constant integer KEY_NUM_LOCK          = 527
        constant integer KEY_SCROLL_LOCK       = 528
        constant integer KEY_PAUSE             = 529
        
        /* Function Buttons */
        constant integer KEY_F1                = 768
        constant integer KEY_F2                = 769
        constant integer KEY_F3                = 770
        constant integer KEY_F4                = 771
        constant integer KEY_F5                = 772
        constant integer KEY_F6                = 773
        constant integer KEY_F7                = 774
        constant integer KEY_F8                = 775
        constant integer KEY_F9                = 776
        constant integer KEY_F10               = 777
        constant integer KEY_F11               = 778
        constant integer KEY_F12               = 779
    endglobals
/*
**************************************************/

    globals
        private Table instance = 0
    endglobals
    
    private module DialogInit 
        private static method onInit takes nothing returns nothing 
            set instance = Table.create()
        endmethod
    endmodule

    struct Dialog
        private dialog dg
        private trigger click
        private string msg
        
        static method getClickedDialog takes nothing returns thistype 
            return instance[GetHandleId(GetClickedDialog())]
        endmethod
        static method getClickedButton takes nothing returns button 
            return GetClickedButton()
        endmethod
        static method getPlayer takes nothing returns player 
            return GetTriggerPlayer()
        endmethod
        
        method operator title= takes string text returns nothing 
            call DialogSetMessage(this.dg, text)
            set this.msg = text
        endmethod
        
        method addButton takes string text, integer hotkey returns button
            return DialogAddButton(this.dg, text, hotkey)
        endmethod
        
        method display takes player p, boolean flag returns nothing
            call DialogDisplay(p, this.dg, flag)
            call DialogSetMessage(this.dg, this.msg)
        endmethod
        method displayAll takes boolean flag returns nothing
            call DialogDisplay(GetLocalPlayer(), this.dg, flag)
            call DialogSetMessage(this.dg, this.msg)
        endmethod
        
        method clear takes nothing returns nothing 
            call DialogClear(this.dg)
            set this.msg = ""
        endmethod
        
        method registerClickEvent takes boolexpr b returns nothing
            if this.click == null then
                set instance[GetHandleId(this.dg)] = this
                set this.click = CreateTrigger()
                call TriggerRegisterDialogEvent(this.click, this.dg)
            endif
            call TriggerAddCondition(this.click, b)
        endmethod
        
        method destroy takes nothing returns nothing 
            debug if this.dg == null then
            debug     call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "[Dialog] Attempted to destroy null dialog.")
            debug endif
            
            if this.click != null then
                call DestroyTrigger(this.click)
                call instance.remove(GetHandleId(this.dg))
                set this.click = null
            endif
            
            call DialogClear(this.dg)
            call DialogDestroy(this.dg)
            set this.dg = null
            call this.deallocate()
        endmethod
    
        static method create takes nothing returns thistype
            local thistype this = thistype.allocate()
            set this.dg = DialogCreate()
            return this
        endmethod
        
        implement DialogInit
    endstruct
    
endlibrary

JASS:
scope DialogSettings initializer Init 

    globals
        private button array buttons
        private button array ButtonTime
        private boolexpr bxpr
        private Dialog Time
        private Dialog Event
        private Dialog ItemBox
        private Dialog Vehicle
        private Dialog Area
    endglobals
    
    private function DialogStart takes nothing returns nothing 
        local Dialog log = Dialog.create()
        set log.title  = "|cffFF7000Settings"
        set buttons[0] = log.addButton("|cff7ebff1Time [|r" + DialogTimeText[DialogTimeSetting] + "|cff7ebff1]|r", 0)
        set buttons[1] = log.addButton("|cff7ebff1Event [|r" + DialogEventText[DialogEventSetting] + "|cff7ebff1]|r", 0)
        set buttons[2] = log.addButton("|cff7ebff1Item Box [|r" + DialogItemBoxText[DialogItemBoxSetting] + "|cff7ebff1]|r", 0)
        set buttons[3] = log.addButton("|cff7ebff1Vehicle [|r" + DialogVehicleText[DialogVehicleSetting] + "|cff7ebff1]|r", 0)
        set buttons[4] = log.addButton("|cff7ebff1Area [|r" + DialogAreaText[DialogAreaSetting] + "|cff7ebff1]|r", 0)
        set buttons[5] = log.addButton("|cff20c000Ready|r", 0)
        call log.display(Player(0), true)
        call log.registerClickEvent(bxpr)
        call ReleaseTimer(GetExpiredTimer())
    endfunction

    private function DialogEvent takes nothing returns boolean
        local Dialog  log = Dialog.getClickedDialog()
        local button  bt   = Dialog.getClickedButton()
        
        if bt == buttons[0] then
            call Time.display(Player(0), true)
        elseif bt == buttons[1] then
            
        elseif bt == buttons[2] then
            
        elseif bt == buttons[3] then
            
        endif
        /* ... */
        call log.destroy()
        set bt = null
        return false 
    endfunction
    
    private function DialogTime takes nothing returns boolean
        local Dialog  log = Dialog.getClickedDialog()
        local button  bt   = Dialog.getClickedButton()
        local integer index = 0
        loop
            exitwhen index > 3
                if bt == ButtonTime[index] then
                    set DialogTimeSetting = index
                endif
            set index = index + 1
        endloop
        call log.display(Player(0), false)
        call TimerStart(NewTimer(), 0, false, function DialogStart)
        set bt = null
        return false 
    endfunction

    private function Init takes nothing returns nothing
        local integer index = 0
        set Time = Dialog.create()
        set Time.title  = "|cffFF7000Time"
        loop
            exitwhen index > 3
                set ButtonTime[index] = Time.addButton(DialogTimeText[index], 0)
            set index = index + 1
        endloop
        call Time.registerClickEvent(Condition(function DialogTime))
        
        call TimerStart(NewTimer(), 0, false, function DialogStart)
        set bxpr = Condition(function DialogEvent)
        
    endfunction
endscope
 
Sorry if you tested around much already.. I have not analysed each detail in code,
but have you tried to change the delay between showing dialogs?
Iirc I had issues with it in past when displaying dialogs within too short time period.

Try to change:
call TimerStart(NewTimer(), 0, false, function DialogStart)
->
call TimerStart(NewTimer(), 1, false, function DialogStart)
 
I tested it shortly by myself, and it seems to work. It does nothing much
but displaying a dialog and onClick displaying a second one. No more logics are
included atm in the demo:

JASS:
struct Test extends array

    private static method dialogTwo takes nothing returns nothing
        local Dialog d = Dialog.create()
        
        set d.title = "Menu 2"
        
        call d.addButton("Text 2", 0)
        
        call d.display(Player(0), true)
    endmethod

    private static method dialogEvent takes nothing returns boolean
        
        call Dialog.getClickedDialog().display(Player(0), false)
        
        call TimerStart(CreateTimer(), 1, false, function thistype.dialogTwo)
        
        
        return false
    endmethod

    private static method dialogOne takes nothing returns nothing
        local Dialog d = Dialog.create()
        
        set d.title = "Menu 1"
        
        call d.addButton("Text 1", 0)
        
        call d.display(Player(0), true)
        
        call d.registerClickEvent(Condition(function thistype.dialogEvent))
    endmethod


    private static method onInit takes nothing returns nothing
        call TimerStart(CreateTimer(), 0, false, function thistype.dialogOne)
    endmethod

endstruct
 
Level 17
Joined
Mar 21, 2011
Messages
1,597
yep it works ;D

here is the code if anyone has a similar problem. This is without the Dialog library

JASS:
/* ---------------Dialog Settings--------------- */
        set DialogItemBoxText[0] = "|cffffffffOften|r"
        set DialogItemBoxText[1] = "|cffffffffMedium|r"
        set DialogItemBoxText[2] = "|cffffffffLow|r"
        set DialogItemBoxText[3] = "|cffffffffOff|r"
        set DialogItemBoxValue[0] = 25
        set DialogItemBoxValue[1] = 50
        set DialogItemBoxValue[2] = 75
        set DialogItemBoxValue[3] = 0
        set DialogItemBoxSetting = 1
        
        set DialogTimeText[0] = "|cffffffff10 minutes|r"
        set DialogTimeText[1] = "|cffffffff15 minutes|r"
        set DialogTimeText[2] = "|cffffffff20 minutes|r"
        set DialogTimeValue[0] = 600
        set DialogTimeValue[1] = 900
        set DialogTimeValue[2] = 1200
        set DialogTimeSetting = 0
        
        set DialogEventText[0] = "|cffffffff120 seconds|r"
        set DialogEventText[1] = "|cffffffff160 seconds|r"
        set DialogEventText[2] = "|cffffffff200 seconds|r"
        set DialogEventText[3] = "|cffffffffOff|r"
        set DialogEventValue[0] = 120
        set DialogEventValue[1] = 160
        set DialogEventValue[2] = 200
        set DialogEventValue[3] = 0
        set DialogEventSetting = 1
        
        set DialogAreaText[0] = "|cffffffffBloomfield|r"
        set DialogAreaText[1] = "|cffffffffIslands|r"
        set DialogAreaValue[0] = 0
        set DialogAreaValue[1] = 1
        set DialogAreaSetting = 0
        
        set DialogVehicleText[0] = "|cffffffffOften|r"
        set DialogVehicleText[1] = "|cffffffffMedium|r"
        set DialogVehicleText[2] = "|cffffffffLow|r"
        set DialogVehicleText[3] = "|cffffffffOff|r"
        set DialogVehicleValue[0] = 170
        set DialogVehicleValue[1] = 215
        set DialogVehicleValue[2] = 260
        set DialogVehicleValue[3] = 0
        set DialogVehicleSetting = 1
        /* --------------------------------------------- */
JASS:
scope Dialog initializer Init

    globals
        private button array ButtonSettings
        private button array ButtonTime
        private button array ButtonEvent
        private button array ButtonItemBox
        private button array ButtonVehicle
        private button array ButtonArea
        
        private dialog Settings
        private dialog Time
        private dialog Event
        private dialog ItemBox
        private dialog Vehicle
        private dialog Area
    endglobals
    
    private function ClearSettings takes nothing returns nothing
        call DialogClear(Settings)
        call DialogSetMessage(Settings, "|cffFF7000Settings")
        set ButtonSettings[0] = DialogAddButton(Settings, "|cff7ebff1Time [|r" + DialogTimeText[DialogTimeSetting] + "|cff7ebff1]|r", 0)
        set ButtonSettings[1] = DialogAddButton(Settings, "|cff7ebff1Event [|r" + DialogEventText[DialogEventSetting] + "|cff7ebff1]|r", 0)
        set ButtonSettings[2] = DialogAddButton(Settings, "|cff7ebff1Item Box [|r" + DialogItemBoxText[DialogItemBoxSetting] + "|cff7ebff1]|r", 0)
        set ButtonSettings[3] = DialogAddButton(Settings, "|cff7ebff1Vehicle [|r" + DialogVehicleText[DialogVehicleSetting] + "|cff7ebff1]|r", 0)
        set ButtonSettings[4] = DialogAddButton(Settings, "|cff7ebff1Area [|r" + DialogAreaText[DialogAreaSetting] + "|cff7ebff1]|r", 0)
        set ButtonSettings[5] = DialogAddButton(Settings, "|cff20c000Ready|r", 0)
        call DialogDisplay(Player(0), Settings, true)
    endfunction
    
    private function Timed takes nothing returns nothing
        local integer index
    
        call ClearSettings()
        
        call DialogSetMessage(Time, "|cffFF7000Time")
        set index = 0
        loop
            exitwhen index > 2
            set ButtonTime[index] = DialogAddButton(Time, DialogTimeText[index], 0)
            set index = index + 1
        endloop
        
        call DialogSetMessage(Event, "|cffFF7000Event")
        set index = 0
        loop
            exitwhen index > 3
            set ButtonEvent[index] = DialogAddButton(Event, DialogEventText[index], 0)
            set index = index + 1
        endloop
        
        call DialogSetMessage(ItemBox, "|cffFF7000Time")
        set index = 0
        loop
            exitwhen index > 3
            set ButtonItemBox[index] = DialogAddButton(ItemBox, DialogItemBoxText[index], 0)
            set index = index + 1
        endloop
        
        call DialogSetMessage(Vehicle, "|cffFF7000Time")
        set index = 0
        loop
            exitwhen index > 3
            set ButtonVehicle[index] = DialogAddButton(Vehicle, DialogVehicleText[index], 0)
            set index = index + 1
        endloop
        
        call DialogSetMessage(Area, "|cffFF7000Time")
        set index = 0
        loop
            exitwhen index > 1
            set ButtonArea[index] = DialogAddButton(Area, DialogAreaText[index], 0)
            set index = index + 1
        endloop
        
        call ReleaseTimer(GetExpiredTimer())
    endfunction
    
    private function Actions takes nothing returns boolean
        local button bt = GetClickedButton()
        local integer index
        
        if bt == ButtonSettings[0] then
            call DialogDisplay(Player(0), Time, true)
        elseif bt == ButtonSettings[1] then
            call DialogDisplay(Player(0), Event, true)
        elseif bt == ButtonSettings[2] then
            call DialogDisplay(Player(0), ItemBox, true)
        elseif bt == ButtonSettings[3] then
            call DialogDisplay(Player(0), Vehicle, true)
        elseif bt == ButtonSettings[4] then
            call DialogDisplay(Player(0), Area, true)
        endif
        
        set index = 0
        loop
            exitwhen index > 2
            if bt == ButtonTime[index] then
                set DialogTimeSetting = index
                call ClearSettings()
            endif
            set index = index + 1
        endloop
        
        set index = 0
        loop
            exitwhen index > 3
            if bt == ButtonEvent[index] then
                set DialogEventSetting = index
                call ClearSettings()
            endif
            set index = index + 1
        endloop
        
        set index = 0
        loop
            exitwhen index > 3
            if bt == ButtonItemBox[index] then
                set DialogItemBoxSetting = index
                call ClearSettings()
            endif
            set index = index + 1
        endloop
        
        set index = 0
        loop
            exitwhen index > 3
            if bt == ButtonVehicle[index] then
                set DialogVehicleSetting = index
                call ClearSettings()
            endif
            set index = index + 1
        endloop
        
        set index = 0
        loop
            exitwhen index > 1
            if bt == ButtonArea[index] then
                set DialogAreaSetting = index
                call ClearSettings()
            endif
            set index = index + 1
        endloop
        
        set bt = null
        return false
    endfunction

    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger()
        
        set Settings = DialogCreate()
        call TriggerRegisterDialogEvent(t, Settings)
        
        set Time = DialogCreate()
        call TriggerRegisterDialogEvent(t, Time)
        
        set Event = DialogCreate()
        call TriggerRegisterDialogEvent(t, Event)
        
        set ItemBox = DialogCreate()
        call TriggerRegisterDialogEvent(t, ItemBox)
        
        set Vehicle = DialogCreate()
        call TriggerRegisterDialogEvent(t, Vehicle)
        
        set Area = DialogCreate()
        call TriggerRegisterDialogEvent(t, Area)
        
        call TriggerAddCondition(t, Condition(function Actions))
        call TimerStart(NewTimer(), 0, false, function Timed)
        set t = null
    endfunction

endscope
 
Status
Not open for further replies.
Top