Skip to main content

Overview

IGameGui handles many aspects of the in-game UI. It provides access to addons, agents, coordinate conversion, and UI visibility state.

Namespace

Dalamud.Plugin.Services

Events

UiHideToggled

public event EventHandler<bool> UiHideToggled;
Fired when the game UI hiding is toggled.
hidden
bool
True if UI is now hidden

HoveredItemChanged

public event EventHandler<ulong> HoveredItemChanged;
Fired when the currently hovered item changes.
itemId
ulong
The new hovered item ID (0 if none)

HoveredActionChanged

public event EventHandler<HoveredAction> HoveredActionChanged;
Fired when the currently hovered action changes.
action
HoveredAction
The new hovered action

AgentUpdate

public event Action<AgentUpdateFlag> AgentUpdate;
Fired when the game sets one or more AgentUpdateFlag values, used by agents to conditionally update their addons.
flags
AgentUpdateFlag
The agent update flags

Properties

GameUiHidden

public bool GameUiHidden { get; }
Gets a value indicating whether the game UI is hidden.
GameUiHidden
bool
True if game UI is hidden

HoveredItem

public ulong HoveredItem { get; set; }
Gets or sets the item ID that is currently hovered by the player. 0 when no item is hovered. If > 1,000,000, subtract 1,000,000 and treat it as HQ.
HoveredItem
ulong
The currently hovered item ID

HoveredAction

public HoveredAction HoveredAction { get; }
Gets the action ID that is currently hovered by the player. 0 when no action is hovered.
HoveredAction
HoveredAction
The currently hovered action

Methods

public bool OpenMapWithMapLink(MapLinkPayload mapLink);
Opens the in-game map with a flag on the location of the parameter.
Link to the map to be opened
return
bool
True if there were no errors and the map could be opened

WorldToScreen

public bool WorldToScreen(Vector3 worldPos, out Vector2 screenPos);
public bool WorldToScreen(Vector3 worldPos, out Vector2 screenPos, out bool inView);
Converts in-world coordinates to screen coordinates (upper left corner origin).
worldPos
Vector3
required
Coordinates in the world
screenPos
Vector2
Converted coordinates (out parameter)
inView
bool
True if screenPos corresponds to a position inside the camera viewport (out parameter)
return
bool
True if worldPos corresponds to a position in front of the camera

ScreenToWorld

public bool ScreenToWorld(Vector2 screenPos, out Vector3 worldPos, float rayDistance = 100000.0f);
Converts screen coordinates to in-world coordinates via raycasting.
screenPos
Vector2
required
Screen coordinates
worldPos
Vector3
Converted coordinates (out parameter)
rayDistance
float
How far to search for a collision (default: 100000.0f)
return
bool
True if successful. On false, worldPos’s contents are undefined

GetUIModule

public UIModulePtr GetUIModule();
Gets a pointer to the game’s UIModule instance.
return
UIModulePtr
A pointer wrapper to UIModule

GetAddonByName

public AtkUnitBasePtr GetAddonByName(string name, int index = 1);
public T* GetAddonByName<T>(string name, int index = 1) where T : unmanaged;
Gets the pointer to the Addon with the given name and index.
name
string
required
Name of addon to find
index
int
Index of addon to find (1-indexed, default: 1)
return
AtkUnitBasePtr | T*
A pointer wrapper to the addon, or typed pointer

GetAgentById

public AgentInterfacePtr GetAgentById(int id);
Finds the agent associated with the given agent ID.
id
int
required
The agent ID
return
AgentInterfacePtr
A pointer wrapper to the agent interface

FindAgentInterface

public AgentInterfacePtr FindAgentInterface(string addonName);
public AgentInterfacePtr FindAgentInterface(AtkUnitBasePtr addon);
Finds the agent associated with an addon.
addonName
string
The addon name
addon
AtkUnitBasePtr
The addon address
return
AgentInterfacePtr
A pointer wrapper to the agent interface

Example Usage

public class MyPlugin : IDalamudPlugin
{
    private readonly IGameGui gameGui;
    
    public MyPlugin(IGameGui gameGui)
    {
        this.gameGui = gameGui;
        
        // Subscribe to UI hide event
        this.gameGui.UiHideToggled += OnUiHideToggled;
        
        // Subscribe to hovered item changes
        this.gameGui.HoveredItemChanged += OnHoveredItemChanged;
    }
    
    private void OnUiHideToggled(object? sender, bool isHidden)
    {
        Log.Information($"UI is now {(isHidden ? "hidden" : "visible")}");
    }
    
    private void OnHoveredItemChanged(object? sender, ulong itemId)
    {
        if (itemId > 0)
        {
            var isHq = itemId > 1_000_000;
            var actualItemId = isHq ? itemId - 1_000_000 : itemId;
            Log.Information($"Hovering item {actualItemId} (HQ: {isHq})");
        }
    }
    
    public void DrawWorldMarker(Vector3 worldPos)
    {
        // Convert world position to screen position
        if (this.gameGui.WorldToScreen(worldPos, out var screenPos))
        {
            // screenPos now contains the screen coordinates
            ImGui.GetForegroundDrawList().AddCircle(
                screenPos,
                10f,
                ImGui.GetColorU32(new Vector4(1, 0, 0, 1)));
        }
    }
    
    public void Dispose()
    {
        this.gameGui.UiHideToggled -= OnUiHideToggled;
        this.gameGui.HoveredItemChanged -= OnHoveredItemChanged;
    }
}

Advanced Usage

Working with Addons

public unsafe void CheckAddon()
{
    // Get an addon by name
    var addon = this.gameGui.GetAddonByName("NamePlate");
    
    if (addon != null && addon.IsVisible)
    {
        Log.Information("NamePlate addon is visible");
    }
    
    // Get a typed addon pointer
    var characterAddon = this.gameGui.GetAddonByName<AddonCharacter>("Character");
    if (characterAddon != null)
    {
        // Work with typed addon
    }
}

Screen to World Raycasting

public void HandleMouseClick(Vector2 mousePos)
{
    if (this.gameGui.ScreenToWorld(mousePos, out var worldPos))
    {
        Log.Information($"Clicked world position: {worldPos}");
    }
}

Opening Map Location

public void OpenMapLocation(uint territoryId, uint mapId, float x, float y)
{
    var mapLink = new MapLinkPayload(
        territoryId,
        mapId,
        (int)(x * 1000),
        (int)(y * 1000));
    
    if (this.gameGui.OpenMapWithMapLink(mapLink))
    {
        Log.Information("Map opened successfully");
    }
}

Remarks

  • Always unsubscribe from events in your plugin’s Dispose() method
  • Addon pointers can become invalid when UIs are closed or reloaded
  • The HoveredItem ID greater than 1,000,000 indicates an HQ item
  • Screen coordinates use upper-left corner as origin (0,0)
  • World coordinate conversion may fail if the position is behind the camera or off-screen

Build docs developers (and LLMs) love