Working on improving the storage box gump on the server I play on. Older one by A_Li_N. Works great though & is easily customizable. I've recently enlarged the gump size for longer name items (moved the buttons over & everything works). Now what is wanted is basically a back button. Currently the largest one has 4 pages (I think) with the pages being created automatically if the current page has 16+ items.. #17 goes on the next page. We have to close the gump out to search through earlier pages & people are wanting a back button if possible. I know very little about gumps & so I'm flying blind here. I have a button setup, ready to go with 2 small problems. 1, it appears on the 1st page where it isnt needed & 2, it doesnt work other than to close the gump out. I know its because it isnt attached to any other pages, but I dont know how to do that part. :(
Code:
        public BaseResourceStorageBoxGump(BaseResourceStorageBox StorageBox, int offset)
            : base(25, 25)
        {
            m_StorageBox = StorageBox;
            m_Offset = offset;

            AddPage(0);

            AddBackground(50, 10, 495, 280, 83);
            AddImageTiled(58, 20, 478, 262, 2624);
            AddAlphaRegion(58, 20, 478, 262);


            AddButton(75, 25, 4026, 4027, 1, GumpButtonType.Reply, 0);
            AddLabel(110, 25, 0x8AB, "Add Resource");

            AddLabel(225, 25, 0x480, m_StorageBox.GumpLabel);
          
            AddPage(1);

            if (m_StorageBox.ResourceTypes.Length > 16)
            {
            AddButton(425, 25, 4005, 4006, 2, GumpButtonType.Reply, 0);
            AddLabel(460, 25, 0x8AB, "More");

            AddButton(425, 55, 4014, 4015, 3, GumpButtonType.Reply, 0);
            AddLabel(460, 55, 0x8AB, "Previous"); // PREV PAGE

           }

                    AddButtonsAndLabels();
                }
        private void AddButtonsAndLabels()
Add Resource & More buttons work beautifully. I've tried using AddPage(2); & so on, but get the same close out when clicking the Previous button even with changing the Reply,0 to Reply,1. If it isnt possible without a rewrite of the entire thing, then I'm not going to stress it. Any help would be greatly appreciated. Even changing the Reply to Page doesnt help.
 
The code you are displaying does not seem to pass any variable that would allow you to even go the "next" page, let alone go back to a previous page. There must be more to it. Basically, to go forward or back by pages, you either have to create the pages and use "Page" type reply buttons, or pass a variable through a "Reply" button that resets the gump, but sets the new start point for the items being displayed. I have done a thousand of these, so I would be happy to lend a hand if you post the whole gump.
 
Consider it done. :)
Code:
/***************************************************************************/
/*                            BaseResourceStorageBox.cs | BaseResourceGump.cs       */
/*                                        Created by A_Li_N                  */
/*                Credits :                                                  */
/*                        Original Gump Layout - Lysdexic                    */
/*                        Hashtable help - UOT and daat99                    */
/***************************************************************************/

using System;
using System.Collections;
using Server;
using Server.Gumps;
using Server.Network;
using Server.Targeting;
using System.Collections.Generic;
using Server.Engines.Craft;
using Server.Items;
using Server.Mobiles;

namespace Server.ResourceStorageBoxes
{
    public class BaseResourceStorageBoxGump : Gump
    {
        private BaseResourceStorageBox m_StorageBox;
        private int m_Offset;

