RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Gumps not closing completely

mdavis93

Sorceror
Gumps not closing completely

I am creating a gump that is a tool kit. The first gump is nothing more than a button that opens the bigger gump -- the kit. The toolkit is turned on by a command, and turned off by the same command. Here is the code:

Code:
[SIZE=2]private static void ToolKit_OnCommand( CommandEventArgs e )[/SIZE]
[SIZE=2]{[/SIZE]
[SIZE=2]	Mobile from = e.Mobile;[/SIZE]
[SIZE=2]	if( from.HasGump( typeof( GMToolKit ) ) )[/SIZE]
[SIZE=2]	{[/SIZE]
[SIZE=2]		from.SendMessage( "GMToolKit is open, now closing..." );[/SIZE]
[SIZE=2]		from.CloseGump( typeof( GMToolKit ) );[/SIZE]
[SIZE=2]		from.CloseGump( typeof( GMMiniKit ) );[/SIZE]
[SIZE=2]		from.CloseAllGumps();[/SIZE]
[SIZE=2]	}[/SIZE]
[SIZE=2]	else[/SIZE]
[SIZE=2]	{[/SIZE]
[SIZE=2]		if( from.HasGump( typeof( GMMiniKit ) ) )[/SIZE]
[SIZE=2]		{[/SIZE]
[SIZE=2]			from.CloseAllGumps();[/SIZE]
[SIZE=2]			from.SendMessage( "GMMiniKit is open, now closing..." );[/SIZE]
[SIZE=2]		}[/SIZE]
[SIZE=2]		else[/SIZE]
[SIZE=2]		{[/SIZE]
[SIZE=2]			from.CloseGump( typeof( GMToolKit ) );[/SIZE]
[SIZE=2]			from.SendGump( new GMToolKit() );[/SIZE]
[SIZE=2]		}[/SIZE]
[SIZE=2]	}[/SIZE]
[SIZE=2]}[/SIZE]

Now when I use the command when I first log in, everythings fine. The toolkit loads, when I close it out by clicking a button or right-click, it returns to the 'button' state. When I click the button, it opens the kit again. However, when I use the command again to shut it off.. It says that the gump is still open.

Why do the Gumps still fail the check even though the command from.CloseGum(...) and from.CloseAllGumps() are used to closed the gumps?
 

Phantom

Knight
If you use the CloseGump method there is no way its not closed.

So you have an issue with your code, that says its open...
 

mdavis93

Sorceror
If that's the case, and the code above is incorrect, could someone advise of the correct method to achieve this?


When the main kit is open, and the user clicks the 'Close' button or left-click's the gump to close it, the gump changes to a button. This button is non-closable. When the user clicks this button, it opens the main toolkit.

If the user wanted to exit out of the toolkit, they would have to use the same command to close it. The command checks to see if the user has a gump of 'GMToolKit' or GMMiniKit', and if so does a CloseGump command on it. This works fine.

However, when the user uses the command again, instead of opening the gump, it says that the gump is still open.. I can't figure out why it's saying the gump is open when it's not.
 

daat99

Moderator
Staff member
mdavis93 said:
If that's the case, and the code above is incorrect, could someone advise of the correct method to achieve this?


When the main kit is open, and the user clicks the 'Close' button or left-click's the gump to close it, the gump changes to a button. This button is non-closable. When the user clicks this button, it opens the main toolkit.

If the user wanted to exit out of the toolkit, they would have to use the same command to close it. The command checks to see if the user has a gump of 'GMToolKit' or GMMiniKit', and if so does a CloseGump command on it. This works fine.

However, when the user uses the command again, instead of opening the gump, it says that the gump is still open.. I can't figure out why it's saying the gump is open when it's not.
Care to post the gump script?
 

Phantom

Knight
mdavis93 said:
If that's the case, and the code above is incorrect, could someone advise of the correct method to achieve this?


When the main kit is open, and the user clicks the 'Close' button or left-click's the gump to close it, the gump changes to a button. This button is non-closable. When the user clicks this button, it opens the main toolkit.

If the user wanted to exit out of the toolkit, they would have to use the same command to close it. The command checks to see if the user has a gump of 'GMToolKit' or GMMiniKit', and if so does a CloseGump command on it. This works fine.

However, when the user uses the command again, instead of opening the gump, it says that the gump is still open.. I can't figure out why it's saying the gump is open when it's not.

You have not posted enough code to help you, so I cannot advise any direction.
 

mdavis93

Sorceror
Sorry took me so long to get back with you guys, had exams at school.

Okay, the gump code looks like this:

