Thread: -Dialog.txt
View Single Post
  #1  
Old 04-28-2008, 10:51 PM
Bell Bell is offline
Registered User
Bell's Avatar
Join Date: Feb 2007
Posts: 1,824
Bell has much to be proud ofBell has much to be proud ofBell has much to be proud ofBell has much to be proud ofBell has much to be proud ofBell has much to be proud ofBell has much to be proud of
-Dialog.txt

For those of you that use party dialog, Novo thought you might find this to be a little more efficient and useful than the standard methods normally used.
PHP Code:
/**
 * Dialog System asks for the user to select an option
 * then returns the value of the selected option.
 *
 * Also allows asking other players.
 *
 * @author Novo
 * @date 27/04/08
 *
 * How to use:
 *  findweapon("-Dialog").openDialog( "Window Title", "Message", {"Options", "Or", {"assoc", "Associative Values"} } );
 *  findweapon("-Dialog").openDialogList( "Window Title", "Message", {"Options", "Or", {"assoc", "Associative Values"} } );
 *  findweapon("-Dialog").openExternalDialog( "Player", "Window Title", "Message", {"Options", "Or", {"assoc", "Associative Values"} } );
 *  findweapon("-Dialog").openExternalDialogList( "Player", "Window Title", "Message", {"Options", "Or", {"assoc", "Associative Values"} } );
 *
 */

/**
 * Mediates between client and server
 */
function onactionserversidecmddialogpltitlemsgoptions ) {
  switch ( 
cmd ) {
    case 
"dialog": case "dialogList":
      
temp.replyTo player.account;
      
with findPlayerpl ) ) {
        
triggerclient"gui""-Dialog"cmddialogtemp.replyTotitlemsgoptions );
      }
    break;
    case 
"replyDialog":
      
with findplayerpl ) ) {
        
triggerclient"gui""-Dialog""replyDialog"dialogparams[3] );
      }
    break;
  }
}

//#CLIENTSIDE
/**
 * Mediates between server and client
 */
function onactionclientsidecmddialogpltitlemsgoptions ) {
  switch ( 
cmd ) {
    case 
"dialog":
      
temp.reply openDialogtitlemsgoptions );
      
triggerserver("gui"name"replyDialog"dialogpltemp.reply );
    break;
    case 
"dialogList":
      
temp.reply openDialogListtitlemsgoptions );
      
triggerserver("gui"name"replyDialog"dialogpltemp.reply );
    break;
    case 
"replyDialog":
      
Replydialogparams[2] );
    break;
  }
}

/**
 * Opens a Dialog in another player. (Buttons)
 *
 * @param pl
 *   Player's Account you want
 * @param title
 *   Dialog's Title.
 * @param msg
 *   Message Asked
 * @param options
 *   An array of values ( format: {{value, text}, ...} or {text, ...}
 *
 * @return
 *   Option selected
 */
public function openExternDialogpltitlemsgoptions ) {
  
this.dialogCount ++;
  
temp.dialog this.dialogCount;

  
triggerserver("gui"name"dialog"temp.dialogpltitlemsgoptions );

  
// Wait until there is a reply.
  
waitforthis"onReplied"temp.dialog );
  
  
// Return reply!
  
return GetReplytemp.dialog );
}

/**
 * Opens Dialog in another player ( List )
 *
 * @see openExternalDialog
 */
public function openExternDialogListpltitlemsgoptions ) {
  
this.dialogCount ++;
  
temp.dialog this.dialogCount;

  
triggerserver("gui"name"dialogList"temp.dialogpltitlemsgoptions );

  
// Wait until there is a reply.
  
waitforthis"onReplied"temp.dialog );
  
  
// Return reply!
  
return GetReplytemp.dialog );
}

/**
 * Opens a dialog and returns answer
 *
 * @see openExternalDialog
 */
public function openDialogtitlemsgoptions ) {
  
// No options!
  
if ( options.size() < )
    return 
null;

  
// One Option? You call that an Option?
  
if ( options.size() == ) {
    if ( 
options[0].type() == )
      return 
options[0][0];
    return 
options[0];
  }

  
this.dialogCount ++; // Unique Dialog ID
  
temp.dialog this.dialogCount;
  
// Conflicting Dialog? ( Happens when you update the code )
  
if ( isObject"Dialog_"this.dialogCount ) )
    (
"Dialog_"this.dialogCount ).destroy();

  new 
