Author Topic: [C# Custom Snippet] Handling Gumps  (Read 10554 times)

0 Members and 1 Guest are viewing this topic.

Offline Crome969Topic starter

  • Moderator
  • *
  • *****
  • Posts: 2098
  • Activity:
    0%
  • Reputation Power: 25
  • Crome969 is on the verge of being accepted.Crome969 is on the verge of being accepted.Crome969 is on the verge of being accepted.Crome969 is on the verge of being accepted.Crome969 is on the verge of being accepted.
  • Gender: Male
  • UO Enthusiast
  • Respect: +559
  • Referrals: 10
    • View Profile
    • ScriptSDK
[C# Custom Snippet] Handling Gumps
« on: October 12, 2013, 09:02:24 PM »
-1
Introduction

I wroted this small Library back then when we were Testing API and i think it could be quiete Useful for some of you.
What this Library contains :
- Interactions with GumpButtons,Radiobuttons,Checkboxes,Textboxes attached on specific Gump
- Generating of GumpObject attached on specific Gump
- Validation of Gump existence
- Filtering Members for Gumpobject Subobjects

Requirements

Stealth 6.0 RC 4 or Higher & ScriptDotNet DLL : https://bitbucket.org/Stealthadmin/stealth-beta-client/downloads
Gump.cs Version 1.0 or Higher : https://bitbucket.org/jsiems/stealth-custom-librarys/downloads
Visual Studio 2012 & .NET 4.5

Function Reference
Code: [Select]
public static uint GetGumpType(uint Serial) // Returns GumpType of specific Serial
public static uint GetSerial(uint GumpID) // Returns Serial of Specific Gump Type

public static int GetIndexbySerial(uint SerialID) // Returns Index of Gump with given Gump Serial
public static int GetIndexbyGumpID(uint GumpID) // Returns Index of Gump with Given Gump Type

public static bool ButtonClick(uint GumpID, int Value) // Fires Push the Button Action on Gump with specific Gump Type
public static bool RadioButtonClick(uint GumpID, int RadioButtonID, int Value) // Use Radiobutton on Gump with specific Gump Type
public static bool CheckBoxClick(uint GumpID, int CheckBoxID, int Value) // Use Combobox on Gump with specific Gump Type
public static bool ChangeTextField(uint GumpID, int TextFieldID, String Content) // Writes into TextBox with specific Gump Type

public static List<T> FilterbyGroup<T>(int GroupNum, List<T> list) // Filters Generic List of Generic Type T through every Object containing the required Groupnumber
public static List<T> FilterbyPage<T>(int Page,List<T> list) // Filters Generic List of Generic Type T through every Object containing the required Page
public static List<T> FilterbyElementNum<T>(int Elementnum, List<T> list) // Filters Generic List of Generic Type T through every Object containing the required Elementnum
public static List<T> FilterbyID<T>(int ID, List<T> list) // Filters Generic List of Generic Type T through every Object containing the required ID
public static List<T> FilterbyPosition<T>(int X, int Y, List<T> list) // Filters Generic List of Generic Type T through every Object containing the required Pos X & Pos Y
public static List<T> FilterbyReleasedID<T>(int ReleasedID, List<T> list) // Filters Generic List of Generic Type T through every Object containing the required ReleasedID
public static List<T> FilterbyPressedID<T>(int PressedID, List<T> list) // Filters Generic List of Generic Type T through every Object containing the required PressedID
public static List<T> FilterbyQuit<T>(int QuitID, List<T> list) // Filters Generic List of Generic Type T through every Object containing the required QuitID
public static List<T> FilterbyPageID<T>(int PageID, List<T> list) // Filters Generic List of Generic Type T through every Object containing the required PageID
public static List<T> FilterbyReturnValue<T>(int ReturnValue, List<T> list) // Filters Generic List of Generic Type T through every Object containing the required ReturnValue
public static List<T> FilterbyArtID<T>(int ArtID, List<T> list) // Filters Generic List of Generic Type T through every Object containing the required ArtID
public static List<T> FilterbyArtPosition<T>(int X, int Y, List<T> list) // Filters Generic List of Generic Type T through every Object containing the required ArtPos X & ArtPos Y
public static List<T> FilterbyHue<T>(int Hue, List<T> list) // Filters Generic List of Generic Type T through every Object containing the required Hue
public static List<T> FilterbyColor<T>(int Color, List<T> list) // Filters Generic List of Generic Type T through every Object containing the required Color
public static List<T> FilterbyStatus<T>(int Status, List<T> list) // Filters Generic List of Generic Type T through every Object containing the required Status
public static List<T> FilterbySize<T>(int width, int height, List<T> list) // Filters Generic List of Generic Type T through every Object containing the required width & height
public static List<T> FilterbyTextID<T>(int TextID, List<T> list) // Filters Generic List of Generic Type T through every Object containing the required TextID
public static List<T> FilterbyGumpID<T>(int GumpID, List<T> list) // Filters Generic List of Generic Type T through every Object containing the required GumpID
public static List<T> FilterbyDefaultTextID<T>(int DefaultTextID, List<T> list) // Filters Generic List of Generic Type T through every Object containing the required DefaultTextID
public static List<T> FilterbyLimit<T>(int Limit, List<T> list) // Filters Generic List of Generic Type T through every Object containing the required Limit
public static List<T> FilterbyClilocID<T>(int ClilocID, List<T> list) // Filters Generic List of Generic Type T through every Object containing the required ClilocID
public static List<T> FilterbBackGround<T>(int BackGround, List<T> list) // Filters Generic List of Generic Type T through every Object containing the required BackGround
public static List<T> FilterbyScrollbar<T>(int ScrollbarID, List<T> list) // Filters Generic List of Generic Type T through every Object containing the required ScrollbarID
public static List<T> FilterbyArgument<T>(String Argument, List<T> list) // Filters Generic List of Generic Type T through every Object containing the required Argument
public static List<T> FilterbyProperty<T>(int PropertyID, List<T> list) // Filters Generic List of Generic Type T through every Object containing the required PropertyID

public static TGumpInfo GetGumpObjectbySerial(uint Serial) // Returns Gump Object of Gump with given Gump Serial
public static TGumpInfo GetGumpObjectbyGumpID(uint GumpID) // Returns Gump Object of Gump with given Gump Serial

public static bool ValidateSerial(uint Serial) // Validate if Serial exist
public static bool ValidateGumpID(uint GumpID) // Validates if GumpType exist

Samples

Crafting with Sewing Kit :

Code: [Select]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using ScriptDotNet;
using Custom.Gumps;

namespace SampleProgram
{
    static class Program
    {
        [STAThread]
        static void Main()
        {
            // Calls Craft Routine for normal Sewingkit and craft Studded Arms on Runuo
            Library.Craft(0x0F9D, 0x0000, 0x38920ABD, 50, 16,true,true);
        }
    }

    public static class Library
    {
        //*******************************************************
        // Method : Craft
        //*******************************************************
        // Parameters :
        // ushort CraftType - Item Type of your Craft Tool
        // ushort CrafColor - Item Color of your Craft Tool
        // uint GumpType    - Gump Type of your Craft Gump
        // int Category     - Packet Value for your specific Category Button
        // int Selection    - Packet Value for your specific Selection Button
        // bool CloseBefore - Selection if old Craft Gump should be closed before
        // bool CloseAfter  - Selection if new Craft Gump should be closed after
        //
        // Note : if Category = 0, Buttons from front Menu like Make Last can be used
        //******************************************************
        // Output :
        // Boolean : returns if you were able to Use CraftMenu
        //******************************************************
        public static bool Craft(ushort CraftToolType, ushort CraftToolColor, uint GumpType, int Category, int Selection,bool Closebefore=false,bool CloseAfter=false)
        {
            uint CraftToolID = Stealth.Script_FindTypeEx(CraftToolType, CraftToolColor, Stealth.Script_GetBackpackID(), false);
            if (CraftToolID > 0)
            {
                // We want to Clean up old Gumps?
                if(Closebefore)
                    while(GlobalGumpHandler.GetIndexbyGumpID(GumpType) > -1)
                        GlobalGumpHandler.ButtonClick(GumpType, 0);
                // Now we Open Gump
                while (GlobalGumpHandler.GetIndexbyGumpID(GumpType) == -1)
                    Stealth.Script_UseObject(CraftToolID);
                // If Category > 0 means you actualy want to push Category Button
                if (Category > 0)
                    while (!GlobalGumpHandler.ButtonClick(GumpType, Category))
                        while (GlobalGumpHandler.GetIndexbyGumpID(GumpType) == -1) ;
                while (GlobalGumpHandler.GetIndexbyGumpID(GumpType) == -1);
                // We actually push the Button to Craft Something or use any featured Action by Button within Gump
                while (!GlobalGumpHandler.ButtonClick(GumpType, Selection))
                    while (GlobalGumpHandler.GetIndexbyGumpID(GumpType) == -1) ;
                // We wait Until Gump is Back or Tool got destroyed
                while ((GlobalGumpHandler.GetIndexbyGumpID(GumpType) == -1) && (Stealth.Script_IsObjectExists(CraftToolID)));
                // We want to kill the Gump after Craft?
                if(CloseAfter)
                    while (GlobalGumpHandler.GetIndexbyGumpID(GumpType) > -1)
                        GlobalGumpHandler.ButtonClick(GumpType, 0);
                return true;
            }
            return false;
        }

    }
}
« Last Edit: October 16, 2013, 11:51:44 AM by Crome969 »

Offline Crome969Topic starter

  • Moderator
  • *
  • *****
  • Posts: 2098
  • Activity:
    0%
  • Reputation Power: 25
  • Crome969 is on the verge of being accepted.Crome969 is on the verge of being accepted.Crome969 is on the verge of being accepted.Crome969 is on the verge of being accepted.Crome969 is on the verge of being accepted.
  • Gender: Male
  • UO Enthusiast
  • Respect: +559
  • Referrals: 10
    • View Profile
    • ScriptSDK
Re: [C# Custom Snippet] Handling Gumps
« Reply #1 on: October 16, 2013, 11:49:57 AM »
-1
Updated Gumps.cs and wroted some preparations for next releases for Property and Context Menu.

Another sample for crafting with the 2 new implemented methods :

Code: [Select]
        public bool Craft(uint ToolID, uint CraftGumpType, int ButtonID, int Category = 0)
        {
            if(Stealth.Script_IsObjectExists(ToolID))
            {
                if ((Stealth.Script_GetLastObject() != ToolID))
                {
                    while (GlobalGumpHandler.ValidateGumpID(CraftGumpType))
                        if (GlobalGumpHandler.ButtonClick(CraftGumpType, 0))
                            while (GlobalGumpHandler.ValidateGumpID(CraftGumpType));
                        else
                            Stealth.Script_Wait(100);
                    while (!GlobalGumpHandler.ValidateGumpID(CraftGumpType))
                    {
                        Stealth.Script_UseObject(ToolID);
                        Stealth.Script_Wait(100);
                        LastToolID = ToolID;
                    }
                }
                uint Serial = 0;
                if(Category != 0)
                {
                    Serial = GlobalGumpHandler.GetSerial(CraftGumpType);
                    while (!GlobalGumpHandler.ButtonClick(CraftGumpType, Category))
                        Stealth.Script_Wait(100);
                    while ((GlobalGumpHandler.ValidateGumpID(CraftGumpType)) && (GlobalGumpHandler.GetSerial(CraftGumpType) == Serial)) ;
                    while (!GlobalGumpHandler.ValidateGumpID(CraftGumpType)) ;
                }
                Serial = GlobalGumpHandler.GetSerial(CraftGumpType);
                while (!GlobalGumpHandler.ButtonClick(CraftGumpType, ButtonID))
                    Stealth.Script_Wait(100);
                while ((GlobalGumpHandler.ValidateGumpID(CraftGumpType))&&(GlobalGumpHandler.GetSerial(CraftGumpType)==Serial));
                while ((!GlobalGumpHandler.ValidateGumpID(CraftGumpType))&&(Stealth.Script_IsObjectExists(ToolID))) ;
                return true;
            }
            return false;
        }

Tags: Stealth Gumps