Code:
[SIZE=2]using System;[/SIZE]
[SIZE=2]using Server;[/SIZE]
[SIZE=2]using Server.Gumps;[/SIZE]
[SIZE=2]using Server.Network;[/SIZE]
[SIZE=2]using Server.Mobiles;[/SIZE]
[SIZE=2]namespace Server.Gumps[/SIZE]
[SIZE=2]{[/SIZE]
[SIZE=2] public class GMToolKit : Gump[/SIZE]
[SIZE=2] {[/SIZE]
[SIZE=2]     public GMToolKit()[/SIZE]
[SIZE=2]         : base( 0, 0 )[/SIZE]
[SIZE=2]     {[/SIZE]
[SIZE=2]         this.Closable = true;[/SIZE]
[SIZE=2]         this.Disposable = true;[/SIZE]
[SIZE=2]         this.Dragable = true;[/SIZE]
[SIZE=2]         this.Resizable = false;[/SIZE]
[SIZE=2]         this.AddPage( 0 );[/SIZE]
[SIZE=2]         this.AddBackground( 234, 97, 295, 388, 9400 );[/SIZE]
[SIZE=2]         this.AddButton( 495, 459, 4005, 4007, (int)Buttons.btn_Shrink, GumpButtonType.Reply, 0 );[/SIZE]
[SIZE=2]         this.AddButton( 338, 288, 2443, 2444, (int)Buttons.btn_Say, GumpButtonType.Reply, 0 );[/SIZE]
[SIZE=2]         this.AddButton( 338, 456, 2443, 2444, (int)Buttons.btn_Emote, GumpButtonType.Reply, 0 );[/SIZE]
[SIZE=2]         this.AddLabel( 356, 290, 0, @"Say" );[/SIZE]
[SIZE=2]         this.AddLabel( 348, 458, 0, @"Emote" );[/SIZE]
[SIZE=2]         this.AddImageTiled( 235, 278, 292, 5, 9401 );[/SIZE]
[SIZE=2]         this.AddImageTiled( 326, 100, 1, 181, 9403 );[/SIZE]
[SIZE=2]         this.AddImageTiled( 427, 101, 1, 181, 9403 );[/SIZE]
[SIZE=2]         this.AddButton( 445, 111, 2443, 2444, (int)Buttons.btn_GMSwap, GumpButtonType.Reply, 0 );[/SIZE]
[SIZE=2]         this.AddLabel( 451, 113, 0, @"+/- GM" );[/SIZE]
[SIZE=2]         this.AddButton( 445, 138, 2443, 2444, (int)Buttons.btn_AnimDead, GumpButtonType.Reply, 0 );[/SIZE]
[SIZE=2]         this.AddLabel( 458, 140, 0, @"A.D.U" );[/SIZE]
[SIZE=2]         this.AddButton( 445, 165, 2443, 2444, (int)Buttons.btn_Stuck, GumpButtonType.Reply, 0 );[/SIZE]
[SIZE=2]         this.AddLabel( 456, 167, 0, @"Stuck" );[/SIZE]
[SIZE=2]         this.AddButton( 445, 192, 2443, 2444, (int)Buttons.btn_Pages, GumpButtonType.Reply, 0 );[/SIZE]
[SIZE=2]         this.AddLabel( 456, 194, 0, @"Pages" );[/SIZE]
[SIZE=2]         this.AddButton( 445, 219, 2443, 2444, (int)Buttons.btn_ViewEquip, GumpButtonType.Reply, 0 );[/SIZE]
[SIZE=2]         this.AddLabel( 460, 221, 0, @"View" );[/SIZE]
[SIZE=2]         this.AddButton( 445, 246, 2443, 2444, (int)Buttons.btn_SpeechLog, GumpButtonType.Reply, 0 );[/SIZE]
[SIZE=2]         this.AddLabel( 450, 247, 0, @"SpchLog" );[/SIZE]
[SIZE=2]         this.AddButton( 345, 111, 2443, 2444, (int)Buttons.btn_Attack, GumpButtonType.Reply, 0 );[/SIZE]
[SIZE=2]         this.AddLabel( 353, 113, 0, @"Attack" );[/SIZE]
[SIZE=2]         this.AddButton( 345, 138, 2443, 2444, (int)Buttons.btn_Bank, GumpButtonType.Reply, 0 );[/SIZE]
[SIZE=2]         this.AddLabel( 359, 140, 0, @"Bank" );[/SIZE]
[SIZE=2]         this.AddButton( 345, 165, 2443, 2444, (int)Buttons.btn_Remove, GumpButtonType.Reply, 0 );[/SIZE]
[SIZE=2]         this.AddLabel( 353, 168, 0, @"Remove" );[/SIZE]
[SIZE=2]         this.AddButton( 345, 192, 2443, 2444, (int)Buttons.btn_Move, GumpButtonType.Reply, 0 );[/SIZE]
[SIZE=2]         this.AddLabel( 358, 194, 0, @"Move" );[/SIZE]
[SIZE=2]         this.AddButton( 345, 219, 2443, 2444, (int)Buttons.btn_Squelch, GumpButtonType.Reply, 0 );[/SIZE]
[SIZE=2]         this.AddLabel( 352, 221, 0, @"Squelch" );[/SIZE]
[SIZE=2]         this.AddButton( 345, 246, 2443, 2444, (int)Buttons.btn_Props, GumpButtonType.Reply, 0 );[/SIZE]
[SIZE=2]         this.AddLabel( 356, 248, 0, @"Props" );[/SIZE]
[SIZE=2]         this.AddButton( 248, 246, 2443, 2444, (int)Buttons.btn_Mortal, GumpButtonType.Reply, 0 );[/SIZE]
[SIZE=2]         this.AddLabel( 257, 248, 0, @"Mortal" );[/SIZE]
[SIZE=2]         this.AddButton( 248, 219, 2443, 2444, (int)Buttons.btn_Invul, GumpButtonType.Reply, 0 );[/SIZE]
[SIZE=2]         this.AddLabel( 264, 221, 0, @"Invul" );[/SIZE]
[SIZE=2]         this.AddButton( 248, 165, 2443, 2444, (int)Buttons.btn_Unhide, GumpButtonType.Reply, 0 );[/SIZE]
[SIZE=2]         this.AddLabel( 258, 168, 0, @"UnHide" );[/SIZE]
[SIZE=2]         this.AddButton( 248, 192, 2443, 2444, (int)Buttons.btn_Tele, GumpButtonType.Reply, 0 );[/SIZE]
[SIZE=2]         this.AddLabel( 265, 194, 0, @"Tele" );[/SIZE]
[SIZE=2]         this.AddButton( 248, 138, 2443, 2444, (int)Buttons.btn_Hide, GumpButtonType.Reply, 0 );[/SIZE]
[SIZE=2]         this.AddLabel( 267, 140, 0, @"Hide" );[/SIZE]
[SIZE=2]         this.AddButton( 248, 111, 2443, 2444, (int)Buttons.btn_Kill, GumpButtonType.Reply, 0 );[/SIZE]
[SIZE=2]         this.AddLabel( 268, 113, 0, @"Kill" );[/SIZE]
[SIZE=2]         this.AddBackground( 244, 318, 275, 130, 3000 );[/SIZE]
[SIZE=2]         this.AddTextEntry( 246, 321, 270, 124, 0, (int)Buttons.TextEntry1, @"" );[/SIZE]
[SIZE=2]     }[/SIZE]
[SIZE=2]     public enum Buttons[/SIZE]
[SIZE=2]     {[/SIZE]
[SIZE=2]         btn_Shrink,[/SIZE]
[SIZE=2]         btn_Say,[/SIZE]
[SIZE=2]         btn_Emote,[/SIZE]
[SIZE=2]         btn_GMSwap,[/SIZE]
[SIZE=2]         btn_AnimDead,[/SIZE]
[SIZE=2]         btn_Stuck,[/SIZE]
[SIZE=2]         btn_Pages,[/SIZE]
[SIZE=2]         btn_ViewEquip,[/SIZE]
[SIZE=2]         btn_SpeechLog,[/SIZE]
[SIZE=2]         btn_Attack,[/SIZE]
[SIZE=2]         btn_Bank,[/SIZE]
[SIZE=2]         btn_Remove,[/SIZE]
[SIZE=2]         btn_Move,[/SIZE]
[SIZE=2]         btn_Squelch,[/SIZE]
[SIZE=2]         btn_Props,[/SIZE]
[SIZE=2]         btn_Mortal,[/SIZE]
[SIZE=2]         btn_Invul,[/SIZE]
[SIZE=2]         btn_Unhide,[/SIZE]
[SIZE=2]         btn_Tele,[/SIZE]
[SIZE=2]         btn_Hide,[/SIZE]
[SIZE=2]         btn_Kill,[/SIZE]
[SIZE=2]         TextEntry1,[/SIZE]
[SIZE=2]     }[/SIZE]
[SIZE=2]     public override void OnResponse( NetState state, RelayInfo info )[/SIZE]
[SIZE=2]     {[/SIZE]
[SIZE=2]         Mobile from = state.Mobile;[/SIZE]
[SIZE=2]         from.CloseGump( typeof( GMToolKit ) );[/SIZE]
[SIZE=2]         from.SendGump( new GMMiniKit() );[/SIZE]
[SIZE=2]     }[/SIZE]
[SIZE=2] }[/SIZE]
 
[SIZE=2]public class GMMiniKit : Gump[/SIZE]
[SIZE=2]{[/SIZE]
[SIZE=2]public GMMiniKit()[/SIZE]
[SIZE=2]         : base( ( 640 / 2 ), ( 480 / 2 ) )[/SIZE]
[SIZE=2]{[/SIZE]
[SIZE=2]this.Closable=false;[/SIZE]
[SIZE=2]this.Disposable=true;[/SIZE]
[SIZE=2]this.Dragable=true;[/SIZE]
[SIZE=2]this.Resizable=false;[/SIZE]
[SIZE=2]this.AddPage(0);[/SIZE]
[SIZE=2]         this.AddBackground( 0, 0, 51, 57, 9400 );[/SIZE]
[SIZE=2]         this.AddButton( 10, 14, 10830, 10830, (int)Buttons.Button1, GumpButtonType.Reply, 0 );[/SIZE]
[SIZE=2]}[/SIZE]
 
[SIZE=2]public enum Buttons[/SIZE]
[SIZE=2]{[/SIZE]
[SIZE=2]Button1,[/SIZE]
[SIZE=2]}[/SIZE]
[SIZE=2]     public override void OnResponse( NetState state, RelayInfo info )[/SIZE]
[SIZE=2]     {[/SIZE]
[SIZE=2]         Mobile from = state.Mobile;[/SIZE]
[SIZE=2]         from.CloseGump( typeof( GMMiniKit ) );[/SIZE]
[SIZE=2]         from.SendGump( new GMToolKit() );[/SIZE]
[SIZE=2]     }[/SIZE]
[SIZE=2]}[/SIZE]
[SIZE=2]}[/SIZE]


