ui

package
v0.0.0-...-6a78d3b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 31, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Overview

Package ui implements the interface file runtime used by the original client's glue screens: table-of-contents loading, XML widget definition parsing, Lua 5.1 script execution, widget objects, and the glue API.

Loader semantics follow the original 3.3.5 client paths documented in the project research notes (GlueXML.toc entry loop, Include/Script dispatch, virtual templates, $parent name substitution, "@%s" chunk names).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeBLP

func DecodeBLP(data []byte) (image.Image, error)

DecodeBLP decodes the first (largest) mip level of a BLP2 texture.

func ScreenRect

func ScreenRect(r Rect, screenHeight float64) image.Rectangle

ScreenRect converts a client-space rect (Y up, BOTTOMLEFT origin) to an image rect (Y down, TOPLEFT origin) for the given screen height.

Types

type AudioHost

type AudioHost interface {
	SetAudioCVar(name, value string)
}

type CharacterEntry

type CharacterEntry struct {
	Name              string
	Race              string
	RaceID            int
	Class             string
	ClassID           int
	Gender            int
	Level             int
	Zone              string
	ZoneID            uint32
	MapID             uint32
	Flags             uint32
	CustomizeFlags    uint32
	Ghost             bool
	PaidCustomization bool
	PaidRaceChange    bool
	PaidFactionChange bool
	BackgroundModel   string
}

CharacterEntry describes one character in the character list.

type Font

type Font struct {
	Name     string
	FontFile string
	Height   float64
	Color    rgba
	Outline  string
	Shadow   bool
	JustifyH string
	JustifyV string
}

Font is a named font object created from a <Font> element.

type GlueState

type GlueState struct {
	Connected         bool
	ServerName        string
	PendingRealmList  bool
	SelectedRealm     int
	Realms            []RealmInfo
	SelectedCharacter int
	Characters        []CharacterEntry
}

GlueState tracks connection-flow state the glue API surfaces to scripts.

type Host

type Host interface {
	ScreenSize() (width, height float64)
	PlaySound(id string)
	PlayMusic(name string)
	PlayAmbience(name string)
	StopMusic()
	StopAmbience()
	StopAllSFX()
	LaunchURL(url string)
	Quit(runLauncher bool)
	ConsoleExec(command string)
	Screenshot()
}

Host is implemented by the client shell to back glue API functions that touch audio, the platform, or connection state.

type Loader

type Loader struct {
	Root string
	// contains filtered or unexported fields
}

Loader reads interface files from a directory tree laid out like the client's Interface data (Interface\GlueXML\...). File lookups are case-insensitive with forward or back slashes, matching the client's MPQ-backed path handling.

func NewLoader

func NewLoader(root string, rt *Runtime) *Loader

NewLoader creates a loader rooted at the given data directory.

func NewLoaderWithAssets

func NewLoaderWithAssets(root, assetRoot string, rt *Runtime) *Loader

func NewMPQLoader

func NewMPQLoader(dataPath, locale string, rt *Runtime) (*Loader, error)

func (*Loader) Close

func (l *Loader) Close() error

func (*Loader) LoadInterfaceFile

func (l *Loader) LoadInterfaceFile(interfacePath string) error

LoadInterfaceFile dispatches one interface file by extension: .lua files execute as script chunks, anything else parses as interface XML. Include elements recurse through this function with paths resolved against the including file's directory.

func (*Loader) LoadTOC

func (l *Loader) LoadTOC(interfaceTOC string, progress func(done, total int)) error

LoadTOC executes a table of contents: every non-comment line names a file relative to the TOC's own directory, entries load in order, and the optional progress callback reports (done, total) after each entry. Entry counting matches the client: non-empty lines that do not start with '#'.

func (*Loader) ReadAsset

func (l *Loader) ReadAsset(path string) ([]byte, error)

ReadAsset resolves and reads an interface asset path, tolerating a missing .blp extension the way the client's texture loader does.

func (*Loader) ReadFile

func (l *Loader) ReadFile(path string) ([]byte, error)

type LoginHost

type LoginHost interface {
	DefaultServerLogin(account, password string)
}

type RealmInfo

type RealmInfo struct {
	Name       string
	Address    string
	Population string
	RealmType  string
	Locale     string
}

RealmInfo describes one realm entry returned by the realm list.

type Rect

type Rect struct {
	X0, Y0, X1, Y1 float64 // top-left, bottom-right in client UI space (Y up)
}

