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!

[RunUO 2.0 RC1] RFC / Beta 0.1 Gump List (clone of ListView)

TMSTKSBK

Lord
RFC / Beta 1.0 Gump List (clone of ListView)

GumpList
(open gump add-on) for developers.

- TMSS 4 Component (not required for use)

Version 1.2

- New features: More debugged, added comments for easy reading/understanding/use in Visual Studio.

DEFINITELY DOES NOT WORK ON 1.0! Requires .NET 2.0 to run.

PREREQUISITE:
This ALSO REQUIRES BaseSkin. You only need implement the BaseSkin portion of the script, although you are certainly free to implement your own derived classes off that common standard.

Introduction:
This is an attempt at recreating the Windows Forms ListView control. It allows you to easily create a list in either "details" or "icons" mode.
Note that not everything in the icons mode of this script has been tested yet!

Usage:

Tutorial:
General concept and use of GumpList

Introduction:
GumpList is a simple method of implementing infinite lists with pages and columns, supporting column entries of checkboxes, buttons and text in label and html format.

Basic Implementation:
There are two modes in GumpList – “details” and “icons”. The default is details. Details mode gives you a listing in a linear format, with columns across the width of the List. Icons is not yet entirely supported, but gives you buttons with an icon across the length and width of the list.

-Example Implementation:

-Declaration:
First, we declare a GumpList. GumpList is not a GumpEntry, so it cannot be added directly to a gump. To declare a GumpList, we do the following:

GumpList gl = new GumpList( <Gump>, <style>, <Skin> );

Where <Gump> is the gump the list will be added to, <style> is “details” or “icons”, and <Skin> is the BaseSkin the List should use to format itself.

-Configuration:
The next step is configuration. You need to specify:
- The number of columns in the list (gl.SetColumnCount(#);)
- The number of items on a given page of the list (gl.numperpage=#;)
- The X and Y location of the start of the list. (gl.X=#; gl.Y=#;)
- (optional) The titles of each column (gl.AddColumn(“name”);)
- (optional) You can turn divider graphics on/off (gl.ShowDividers…)

-Addition of Entries:
After declaring the list and configuring, we need to add GumpListEntries to it. We do this like so:

GumpListEntry gle = new GumpListEntry( 0, 0, gl, 0, 0 )
gle.AddColumn(<text> or <GumpButton> or <GumpCheck>);

Arguments are X, Y, Parent List, Width, Height. Note that the GumpButtons or GumpChecks are created and configured before sending them to the list. This provides accurate and predictable responses from the list.

After adding columns to the GLE, it is added to the GumpList like so:

gl.Add(gle);

-Finalization:
Finally, after adding all entries to the GumpList, gl.CommitList() is called to send all entries to the gump.
Create a GumpList, then add GumpListEntries to it. After that, call CommitList() to add to the supplied gump.
Example:
Code:
    public class ListTestGump :Gump
    {
        public ListTestGump() : base(0,0)
        {
            SkillSettings.doTell("Setting up new ListTestGump.");
            BaseTMSkin skin = SkinHelper.getSkin( SkillSettings.ControlSkinName );
            this.AddBackground( 0, 0, 500, 500, 9270 );
            GumpList list = new GumpList(this, "details", skin );
            SkillSettings.doTell("List Created.");
            GumpListEntry e1 = new GumpListEntry(0, 0, list, skin.EntryDefaultWidth, skin.EntryDefaultHeight);
            e1.AddColumn("This is a column.");
            e1.AddColumn("This is a 2nd column.");
            e1.AddColumn("This is the 3rd column.");
            SkillSettings.doTell("Entry 1 Created.");
            GumpListEntry e2 = new GumpListEntry(0, 0, list, skin.EntryDefaultWidth, skin.EntryDefaultHeight);
            e2.AddColumn("This is r2 c1.");
            e2.AddColumn("this is r2 c2.");
            e2.AddColumn("this is r2 c3.");
            SkillSettings.doTell("Entry 2 Created.");
            list.Add( e1 );
            list.Add( e2 );
            SkillSettings.doTell("Entries added to list.");
            list.AddColumn( "1st column." );
            list.AddColumn( "2nd column." );
            list.AddColumn( "3rd column." );
            SkillSettings.doTell("List columns added.");
            list.columns = 3;
            list.CommitList();
        }
    }

That is about as simple as it gets.

It can also be used in a looping manner to create a longer list. The GumpList is capable of creating new pages as necessary, based on information supplied to it in BaseSkin.

Slightly more involved example from TMSS 4's Skill Gump:
GumpList stuff is highlighted in red, and ListEntry stuff in blue. TMQueryPage is a gump with some additional information.
Code:
public void GetGumpCode(TMQueryPage page)
        {
            Page = page;
            SkillSettings.DoTell("GetGumpCode, Skill Gump.");
            if (Profile == null)
            {
                try
                {
                    Dictionary<string, object> h = (Dictionary<string, object>)Page.GetValueSet();
                    Profile = (SkillProfile)h["Profile"];
                    Skin = (TMSS4Skin)h["Skin"];
                    Session = (TMSkillSession)h["Session"];
                }
                catch (Exception e)
                {
                    SkillSettings.DoTell("Error when generating skill gump: " + e);
                    return;
                }
            }
            if (Profile == null)
            { SkillSettings.DoTell("Profile is still null. Cannot continue."); return; }
            if( !Profile.SkillEnable )
            {
                SkillSettings.DoTell("Skills not enabled on this profile.");
                return;
            }
            this.Dragable = false;
            Page.BaseSkinByType(this);
            Page.AddTitle( "Skill Gump for "+Profile.ProfileName+": ", "Control",this);
            if (Profile.IconID > 0)
            { 
                SkillSettings.DoTell("Adding Icon: "+Profile.IconID);
                Page.AddIcon(Profile.IconID, "Control", this); 
            }
            this.AddLabel(35, Skin.GetCoord("Control", "H") - 40, Skin.HighlightText, "Profile Maximum: " + Profile.SkillPoints + " pts");
            ButtonInfo inf2 = Skin.ButtonInfo["SessionAddButton"];
            SkillSettings.DoTell("Inf2: X: "+inf2.X+" Y: "+inf2.Y+" W: "+inf2.W+" H: " +inf2.H+" BG: "+inf2.bgID+ " TX: "+inf2.text);
            Page.AddSuperButton(inf2.X, Page.Y+inf2.Y, inf2.H, inf2.W, inf2.bgID, Skin.ListUnderButtonN, Skin.ListUnderButtonP, Skin.AddLabel, GumpButtonType.Reply, 1, 0,this);
            IEnumerator ie = Profile.MasterHash.GetEnumerator();
           [COLOR=red] GumpList l = new GumpList(this, "details", this.Skin);[/COLOR]
            [COLOR=red]l.numperpage=8;[/COLOR]
[COLOR=red]            l.AddColumn("Skill Name");[/COLOR]
[COLOR=red]            l.AddColumn("Skill Value");[/COLOR]
[COLOR=red]            l.AddColumn("Weight");[/COLOR]
[COLOR=red]            l.AddColumn("Select");[/COLOR]
[COLOR=red]            l.SetColumnCount(4);[/COLOR]
[COLOR=red]            l.ChangeColumnWidth(0, 200);[/COLOR]
[COLOR=red]            l.X = Skin.SelectStartX;[/COLOR]
[COLOR=red]            l.Y = Skin.SelectStartY;[/COLOR]
[COLOR=red]            l.ShowDividers = true;[/COLOR]
            int colcount = 3; // at least columns for title, value, and checkbox.
            if (Profile.CapEnable)
                colcount++;
            if (Profile.WeightEnable)
                colcount++;
            [COLOR=red]l.SetColumnCount(colcount);[/COLOR]
            int checkID = 0;
            if (!Profile.Manual)
                checkID = 1000;
            else
                checkID = 3000;
            Dictionary<string,TMUsedInfo> selitem = Session.HasSelectedItems( Profile.ProfileName );
            while (ie.MoveNext())
            {
                TMSkillInfo inf = (TMSkillInfo)((KeyValuePair<string,TMSkillInfo>)ie.Current).Value;
                /*
                if (y % sk.NumPerPage == 0)
                {Page.SetupPage(thisProfile.ProfileName, y == 0, thisProfile.MasterHash.Count - y < sk.NumPerPage ? true : false, page); page++;}
                Page.AddEntryCheck( 0, y%sk.NumPerPage, sk.SelectUp, sk.SelectDn, false, (1000 * page) + (y % sk.NumPerPage), ""+inf.SkillName, ""+inf.SkillWeight, ""+inf.SkillValue );
                y++;*/
               [COLOR=sandybrown] [/COLOR][COLOR=deepskyblue]GumpListEntry e = new GumpListEntry(0, 0, l, Skin.EntryDefaultWidth, Skin.EntryDefaultHeight);[/COLOR]
[COLOR=sandybrown][/COLOR] 
                [COLOR=deepskyblue]e.AddColumn(inf.SkillName);[/COLOR]
[COLOR=deepskyblue]                e.AddColumn("" + inf.SkillValue);[/COLOR]
                if (Profile.CapEnable)
                   [COLOR=deepskyblue] e.AddColumn("" + inf.SkillCap);[/COLOR]
                if (Profile.WeightEnable)
                   [COLOR=deepskyblue] e.AddColumn("" + inf.SkillWeight);[/COLOR]
                if (!Profile.Manual)
                   [COLOR=deepskyblue] e.AddColumn(new GumpCheck(-2, 0, Skin.EntryDefaultCheckUp, Skin.EntryDefaultCheckDn, selitem.ContainsKey(inf.SkillName), checkID));[/COLOR]
                else
                {
                  [COLOR=deepskyblue]  e.AddColumn(new GumpTextEntry(0, 0, 30, Skin.EntryDefaultHeight, Skin.NormalText, checkID, ""));[/COLOR]
                }
                checkID++;
               [COLOR=red] l[/COLOR][COLOR=red].Add[/COLOR]([COLOR=deepskyblue]e[/COLOR]);
            }
            [COLOR=red]l.CommitList();[/COLOR]    
            Session.Mobile.SendGump(this);
        }


Issues/Comments, post here.
 

Attachments

  • GumpList.cs
    25 KB · Views: 100
You should post a screenshot, but im testing it right now so mehbeh I will.

[Edit] You do realize you have doTell(. . .) all over this right? Im looking through the GumpList aswell as the TMSkill and I dont see that function in either one .... ( easy reem i know but just thought id mention it )[/Edit]
 

TMSTKSBK

Lord
sorry. Just do a find/replace with Console.WriteLine. These scripts really aren't supposed to work right out of the box...although this one kinda is..

time for work!
 

TMSTKSBK

Lord
Ok. New release. This one is debugged, and being used in TMSS 4. To see screenies of it in action, go check out the second post in the TMSS 4 thread (see link in sig).
 

TMSTKSBK

Lord
Nicely cleaned up and ready for public consumption. Details mode is stable and non-beta. Icons mode probably needs some work.

- Added a new example for further study and consideration.

- Added XML comments for Visual Studio use. Arguments, returns and description are added.

- Added #region tags to script for easy reading.
 
Top