Worldedit
  Worldedit
Le site sur l'éditeur de warcraft 3 !
 
  FAQFAQ   RechercherRechercher   Liste des MembresListe des Membres    Groupes d'utilisateursGroupes d'utilisateurs   medals.php?sid=79c08d9128748c3463610428f2da0527Médailles   S'enregistrerS'enregistrer 
 ProfilProfil   Se connecter pour vérifier ses messages privésSe connecter pour vérifier ses messages privés   ConnexionConnexion 
  FAQFAQ World Editor   UploadUploader une map ou une image    UploadAjouter sa map à l'annuaire   UploadConsulter l'annuaire

Library: JSDialog

 
Poster un nouveau sujet   Répondre au sujet    Worldedit Index du Forum -> Aide sur les déclencheurs
Voir le sujet précédent :: Voir le sujet suivant  
Auteur Message
 jk2pach
Invité








MessagePosté le: 18/03/10 19:18    Sujet du message: Library: JSDialog Citer

Jass:
library JSDialog initializer init
//***************************************************************************************************
//*  JSDialog
//* ----------
//* Author: Profet
//*
//*
//*
//*
//*  To implement, just get a vJass compiler and
//* copy this library/trigger to your map.
//*
//***************************************************************************************************

//* SETTING CONSTANTS
    globals
        private constant integer    MAX_BUTTONS = 7                             // Maximum number of buttons by dialog.
        private constant integer    CANCEL_HOTKEY = 512                         // ASCII number of cancel shortcut (Esc=512).
        private constant string     CANCEL_STRING = "|cffFF0000< Cancel >|r"    // Defaut "cancel" button's text.
    endglobals
   
//===========================================================================
//* FUNCTIONS INTERFACES
//  ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
//      IFuncDialogBtnAction :  <p>                 Id of the player who clicked the button.
//                              <dialogUnit>        Unit attached to the dialog.
//                              <dialogInteger>     Integer value attached to the dialog.
//                              <btnInteger>        Integer value attached to the clicked button.
//
//===========================================================================
    function interface IFuncDialogBtnAction takes integer p, unit dialogUnit, integer dialogInteger, string btnString, integer btnInteger returns nothing
   
   
//===========================================================================
//* LIBRARY'S CORE
//  ¯¯¯¯¯¯¯¯¯¯¯¯¯¯
//*
//*  Do NOT modify without a really good reason !!
//*
//===========================================================================
    private keyword s_dialog
    globals
        private s_dialog array DIALOG
    endglobals
   
    private function init takes nothing returns nothing
    local integer i = 0
        loop
            exitwhen( i==12 )
            set DIALOG[i] = s_dialog.create(i)
            set i=i+1
        endloop
    endfunction
   
    private struct s_dialog
       
        // Dialog's members.
            private dialog d
            private integer p
            private trigger t
            private integer dialogInteger   = 0
            private unit    dialogUnit      = null
       
        // Buttons' members.
            private integer btnCount = 0
            private button  array btnList[MAX_BUTTONS]
            private string  array btnString[MAX_BUTTONS]
            private integer array btnInteger[MAX_BUTTONS]
            private IFuncDialogBtnAction array btnFunc[MAX_BUTTONS]
       
        // Constructor.
            static method create takes integer p returns s_dialog
            local s_dialog this = s_dialog.allocate()
                set this.p = p
                set this.d = DialogCreate()
                set this.t = CreateTrigger()
                call TriggerAddAction( this.t, function s_dialog.clicked_Actions )
                call TriggerRegisterDialogEvent( this.t, this.d )
                return this
            endmethod
       
        // Static trigger action and method.
            private static method clicked_Actions takes nothing returns nothing
                call DIALOG[GetPlayerId(GetTriggerPlayer())].clicked(GetClickedButton())
            endmethod
           
            method clicked takes button btn returns nothing
                local integer i=0
                loop
                    exitwhen( i==.btnCount )
                    if( .btnList[i]==btn )then
                        if( .btnFunc[i]>0 )then
                            call .btnFunc[i].evaluate( .p, .dialogUnit, .dialogInteger, .btnString[i], .btnInteger[i] )
                        endif
                        return
                    endif
                    set i=i+1
                endloop
            endmethod
       
        // .
            method Clear takes string title, unit un, integer attachedInt returns nothing
                set .dialogUnit = un
                set .dialogInteger = attachedInt
                call DialogClear(.d)
                call DialogSetMessage( .d, title )
                set .btnCount = 0
            endmethod
           
        // .
            method AddButton takes string text, IFuncDialogBtnAction func, integer key, string attachedString, integer attachedInt returns boolean
                if( .btnCount<MAX_BUTTONS )then//-1 or (key==CANCEL_HOTKEY and .btnCount<MAX_BUTTONS)
                    set .btnList[.btnCount] = DialogAddButton( .d, text, key )
                    set .btnFunc[.btnCount] = func
                    set .btnString[.btnCount] = attachedString
                    set .btnInteger[.btnCount] = attachedInt
                    set .btnCount = .btnCount + 1
                    return true
                endif
                return false
            endmethod
           
        // .
            method Show takes nothing returns nothing
                if( .btnCount==0 )then
                    call .AddButton(CANCEL_STRING,0,CANCEL_HOTKEY,"",0)
                endif
                call DialogDisplay( Player(.p), .d, true )
            endmethod
       
    endstruct


//===========================================================================
//* PUBLIC FUNCTIONS
//===========================================================================

    // Show the specified player's dialog.
         function Show takes integer playerId returns nothing
            call DIALOG[playerId].Show()
        endfunction
       
    // Remove all buttons from the player's dialog, change it's title and attached values.
         function Clear takes integer playerId, string title, unit attachedUnit, integer attachedInt returns nothing
            call DIALOG[playerId].Clear( title, attachedUnit, attachedInt )
        endfunction
       
    // Add a button to the player's dialog, return FALSE if there are already too many buttons (MAX_BUTTONS) in the dialog.
         function AddButton takes integer playerId, string text, IFuncDialogBtnAction func, integer key, string attachedString, integer attachedInt returns boolean
            return DIALOG[playerId].AddButton( text, func, key, attachedString, attachedInt )
        endfunction
       
    // Return the maximum number of buttons by dialog.
         function MaxButtons takes nothing returns integer
            return MAX_BUTTONS
        endfunction
       
    // Return the default Cancel button string.
         function CancelText takes nothing returns string
            return CANCEL_STRING
        endfunction
       
    // Return the default Cancel button hotkey.
         function CancelHotkey takes nothing returns integer
            return CANCEL_HOTKEY
        endfunction
       
endlibrary

_________________
Revenir en haut
Montrer les messages depuis:   
Poster un nouveau sujet   Répondre au sujet    Worldedit Index du Forum -> Aide sur les déclencheurs Toutes les heures sont au format GMT + 1 Heure
Page 1 sur 1
La question posée dans ce topic a été résolue !

 
Sauter vers:  
Vous ne pouvez pas poster de nouveaux sujets dans ce forum
Vous ne pouvez pas répondre aux sujets dans ce forum
Vous ne pouvez pas éditer vos messages dans ce forum
Vous ne pouvez pas supprimer vos messages dans ce forum
Vous ne pouvez pas voter dans les sondages de ce forum


Powered by phpBB © 2001, 2005 phpBB Group
Traduction par : phpBB-fr.com