and the code that handles the command is:

Code:
[SIZE=2]private static void ToolKit_OnCommand( CommandEventArgs e )[/SIZE]
[SIZE=2]     {[/SIZE]
[SIZE=2]         Mobile from = e.Mobile;[/SIZE]
[SIZE=2]         if( from.HasGump( typeof( GMToolKit ) ) )[/SIZE]
[SIZE=2]         {[/SIZE]
[SIZE=2]             from.SendMessage( "GMToolKit is open, now closing..." );[/SIZE]
[SIZE=2]             from.CloseGump( typeof( GMToolKit ) );[/SIZE]
[SIZE=2]             from.CloseGump( typeof( GMMiniKit ) );[/SIZE]
[SIZE=2]             from.CloseAllGumps();[/SIZE]
[SIZE=2]         }[/SIZE]
[SIZE=2]         else[/SIZE]
[SIZE=2]         {[/SIZE]
[SIZE=2]             if( from.HasGump( typeof( GMMiniKit ) ) )[/SIZE]
[SIZE=2]             {[/SIZE]
[SIZE=2]                 from.CloseAllGumps();[/SIZE]
[SIZE=2]                 from.SendMessage( "GMMiniKit is open, now closing..." );[/SIZE]
[SIZE=2]             }[/SIZE]
[SIZE=2]             else[/SIZE]
[SIZE=2]             {[/SIZE]
[SIZE=2]                 from.CloseAllGumps() );[/SIZE]
[SIZE=2]                 from.SendGump( new GMToolKit() );[/SIZE]
[SIZE=2]             }[/SIZE]
[SIZE=2]         }[/SIZE]
[SIZE=2]     }[/SIZE]