        public BaseResourceStorageBoxGump(BaseResourceStorageBox StorageBox, int offset)
            : base(25, 25)
        {
            m_StorageBox = StorageBox;
            m_Offset = offset;

            AddPage(0);

            AddBackground(50, 10, 495, 280, 83);
            AddImageTiled(58, 20, 478, 262, 2624);
            AddAlphaRegion(58, 20, 478, 262);


            AddButton(75, 25, 4026, 4027, 1, GumpButtonType.Reply, 0);
            AddLabel(110, 25, 0x8AB, "Add Resource");

            AddLabel(225, 25, 0x480, m_StorageBox.GumpLabel);
           
            AddPage(1);

            if (m_StorageBox.ResourceTypes.Length > 16)
            {
            AddButton(425, 25, 4005, 4006, 2, GumpButtonType.Reply, 0);
            AddLabel(460, 25, 0x8AB, "More");

            AddButton(425, 55, 4014, 4015, 3, GumpButtonType.Reply, 0);
            AddLabel(460, 55, 0x8AB, "Previous"); // PREV PAGE

           }

                    AddButtonsAndLabels();
                }
        private void AddButtonsAndLabels()
        {
            for( int i = m_Offset; i < m_StorageBox.ResourceTypes.Length && i < 16 + m_Offset; i++ )
            {
                Type type = m_StorageBox.ResourceTypes[i];

                if( !m_StorageBox.Resources.ContainsKey( type ) )
                    continue;

                if( (i - m_Offset) <= 7 )
                {
                    AddLabel( 110, 75+((i-m_Offset)*25), 1153, type.Name );
                    AddLabel( 255, 75+((i-m_Offset)*25), 1152, ((int)m_StorageBox.Resources[type]).ToString() );
                    AddButton( 75, 75+((i-m_Offset)*25), 4029, 4030, i+100, GumpButtonType.Reply, 0 );
                }
                else
                {
                    AddLabel(340, 75 + ((i - 8 - m_Offset) * 25), 1152, type.Name);
                    AddLabel(485, 75 + ((i - 8 - m_Offset) * 25), 1152, ((int)m_StorageBox.Resources[type]).ToString());
                    AddButton(305, 75 + ((i - 8 - m_Offset) * 25), 4029, 4030, i + 100, GumpButtonType.Reply, 0);
                }
            }
        }

        private class ResourceStorageBoxTarget : Target
        {
            private BaseResourceStorageBox m_StorageBox;
            private int m_Offset;

            public ResourceStorageBoxTarget( BaseResourceStorageBox StorageBox, int offset ) : base( 18, false, TargetFlags.None )
            {
                    m_StorageBox = StorageBox;
                    m_Offset = offset;
            }

            protected override void OnTarget( Mobile from, object targeted )
            {
                if ( m_StorageBox.Deleted )
                    return;

                if( !from.InRange( m_StorageBox, 10 ) )
                {
                    from.SendMessage( "You must be within 10 spaces of the Storage Box to use it." );
                    return;
                }

                if( targeted is Item )
                {
                    if( m_StorageBox.TryAdd( targeted as Item ) )
                        from.SendMessage( "Resource added, please choose another." );
                    else
                        from.SendMessage( "Resource could not be added, please try another." );

                    from.Target = new ResourceStorageBoxTarget( m_StorageBox, m_Offset );
                }
            }

            protected override void OnTargetCancel( Mobile from, TargetCancelType cancelType )
            {
                from.SendGump( new BaseResourceStorageBoxGump( m_StorageBox, m_Offset ) );
            }
      }

        public override void OnResponse( NetState state, RelayInfo info )
        {
            if( m_StorageBox == null )
                return;

            Mobile from = state.Mobile;
            int BID = info.ButtonID;

            if( !from.InRange( m_StorageBox, 10 ) )
            {
                from.SendMessage( "You must be within 10 spaces of the Storage Box to use it." );
                return;
            }

            if( BID == 1 )
            {
                from.SendMessage( "Target a resource to add" );
                from.Target = new ResourceStorageBoxTarget( m_StorageBox, m_Offset );
            }

            else if( BID == 2 )
            {
                from.SendGump( new BaseResourceStorageBoxGump( m_StorageBox, m_Offset + 16 ) );
            }

            //else if( BID >= 100 )
            else if( BID >= 100 && BID - 100 < m_StorageBox.ResourceTypes.Length  ) // ".Count" ".Length"  ".Size()"
            {
                Type type = m_StorageBox.ResourceTypes[BID-100];
                m_StorageBox.ExtractResource( from, type );

                from.SendGump( new BaseResourceStorageBoxGump( m_StorageBox, m_Offset ) );
            }
        }
    }
}
 
this is how I usually do it

