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

DS Extensions

Level 11
Joined
Nov 4, 2007
Messages
337
These are extensions for the Dialog system;
Optional modules which give more comfort.

I want to present three extensions:
JASS:
                        ---- Hotkey Extension ----
                        
        Gives:
        The method MakeFirstLetterHotkeyMap.
        This method makes hotkeys for all options, the hotkey is always the first letter
        of a word that is not used by another hotkey.
        Example:
        
        Option      ==> Hotkey O
        Operation   ==> Hotkey P
        Opera       ==> Hotkey E
        After       ==> Hotkey A
        Before      ==> Hotkey B
        
        Implementation: Write 
        //! runtextmacro implementHotkeyExtension
        somewhere inside of the dialog struct


JASS:
//! textmacro implementHotkeyExtension
    method MakeFirstLetterHotkeyMap takes nothing returns nothing
        local integer i2 = Temp_Starter
        local integer i3 = 0
        local integer i4 = 0
        local integer endAt
        local integer givenCount = 0
        local string array given
        local string tempString
        local boolean correct = false

        if .OptionCount > ABC_LENGTH then
            set .Rebuild = true
        endif
        
        if .Rebuild then
            set endAt = i2 + MAX_OPTIONS_PER_PAGE
        else
            set endAt = .OptionCount
        endif
        
        loop
            set i2 = i2 + 1
            exitwhen i2 > endAt
            
            if .Hotkeys[i2] == 0 then
            set i3 = 0
                loop
                    set i3 = i3 + 1
                    exitwhen i3 > StringLength(.Options[i2])
                    set tempString = SubString(.Options[i2],i3-1,i3)
                    set i4 = 0
                    set correct = true
                    loop
                        set i4 = i4 + 1
                        exitwhen i4 > givenCount
                        
                        if tempString == given[i4]  then
                            set correct = false // Strings can't have more than 820 letters, so this is safe.
                        endif
                        

                    endloop
                    if correct then
                        set givenCount = givenCount + 1
                        set given[givenCount] = tempString
                        call StringContainsString(HOTKEY_CHARMAP,tempString)
                        set .Hotkeys[i2] = FoundAt
                        set .Options[i2] = SubString(.Options[i2],0,i3-1)+HOTKEY_COLOR+SubString(.Options[i2],i3-1,i3)+"|r"+SubString(.Options[i2],i3,StringLength(.Options[i2]))
                        set i3 = 850
                    endif
                    
                endloop
            endif
            
        endloop
        set Temp_Starter = 0
    endmethod
//! endtextmacro




JASS:
                   ---- Capital Extension ----
                        
        Gives:
        In fact this is no code, since the JassHelper inlines all methods of the code, so it will not take any
        bonus space. This allows you to call the systems methods also with a small first letter.
        So instead of myDialog.ShowAll() you can also write myDialog.showAll() then.
        I guess this is pretty more usual.
        
        Implementation: Write
        implement DialogSystem__CapitalExtension
        somewhere inside of the dialog struct

JASS:
module DialogSystem__CapitalExtension
    method changeName takes string s returns nothing
        call .ChangeName(s)
    endmethod
    
    static method stopVote takes nothing returns nothing
        call Dialog.StopVote()
    endmethod
    
    method showAll takes nothing returns nothing
        call .ShowAll()
    endmethod
    
    method hideAll takes nothing returns nothing
        call .HideAll()
    endmethod
    
    method hideFor takes player p returns nothing
        call .HideFor(p)
    endmethod
    
    method showFor takes player p returns nothing
        call .ShowFor(p)
    endmethod
    
    method attachData takes integer data returns nothing
        set .Data = data
    endmethod
    
    method getAttachedData takes nothing returns integer
        return .Data
    endmethod
    
    method changeEndCode takes AfterCode b returns nothing
        call .ChangeEndCode(b)
    endmethod
    
    method getId takes nothing returns integer
        return this
    endmethod
        
    method startVoteClickReaction takes AfterCode onClick returns nothing
        call .StartVoteClickReaction(onClick)
    endmethod
    
    static method doDebug takes nothing returns nothing
        call Dialog.DoDebug()
    endmethod
    
    method setHotkey takes string HK returns nothing
        call .SetHotkey(HK)
    endmethod
    
    method makeHotkeyMap takes nothing returns nothing
        call .MakeHotkeyMap()
    endmethod
    
    method addTextOptions takes string whichOptions returns nothing
        call .AddTextOptions(whichOptions)
    endmethod
    
    method getVote takes player p returns integer
        return .GetVote(p)
    endmethod
    
    method startVote takes nothing returns nothing
        call .StartVote()
    endmethod
    
    method addValueOptions takes string before, string after, integer End, real b, real m returns nothing
        call .AddValueOptions(before,after,End,b,m)
    endmethod
    
    method addSpecialOption takes string option, integer value, integer place, string Hotkey returns nothing
        call .AddSpecialOption(option,value,place,Hotkey)
    endmethod
    
    method addOption takes string option, integer value returns nothing
        call .AddOption(option,value)
    endmethod
    
endmodule

JASS:
                        ---- Timer Extension ----
                
        Gives:
        function SetDialogTime takes Dialog d, real time, boolean destroy returns nothing
        
        With this extension you can add counters to dialogs.
        Every second the time until the dialog will be cleared will be updated
        in the Dialog heading. If destroy is true, the dialog will be completely destroyed
        when the time ends.
        
        If not, the dialog will simply be cleared.
        
        Implementation:
        Just copy the trigger and paste it to your map.


JASS:
library DialogTimers initializer Init requires DialogSystem

private struct Timer
    integer Max
    integer Expired
    Dialog d
    string Msg
    boolean ddestroy
    
    // implement Collector      :(        Not approved
    // So:
    
    integer position
    static thistype array Data
    static integer Instances = 0
    
    method onDestroy takes nothing returns nothing
        set .Data[.position] = .Data[.Instances]
        set .Instances = .Instances - 1
    endmethod

    static method create takes nothing returns thistype
        local thistype w = thistype.allocate()
        set .Instances = .Instances + 1
        set w.position = .Instances
        set .Data[.Instances] = w
        return w
    endmethod
    
endstruct

    private function Loop takes nothing returns nothing
        local integer i = 0
        local Timer t
        loop
            set i = i + 1
            exitwhen i > Timer.Instances
            set t = Timer.Data[i]
            set t.Expired = t.Expired + 1
            
            if t.Expired > t.Max then
                if t.ddestroy then
                    call t.d.destroy()
                else
                    call t.d.HideAll()
                endif
                return
            endif
            
            call t.d.ChangeName(t.Msg+"|n|cffff0000"+I2S(t.Max-t.Expired)+"|r seconds left.|r")       // The Dialog System will not parse this, since it contains |n
        endloop
    endfunction

    function SetDialogTime takes Dialog d, real time, boolean destroy returns nothing
        local Timer t = Timer.create()
        set t.Max = R2I(time+0.5)
        set t.d = d
        set t.Msg = d.Name
        set t.Expired = 0
        set t.ddestroy = destroy
    endfunction
    
    private function Init takes nothing returns nothing
        call TimerStart(CreateTimer(),1.,true,function Loop)
    endfunction
endlibrary

I wanted to part this from the actual system, sense it shall not be an official part of it.
But I have no problem, if this thread is deleted and I shall post in the Dialog System thread.

I will make more Extensions!
 
Level 11
Joined
Feb 22, 2006
Messages
752
This should really go into the dialog system thread. Specifically, in the original post.

I wanted to part this from the actual system, sense it shall not be an official part of it.

If you don't want to make it official, don't release it. If you want to release it, put it with Dialog System since this clearly is meant to be used with that system and can ONLY be used with that system.
 
Top