Slice and dice away :D

*Edit* The command "from.CloseAllGumps" will be changed to "from.CloseGump( typeof (GumpName ) )" once I get this working, I don't want to close all their gumps :D Just the GMToolKit or GMMiniKit, whichever they have open at the time.
 

kmwill23

Sorceror
Okay, here's the deal with CloseGump()

When you use CloseGump, the server sends a button action of '0'. That is why with CloseGump it allows you to specify a buttonid:

Code:
mob.CloseGump( typeof( WhateverGump ), 5 );

If in your OnResponse method you handle buttonid '0' in a way that recreates the gump, it will. That is why, traditionally, switch statements in OnResponse will show:

Code:
case 0: break; // Close Gump

Or something similar.

So, when you do this right here:

Code:
          Mobile from = state.Mobile;
          from.CloseGump( typeof( GMMiniKit ) );
          from.SendGump( new GMToolKit() );

It will always create and send the new gump, even with CloseGump. Add this in there:

Code:
if ( info.ButtonID == 0 )
          return;
 

mdavis93

Sorceror
Okay, if I exit the gump by right-clicking it, then it will close, and the ToolKit command will re-open it. But if I close it by the ToolKit command, it will not re-open. It says "The GMToolKit is open.. now closing" which is what I have it to say in the code if the gump is open...
 

kmwill23

Sorceror
mdavis93 said:
Okay, if I exit the gump by right-clicking it, then it will close, and the ToolKit command will re-open it. But if I close it by the ToolKit command, it will not re-open. It says "The GMToolKit is open.. now closing" which is what I have it to say in the code if the gump is open...

Based on that...

Code:
         if( from.HasGump( typeof( GMToolKit ) ) )
         {
             from.SendMessage( "GMToolKit is open, now closing..." );
             from.CloseGump( typeof( GMToolKit ) );
             from.CloseGump( typeof( GMMiniKit ) );
             from.CloseAllGumps();
         }
         else
         {
             if( from.HasGump( typeof( GMMiniKit ) ) )
             {
                 from.CloseAllGumps();
                 from.SendMessage( "GMMiniKit is open, now closing..." );
             }
             else
             {
                 from.CloseAllGumps() );
                 from.SendGump( new GMToolKit() );
             }
         }

When you are trying to close it using the command, meaning the gump is open when you run the command, then "from.HasGump( typeof( GMToolKit )" will return true. In that if statement you don't tell it to open any new gump. After the if statement you don't have it doing anything, so no new gump will open.

Addition: Need some clarification... Are you saying that when you close it using the command, it will not reopen using the command?
 

A_Li_N

Knight
GMToolKit
Code:
     public override void OnResponse( NetState state, RelayInfo info )
     {
         Mobile from = state.Mobile;
         from.CloseGump( typeof( GMToolKit ) );
         from.SendGump( new GMMiniKit() );
     }

GMMimiKit
Code:
     public override void OnResponse( NetState state, RelayInfo info )
     {
         Mobile from = state.Mobile;
         from.CloseGump( typeof( GMMiniKit ) );
         from.SendGump( new GMToolKit() );
     }

As stated before, the action of Closing a gump inherantly calls the OnResponse method with teh same action as pressing a button with an ID of 0. This means that if you right click on a gump to close it, you 'click' button 0. If a command closes a gump, the command 'clicks' button 0.
Thats beside the fact in your case. You don't even check the buttons pressed. No matter what button is pressed (or however you close the gump), doing so will call a new gump. If you have the MiniKit gump open and hit any button or right click on it or close it with a command, you will simply close the gump (both because clicking a button closes the gump AND because you tell it to close with CloseGump( typeof( GMMiniKit ) );), but then it will open the GMToolKit. The same goes for closing/pressing in the GMToolKit...it will close the GMToolKit and automatically open the GMMiniKit.

If you want to get this to work, I suggest you do your switch statements to incorperate all your buttons and make a single button that opens the big kit and a single button that 'minimizes' the big kit. Your command would most likely work after that with the CloseGump( typeof() );.
 

mdavis93

Sorceror
I have, indeed, added a statement to check if ButtonID 0 was used.