Rect is a resolved screen-space rectangle. Y grows downward to match the interface coordinate system (BOTTOMLEFT is the origin of the client's UI space; callers convert when drawing).

func ResolveRect

func ResolveRect(w *widget, parent Rect) Rect

ResolveRect computes the layout rect of a widget against its parent rect.

func (Rect) H

func (r Rect) H() float64

func (Rect) W

func (r Rect) W() float64

type Runtime

type Runtime struct {
	L *lua.LState

	// Glue carries the connection-flow state surfaced by the realm and
	// character list API functions.
	Glue GlueState

	// Host hooks supply client state that lives outside the interface
	// runtime: screen size, audio, login actions, realm and character
	// data. Nil hooks behave as an idle, unconnected client.
	Host Host
	// contains filtered or unexported fields
}

Runtime owns the Lua state, widget registry, virtual template registry, cvar store, and glue event dispatch for one interface session.

func NewRuntime

func NewRuntime(host Host) *Runtime

NewRuntime creates the Lua state and registers the glue API and widget method tables. Callers must Close it when done.

func (*Runtime) Close

func (rt *Runtime) Close()

Close releases the Lua state.

func (*Runtime) Execute

func (rt *Runtime) Execute(source, chunkName string) bool

Execute runs Lua source with the given chunk name, recording errors the way the original client logs them. Inline XML bodies pass their enclosing file as the chunk source for error attribution.

func (*Runtime) FireEvent

func (rt *Runtime) FireEvent(event string, payload ...lua.LValue) int

FireEvent dispatches a glue event to every subscribed widget, passing the event name and payload after the widget argument, matching the OnEvent calling convention the interface scripts expect.

func (*Runtime) GetCVar

func (rt *Runtime) GetCVar(name string) (string, bool)

GetCVar reads a cvar through the same case-insensitive lookup the client uses for console variables.

func (*Runtime) ScriptErrors

func (rt *Runtime) ScriptErrors() []ScriptError

ScriptErrors returns the script failures recorded so far.

func (*Runtime) SetCVar

func (rt *Runtime) SetCVar(name, value string)

func (*Runtime) SetCVarDefault

func (rt *Runtime) SetCVarDefault(name, value string)

SetCVarDefault registers the default value returned by GetCVarDefault.

func (*Runtime) TraceInvocations

func (rt *Runtime) TraceInvocations() []string

TraceInvocations records handler dispatches for diagnostics.

type ScriptError

type ScriptError struct {
	Source  string
	Message string
}

ScriptError records one Lua load or runtime failure with the chunk name it occurred in, mirroring what the original client writes to its glue log.

func (ScriptError) Error

func (e ScriptError) Error() string

type UIEngine

type UIEngine struct {
	Rt          *Runtime
	FontObj     *opentype.Font
	FontObjSm   *opentype.Font
	AssetLoader *Loader
	Cache       map[string]image.Image
	BgImagePath string // Path to a static background image (JPEG/PNG)
	// contains filtered or unexported fields
}

func LoadUIEngine

func LoadUIEngine(glue, frame, assets string, bgImagePath string) (*UIEngine, error)

func LoadUIEngineFromMPQ

func LoadUIEngineFromMPQ(dataPath, locale, bgImagePath string) (*UIEngine, error)

func (*UIEngine) Close

func (eng *UIEngine) Close()

func (*UIEngine) HandleChar

func (eng *UIEngine) HandleChar(char rune) bool

func (*UIEngine) HandleCursor

func (eng *UIEngine) HandleCursor(x, y float64) bool

func (*UIEngine) HandleKey

func (eng *UIEngine) HandleKey(key window.Key) bool

func (*UIEngine) HandleKeyUp

func (eng *UIEngine) HandleKeyUp(key window.Key) bool

func (*UIEngine) HandleKeyWithMods

func (eng *UIEngine) HandleKeyWithMods(key window.Key, mods window.ModifierKey) bool

func (*UIEngine) HandleMouse

func (eng *UIEngine) HandleMouse(x, y float64, button window.MouseButton, down bool) bool

func (*UIEngine) Render

func (eng *UIEngine) Render(screenWidth, screenHeight int) *image.RGBA

func (*UIEngine) SetGlueState

func (eng *UIEngine) SetGlueState(state GlueState)

func (*UIEngine) SetInitialCredentials

func (eng *UIEngine) SetInitialCredentials(account, password string, rememberMe bool)

func (*UIEngine) SetStatusKey

func (eng *UIEngine) SetStatusKey(key string)

func (*UIEngine) Update

func (eng *UIEngine) Update(elapsed float64)

type WorldHost

type WorldHost interface {
	EnterWorld(index int)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL