- Joined
- Mar 18, 2012
- Messages
- 1,716
UIPackage
For your custom UI needs.
Click to view an ingame screenshot:

Click to view the required code to create the window shown above ( fully MUI ):
JASS:
library UIDemo initializer Init uses UIPackage
//* Main screen. Always extend from UIScreen.
struct DemoScreen extends UIScreen
//* add your code here.
endstruct
//* Window within the screen. Always extend from UIWindow.
struct DemoWindow extends UIWindow
//* stub method onHover from UIWindow.
private method onHover takes DemoScreen screen, UIButton hovered returns nothing
call BJDebugMsg("Data on this button is " + I2S(hovered.data))
endmethod
//* stub method onClick from UIWindow.
private method onClick takes DemoScreen screen, UIButton clicked returns nothing
if (clicked.data == 1) then//* Close button.
call screen.show(false)
endif
//* UISound API.
call audio.bigButtonClick()
endmethod
static method onCreate takes thistype this returns nothing
local string s = "war3mapImported\\64x64Track.mdx"
local UIButton b1 = addDestButton(s, 128, 128, 0., 270., 'cwcc', 1.)
local UIButton b2 = addDestButton(s, 256, 128, 0., 270., 'cwdp', 1.)
//* Buttons can have data. You can read the data when they are hovered or clicked.
set b1.data = 1
set b2.data = 'A00A'
//* Draw a border around the window. "1." is the border scaling.
call frame(1.)
endmethod
endstruct
//* Window within the screen. Always extend from UIWindow.
struct DemoWindow3 extends UIWindow
static method onCreate takes thistype this returns nothing
local string s = "UI\\Widgets\\EscMenu\\Human\\human-options-button-background-disabled.blp"
call frame(1.)
call SetImageColor(addScreenImage(s, 0, 0, screen.width, screen.height, 4), 150, 255, 150, 255)
endmethod
endstruct
//* Window within the screen. Always extend from UIWindow.
struct DemoWindow2 extends UIWindow
static method onCreate takes thistype this returns nothing
local string s = "war3mapImported\\64x64Track.mdx"
local UIButton b1
local UIButton b2
//* Add buttons to the window.
//* Arguments:
//* ==========
//* s - Trackable file
//* x, y, z, face, objectId, scale
//*
//* x and y are relative to the window sizes.
//* Example: x = 32 means window.originX + 32
//* y = 32 means window.originY + 32
//* |
//* |
//* 32| b1 b2
//* |_________
//* 0/0 32 64
set b1 = addDestButton(s, 32, 32, 0., 270., 'B004', .75)
set UI_BORDER_BACKGROUND = ""
//* Draw a border around the window. "1." is the border scaling.
call frame(1.)
endmethod
endstruct
globals
private DemoScreen demo = 0
endglobals
private function InitDemo takes nothing returns nothing
local UIWindow window
//* Create a new UIScreen. The best width, height ratio is ~ 1.8
set demo = DemoScreen.create(Player(0), -2000, -2000, 1632, 906)
//* Add a window to the screen.
set window = DemoWindow.create(demo, 100, 100, 384, 256)
//* JassHelper limitation. We have to add the window by ourself.
call demo.addWindowOfType(window.getType(), window, true)
//* Another JassHelper limitation. Can't execute onCreate....
//* We can do that also by ourself
call DemoWindow.onCreate(window)
set window = DemoWindow2.create(demo, 700, 500, 64, 70)
call demo.addWindowOfType(window.getType(), window, true)
call DemoWindow2.onCreate(window)
set window = DemoWindow3.create(demo, 700, 100, 256, 256)
call demo.addWindowOfType(window.getType(), window, true)
call DemoWindow3.onCreate(window)
//* In debug you can draw a lightings to see everything looks good.
debug call demo.highlight()
debug call window.highlight()
endfunction
//* We show the UI via Esc event:
//* =============================
private function OnEsc takes nothing returns nothing
call demo.show(not demo.enabled)
endfunction
private function Init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterPlayerEventEndCinematic(t, Player(0))
call TriggerAddAction(t, function OnEsc)
call InitDemo()
endfunction
endlibrary
UIPackage | Description |
[td]Collection of the entire UIPackage API. [tr][TD][TD]Collection of data and functions used all over the UI package. [tr][td][td]Handles the camerasetup while viewing a custom UI. [tr][TD][TD]Struct UIScreen is the parent struct you base your UIs on. [tr][td][td]Struct UIWindow is the parent struct you base your windows in an UIScreen on. [tr][TD][TD]Creates borders, including a background image for full screen systems. [tr][td][td]Creates interactable buttons for a UIWindow. [tr][TD] UISound ( optional ) [TD]Play sounds while beeing in an UI.[tr][td] UIBoard (optional ) [td]Creates a multiboard per player within the UI.[tr][TD] UIText ( optional ) [TD]Creates textboxes from TextSplats. ( not yet started to code ) |
Changelog
Demo: Inventory
So I started to create a full screen inventory using the UIPackage.
It's still far from beeing ready, but if you want you can take a look into it.
One thing which I discovered is that you should only place multiple UI
on the same location, if they are identical. Otherwise the trackable events
are not reliable.
Attachments
Last edited: