Skip to content

ZH TW API UO GetGump

LIHACHTETAN edited this page Nov 28, 2026 · 3 revisions

Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어

UO.GetGump

家 · C# · IDE · UO API · A–Z · 範例 · Languages

C# 簽章

dynamic UO.GetGump(object? identifier);
dynamic UO.GetGump(object? gumpId, object? identifier);
dynamic UO.GetGump(object? gumpId, object? identifier, object? key);

讀取所選伺服器口令的一個欄位。允許您明確設定視窗選擇器。

參數

  • gumpId - 可選的第一個int,形式為(gumpId,標識符)和(gumpId,標識符,密鑰)。 int 或數字字串:首先尋找精確的 GumpID/serial 匹配,然後尋找帶有 0 的索引。 -1是該腳本選擇的gump,如果不存在,則為目前清單中的最後一個。其他負數int保留32位ID。這是一個選擇器,與 NumGump* 中嚴格的 GumpIndex 相反。
  • identifier - string 不區分大小寫。傳回部分列出了所有支援的值和結果類型。未知名稱傳回空字串。
  • key - 可選int,預設 - 1。按鈕/文字/object/指令的索引為0;這不是ID控制。負索引和越界會導致按鈕出現 0 或文字欄位出現空字串。其他識別符不使用密鑰。

傳回值

結果的類型取決於標識符。 int:buttonlen — 常規按鈕的數量; Button — 按索引鍵的 ButtonID; textlen — 可用文字元素的數量; injid — 目前視窗索引;回复- 0 (不儲存回應歷史記錄);客戶內部— 1 對於找到的即時窗口, 0 在缺席的情況下; objectcount — 即時控制項的數量,包括嵌套控制項。 string: serial 和 gutpid - 十六進位字串 0xXXXXXXXX; text — 索引鍵處的元素文字; object ——控制類型名稱;指令——控制描述(類型、頁面、 ID、座標、尺寸和支援的欄位)。在沒有視窗的情況下,數字標識符給出 0, string - 空字串。因吉德=0 也是一個有效的第一個索引:就其本身而言 0 並不能證明沒有窗口。這不是 Array 或 Pascal TGumpInfo。

行為

  • 與活動伺服器 Gump 一起使用。背包、地圖、設定等本地視窗不包含在此列表中。一次呼叫讀取遊戲執行緒中的資料;不同的呼叫可能會看到列表的不同狀態。
  • SelectGump/InfoGump 指定僅在目前運行時選擇的視窗。如果選定的視窗關閉,則使用目前清單中的最後一項,這不一定是時間上最新的項。
  • textlen/text 指的是可用的文字控件,而不是伺服器包的原始字串池。 object/command 指的是整個即時控制樹。來自不同列表的索引不能混合。
  • 每個呼叫分別讀取當前狀態。對於匹配的serial、GumpID 和列表,請使用GetGumpInfo。

獨立的 C# 腳本

每個範例都可以儲存為單獨的檔案.csx並在IDE中運行。 UO物件和等待函數提供當前遊戲會話的主機。將演示 serial 名稱、座標和地址替換為您自己的。

簡單範例

將這段程式碼存為獨立的 .csx 檔案執行。參數直接出現在呼叫中;請將範例名稱、serial 和網址替換成自己的值。

將一次呼叫的結果輸出到日誌。數值不會轉換成 bool;若結果是陣列,則顯示元素數量。

object? result = UO.GetGump("gumpid");
UO.Print(result is Array values ? "Count: " + values.Length : Convert.ToString(result));

1。讀取所選視窗的ID - 直接腳本

參數與執行流程:

  • gigpid 和 serial 傳回已格式化為十六進位的字串;不需要額外的十六進位。空白行表示讀取時沒有視窗。
var id = UO.GetGump("gumpid");
var serial = UO.GetGump("serial");
UO.Print(id + " / " + serial);

2。枚舉 ButtonID - 腳本函數

參數與執行流程:

  • Buttonlen — 按鈕數量; i 是從 0 到 count-1 的行索引。按鈕 - ID 用於答案,而不是圖形或索引。更換視窗時,請重新閱讀清單。
return  RunScenario();
 object? RunScenario()
{
    var count = UO.GetGump("buttonlen");
    var i = 0;
    while (Truth(i < count))
    {
        var button = UO.GetGump("button", i);
        UO.Print(Convert.ToString(button));
        i = i + 1;
    }

    return null;
}

bool Truth(object? value) => value is bool flag ? flag : value is string text ? !string.IsNullOrEmpty(text) : value != null && Convert.ToDouble(value) != 0;

3。選擇後讀取文字 - 腳本類

參數與執行流程:

  • 0x12345678 是 GumpID/serial 的範例,將 ID 替換為所需的形式。 key=0的文字讀取第一個可用的文字控制項;這是一個與按鈕不同的清單。
  • SelectGump 報告指定視窗不存在,但不阻塞後續讀取:如有必要,單獨檢查傳回的gumpid。
return  new ScriptScenario(UO, WaitAsync, Args, Cancellation, Checkpoint).RunScenario();
class ScriptScenario
{
    private readonly global::ClassicUO.CSharp.CSharpGameApi UO;
    private readonly Func<int, Task> WaitAsync;
    private readonly string[] Args;
    private readonly CancellationToken Cancellation;
    private readonly Action Checkpoint;
    public ScriptScenario(global::ClassicUO.CSharp.CSharpGameApi api, Func<int, Task> wait, string[] args, CancellationToken cancellation, Action checkpoint)
    {
        UO = api;
        WaitAsync = wait;
        Args = args;
        Cancellation = cancellation;
        Checkpoint = checkpoint;
    }

     public object? RunScenario()
    {
        UO.SelectGump(0x12345678);
        if (Truth(UO.GetGump("inclient")))
        {
            var count = UO.GetGump("textlen");
            if (Truth(count > 0))
            {
                UO.Print(UO.GetGump("text", 0));
            }
        }

        return null;
    }

    bool Truth(object? value) => value is bool flag ? flag : value is string text ? !string.IsNullOrEmpty(text) : value != null && Convert.ToDouble(value) != 0;
}

命令實作

C# 區分大小寫。請使用正確的 UO 名稱。數值旗標應與 0 比較;只有回傳型別為 bool 時才使用 bool。

UO.GetGump(identifier) — UO.GetGump(String)

參數: identifier (String)

結果: dynamic / Any.

呼叫時:

內部實作程式碼,不能作為獨立腳本執行。

public InjectionValue GetGump(string identifier) => LastGump(identifier, -1);

UO.GetGump(gumpId, identifier) — UO.GetGump(Integer,String)

參數: gumpId (Integer/String), identifier (String/Integer)

結果: dynamic / Any.

呼叫時:

內部實作程式碼,不能作為獨立腳本執行。

public InjectionValue GetGump(int gumpId, string identifier) => GetGump(gumpId, identifier, -1);

UO.GetGump(gumpId, identifier) — UO.GetGump(String,Integer)

參數: gumpId (Integer/String), identifier (String/Integer)

結果: dynamic / Any.

呼叫時:

內部實作程式碼,不能作為獨立腳本執行。

public InjectionValue GetGump(string identifier, int key) => LastGump(identifier, key);

UO.GetGump(gumpId, identifier, key) — UO.GetGump(Integer,String,Integer)

參數: gumpId (Integer), identifier (String), key (Integer)

結果: dynamic / Any.

呼叫時:

內部實作程式碼,不能作為獨立腳本執行。

public InjectionValue GetGump(int gumpId, string identifier, int key)

            => ConvertGumpValue(identifier, bridge.GetGumpValue(gumpId, identifier, key));

Clone this wiki locally