Code:
public MyGump(Mobile from, int page ) : base( 0, 0 )
        {
            _from = from;
            Page = page;

Code:
if( Page > 0 )
            {
                AddButton(35, 79, 5603, 5603, (int)ButtonName.Previous, GumpButtonType.Reply, 0); // "left" page button
            }
            AddButton(711, 79, 5601, 5601, (int)ButtonName.Next, GumpButtonType.Reply, 0); // "right" page button

additional code can be added if you're using a list that you want to show only a certain number of at a time
 
The way this is set up is 16 or less different items in storage doesnt show the "more" button (only has the 1st page). 17 or more shows the "more" button which takes you to the next "page". 16 different items = 1 page. So the main or 1st page only needs the "more" if theres more than 16 different items held in the storage box. That part already works. I just need a "back" button for the following pages to show up on those pages & take the player back to the previous page.
 
Anything added to page 0 is classed as the background frame and is repeated on every page.
Page 0 is where you draw your initial background and layout.

If your gump doesn't need more pages, you can just do everything on page 0.

Whenever you add a new page, anything on that page will be shown only on that page.
Entries are attributed to the last page number that was added to the gump.
Pages end only when the next AddPage is called.

In order for the previous page button to show, you need it on every page above 1.
For the next button to show, you need it on every page (including 0 and 1), except the last page.

Something like this should work, as long as you pre-compute how many pages you need to display.
Code:
AddPage( 0 );

AddBackground( 0, 0, 800, 600, 9270 );

var pages = 10;

for( var page = 1; page <= pages; page++ )
{
    if( page < pages )
    {
        // Add Next Page Button ( page + 1 )
    }

    AddPage( page );

    if( page > 1 )
    {
        // Add Prev Page Button ( page - 1 )
    }

    AddHtml( 10, 10, 780, 580, "Page " + page, false, false );
}
 
I setup page as just a multiplier for a list

Code:
int DisplayPerPage = 4;
for (int i = 0; i < DisplayPerPage && ( Page*DisplayPerPage + i) < list.Count; i++)
            {
                AddBackground(63 + i*168, 72, 133, 32, 9400);
                AddHtmlOutlined( this, 67 + i*169, 79, 128, 23,String.Format("<center>{0}", list[ Page*4 + i].PageName), false, false);
                   
            }
 
I also prefer not to use the built-in pagination and prefer to go for the indexed range selection method too.
Main reason for this is that refreshing the gump doesn't persist the selected page, so you always end up going back to page 0.
 
I think this should do it for you. The key was m_Offset. As long as we know the value to compare with the size of the collection, we can figure out the pagination. Try this out.

Code:
/***************************************************************************/
/*                            BaseResourceStorageBox.cs | BaseResourceGump.cs       */
/*                                        Created by A_Li_N                  */
/*                Credits :                                                  */
/*                        Original Gump Layout - Lysdexic                    */
/*                        Hashtable help - UOT and daat99                    */
/***************************************************************************/
using System;
using System.Collections;
using Server;
using Server.Gumps;
using Server.Network;
using Server.Targeting;
using System.Collections.Generic;
using Server.Engines.Craft;
using Server.Items;
using Server.Mobiles;
namespace Server.ResourceStorageBoxes
{
    public class BaseResourceStorageBoxGump : Gump
    {
        private BaseResourceStorageBox m_StorageBox;
        private int m_Offset;
        public BaseResourceStorageBoxGump(BaseResourceStorageBox StorageBox, int offset)
            : base(25, 25)
        {
            m_StorageBox = StorageBox;
            m_Offset = offset;
            AddPage(0);
            AddBackground(50, 10, 495, 280, 83);
            AddImageTiled(58, 20, 478, 262, 2624);
            AddAlphaRegion(58, 20, 478, 262);
            AddButton(75, 25, 4026, 4027, 1, GumpButtonType.Reply, 0);
            AddLabel(110, 25, 0x8AB, "Add Resource");
            AddLabel(225, 25, 0x480, m_StorageBox.GumpLabel);
          
            AddPage(1);
            if (m_Offset + 16 < m_StorageBox.ResourceTypes.Length)
            {
                AddButton(425, 25, 4005, 4006, 2, GumpButtonType.Reply, 0);
                AddLabel(460, 25, 0x8AB, "More");
            }
            if (m_Offset == 0)
            {
                AddButton(425, 55, 4014, 4015, 3, GumpButtonType.Reply, 0);
                AddLabel(460, 55, 0x8AB, "Previous"); // PREV PAGE
            }
            AddButtonsAndLabels();
        }
        private void AddButtonsAndLabels()
        {
            for( int i = m_Offset; i < m_StorageBox.ResourceTypes.Length && i < 16 + m_Offset; i++ )
            {
                Type type = m_StorageBox.ResourceTypes[i];
                if( !m_StorageBox.Resources.ContainsKey( type ) )
                    continue;
                if( (i - m_Offset) <= 7 )
                {
                    AddLabel( 110, 75+((i-m_Offset)*25), 1153, type.Name );
                    AddLabel( 255, 75+((i-m_Offset)*25), 1152, ((int)m_StorageBox.Resources[type]).ToString() );
                    AddButton( 75, 75+((i-m_Offset)*25), 4029, 4030, i+100, GumpButtonType.Reply, 0 );
                }
                else
                {
                    AddLabel(340, 75 + ((i - 8 - m_Offset) * 25), 1152, type.Name);
                    AddLabel(485, 75 + ((i - 8 - m_Offset) * 25), 1152, ((int)m_StorageBox.Resources[type]).ToString());
                    AddButton(305, 75 + ((i - 8 - m_Offset) * 25), 4029, 4030, i + 100, GumpButtonType.Reply, 0);
                }
            }
        }
        private class ResourceStorageBoxTarget : Target
        {
            private BaseResourceStorageBox m_StorageBox;
            private int m_Offset;
            public ResourceStorageBoxTarget( BaseResourceStorageBox StorageBox, int offset ) : base( 18, false, TargetFlags.None )
            {
                    m_StorageBox = StorageBox;
                    m_Offset = offset;
            }
            protected override void OnTarget( Mobile from, object targeted )
            {
                if ( m_StorageBox.Deleted )
                    return;
                if( !from.InRange( m_StorageBox, 10 ) )
                {
                    from.SendMessage( "You must be within 10 spaces of the Storage Box to use it." );
                    return;
                }
                if( targeted is Item )
                {
                    if( m_StorageBox.TryAdd( targeted as Item ) )
                        from.SendMessage( "Resource added, please choose another." );
                    else
                        from.SendMessage( "Resource could not be added, please try another." );
                    from.Target = new ResourceStorageBoxTarget( m_StorageBox, m_Offset );
                }
            }
            protected override void OnTargetCancel( Mobile from, TargetCancelType cancelType )
            {
                from.SendGump( new BaseResourceStorageBoxGump( m_StorageBox, m_Offset ) );
            }
      }
        public override void OnResponse( NetState state, RelayInfo info )
        {
            if( m_StorageBox == null )
                return;
            Mobile from = state.Mobile;
            int BID = info.ButtonID;
            if( !from.InRange( m_StorageBox, 10 ) )
            {
                from.SendMessage( "You must be within 10 spaces of the Storage Box to use it." );
                return;
            }
            if( BID == 1 )
            {
                from.SendMessage( "Target a resource to add" );
                from.Target = new ResourceStorageBoxTarget( m_StorageBox, m_Offset );
            }
            else if( BID == 2 )
            {
                from.SendGump( new BaseResourceStorageBoxGump( m_StorageBox, m_Offset + 16 ) );
            }
            //else if( BID >= 100 )
            else if( BID >= 100 && BID - 100 < m_StorageBox.ResourceTypes.Length  ) // ".Count" ".Length"  ".Size()"
            {
                Type type = m_StorageBox.ResourceTypes[BID-100];
                m_StorageBox.ExtractResource( from, type );
                from.SendGump( new BaseResourceStorageBoxGump( m_StorageBox, m_Offset ) );
            }
        }
    }
}
 
Didnt quite work. The Previous button was right there on the 1st (main) gump page & vanished as soon as I clicked the More button. :(
 
Awesome! Now it only appears after the first page. Only 1 small problem. The Previous button seems to think that previous means to go to before you opened the storage box in the 1st place (works great as a close button). Back to experimenting. lol
 
Awesome! Now it only appears after the first page. Only 1 small problem. The Previous button seems to think that previous means to go to before you opened the storage box in the 1st place (works great as a close button). Back to experimenting. lol

Oops. You had the button already there, I assumed you created the method for it. My bad.

In "On Response" method, after the part where you have the "else if (BID == 2)" section, add this:

Code:
            else if( BID == 3 )
            {
                from.SendGump( new BaseResourceStorageBoxGump( m_StorageBox, m_Offset - 16 ) );
            }
 
Looks like that worked. Sorry for the hassle. I'm sort of clueless for the most part on gumps. Thankyou!
no hassle here, we all have our own areas that we need help with.

for the longest time for loops and lists made absolutely zero sense to me, and now i feel like crying over how long I spent writing out things the hard way
 
I used to hate gumps and coding their logic, but (shameless self plug) now that I use VNc's SuperGumps, it couldn't be more fun.
All of the hard work is done for you, behind the scenes. Pagination? Easy! Inherit from SuperGumpPages, SuperGumpList<T>, or the themeable ListGump<T> (each inherits the previous, successively adding more features).

If I hadn't created SuperGumps, I would still hate gumps and probably totally suck at them lol.

Speaking of things we're not comfortable doing... mine is bitwise operations and pointers, no matter how hard I try, I can never write implementations fluently, having to always revert to documentation to remind me. It just won't sink in, and I don't know why. Unfortunately, it's not something I can really get help with around here when I need it :(
 
Back