GuiWindowCtrl"Dialog_"temp.dialog ) {
    
this.text title;
    
this.dialog temp.dialog;
    
extent = {50 50 options.size(), 80};
    
position = { (GraalControl.width this.width) / 2, (GraalControl.height this.height) / };
    new 
GuiMLTextCtrl"DialogMessage_"this.dialog ) {
      
15;
      
20;
      
this.text msg;
    }

    for ( 
temp.0temp.options.size(); temp.++ ) {
      new 
GuiButtonCtrl"DialogButton_"this.dialog @"_"temp.) {
        
40;
        
25 50 temp.i;
        
width 45;

        
this.dialog temp.dialog;
        if ( 
optionstemp.].type() == ) {
          
this.option optionstemp.][0];
          
this.text optionstemp.][1];
        } else {
          
this.option optionstemp.];
          
this.text optionstemp.];
        }

        
thiso.catcheventthis.name"onAction""onReply" );
      }
    }
  }

  
// Wait until there is a reply.
  
waitforthis"onReplied"temp.dialog );
  
  
// Return reply!
  
return GetReplytemp.dialog );
}

/**
 * Opens Dialog List
 *
 * @see openExternalDialogList
 */
public function openDialogListtitlemsgoptions ) {
  
// No options!
  
if ( options.size() < )
    return 
null;

  
// One Option? You call that an Option?
  
if ( options.size() == ) {
    if ( 
options[0].type() == )
      return 
options[0][0];
    return 
options[0];
  }

  
this.dialogCount ++; // Unique Dialog ID
  
temp.dialog this.dialogCount;
  
// Conflicting Dialog? ( Happens when you update the code )
  
if ( isObject"Dialog_"this.dialogCount ) )
    (
"Dialog_"this.dialogCount ).destroy();

  new 
GuiWindowCtrl"Dialog_"temp.dialog ) {
    
this.text title;
    
this.dialog temp.dialog;
    
extent = { 300330};
    
position = { (GraalControl.width this.width) / 2, (GraalControl.height this.height) / };
    new 
GuiMLTextCtrl"DialogMessage_"this.dialog ) {
      
15;
      
20;
      
this.text msg;
    }

    new 
GuiScrollCtrl"DialogScroll_"temp.dialog ) {
      
position = {1040};
      
extent = {280280};
      
vscrollbar "dynamic";
      
hscrollbar "dynamic";

      new 
GuiTextListCtrl"DialogList_"temp.dialog ) {
        
extent = {280280};
        
fitparentwidth true;
        
this.dialog temp.dialog;

        
thiso.catcheventthis.name"onDblClick""onReplyList" );
      }
    }
  }
  
  (
"DialogList_"temp.dialog ).clearrows();
  for ( 
temp.0temp.options.size(); temp.++ ) {
    if ( 
optionstemp.].type() == ) {
      
temp.option optionstemp.][0];
      
temp.msg optionstemp.][1];
    } else {
      
temp.option optionstemp.];
      
temp.msg optionstemp.];
    }

    
with ( ("DialogList_"temp.dialog ).addRow0temp.msg ) ) {
      
this.dialog temp.dialog;
      
this.option temp.option;
    }
  }

  
// Wait until there is a reply.
  
waitforthis"onReplied"temp.dialog );
  
  
// Return reply!
  
return GetReplytemp.dialog );
}

/**
 * Used for replies using list object
 */
function onReplyListguientryidentrytextentryindex ) {
  
temp.dialog gui.dialog;
  
temp.response gui.rowsentryindex ].option;

  
// Dispose of GUI
  
("Dialog_"temp.dialog ).destroy();

  
// Send the response
  
Replytemp.dialogtemp.response );
}

/**
 * Used for replies using buttons
 */
function onReplygui ) {
  
temp.response gui.option;
  
temp.dialog gui.dialog;

  
// Dispose of GUI
  
("Dialog_"temp.dialog ).destroy();

  
// Send the response
  
Replytemp.dialogtemp.response );
}

/**
 * Main reply module
 *
 * Sets and triggers reply event
 */
function Replydialogreply ) {
  
this.(@"reply_"dialog ) = reply;

  
// This allows 'waitfor' to stop it's wait
  
trigger("onReplied"dialog"" );
}

/**
 * Returns the answer of a given dialog
 */
function GetReplydialog ) {
  return 
this.(@"reply_"dialog );

__________________
For support contact
http://support.toonslab.com/

Last edited by Skyld; 04-28-2008 at 11:15 PM.. Reason: Adding PHP tags for clarity
Reply With Quote