Here's the new code
Code:
using System;
using Server;
using Server.Gumps;
using Server.Network;
using Server.Mobiles;
namespace Server.Gumps
{
    public class GMToolKit : Gump
    {
        public GMToolKit()
            : base( 0, 0 )
        {
            this.Closable = true;
            this.Disposable = true;
            this.Dragable = true;
            this.Resizable = false;
            this.AddPage( 0 );
            this.AddBackground( 234, 97, 295, 388, 9400 );
            this.AddButton( 495, 459, 4005, 4007, (int)Buttons.btn_Shrink, GumpButtonType.Reply, 1 );
            this.AddButton( 338, 288, 2443, 2444, (int)Buttons.btn_Say, GumpButtonType.Reply, 2 );
            this.AddButton( 338, 456, 2443, 2444, (int)Buttons.btn_Emote, GumpButtonType.Reply, 3 );
            this.AddLabel( 356, 290, 0, @"Say" );
            this.AddLabel( 348, 458, 0, @"Emote" );
            this.AddImageTiled( 235, 278, 292, 5, 9401 );
            this.AddImageTiled( 326, 100, 1, 181, 9403 );
            this.AddImageTiled( 427, 101, 1, 181, 9403 );
            this.AddButton( 445, 111, 2443, 2444, (int)Buttons.btn_GMSwap, GumpButtonType.Reply, 4 );
            this.AddLabel( 451, 113, 0, @"+/- GM" );
            this.AddButton( 445, 138, 2443, 2444, (int)Buttons.btn_AnimDead, GumpButtonType.Reply, 5 );
            this.AddLabel( 458, 140, 0, @"A.D.U" );
            this.AddButton( 445, 165, 2443, 2444, (int)Buttons.btn_Stuck, GumpButtonType.Reply, 6 );
            this.AddLabel( 456, 167, 0, @"Stuck" );
            this.AddButton( 445, 192, 2443, 2444, (int)Buttons.btn_Pages, GumpButtonType.Reply, 7 );
            this.AddLabel( 456, 194, 0, @"Pages" );
            this.AddButton( 445, 219, 2443, 2444, (int)Buttons.btn_ViewEquip, GumpButtonType.Reply, 8 );
            this.AddLabel( 460, 221, 0, @"View" );
            this.AddButton( 445, 246, 2443, 2444, (int)Buttons.btn_SpeechLog, GumpButtonType.Reply, 9 );
            this.AddLabel( 450, 247, 0, @"SpchLog" );
            this.AddButton( 345, 111, 2443, 2444, (int)Buttons.btn_Attack, GumpButtonType.Reply, 10 );
            this.AddLabel( 353, 113, 0, @"Attack" );
            this.AddButton( 345, 138, 2443, 2444, (int)Buttons.btn_Bank, GumpButtonType.Reply, 11 );
            this.AddLabel( 359, 140, 0, @"Bank" );
            this.AddButton( 345, 165, 2443, 2444, (int)Buttons.btn_Remove, GumpButtonType.Reply, 12 );
            this.AddLabel( 353, 168, 0, @"Remove" );
            this.AddButton( 345, 192, 2443, 2444, (int)Buttons.btn_Move, GumpButtonType.Reply, 13 );
            this.AddLabel( 358, 194, 0, @"Move" );
            this.AddButton( 345, 219, 2443, 2444, (int)Buttons.btn_Squelch, GumpButtonType.Reply, 14 );
            this.AddLabel( 352, 221, 0, @"Squelch" );
            this.AddButton( 345, 246, 2443, 2444, (int)Buttons.btn_Props, GumpButtonType.Reply, 15 );
            this.AddLabel( 356, 248, 0, @"Props" );
            this.AddButton( 248, 246, 2443, 2444, (int)Buttons.btn_Mortal, GumpButtonType.Reply, 16 );
            this.AddLabel( 257, 248, 0, @"Mortal" );
            this.AddButton( 248, 219, 2443, 2444, (int)Buttons.btn_Invul, GumpButtonType.Reply, 17 );
            this.AddLabel( 264, 221, 0, @"Invul" );
            this.AddButton( 248, 165, 2443, 2444, (int)Buttons.btn_Unhide, GumpButtonType.Reply, 18 );
            this.AddLabel( 258, 168, 0, @"UnHide" );
            this.AddButton( 248, 192, 2443, 2444, (int)Buttons.btn_Tele, GumpButtonType.Reply, 19 );
            this.AddLabel( 265, 194, 0, @"Tele" );
            this.AddButton( 248, 138, 2443, 2444, (int)Buttons.btn_Hide, GumpButtonType.Reply, 20 );
            this.AddLabel( 267, 140, 0, @"Hide" );
            this.AddButton( 248, 111, 2443, 2444, (int)Buttons.btn_Kill, GumpButtonType.Reply, 21 );
            this.AddLabel( 268, 113, 0, @"Kill" );
            this.AddBackground( 244, 318, 275, 130, 3000 );
            this.AddTextEntry( 246, 321, 270, 124, 0, (int)Buttons.TextEntry1, @"" );
        }
        public enum Buttons
        {
            btn_Shrink,
            btn_Say,
            btn_Emote,
            btn_GMSwap,
            btn_AnimDead,
            btn_Stuck,
            btn_Pages,
            btn_ViewEquip,
            btn_SpeechLog,
            btn_Attack,
            btn_Bank,
            btn_Remove,
            btn_Move,
            btn_Squelch,
            btn_Props,
            btn_Mortal,
            btn_Invul,
            btn_Unhide,
            btn_Tele,
            btn_Hide,
            btn_Kill,
            TextEntry1,
        }
        public override void OnResponse( NetState state, RelayInfo info )
        {
            if( info.ButtonID == 0 )
            {
                state.Mobile.SendMessage( "You pushed button: " + info.ButtonID );
                return;
            }
            Mobile from = state.Mobile;
            from.CloseGump( typeof( GMToolKit ) );
            from.SendGump( new GMMiniKit() );
        }
    }

 public class GMMiniKit : Gump
 {
  public GMMiniKit()
            : base( ( 640 / 2 ), ( 480 / 2 ) )
  {
   this.Closable=false;
   this.Disposable=true;
   this.Dragable=true;
   this.Resizable=false;
   this.AddPage(0);
            this.AddBackground( 0, 0, 51, 57, 9400 );
            this.AddButton( 10, 14, 10830, 10830, (int)Buttons.Button1, GumpButtonType.Reply, 1 );
  }
  
  public enum Buttons
  {
   Button1,
  }
        public override void OnResponse( NetState state, RelayInfo info )
        {
            if( info.ButtonID == 0 )
            {
                return;
            }
            Mobile from = state.Mobile;
            from.CloseGump( typeof( GMMiniKit ) );
            from.SendGump( new GMToolKit() );
        }
 }
}

If I exit the gump via right-click, then it's all good and fine. If I click the 'Shrink' button, it doesn't show the GMMiniKit, instead it closes the dialog and says "You pushed button: 0" and it's assigned ID of '1'. However, if I click *any* of the other buttons, it will close the ToolKit and open the MiniKit.

If I click the button on the MiniKit, it closes the gump. In both of these instances (if the gump is closed by pushing either button on either gump) I can use the toolkit command and the gump opens fine. However, if I use the toolkit command to dispose of the gump, it will. Then when I use the command a third time to close it, it says "GMToolKit is open, now closing..."

-I want the toolkit command to start the kit, and the *only* way to close it is to re-use the comand. This is to prevent accidental closing-
 

A_Li_N

Knight
Code:
        public enum Buttons
        {
            btn_Shrink,
With an enum, if you don't assign the values of the first one, it will assign it to 0. So if your shrink button is assigned to the Buttons.btn_Shrink, it is assigned as '0' because it's the first one in that enum. Try adding something like this to the enum...
Code:
        public enum Buttons
        {
            Exit,
            btn_Shrink,

On kinda a side note, this is what I would do...
Pseudo:
Code:
ToolKit()
{
    Closable = false;
    ...
}

OnResponse(...)
{
    BID = info.ButtonID;
    if BID is Buttons.Exit
        return;
    else if BID is Buttons.Shrink
        SendGump( new MiniGump );
    else if BID is Buttons.Etc
        DoWhatever()
        SendGump( new ToolKit )
}
 

mdavis93

Sorceror
hmm.. wasn't aware that I could refer to them by name. I learned something today :D
Also thought the '1' in
Code:
this.AddButton ( 275, 460, 247, 248, (int)Buttons.Button1, GumpsButtonType.Reply, 1 );
was the value that was passed when I checked the ButtonID. But now that I think about it, I don't think I was even thinking :eek:

Going to toy around a bit more and see why the command isn't closing the gumps out, the buttons do it fine. I can use the toolkit command to open the gump and close it with one of the buttons and re-open it all day long.. but as soon as I close it with the command.. it closes it.. but it keeps saying that it still exists. I use this test to see if the invoking mobile has the gump open:

Code:
if( from.HasGump(typeof(GMToolKit) || from.HasGump(typeof(GMMiniKit) ) )
  from.CloseGump(typeof(GMToolKit));  from.CloseGump(typeof(GMMiniKit) );
else
  from.SendGump( new GMToolKit() );



Below is the actual file that the code is found in. The segment that pertains to this function is highlighted in red.

Code:
using System;
using Server;
using Server.Targeting;
using Server.Network;
using Server.Accounting;
using Server.Mobiles;
using Server.Gumps;
namespace Server.Custom
{
 public class StaffCommands
 {
        public static Mobile targ, targ2;
  public static void Initialize()
  {
   Server.Commands.Register( "GM", AccessLevel.Player, new CommandEventHandler( MakeGM_OnCommand ) );
            Server.Commands.Register( "Attack", AccessLevel.GameMaster, new CommandEventHandler( Attack_OnCommand ) );
            Server.Commands.Register( "Toolkit", AccessLevel.Seer, new CommandEventHandler( ToolKit_OnCommand ) );
  }
        [COLOR=red]private static void ToolKit_OnCommand( CommandEventArgs e )
        {
            Mobile from = e.Mobile;[/COLOR]
[COLOR=red]          if( from.HasGump( typeof( GMToolKit ) ) )
            {
                from.SendMessage( "GMToolKit is open, now closing..." );
                from.CloseGump( typeof( GMToolKit ) );
                from.CloseGump( typeof( GMMiniKit ) );
                from.CloseAllGumps();
            }
            else
            {
                if( from.HasGump( typeof( GMMiniKit ) ) )
                {
                    from.CloseAllGumps();
                    from.SendMessage( "GMMiniKit is open, now closing..." );
                }
                else
                {
                    from.CloseGump( typeof( GMToolKit ) );
                    from.SendGump( new GMToolKit() );
                }
            }
        }[/COLOR]
        [Usage( "Attack" )]
        [Description( "Causes a targeted NPC to attack targeted Mobile on command." )]
        private static void Attack_OnCommand( CommandEventArgs e )
        {
            if( e.Mobile is PlayerMobile )
            {
                e.Mobile.Target = new AttackTarget();
                e.Mobile.SendMessage( "Select an NPC to command." );
             //   e.Mobile.SendMessage( "You told " + targ.Name + " to attack " + targ2.Name + "." );
            }
        }
 
  [Usage( "GM [on/off]" )]
  [Description( "Toggles your access level between player and your current level." )]
  private static void MakeGM_OnCommand( CommandEventArgs e )
  {
   PlayerMobile from = e.Mobile as PlayerMobile;
   //AccessLevel oldLevel = from.AccessLevel;
 
   if( from.AccessLevel != AccessLevel.Player )
   {
    if( from.CanRevert )
    {
    // from.oldLevel = oldLevel;
     from.AccessLevel = AccessLevel.Player;
     //from.SendMessage( "You have been reverted to " + from.AccessLevel + " status." );
    }
    else
    {
     from.SendMessage( "You do not have access to this command." );
    }
   }
   else
   {
    Account status = from.Account as Account;
       from.AccessLevel = status.AccessLevel;;
    //from.SendMessage( "You have been granted " + from.AccessLevel + " status" );
   }
  }
        private class AttackTarget : Target
        {
            public AttackTarget()
                : base( -1, false, TargetFlags.None )
            {
            }
            protected override void OnTarget( Mobile from, object targeted )
            {
                if( from is PlayerMobile && targeted is Mobile )
                {
                    targ = (Mobile)targeted;
                    from.Target = new VictimTarget();
                    from.SendMessage( "Whom shall " + targ.Name + " attack?" );
                }
            }
        }
        private class VictimTarget : Target
        {
            public VictimTarget()
                : base( -1, false, TargetFlags.None )
            {
            }
            protected override void OnTarget( Mobile from, object targeted )
            {
             BaseCreature creature1;
             BaseCreature creature2;
                if( from is PlayerMobile && targeted is Mobile )
                {
                    targ2 = (Mobile)targeted;
                }
 
                from.SendMessage( "You commanded " + targ.Name + " to attack " + targ2.Name + "." );
 
                if (targ is BaseCreature )
                {
                 creature1 = (BaseCreature)targ;
 
                 if (targ2 is BaseCreature)
                 {
                  creature2 = (BaseCreature)targ2;
                  // creature1.WarMode = true;
                  creature1.Combatant = creature2;
                  creature1.PublicOverheadMessage( MessageType.Regular, from.EmoteHue, false, "*" + creature1.Name + " is attacking " + creature2.Name + "*" );
                 }
                }
            }
        }
 }
}
 

mdavis93

Sorceror
Could anyone revie my latest code and tell me if I have it correct? It looks correct to me, but when I activate it in game it doesn't work as expected.

If I close the gump using a gump button, all is good. But if I close the gump using the toolkit command, I get the message "GMToolKit is open, now closing..." constantly.. and I can't figure out why.

I have it set to give that message only if the statement:
Code:
if(from.HasGump( typeof( GMTollKit ) )
which shouldn't pass if they don't have it open.
 

daat99

Moderator
Staff member
Please post the code as you have it now and describe exactly what happens when you used each command.
This thread got me realy confused :(
 

Vorspire

Knight
send the scripts to do with this, to my email.. all of them, gumps, commands etc, and ill take a look.. easier than reading a confusing thread :/
 

mdavis93

Sorceror
Here is the code that handles the toolkit command:
Code:
private static void ToolKit_OnCommand( CommandEventArgs e )
{
  Mobile from = e.Mobile;
  if( from.HasGump( typeof( GMToolKit ) ) )
  {
    from.SendMessage( "GMToolKit is open, now closing..." );
    from.CloseGump( typeof( GMToolKit ) );
    from.CloseGump( typeof( GMMiniKit ) );
    from.CloseAllGumps();
  }
  else
  {
    if( from.HasGump( typeof( GMMiniKit ) ) )
    {
      from.CloseAllGumps();
      from.SendMessage( "GMMiniKit is open, now closing..." );
    }
    else
    {
      from.CloseGump( typeof( GMToolKit ) );
      from.SendGump( new GMToolKit() );
    }
  }
}

And here is the gump file:
Code:
using System;
using Server;
using Server.Gumps;
using Server.Network;
using Server.Mobiles;
namespace Server.Gumps
{
    public class GMToolKit : Gump
    {
        public GMToolKit()
            : base( 0, 0 )
        {
            this.Closable = true;
            this.Disposable = true;
            this.Dragable = true;
            this.Resizable = false;
            this.AddPage( 0 );
            this.AddBackground( 234, 97, 295, 388, 9400 );
            this.AddButton( 495, 459, 4005, 4007, (int)Buttons.btn_Shrink, GumpButtonType.Reply, 1 );
            this.AddButton( 338, 288, 2443, 2444, (int)Buttons.btn_Say, GumpButtonType.Reply, 2 );
            this.AddButton( 338, 456, 2443, 2444, (int)Buttons.btn_Emote, GumpButtonType.Reply, 3 );
            this.AddLabel( 356, 290, 0, @"Say" );
            this.AddLabel( 348, 458, 0, @"Emote" );
            this.AddImageTiled( 235, 278, 292, 5, 9401 );
            this.AddImageTiled( 326, 100, 1, 181, 9403 );
            this.AddImageTiled( 427, 101, 1, 181, 9403 );
            this.AddButton( 445, 111, 2443, 2444, (int)Buttons.btn_GMSwap, GumpButtonType.Reply, 4 );
            this.AddLabel( 451, 113, 0, @"+/- GM" );
            this.AddButton( 445, 138, 2443, 2444, (int)Buttons.btn_AnimDead, GumpButtonType.Reply, 5 );
            this.AddLabel( 458, 140, 0, @"A.D.U" );
            this.AddButton( 445, 165, 2443, 2444, (int)Buttons.btn_Stuck, GumpButtonType.Reply, 6 );
            this.AddLabel( 456, 167, 0, @"Stuck" );
            this.AddButton( 445, 192, 2443, 2444, (int)Buttons.btn_Pages, GumpButtonType.Reply, 7 );
            this.AddLabel( 456, 194, 0, @"Pages" );
            this.AddButton( 445, 219, 2443, 2444, (int)Buttons.btn_ViewEquip, GumpButtonType.Reply, 8 );
            this.AddLabel( 460, 221, 0, @"View" );
            this.AddButton( 445, 246, 2443, 2444, (int)Buttons.btn_SpeechLog, GumpButtonType.Reply, 9 );
            this.AddLabel( 450, 247, 0, @"SpchLog" );
            this.AddButton( 345, 111, 2443, 2444, (int)Buttons.btn_Attack, GumpButtonType.Reply, 10 );
            this.AddLabel( 353, 113, 0, @"Attack" );
            this.AddButton( 345, 138, 2443, 2444, (int)Buttons.btn_Bank, GumpButtonType.Reply, 11 );
            this.AddLabel( 359, 140, 0, @"Bank" );
            this.AddButton( 345, 165, 2443, 2444, (int)Buttons.btn_Remove, GumpButtonType.Reply, 12 );
            this.AddLabel( 353, 168, 0, @"Remove" );
            this.AddButton( 345, 192, 2443, 2444, (int)Buttons.btn_Move, GumpButtonType.Reply, 13 );
            this.AddLabel( 358, 194, 0, @"Move" );
            this.AddButton( 345, 219, 2443, 2444, (int)Buttons.btn_Squelch, GumpButtonType.Reply, 14 );
            this.AddLabel( 352, 221, 0, @"Squelch" );
            this.AddButton( 345, 246, 2443, 2444, (int)Buttons.btn_Props, GumpButtonType.Reply, 15 );
            this.AddLabel( 356, 248, 0, @"Props" );
            this.AddButton( 248, 246, 2443, 2444, (int)Buttons.btn_Mortal, GumpButtonType.Reply, 16 );
            this.AddLabel( 257, 248, 0, @"Mortal" );
            this.AddButton( 248, 219, 2443, 2444, (int)Buttons.btn_Invul, GumpButtonType.Reply, 17 );
            this.AddLabel( 264, 221, 0, @"Invul" );
            this.AddButton( 248, 165, 2443, 2444, (int)Buttons.btn_Unhide, GumpButtonType.Reply, 18 );
            this.AddLabel( 258, 168, 0, @"UnHide" );
            this.AddButton( 248, 192, 2443, 2444, (int)Buttons.btn_Tele, GumpButtonType.Reply, 19 );
            this.AddLabel( 265, 194, 0, @"Tele" );
            this.AddButton( 248, 138, 2443, 2444, (int)Buttons.btn_Hide, GumpButtonType.Reply, 20 );
            this.AddLabel( 267, 140, 0, @"Hide" );
            this.AddButton( 248, 111, 2443, 2444, (int)Buttons.btn_Kill, GumpButtonType.Reply, 21 );
            this.AddLabel( 268, 113, 0, @"Kill" );
            this.AddBackground( 244, 318, 275, 130, 3000 );
            this.AddTextEntry( 246, 321, 270, 124, 0, (int)Buttons.TextEntry1, @"" );
        }
        public enum Buttons
        {
            Close,
            btn_Shrink,
            btn_Say,
            btn_Emote,
            btn_GMSwap,
            btn_AnimDead,
            btn_Stuck,
            btn_Pages,
            btn_ViewEquip,
            btn_SpeechLog,
            btn_Attack,
            btn_Bank,
            btn_Remove,
            btn_Move,
            btn_Squelch,
            btn_Props,
            btn_Mortal,
            btn_Invul,
            btn_Unhide,
            btn_Tele,
            btn_Hide,
            btn_Kill,
            TextEntry1,
        }
        public override void OnResponse( NetState state, RelayInfo info )
        {
            switch( info.ButtonID )
            {
                case 0:
                    {
                        state.Mobile.SendMessage( "You pushed button: " + info.ButtonID );
                        break;
                    }
                default:
                    {
                        Mobile from = state.Mobile;
                        from.CloseGump( typeof( GMToolKit ) );
                        from.SendGump( new GMMiniKit() );
                        break;
                    }
            }
        }
    }

 public class GMMiniKit : Gump
 {
  public GMMiniKit()
            : base( ( 640 / 2 ), ( 480 / 2 ) )
  {
   this.Closable=false;
   this.Disposable=true;
   this.Dragable=true;
   this.Resizable=false;
   this.AddPage(0);
            this.AddBackground( 0, 0, 51, 57, 9400 );
            this.AddButton( 10, 14, 10830, 10830, (int)Buttons.Button1, GumpButtonType.Reply, 1 );
  }
  
  public enum Buttons
  {
            Close,
   Button1,
  }
        public override void OnResponse( NetState state, RelayInfo info )
        {
            switch( info.ButtonID )
            {
                case 0:
                    {
                        state.Mobile.SendMessage( "You pushed button: " + info.ButtonID );
                        return;
                    }
                default:
                    {
                        Mobile from = state.Mobile;
                        state.Mobile.SendMessage( "You pushed button: " + info.ButtonID );
                        from.CloseGump( typeof( GMMiniKit ) );
                        from.SendGump( new GMToolKit() );
                        break;
                    }
            }
        }
 }
}

What it's doing:

When I use the toolkit command to turn on the gump, the gump responds and is displayed with GMToolKit being displayed. When I close out of this gump (either by right-click or clicking the lower button called "Shrink") then the smaller gump called GMMiniKit is displayed. This gump consists of only a button.

When I click this button, it closes the GMMiniKit gump properly and opens the GMToolKit gump properly.

All up to this point is great.. however, when I use the toolkit command to exit the system (the only way to close it) then I get the message "GMToolKit is open, now closing..." (or "GMMiniKit is open, now closing...") and you can see in the script that it is coded to show only if they actually have that respective gump open.

Here's the problem. After I use the command to close the gump, i use the command to close the gump.. but it says that the gump is still open.

I have recorded a screen shot that shows this, it's 25 Megs, and I have no clue what the limit is up here. If you need more detail, let me know.
 
Top