function w3x takes nothing returns nothing
endfunction
Name | Type | is_array | initial_value |
library UIUtils requires LinkedListModule
/*********************************************************************************
*
* UI Utils v1.05
*
* Create and manage user interface in highly convenient and intuitive way!
*
* Check for update at: https://www.hiveworkshop.com/threads/320005/
*
* Features:
* • Includes several primitive frame types (texture, text, slider, etc.)
* • Compatible with custom frame definition
* • Uses pixel as measurement unit
* • Friendly UI native wrappers
* • Custom hierarchy system with in-depth inheritance control
* • Automatically prevents non-simple frame from going out of the 4:3 bounds
* • Enhanced frame pivot & anchor point feature for all-resolution support
* • Automatic create context handling
* • Extra security measures (prevents UI native related crashes out of the box)
* • Customizable full-screen mode
* • Essential default/original frames container
* • Includes all available built-in fdf files
*
* I. System requirements:
* • LinkedListModule : http://hiveworkshop.com/threads/snippet-linkedlistmodule.206552/
* • Warcraft III version 1.31+
*
* II. Installation:
* • Import LinkedListModule
* • Copy UIUtils trigger to your map
* • Go to Import Manager and import following files to your map:
* - UIUtils.toc
* - UIUtils.fdf
* • Configure the system below
* • For true fullscreen you might need to manually remove the inventory cover texture
*
* III. Credits:
* • Tasyen | UI tutorials & researches
* • Dirac | LinkedListModule
*
* IV. API - (Complete manual: https://www.hiveworkshop.com/threads/320046/)
*
* struct UIFrame */static if FOLD then /*
1. Ctor & dtor
- Let "isSimple" be "true" if it is a simple frame type
| static method create takes boolean isSimple, string frameType, UIFrame parent, real x, real y, integer level returns UIFrame
- Dispose the frame
| method destroy takes nothing returns nothing
2. Wrappers
- Set & get frame's textures
• Might not be compatible with custom frame definition
• Some only work for specific type of primitive frames
• Some might not work properly just yet (blizzard limitation)
> Default main texture
| method operator texture= takes string filePath returns nothing
| method operator texture takes nothing returns string
> Texture displayed when frame is disabled
| method operator disabledTexture= takes string filePath returns nothing
| method operator disabledTexture takes nothing returns string
> Highlighter texture
| method operator highlightTexture= takes string filePath returns nothing
| method operator highlightTexture takes nothing returns string
> Texture displayed when frame is pressed
| method operator pushedTexture= takes string filePath returns nothing
| method operator pushedTexture takes nothing returns string
> Background texture for the frame
| method operator backgroundTexture= takes string filePath returns nothing
| method operator backgroundTexture takes nothing returns string
> Border texture for the frame
| method operator borderTexture= takes string filePath returns nothing
| method operator borderTexture takes nothing returns string
- Set & get frame's parent
| method operator parent= takes UIFrame frame returns nothing
| method operator parent takes nothing returns UIFrame
- Get frame's screen space position
• Values might be affected by frame's parent anchor point
| method operator screenPosX takes nothing returns real
| method operator screenPosY takes nothing returns real
- Get frame's bounds
| method operator left takes nothing returns real
| method operator right takes nothing returns real
| method operator top takes nothing returns real
| method operator bottom takes nothing returns real
- Get frame's true (scaled) size in pixel
| method operator width takes nothing returns real
| method operator height takes nothing returns real
- Set & get frame's scale factor
> Frame's independent scale factor
| method operator localScale= takes real r returns nothing
| method operator localScale takes nothing returns real
> Frame's true scale
| method operator scale takes nothing returns real
- Set & get frame's visibility state
| method operator visible= takes boolean state returns nothing
| method operator visible takes nothing returns boolean
- Set & get frame's transparency (0-255)
| method operator opacity= takes integer amount returns nothing
| method operator opacity takes nothing returns integer
- Set & get enable state of the frame
| method operator enabled= takes boolean state returns nothing
| method operator enabled takes nothing returns boolean
- Set & get frame's self sorting/layering order
| method operator level= takes integer level returns nothing
| method operator level takes nothing returns integer
> Get frame's actual sorting/layering order
| method operator trueLevel takes nothing returns integer
- Set & get frame's text content
| method operator text= takes string str returns nothing
| method operator text takes nothing returns string
- Set & get frame's text content length limit
| method operator maxLength= takes integer length returns nothing
| method operator maxLength takes nothing returns integer
- Set frame's text color
> Use "BlzConvertColor" function to convert ARGB color
| method operator textColor= takes integer color returns nothing
- Set & get frame's model file
| method operator model= takes string filePath returns nothing
| method operator model takes nothing returns string
- Set vertex color of the model frame
> Use "BlzConvertColor" function to convert ARGB color
| method operator vertexColor= takes integer color returns nothing
- Set & get value of slider frame
| method operator value= takes real r returns nothing
| method operator value takes nothing returns real
- Step size is increment of slider bar relative to its min max value
| method operator stepSize= takes real r returns nothing
| method operator stepSize takes nothing returns real
- Set & get tooltips frame
| method operator tooltips= takes UIFrame frame returns nothing
| method operator tooltips takes nothing returns UIFrame
- Get sub-frame handle based on passed name
• Usage: tempFrame.subFrame["tempFrameText"] => returns subframe handle of "tempFrame" by name of "tempFrameText"
| method operator subFrame[] takes string name returns framehandle
- Register any event happen to the frame (click, mouse enter/leave, etc.)
• Use "UIFrame.TriggerComponent" to get the triggering frame
• Use "BlzGetTriggerFrameEvent()" function to get the event type
| method operator onAnyEvent= takes code func returns triggercondition
2. Methods
- Iterates through all child frames of the frame
• Use "UIFrame.EnumChild" to get the iterated child frame
| method forEachChild takes code func returns nothing
- Set frame's text properties
| method setTextAlignment takes textaligntype vertical, textaligntype horizontal returns nothing
| method setFont takes string fontType, real fontSize, integer flags returns nothing
- Set slider min max values
| method setMinMaxValue takes real min, real max returns nothing
- Animate frame texture
| method setSpriteAnimate takes integer primaryProp, integer flags returns nothing
- Give focus to the frame
| method setFocus takes boolean state returns nothing
- Cage mouse inside the frame's boundaries
| method cageMouse takes boolean state returns nothing
- Emulate click on the frame
| method click takes nothing returns nothing
- Force update the frame
| method refresh takes nothing returns nothing
- Modify frame's position
> Set frame's local position
| method move takes real x, real y returns nothing
> Set frame's screen position (ignores parent position)
| method moveEx takes real x, real y returns nothing
> Set frame position relative to other specified frame
| method relate takes UIFrame relative, real x, real y returns nothing
- Set dimension of the frame
| method setSize takes real width, real height returns nothing
- Set frame's anchor & pivot point
| method setPivotPoint takes real x, real y returns nothing
| method setAnchorPoint takes real x, real y returns nothing
3. Members
- Main frame handle
| readonly framehandle frame
- Set & get frame's name
| string name
- Set & get property inheritance
• Frame refresh is recommended after modifying inheritance
| boolean inheritScale
| boolean inheritOpacity
| boolean inheritVisibility
| boolean inheritEnableState
| boolean inheritPosition
| boolean inheritLevel
| boolean scalePosition
- Frame's type name
| readonly string frameType
- Frame's local space position
| readonly real localPosX
| readonly real localPosY
- Frame's anchor & pivot points
| readonly real anchorX
| readonly real anchorY
| readonly real pivotX
| readonly real pivotY
- Frame's unscaled size
| readonly real unscaledWidth
| readonly real unscaledHeight
- Get frame text font properties
| readonly integer fontFlags
| readonly real fontSize
| readonly string fontType
- Slider frame's min max value
| readonly real valueMin
| readonly real valueMax
- Create context index of the frame
| readonly integer context
- Local states of the frame
| readonly boolean visibleSelf
| readonly boolean enabledSelf
- Is the frame a simple frame type or not
| readonly boolean isSimple
- Local transparency of the frame
| readonly integer localOpacity
4. Static Members
- Representation for null frame
| readonly static UIFrame Null
- Currently iterated frame of "forEachChild" method
| readonly static UIFrame EnumChild
- Triggerer of the "onAnyEvent"
| readonly static UIFrame TriggerComponent
- Primitive frame names
| readonly static string TYPE_TEXT
| readonly static string TYPE_SIMPLE_TEXT
| readonly static string TYPE_TEXTURE
| readonly static string TYPE_SIMPLE_TEXTURE
| readonly static string TYPE_BUTTON
| readonly static string TYPE_SIMPLE_BUTTON
| readonly static string TYPE_BAR
| readonly static string TYPE_H_SLIDER
| readonly static string TYPE_V_SLIDER
*/
endif
/* struct UIUtils */static if FOLD then /*
1. Static Methods
- Calculate aspect ratio height
| static method CalcAspectRatio takes real w, real h, real aspectWidth returns integer
- Convert pixel unit to DPI and vice versa
• Usage: [value]*UIUtils.PXTODPI
[value]*UIUtils.DPITOPX
| static method operator PXTODPI takes nothing returns real
| static method operator DPITOPX takes nothing returns real
- Width of the 4:3 bound
| static method operator FrameBoundWidth takes nothing returns real
- Convert from pixel to screen x/y coordinate (in DPI unit)
| static method GetScreenPosX takes real x returns real
| static method GetScreenPosY takes real y returns real
- Force update default frames
| static method RefreshDefaultFrames takes nothing returns nothing
- Force update resolution
| static method RefreshResolution takes nothing returns nothing
- Resolution change event
| static method RegisterOnResolutionChangeEvent takes code func returns triggercondition
| static method RemoveOnResolutionChangeEvent takes triggercondition cond returns nothing
2. Static Members
- Updated after resolution change event
• Values might be async between clients
| readonly static integer ResolutionWidth
| readonly static integer ResolutionHeight
| readonly static integer AspectWidth
| readonly static integer AspectHeight
*/
endif
/* struct DefaultFrame (singleton) */static if FOLD then /*
- Origin frames
| readonly static framehandle Game
| readonly static framehandle World
| readonly static framehandle HeroBar
| readonly static framehandle array HeroButton [0 - 6]
| readonly static framehandle array HeroHPBar [0 - 6]
| readonly static framehandle array HeroMPBar [0 - 6]
| readonly static framehandle array HeroIndicator [0 - 6]
| readonly static framehandle array ItemButton [0 - 5]
| readonly static framehandle array CommandButton [0 - 11]
| readonly static framehandle array SystemButton [0 - 3]
| readonly static framehandle Portrait
| readonly static framehandle Minimap
| readonly static framehandle array MinimapButton [0 - 4]
| readonly static framehandle Tooltip
| readonly static framehandle UberTooltip
| readonly static framehandle ChatMsg
| readonly static framehandle UnitMsg
| readonly static framehandle TopMsg
- Other frames
| readonly static framehandle Console
| readonly static framehandle GoldText
| readonly static framehandle LumberText
| readonly static framehandle FoodText
| readonly static framehandle UnitNameText
| readonly static framehandle ResourceBar
| readonly static framehandle UpperButtonBar
*/
endif
/*
* V. Configurations
* */globals
// 1. TOC file path
private constant string TOC_FILE = "war3mapimported\\UIUtils.toc"
// 2. Temporary cache name
private constant string CACHE_NAME = "UIUtils.w3v"
// 3. Resolution change detection interval
private constant real RESOLUTION_CHECK_INTERVAL = 0.1
// 4. true : hides console frames on map init (full screen)
private constant boolean HIDE_CONSOLE_FRAME = true
// 5. true : frame's properties will be retained when it changes parent
private constant boolean PERSISTENT_CHILD_PROPERTIES = true
// 6. true : helps to prevent non-simple frame from going beyond the 4:3 bounds
private constant boolean REFRAIN_NON_SIMPLE_FRAME = true
// 7. Reference resolution, as which is used to design the interface
private constant integer RESOLUTION_WIDTH = 1360
private constant integer RESOLUTION_HEIGHT = 768
// 8. Configure in-game message frame
private constant boolean MESSAGE_FRAME_VISIBLE = true
private constant real MESSAGE_FRAME_ANCHOR_X = 0.0
private constant real MESSAGE_FRAME_ANCHOR_Y = 1.0
private constant real MESSAGE_FRAME_PIVOT_X = 0.0
private constant real MESSAGE_FRAME_PIVOT_Y = 1.0
private constant real MESSAGE_FRAME_POS_X = 100.0
private constant real MESSAGE_FRAME_POS_Y = -150.0
// 9. Configure in-game chat frame
private constant boolean CHAT_FRAME_VISIBLE = true
private constant real CHAT_FRAME_ANCHOR_X = 0.0
private constant real CHAT_FRAME_ANCHOR_Y = 0.0
private constant real CHAT_FRAME_PIVOT_X = 0.0
private constant real CHAT_FRAME_PIVOT_Y = 0.0
private constant real CHAT_FRAME_POS_X = 10.0
private constant real CHAT_FRAME_POS_Y = 100.0
// 10. Configure tooltips frame
private constant boolean TOOLTIPS_FRAME_VISIBLE = true
private constant real TOOLTIPS_FRAME_ANCHOR_X = 1.0
private constant real TOOLTIPS_FRAME_ANCHOR_Y = 0.0
private constant real TOOLTIPS_FRAME_PIVOT_X = 1.0
private constant real TOOLTIPS_FRAME_PIVOT_Y = 0.0
private constant real TOOLTIPS_FRAME_POS_X = -50.0
private constant real TOOLTIPS_FRAME_POS_Y = 0.0
// 11. Configure minimap frame
private constant boolean MINIMAP_FRAME_VISIBLE = true
private constant real MINIMAP_FRAME_ANCHOR_X = 1.0
private constant real MINIMAP_FRAME_ANCHOR_Y = 1.0
private constant real MINIMAP_FRAME_PIVOT_X = 1.0
private constant real MINIMAP_FRAME_PIVOT_Y = 1.0
private constant real MINIMAP_FRAME_POS_X = 0.0
private constant real MINIMAP_FRAME_POS_Y = 0.0
// 12. Configure unit portrait frame
private constant boolean PORTRAIT_FRAME_VISIBLE = false
private constant real PORTRAIT_FRAME_ANCHOR_X = 0.0
private constant real PORTRAIT_FRAME_ANCHOR_Y = 0.0
private constant real PORTRAIT_FRAME_PIVOT_X = 0.0
private constant real PORTRAIT_FRAME_PIVOT_Y = 0.0
private constant real PORTRAIT_FRAME_POS_X = 0.0
private constant real PORTRAIT_FRAME_POS_Y = 0.0
// 13. Configure other frame visibility
private constant boolean RESOURCE_FRAME_VISIBLE = false
private constant boolean CMD_BUTTON_FRAME_VISIBLE = false
endglobals
/*
* END OF DOCUMENT ----- Modify following codes on your own risk
*
*********************************************************************************/
private module DefaultFrameInit
private static method onInit takes nothing returns nothing
local integer i
set Game = BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0)
set World = BlzGetOriginFrame(ORIGIN_FRAME_WORLD_FRAME, 0)
set HeroBar = BlzGetOriginFrame(ORIGIN_FRAME_HERO_BAR, 0)
set Portrait = BlzGetOriginFrame(ORIGIN_FRAME_PORTRAIT, 0)
set Minimap = BlzGetOriginFrame(ORIGIN_FRAME_MINIMAP, 0)
set Tooltip = BlzGetOriginFrame(ORIGIN_FRAME_TOOLTIP, 0)
set UberTooltip = BlzGetOriginFrame(ORIGIN_FRAME_UBERTOOLTIP, 0)
set ChatMsg = BlzGetOriginFrame(ORIGIN_FRAME_CHAT_MSG, 0)
set UnitMsg = BlzGetOriginFrame(ORIGIN_FRAME_UNIT_MSG, 0)
set TopMsg = BlzGetOriginFrame(ORIGIN_FRAME_TOP_MSG, 0)
set i = 0
loop
exitwhen i > 11
set HeroButton[i] = BlzGetOriginFrame(ORIGIN_FRAME_HERO_BUTTON, i)
set HeroHPBar[i] = BlzGetOriginFrame(ORIGIN_FRAME_HERO_HP_BAR, i)
set HeroMPBar[i] = BlzGetOriginFrame(ORIGIN_FRAME_HERO_MANA_BAR, i)
set HeroIndicator[i] = BlzGetOriginFrame(ORIGIN_FRAME_HERO_BUTTON_INDICATOR, i)
set ItemButton[i] = BlzGetOriginFrame(ORIGIN_FRAME_ITEM_BUTTON, i)
set CommandButton[i] = BlzGetOriginFrame(ORIGIN_FRAME_COMMAND_BUTTON, i)
set SystemButton[i] = BlzGetOriginFrame(ORIGIN_FRAME_SYSTEM_BUTTON, i)
set MinimapButton[i] = BlzGetOriginFrame(ORIGIN_FRAME_MINIMAP_BUTTON, i)
set i = i + 1
endloop
set Console = BlzGetFrameByName("ConsoleUI", 0)
set GoldText = BlzGetFrameByName("ResourceBarGoldText", 0)
set LumberText = BlzGetFrameByName("ResourceBarLumberText", 0)
set FoodText = BlzGetFrameByName("ResourceBarSupplyText", 0)
set ResourceBar = BlzGetFrameByName("ResourceBarFrame", 0)
set UnitNameText = BlzGetFrameByName("SimpleNameValue", 0)
set UpperButtonBar = BlzGetFrameByName("UpperButtonBarFrame", 0)
endmethod
endmodule
private module UIUtilsInit
private static method onInit takes nothing returns nothing
local integer i
call RefreshResolution()
static if HIDE_CONSOLE_FRAME then
call BlzEnableUIAutoPosition(false)
call BlzFrameClearAllPoints(DefaultFrame.World)
call BlzFrameClearAllPoints(DefaultFrame.Console)
call BlzFrameSetAllPoints(DefaultFrame.World, DefaultFrame.Game)
call BlzFrameSetAbsPoint(DefaultFrame.Console, FRAMEPOINT_TOPRIGHT, -999.0, -999.0)
call RefreshDefaultFrames()
static if not RESOURCE_FRAME_VISIBLE then
call BlzFrameClearAllPoints(DefaultFrame.GoldText)
call BlzFrameSetAbsPoint(DefaultFrame.GoldText, FRAMEPOINT_BOTTOMLEFT, -999.0, -999.0)
call BlzFrameClearAllPoints(DefaultFrame.LumberText)
call BlzFrameSetAbsPoint(DefaultFrame.LumberText, FRAMEPOINT_BOTTOMLEFT, -999.0, -999.0)
call BlzFrameClearAllPoints(DefaultFrame.FoodText)
call BlzFrameSetAbsPoint(DefaultFrame.FoodText, FRAMEPOINT_BOTTOMLEFT, -999.0, -999.0)
call BlzFrameClearAllPoints(DefaultFrame.ResourceBar)
call BlzFrameSetAbsPoint(DefaultFrame.ResourceBar, FRAMEPOINT_BOTTOMLEFT, -999.0, -999.0)
endif
static if not CMD_BUTTON_FRAME_VISIBLE then
set i = 0
loop
exitwhen DefaultFrame.CommandButton[i] == null
call BlzFrameClearAllPoints(DefaultFrame.CommandButton[i])
call BlzFrameSetAbsPoint(DefaultFrame.CommandButton[i], FRAMEPOINT_BOTTOMLEFT, -999.0, -999.0)
set i = i + 1
endloop
endif
endif
call TimerStart(CreateTimer(), RESOLUTION_CHECK_INTERVAL, true, function thistype.CheckResolution)
endmethod
endmodule
struct DefaultFrame extends array
readonly static framehandle Game = null
readonly static framehandle World = null
readonly static framehandle HeroBar = null
readonly static framehandle array HeroButton
readonly static framehandle array HeroHPBar
readonly static framehandle array HeroMPBar
readonly static framehandle array HeroIndicator
readonly static framehandle array ItemButton
readonly static framehandle array CommandButton
readonly static framehandle array SystemButton
readonly static framehandle Portrait = null
readonly static framehandle Minimap = null
readonly static framehandle array MinimapButton
readonly static framehandle Tooltip = null
readonly static framehandle UberTooltip = null
readonly static framehandle ChatMsg = null
readonly static framehandle UnitMsg = null
readonly static framehandle TopMsg = null
readonly static framehandle Console = null
readonly static framehandle GoldText = null
readonly static framehandle LumberText = null
readonly static framehandle FoodText = null
readonly static framehandle UnitNameText = null
readonly static framehandle ResourceBar = null
readonly static framehandle UpperButtonBar = null
implement DefaultFrameInit
endstruct
private keyword AllComponents
struct UIUtils extends array
readonly static integer ResolutionWidth = RESOLUTION_WIDTH
readonly static integer ResolutionHeight = RESOLUTION_HEIGHT
readonly static real ScaleFactor = 1
private static trigger resolutionChangeTrigg = CreateTrigger()
static method CalcAspectRatio takes real w, real h, real aspectWidth returns integer
return R2I(aspectWidth*h/w+0.5)
endmethod
static method operator PXTODPI takes nothing returns real
return 0.6/ResolutionHeight
endmethod
static method operator DPITOPX takes nothing returns real
return ResolutionHeight/0.6
endmethod
static method operator FrameBoundWidth takes nothing returns real
return (ResolutionWidth-ResolutionHeight/600.*800.)/2.
endmethod
static method GetScreenPosX takes real x returns real
return (-FrameBoundWidth+x)*PXTODPI
endmethod
static method GetScreenPosY takes real y returns real
return y*PXTODPI
endmethod
static method RefreshDefaultFrames takes nothing returns nothing
static if MESSAGE_FRAME_VISIBLE then
call BlzFrameClearAllPoints(DefaultFrame.UnitMsg)
call BlzFrameSetAbsPoint(DefaultFrame.UnitMsg, FRAMEPOINT_BOTTOMLEFT,/*
*/ GetScreenPosX(MESSAGE_FRAME_POS_X+ResolutionWidth*MESSAGE_FRAME_ANCHOR_X-BlzFrameGetWidth(DefaultFrame.UnitMsg)*DPITOPX*MESSAGE_FRAME_PIVOT_X),/*
*/ GetScreenPosY(MESSAGE_FRAME_POS_Y+ResolutionHeight*MESSAGE_FRAME_ANCHOR_Y-BlzFrameGetHeight(DefaultFrame.UnitMsg)*DPITOPX*MESSAGE_FRAME_PIVOT_Y))
endif
static if CHAT_FRAME_VISIBLE then
call BlzFrameSetAbsPoint(DefaultFrame.ChatMsg, FRAMEPOINT_BOTTOMLEFT,/*
*/ GetScreenPosX(CHAT_FRAME_POS_X+ResolutionWidth*CHAT_FRAME_ANCHOR_X-BlzFrameGetWidth(DefaultFrame.ChatMsg)*DPITOPX*CHAT_FRAME_PIVOT_X),/*
*/ GetScreenPosY(CHAT_FRAME_POS_Y+ResolutionHeight*CHAT_FRAME_ANCHOR_Y-BlzFrameGetHeight(DefaultFrame.ChatMsg)*DPITOPX*CHAT_FRAME_PIVOT_Y))
endif
static if TOOLTIPS_FRAME_VISIBLE then
call BlzFrameClearAllPoints(DefaultFrame.UberTooltip)
call BlzFrameSetAbsPoint(DefaultFrame.UberTooltip, FRAMEPOINT_BOTTOMLEFT,/*
*/ GetScreenPosX(TOOLTIPS_FRAME_POS_X+ResolutionWidth*TOOLTIPS_FRAME_ANCHOR_X-BlzFrameGetWidth(DefaultFrame.UberTooltip)*DPITOPX*TOOLTIPS_FRAME_PIVOT_X),/*
*/ GetScreenPosY(TOOLTIPS_FRAME_POS_Y+ResolutionHeight*TOOLTIPS_FRAME_ANCHOR_Y-BlzFrameGetHeight(DefaultFrame.UberTooltip)*DPITOPX*TOOLTIPS_FRAME_PIVOT_Y))
endif
call BlzFrameClearAllPoints(DefaultFrame.Minimap)
static if MINIMAP_FRAME_VISIBLE then
call BlzFrameSetAbsPoint(DefaultFrame.Minimap, FRAMEPOINT_BOTTOMLEFT,/*
*/ GetScreenPosX(MINIMAP_FRAME_POS_X+ResolutionWidth*MINIMAP_FRAME_ANCHOR_X-BlzFrameGetWidth(DefaultFrame.Minimap)*DPITOPX*MINIMAP_FRAME_PIVOT_X),/*
*/ GetScreenPosY(MINIMAP_FRAME_POS_Y+ResolutionHeight*MINIMAP_FRAME_ANCHOR_Y-BlzFrameGetHeight(DefaultFrame.Minimap)*DPITOPX*MINIMAP_FRAME_PIVOT_Y))
else
call BlzFrameSetAbsPoint(DefaultFrame.Minimap, FRAMEPOINT_BOTTOMLEFT, -999.0, -999.0)
endif
call BlzFrameClearAllPoints(DefaultFrame.Portrait)
static if PORTRAIT_FRAME_VISIBLE then
call BlzFrameSetAbsPoint(DefaultFrame.Portrait, FRAMEPOINT_BOTTOMLEFT,/*
*/ GetScreenPosX(PORTRAIT_FRAME_POS_X+ResolutionWidth*PORTRAIT_FRAME_ANCHOR_X-BlzFrameGetWidth(DefaultFrame.Portrait)*DPITOPX*PORTRAIT_FRAME_PIVOT_X),/*
*/ GetScreenPosY(PORTRAIT_FRAME_POS_Y+ResolutionHeight*PORTRAIT_FRAME_ANCHOR_Y-BlzFrameGetHeight(DefaultFrame.Portrait)*DPITOPX*PORTRAIT_FRAME_PIVOT_Y))
else
call BlzFrameSetAbsPoint(DefaultFrame.Portrait, FRAMEPOINT_BOTTOMLEFT, -999.0, -999.0)
endif
endmethod
static method RefreshResolution takes nothing returns nothing
local AllComponents node
set ResolutionWidth = BlzGetLocalClientWidth()
set ResolutionHeight = BlzGetLocalClientHeight()
set ScaleFactor = I2R(ResolutionHeight)/I2R(RESOLUTION_HEIGHT)
set node = AllComponents.base.next
loop
exitwhen node.head or node == 0
if UIFrame(node).parent == UIFrame.Null then
call UIFrame(node).refresh()
endif
set node = node.next
endloop
endmethod
private static method CheckResolution takes nothing returns nothing
if BlzGetLocalClientWidth() != ResolutionWidth or BlzGetLocalClientHeight() != ResolutionHeight then
call RefreshResolution()
call RefreshDefaultFrames()
call TriggerEvaluate(resolutionChangeTrigg)
endif
endmethod
static method RegisterOnResolutionChangeEvent takes code func returns triggercondition
return TriggerAddCondition(resolutionChangeTrigg, Condition(func))
endmethod
static method RemoveOnResolutionChangeEvent takes triggercondition cond returns nothing
call TriggerRemoveCondition(resolutionChangeTrigg, cond)
endmethod
implement UIUtilsInit
endstruct
private struct UISubFrame
static UIFrame frame = 0
method operator [] takes string s returns framehandle
return BlzGetFrameByName(s, frame.context)
endmethod
endstruct
struct UIFrame extends array
implement LinkedList
string name
boolean inheritScale
boolean inheritOpacity
boolean inheritVisibility
boolean inheritEnableState
boolean inheritPosition
boolean inheritLevel
boolean scalePosition
readonly string frameType
readonly real localPosX
readonly real localPosY
readonly real anchorX
readonly real anchorY
readonly real pivotX
readonly real pivotY
readonly real unscaledWidth
readonly real unscaledHeight
readonly real valueMin
readonly real valueMax
readonly real fontSize
readonly string fontType
readonly integer fontFlags
readonly integer context
readonly boolean isSimple
readonly boolean visibleSelf
readonly boolean enabledSelf
readonly integer localOpacity
private integer m_level
private integer m_opacity
private real m_localScale
private real m_stepSize
private real m_width
private real m_height
private real m_scale
private real m_left
private real m_bottom
private real m_screenPosX
private real m_screenPosY
private real m_scaledLeft
private real m_scaledBottom
private real m_scaledScreenPosX
private real m_scaledScreenPosY
private thistype m_parent
private thistype m_childs
private thistype m_tooltips
private string mainTextureFile
private string disabledTextureFile
private string pushedTextureFile
private string highlightTextureFile
private string backgroundTextureFile
private string borderTextureFile
private string modelFile
private trigger anyEventTrigg
readonly framehandle frame
private framehandle textFrameH
private framehandle modelFrameH
private framehandle mainTextureH
private framehandle disabledTextureH
private framehandle pushedTextureH
private framehandle highlightTextureH
private framehandle backgroundTextureH
private framehandle borderTextureH
readonly static thistype Null = 0
readonly static thistype EnumChild = 0
readonly static thistype TriggerComponent = 0
readonly static string TYPE_TEXT = "UIUtilsText"
readonly static string TYPE_SIMPLE_TEXT = "UIUtilsSimpleText"
readonly static string TYPE_TEXTURE = "UIUtilsTexture"
readonly static string TYPE_SIMPLE_TEXTURE = "UIUtilsSimpleTexture"
readonly static string TYPE_BUTTON = "UIUtilsButton"
readonly static string TYPE_SIMPLE_BUTTON = "UIUtilsSimpleButton"
readonly static string TYPE_BAR = "UIUtilsBar"
readonly static string TYPE_H_SLIDER = "UIUtilsSliderH"
readonly static string TYPE_V_SLIDER = "UIUtilsSliderV"
private static trigger ExecTrigg = CreateTrigger()
private static gamecache GC
private static hashtable HT
private static method IsSimple takes string frameType, boolean isSimple returns boolean
return frameType == TYPE_SIMPLE_TEXT or frameType == TYPE_SIMPLE_TEXTURE or frameType == TYPE_BAR or isSimple and not (frameType == TYPE_TEXT or frameType == TYPE_TEXTURE or frameType == TYPE_BUTTON or frameType == TYPE_H_SLIDER or frameType == TYPE_V_SLIDER)
endmethod
private static method GetTriggerComponent takes nothing returns boolean
set TriggerComponent = LoadInteger(HT, GetHandleId(BlzGetTriggerFrame()), 0)
return false
endmethod
method operator subFrame takes nothing returns UISubFrame
set UISubFrame.frame = this
return 0
endmethod
method operator onAnyEvent= takes code func returns triggercondition
local integer i
if .anyEventTrigg == null then
set .anyEventTrigg = CreateTrigger()
set i = 1
loop
exitwhen i > 16
call BlzTriggerRegisterFrameEvent(.anyEventTrigg, .frame, ConvertFrameEventType(i))
set i = i + 1
endloop
call TriggerAddCondition(.anyEventTrigg, Condition(function thistype.GetTriggerComponent))
endif
return TriggerAddCondition(.anyEventTrigg, Condition(func))
endmethod
method operator parent= takes thistype frm returns nothing
if frm != Null then
if .m_parent != frm then
call .removeNode()
endif
call frm.m_childs.insertNode(this)
endif
static if not PERSISTENT_CHILD_PROPERTIES then
if .m_parent != Null then
set .localScale = .localScale*.m_parent.localScale
endif
set .localPosX = .screenPosX - frm.screenPosX
set .localPosY = .screenPosY - frm.screenPosY
endif
set .m_parent = frm
endmethod
method operator parent takes nothing returns thistype
return .m_parent
endmethod
method operator text= takes string str returns nothing
call BlzFrameSetText(.textFrameH, str)
endmethod
method operator text takes nothing returns string
return BlzFrameGetText(.textFrameH)
endmethod
method operator maxLength= takes integer length returns nothing
call BlzFrameSetTextSizeLimit(.textFrameH, length)
endmethod
method operator maxLength takes nothing returns integer
return BlzFrameGetTextSizeLimit(.textFrameH)
endmethod
method operator textColor= takes integer color returns nothing
call BlzFrameSetTextColor(.textFrameH, color)
endmethod
method operator texture= takes string filePath returns nothing
set .mainTextureFile = filePath
call BlzFrameSetTexture(.mainTextureH, filePath, 0, true)
if StringLength(.disabledTextureFile) == 0 then
set .disabledTexture = filePath
endif
if StringLength(.pushedTextureFile) == 0 then
set .pushedTexture = filePath
endif
endmethod
method operator texture takes nothing returns string
return .mainTextureFile
endmethod
method operator disabledTexture= takes string filePath returns nothing
set .disabledTextureFile = filePath
call BlzFrameSetTexture(.disabledTextureH, filePath, 0, true)
endmethod
method operator disabledTexture takes nothing returns string
return .disabledTextureFile
endmethod
method operator highlightTexture= takes string filePath returns nothing
set .highlightTextureFile = filePath
call BlzFrameSetTexture(.highlightTextureH, filePath, 0, true)
endmethod
method operator highlightTexture takes nothing returns string
return .highlightTextureFile
endmethod
method operator pushedTexture= takes string filePath returns nothing
set .pushedTextureFile = filePath
call BlzFrameSetTexture(.pushedTextureH, filePath, 0, true)
endmethod
method operator pushedTexture takes nothing returns string
return .pushedTextureFile
endmethod
method operator backgroundTexture= takes string filePath returns nothing
set .backgroundTextureFile = filePath
call BlzFrameSetTexture(.backgroundTextureH, filePath, 0, true)
endmethod
method operator backgroundTexture takes nothing returns string
return .backgroundTextureFile
endmethod
method operator borderTexture= takes string filePath returns nothing
set .borderTextureFile = filePath
call BlzFrameSetTexture(.borderTextureH, filePath, 0, true)
endmethod
method operator borderTexture takes nothing returns string
return .borderTextureFile
endmethod
method operator model= takes string filePath returns nothing
set .modelFile = filePath
call BlzFrameSetModel(.modelFrameH, filePath, 0)
endmethod
method operator model takes nothing returns string
return .modelFile
endmethod
method operator width takes nothing returns real
return .m_width
endmethod
method operator height takes nothing returns real
return .m_height
endmethod
method operator localScale= takes real r returns nothing
local thistype node = .m_childs.next
set .m_localScale = RMaxBJ(r, 0.0001)
if .parent == Null or not .inheritScale then
set .m_scale = .localScale
else
set .m_scale = .localScale*.parent.scale
endif
set .m_width = .unscaledWidth*.scale
set .m_height = .unscaledHeight*.scale
call setSize(.unscaledWidth, .unscaledHeight)
call setFont(.fontType, .fontSize, .fontFlags)
call move(.localPosX, .localPosY)
loop
exitwhen node.head or node == 0
set node.localScale = node.localScale
set node = node.next
endloop
endmethod
method operator localScale takes nothing returns real
return .m_localScale
endmethod
method operator scale takes nothing returns real
return .m_scale
endmethod
method operator opacity= takes integer amount returns nothing
local thistype node = .m_childs.next
set .localOpacity = amount
if .parent == Null or not .inheritOpacity then
set .m_opacity = .localOpacity
else
set .m_opacity = R2I(I2R(.localOpacity)*I2R(.parent.opacity)/255.)
endif
call BlzFrameSetAlpha(.frame, .opacity)
loop
exitwhen node.head or node == 0
set node.opacity = node.localOpacity
set node = node.next
endloop
endmethod
method operator opacity takes nothing returns integer
return m_opacity
endmethod
method operator level= takes integer level returns nothing
local thistype node = .m_childs.next
set .m_level = level
call BlzFrameSetLevel(.frame, .trueLevel)
loop
exitwhen node.head or node == 0
set node.level = node.m_level
set node = node.next
endloop
endmethod
method operator level takes nothing returns integer
return .m_level
endmethod
method operator trueLevel takes nothing returns integer
if .parent == Null or not .inheritLevel then
return .m_level
else
return .m_level+.parent.level
endif
endmethod
method operator visible= takes boolean state returns nothing
local thistype node = .m_childs.next
set .visibleSelf = state
call BlzFrameSetVisible(.frame, .visible)
loop
exitwhen node.head or node == 0
set node.visible = node.visibleSelf
set node = node.next
endloop
endmethod
method operator visible takes nothing returns boolean
if .parent == Null or not .inheritVisibility then
return .visibleSelf
else
return .visibleSelf and .parent.visible
endif
endmethod
method operator enabled= takes boolean state returns nothing
local thistype node = .m_childs.next
set .enabledSelf = state
call BlzFrameSetEnable(.frame, .enabled)
loop
exitwhen node.head or node == 0
set node.enabled = node.enabledSelf
set node = node.next
endloop
endmethod
method operator enabled takes nothing returns boolean
if .parent == Null or not .inheritEnableState then
return .enabledSelf
else
return .enabledSelf and .parent.enabled
endif
endmethod
method operator vertexColor= takes integer color returns nothing
call BlzFrameSetVertexColor(.modelFrameH, color)
endmethod
method operator value= takes real r returns nothing
call BlzFrameSetValue(.frame, r)
endmethod
method operator value takes nothing returns real
return BlzFrameGetValue(.frame)
endmethod
method operator stepSize= takes real r returns nothing
set .m_stepSize = RMaxBJ(r, 0.0001)
call BlzFrameSetStepSize(.frame, .m_stepSize)
endmethod
method operator stepSize takes nothing returns real
return .m_stepSize
endmethod
method operator tooltips= takes thistype frame returns nothing
set .m_tooltips = frame
call BlzFrameSetTooltip(.frame, frame.frame)
endmethod
method operator tooltips takes nothing returns thistype
return .m_tooltips
endmethod
method operator left takes nothing returns real
return .m_left
endmethod
method operator right takes nothing returns real
return .left+.width
endmethod
method operator bottom takes nothing returns real
return .m_bottom
endmethod
method operator top takes nothing returns real
return .bottom+.height
endmethod
method operator screenPosX takes nothing returns real
return .m_screenPosX
endmethod
method operator screenPosY takes nothing returns real
return .m_screenPosY
endmethod
private method normalizePosX takes real x returns real
return RMinBJ(RMaxBJ(x, UIUtils.FrameBoundWidth+.width*.pivotX), UIUtils.ResolutionWidth-UIUtils.FrameBoundWidth-.width*(1.-.pivotX))
endmethod
private method normalizeScaledPosX takes real x returns real
return RMinBJ(RMaxBJ(x, UIUtils.FrameBoundWidth+.width*.pivotX*UIUtils.ScaleFactor), UIUtils.ResolutionWidth-UIUtils.FrameBoundWidth-.width*(1.-.pivotX)*UIUtils.ScaleFactor)
endmethod
private method operator scaledLeft takes nothing returns real
return .m_scaledLeft
endmethod
private method operator scaledBottom takes nothing returns real
return .m_scaledBottom
endmethod
private method operator scaledScreenPosX takes nothing returns real
return .m_scaledScreenPosX
endmethod
private method operator scaledScreenPosY takes nothing returns real
return .m_scaledScreenPosY
endmethod
method setAnchorPoint takes real x, real y returns nothing
set .anchorX = x
set .anchorY = y
call move(.localPosX, .localPosY)
endmethod
method setPivotPoint takes real x, real y returns nothing
set .pivotX = x
set .pivotY = y
call move(.localPosX, .localPosY)
endmethod
method setSize takes real width, real height returns nothing
set .unscaledWidth = RMaxBJ(width, 0)
set .unscaledHeight = RMaxBJ(height, 0)
set .m_width = .unscaledWidth*.scale
set .m_height = .unscaledHeight*.scale
call BlzFrameSetSize(.frame, .width*UIUtils.ScaleFactor*UIUtils.PXTODPI, .height*UIUtils.ScaleFactor*UIUtils.PXTODPI)
call move(.localPosX, .localPosY)
endmethod
private method calcRect takes nothing returns nothing
local real pivotOffsetX = .width*.pivotX
local real pivotOffsetY = .height*.pivotY
set .m_left = .screenPosX-pivotOffsetX
set .m_bottom = .screenPosY-pivotOffsetY
set .m_scaledLeft = .scaledScreenPosX-pivotOffsetX*UIUtils.ScaleFactor
set .m_scaledBottom = .scaledScreenPosY-pivotOffsetY*UIUtils.ScaleFactor
endmethod
method move takes real x, real y returns nothing
local thistype node = .m_childs.next
local real anchorOffsetX
local real anchorOffsetY
local real scale
set .localPosX = x
set .localPosY = y
if .parent == Null or not .inheritPosition then
set anchorOffsetX = UIUtils.ResolutionWidth*.anchorX
set anchorOffsetY = UIUtils.ResolutionHeight*.anchorY
if not .isSimple then
set .m_screenPosX = normalizePosX(.localPosX+anchorOffsetX)
set .m_scaledScreenPosX = normalizeScaledPosX(.localPosX*UIUtils.ScaleFactor+anchorOffsetX)
else
set .m_screenPosX = .localPosX+anchorOffsetX
set .m_scaledScreenPosX = .localPosX*UIUtils.ScaleFactor+anchorOffsetX
endif
set .m_screenPosY = .localPosY+anchorOffsetY
set .m_scaledScreenPosY = .localPosY*UIUtils.ScaleFactor+anchorOffsetY
else
if .scalePosition then
set scale = .parent.scale
else
set scale = 1
endif
set anchorOffsetX = .parent.width*.anchorX
set anchorOffsetY = .parent.height*.anchorY
set .m_screenPosX = .parent.left+anchorOffsetX+.localPosX*scale
set .m_screenPosY = .parent.bottom+anchorOffsetY+.localPosY*scale
set .m_scaledScreenPosX = .parent.scaledLeft+(anchorOffsetX+.localPosX*scale)*UIUtils.ScaleFactor
set .m_scaledScreenPosY = .parent.scaledBottom+(anchorOffsetY+.localPosY*scale)*UIUtils.ScaleFactor
endif
call calcRect()
if .isSimple then
set x = .scaledScreenPosX-.width*.pivotX*UIUtils.ScaleFactor
else
set x = normalizeScaledPosX(.scaledScreenPosX-.width*.pivotX*UIUtils.ScaleFactor)
endif
call BlzFrameSetAbsPoint(.frame, FRAMEPOINT_BOTTOMLEFT, UIUtils.GetScreenPosX(x), UIUtils.GetScreenPosY(.scaledScreenPosY-.height*.pivotY*UIUtils.ScaleFactor))
loop
exitwhen node.head or node == 0
call node.move(node.localPosX, node.localPosY)
set node = node.next
endloop
endmethod
method moveEx takes real x, real y returns nothing
if .parent == Null or not .inheritPosition then
call move(x, y)
else
call move((x-.parent.screenPosX)/.parent.localScale, (y-.parent.screenPosY)/.parent.localScale)
endif
endmethod
method relate takes thistype relative, real x, real y returns nothing
if .parent == Null then
call move(relative.screenPosX+x, relative.screenPosY+y)
else
call moveEx(relative.screenPosX+x, relative.screenPosY+y)
endif
endmethod
method click takes nothing returns nothing
call BlzFrameClick(.frame)
endmethod
method cageMouse takes boolean state returns nothing
call BlzFrameCageMouse(.frame, state)
endmethod
method setFocus takes boolean state returns nothing
call BlzFrameSetFocus(.frame, state)
endmethod
method setSpriteAnimate takes integer primaryProp, integer flags returns nothing
call BlzFrameSetSpriteAnimate(.frame, primaryProp, flags)
endmethod
method setMinMaxValue takes real min, real max returns nothing
set .valueMin = min
set .valueMax = max
call BlzFrameSetMinMaxValue(.frame, min, max)
endmethod
method setFont takes string fontType, real fontSize, integer flags returns nothing
set .fontSize = fontSize
set .fontType = fontType
set .fontFlags = flags
if .frameType == TYPE_SIMPLE_TEXT then
call BlzFrameSetFont(.textFrameH, .fontType, .fontSize*.scale, .fontFlags)
endif
endmethod
method setTextAlignment takes textaligntype vertical, textaligntype horizontal returns nothing
call BlzFrameSetTextAlignment(.textFrameH, vertical, horizontal)
endmethod
method refresh takes nothing returns nothing
local thistype node
set .enabled = .enabledSelf
set .opacity = .localOpacity
set .level = .m_level
set .localScale = .localScale
set node = .m_childs.next
loop
exitwhen node.head or node == 0
call node.refresh()
set node = node.next
endloop
endmethod
private method getSubFrame takes string name returns framehandle
local framehandle h = BlzGetFrameByName(name, .context)
if h == null then
return .frame
else
return h
endif
endmethod
method forEachChild takes code func returns nothing
local thistype node = .m_childs.next
call TriggerAddAction(ExecTrigg, func)
loop
exitwhen node.head or node == 0
set EnumChild = node
call TriggerExecute(ExecTrigg)
set node = node.next
endloop
call TriggerClearActions(ExecTrigg)
endmethod
method destroy takes nothing returns nothing
local thistype node = .m_childs.next
loop
exitwhen node.head or node == 0
call node.destroy()
set node = node.next
endloop
call BlzDestroyFrame(.frame)
call DestroyTrigger(.anyEventTrigg)
call StoreInteger(GC, name, I2S(.context), GetStoredInteger(GC, name, "0"))
call StoreInteger(GC, name, "0", .context)
call AllComponents.remove(this)
call .m_childs.flushNode()
call removeNode()
call deallocate()
set .anyEventTrigg = null
set .mainTextureH = null
set .disabledTextureH = null
set .highlightTextureH = null
set .pushedTextureH = null
set .backgroundTextureH = null
set .borderTextureH = null
set .textFrameH = null
set .modelFrameH = null
set .frame = null
set .name = null
set .frameType = null
set .m_parent = Null
set .m_childs = 0
endmethod
static method create takes boolean isSimple, string frameType, thistype parent, real x, real y, integer level returns thistype
local thistype this = allocate()
local integer tempInt
set .context = GetStoredInteger(GC, frameType, "0")
set tempInt = GetStoredInteger(GC, frameType, I2S(context))
if tempInt == 0 then
call StoreInteger(GC, frameType, "0", context+1)
else
call StoreInteger(GC, frameType, "0", tempInt)
endif
set .parent = parent
set .m_childs = createNode()
set .isSimple = IsSimple(frameType, isSimple)
if .isSimple then
set .frame = BlzCreateSimpleFrame(frameType, DefaultFrame.Game, .context)
else
set .frame = BlzCreateFrame(frameType, DefaultFrame.Game, 0, .context)
endif
set .mainTextureH = getSubFrame(frameType + "Texture")
set .disabledTextureH = getSubFrame(frameType + "Disabled")
set .highlightTextureH = getSubFrame(frameType + "Highlight")
set .pushedTextureH = getSubFrame(frameType + "Pushed")
set .backgroundTextureH = getSubFrame(frameType + "Background")
set .borderTextureH = getSubFrame(frameType + "Border")
set .textFrameH = getSubFrame(frameType + "Text")
set .modelFrameH = getSubFrame(frameType + "Model")
set .inheritScale = true
set .inheritOpacity = true
set .inheritVisibility = true
set .inheritEnableState = true
set .inheritPosition = true
set .inheritLevel = true
set .scalePosition = true
set .unscaledWidth = BlzFrameGetWidth(.frame)*(RESOLUTION_HEIGHT/0.6)
set .unscaledHeight = BlzFrameGetHeight(.frame)*(RESOLUTION_HEIGHT/0.6)
set .frameType = frameType
set .name = frameType + I2S(.context)
set .level = level
set .visibleSelf = true
set .enabledSelf = true
set .fontType = "Fonts\\FRIZQT__.TTF"
set .fontSize = 0.013
set .fontFlags = 0
set .value = 0.0
set .localScale = 1.0
set .anchorX = 0.0
set .anchorY = 0.0
set .pivotX = 0.0
set .pivotY = 0.0
set .opacity = 255
set .mainTextureFile = ""
set .disabledTextureFile = ""
set .pushedTextureFile = ""
set .highlightTextureFile = ""
set .backgroundTextureFile = ""
set .borderTextureFile = ""
set .modelFile = ""
call move(x, y)
call setMinMaxValue(0.0, 1.0)
call refresh()
call AllComponents.add(this)
call SaveInteger(HT, GetHandleId(.frame), 0, this)
return this
endmethod
private static method onInit takes nothing returns nothing
set HT = InitHashtable()
set GC = InitGameCache(CACHE_NAME)
call BlzLoadTOCFile(TOC_FILE)
endmethod
endstruct
private struct AllComponents extends array
implement LinkedList
static method add takes thistype this returns nothing
call base.insertNode(this)
endmethod
static method remove takes thistype this returns nothing
call removeNode()
endmethod
endstruct
endlibrary
library LinkedListModule /* v2.3.1
Easy implementation of linked lists into structs.
***********************************************************************
*
* module LinkedList
*
* - Implement at the top of your struct, must extend array
*
* thistype next
* thistype prev
* boolean head
*
* readonly static thistype base
* - Precreated head, useful for non-dynamic lists.
*
* static method allocate takes nothing returns thistype
* method deallocate takes nothing returns nothing
*
* static method createNode takes nothing returns thistype
* - Allocates a new node pointing towards itself.
* - These nodes are considered "heads" therefore it's head
* - boolean member is set to true.
* method insertNode takes thistype toInsert returns thistype
* - Inserts the instance before the node.
* method removeNode takes nothing returns nothing
* - Removes the node from the list.
* method clearNode takes nothing returns nothing
* - Deallocates all the instances within the node's range.
* method flushNode takes nothing returns nothing
* - Clears and deallocates the node.
*
* module LinkedListLite
* - Only has the members and the allocation methods.
* - To be used with the provided textmacros.
*
* textmacro LINKED_LIST_HEAD takes node
* - Turns the node into a head.
* textmacro LINKED_LIST_INSERT takes node, toInsert
* - Inserts the instance before the node.
* textmacro LINKED_LIST_REMOVE takes node
* - Removes the node from the list.
* textmacro LINKED_LIST_CLEAR takes node
* - Deallocates all the instances within the node's range.
* textmacro LINKED_LIST_FLUSH takes node
* - Clears and deallocates the node.
* textmacro LINKED_LIST_MERGE takes nodeA, nodeB
* - Merges two lists together (Don't merge loose nodes!)
*
**********************************************************************/
module LinkedListLite
private static integer instanceCount = 0
thistype next
thistype prev
boolean head
static method allocate takes nothing returns thistype
local thistype this = thistype(0).prev
if this==0 then
debug if instanceCount==8190 then
debug call BJDebugMsg("[LinkedList] Error: attempted to allocate too many instances.")
debug return 0
debug endif
set instanceCount = instanceCount+1
return instanceCount
endif
set thistype(0).prev = prev
return this
endmethod
method deallocate takes nothing returns nothing
set this.prev=thistype(0).prev
set thistype(0).prev=this
set this.head=false
endmethod
endmodule
module LinkedList
implement LinkedListLite
static method operator base takes nothing returns thistype
return 8190
endmethod
static method createNode takes nothing returns thistype
local thistype this=allocate()
//! runtextmacro LINKED_LIST_HEAD("this")
return this
endmethod
method clearNode takes nothing returns nothing
//! runtextmacro LINKED_LIST_CLEAR("this")
endmethod
method flushNode takes nothing returns nothing
//! runtextmacro LINKED_LIST_FLUSH("this")
endmethod
method insertNode takes thistype toInsert returns nothing
//! runtextmacro LINKED_LIST_INSERT("this","toInsert")
endmethod
method removeNode takes nothing returns nothing
//! runtextmacro LINKED_LIST_REMOVE("this")
endmethod
private static method onInit takes nothing returns nothing
set thistype(8190).next = 8190
set thistype(8190).prev = 8190
set thistype(8190).head = true
endmethod
static if DEBUG_MODE then
method print takes nothing returns nothing
local string s=""
local thistype exit=this
loop
set s=s+I2S(this)
set this = next
exitwhen this==exit
set s = s+" - "
endloop
call BJDebugMsg("[ "+s+" ]")
endmethod
endif
endmodule
//! textmacro LINKED_LIST_HEAD takes node
set $node$.next = this
set $node$.prev = this
set $node$.head = true
//! endtextmacro
//! textmacro LINKED_LIST_CLEAR takes node
if $node$!=$node$.next then
set $node$.next.prev = thistype(0).prev
set thistype(0).prev = $node$.prev
set $node$.next = $node$
set $node$.prev = $node$
endif
//! endtextmacro
//! textmacro LINKED_LIST_FLUSH takes node
set $node$.next.prev = thistype(0).prev
set thistype(0).prev = $node$
set $node$.head = false
//! endtextmacro
//! textmacro LINKED_LIST_INSERT takes node, toInsert
set $node$.prev.next = $toInsert$
set $toInsert$.prev = $node$.prev
set $node$.prev = $toInsert$
set $toInsert$.next = $node$
//! endtextmacro
//! textmacro LINKED_LIST_REMOVE takes node
set $node$.prev.next = $node$.next
set $node$.next.prev = $node$.prev
//! endtextmacro
//! textmacro LINKED_LIST_MERGE takes nodeA, nodeB
set $nodeA$.next.prev = $nodeB$.prev
set $nodeB$.prev.next = $nodeA$.next
set $nodeA$.next = $nodeB$
set $nodeB$.prev = $nodeA$
//! endtextmacro
endlibrary
scope TemplateFrameDemo initializer init
globals
integer LocalPlayerId
UIFrame textTemplate
UIFrame inventoryFrame
UIFrame simpleCharacterBar
UIFrame footmanIcon
UIFrame testSimpleButton
UIFrame healthbarFrame
UIFrame testSliderH
UIFrame testSliderV
private UIFrame Scaler
boolean array IsFilled[5][5]
endglobals
private function FrameEvent takes nothing returns boolean
local frameeventtype eventType = BlzGetTriggerFrameEvent()
if eventType == FRAMEEVENT_CONTROL_CLICK then
call BJDebugMsg("Click |cffffcc00[" + UIFrame.TriggerComponent.name + "]|r")
elseif eventType == FRAMEEVENT_MOUSE_ENTER then
call BJDebugMsg("Enter |cffffcc00[" + UIFrame.TriggerComponent.name + "]|r")
elseif eventType == FRAMEEVENT_MOUSE_LEAVE then
call BJDebugMsg("Leave |cffffcc00[" + UIFrame.TriggerComponent.name + "]|r")
elseif eventType == FRAMEEVENT_MOUSE_UP then
call BJDebugMsg("Mouse Up |cffffcc00[" + UIFrame.TriggerComponent.name + "]|r")
elseif eventType == FRAMEEVENT_MOUSE_DOWN then
call BJDebugMsg("Mouse Down |cffffcc00[" + UIFrame.TriggerComponent.name + "]|r")
elseif eventType == FRAMEEVENT_MOUSE_WHEEL then
call BJDebugMsg("Mouse Wheel |cffffcc00[" + UIFrame.TriggerComponent.name + "]|r")
//elseif eventType == FRAMEEVENT_SLIDER_VALUE_CHANGED then
//call BJDebugMsg("Value Changed |cffffcc00[" + UIFrame.TriggerComponent.name + "]|r")
endif
return false
endfunction
private function AddRandomItem takes integer row, integer col returns nothing
local UIFrame f
local real startX = 50.0
local real startY = -100.0
local real offset = 60.0
set f = UIFrame.create(false, UIFrame.TYPE_BUTTON, inventoryFrame, startX+offset*col, startY-offset*row, 0)
set f.name = "TemplateItem"
set f.texture = "war3mapImported\\item" + I2S(GetRandomInt(1, 4)) + ".blp"
set f.highlightTexture = "war3mapImported\\Selection.blp"
call f.setAnchorPoint(0.0, 1.0) // Top
call f.setPivotPoint(0.5, 0.5) // Center
call f.setSize(50.0, 50.0)
call f.refresh()
endfunction
private function createFrame takes nothing returns nothing
local integer i
local integer r
local integer c
// 1. Create simple text
// - Instantiate a new frame
// - Simple frame must let "isSimple" parameter be "true"
// - Set the parent to Null so it has no parent
set textTemplate = UIFrame.create(true, UIFrame.TYPE_SIMPLE_TEXT, UIFrame.Null, -200.0, -50.0, 0)
// - Change frame name for event identification (demo)
set textTemplate.name = "Template Text"
// - Change text content
set textTemplate.text = "|cff00ff00Hello world!|r"
// - Register event
set textTemplate.onAnyEvent = function FrameEvent
// - Set anchor point to top right
// - This frame has no parent so it anchors at the screen's top right
call textTemplate.setAnchorPoint(1.0, 1.0) // Top Right
// - Set pivot point to right
call textTemplate.setPivotPoint(1.0, 0.5) // Right
// - Modify text alignment
call textTemplate.setTextAlignment(TEXT_JUSTIFY_RIGHT, TEXT_JUSTIFY_TOP)
call textTemplate.refresh()
// 2. Create texture frame, in this case, the inventory's frame
// - "Texture" is not a simple frame, hence let "isSimple" be "false"
// - Non-simple frames can't go beyond the 4:3 bounds
set inventoryFrame = UIFrame.create(false, UIFrame.TYPE_TEXTURE, UIFrame.Null, 0.0, 0.0, 0)
set inventoryFrame.name = "Inventory Frame"
// - Change frame's texture
set inventoryFrame.texture = "war3mapImported\\Inventory.tga"
set inventoryFrame.onAnyEvent = function FrameEvent
// - This frame has no parent so it anchors at the screen's center
call inventoryFrame.setAnchorPoint(1.0, 0.5) // Right
call inventoryFrame.setPivotPoint(1.0, 0.5) // Right
// - Modify frame's dimension according to the texture file's dimension
call inventoryFrame.setSize(293.0, 438.0)
call inventoryFrame.refresh()
// 3. Create simple texture template
// - This is a simple frame type so it can go beyond the 4:3 bounds
set simpleCharacterBar = UIFrame.create(true, UIFrame.TYPE_SIMPLE_TEXTURE, UIFrame.Null, 0.0, 0.0, 0)
set simpleCharacterBar.name = "Character Bar"
set simpleCharacterBar.texture = "war3mapImported\\HP.tga"
set simpleCharacterBar.onAnyEvent = function FrameEvent
call simpleCharacterBar.setAnchorPoint(0.0, 1.0) // Top Left
call simpleCharacterBar.setPivotPoint(0.0, 1.0) // Top Left
call simpleCharacterBar.setSize(400.0, 127.0)
call simpleCharacterBar.refresh()
// 4. Create button template
// - Not a simple frame type
// - You can modify the button's textures
set footmanIcon = UIFrame.create(false, UIFrame.TYPE_BUTTON, UIFrame.Null, 0, 100.0, 0)
set footmanIcon.name = "Footman Icon"
set footmanIcon.texture = "ReplaceableTextures\\CommandButtons\\BTNFootman.blp"
set footmanIcon.onAnyEvent = function FrameEvent
call footmanIcon.setAnchorPoint(0.0, 0.0) // Bottom Left
call footmanIcon.setPivotPoint(0.0, 0.0) // Bottom Left
call footmanIcon.refresh()
// 5. Simple form of button frame
// - Can go beyond 4:3 bounds but can't change textures
// - In exchange you can modify it's text
set testSimpleButton = UIFrame.create(true, UIFrame.TYPE_SIMPLE_BUTTON, UIFrame.Null, 5.0, 5.0, 0)
set testSimpleButton.name = "Template Simple Button"
set testSimpleButton.text = "Hello Reforged!"
set testSimpleButton.onAnyEvent = function FrameEvent
call testSimpleButton.setAnchorPoint(0.0, 0.0) // Bottom Left
call testSimpleButton.setPivotPoint(0.0, 0.0) // Bottom Left
call testSimpleButton.setSize(120, 40)
call testSimpleButton.refresh()
// 6. Create a simple healthbar template
// - This is a simple frame type
// - We want to put it under the footman icon so let set its parent
set healthbarFrame = UIFrame.create(true, UIFrame.TYPE_BAR, footmanIcon, 0, -5, 0)
set healthbarFrame.name = "Health Bar"
// - Change texture according to player's team color
set healthbarFrame.texture = "Replaceabletextures\\Teamcolor\\Teamcolor0" + I2S(LocalPlayerId) + ".blp"
set healthbarFrame.onAnyEvent = function FrameEvent
// - Health is initially full
set healthbarFrame.value = healthbarFrame.valueMax
// - This frame has a parent, which is the footman icon, so it will anchors on the bottom of the icon
call healthbarFrame.setAnchorPoint(0.5, 0.0) // Bottom
call healthbarFrame.setPivotPoint(0.5, 1.0) // Top
// - Match the bar's width to footman icon's width
call healthbarFrame.setSize(footmanIcon.width, healthbarFrame.height)
call healthbarFrame.refresh()
// 7. Create horizontal slider template
// - Sliders aren't simple frame type
// - These two sliders will later be used for the radar-like thing
set testSliderH = UIFrame.create(false, UIFrame.TYPE_H_SLIDER, UIFrame.Null, 0.0, 100, 0)
set testSliderH.name = "Radar H Slider"
set testSliderH.onAnyEvent = function FrameEvent
call testSliderH.setAnchorPoint(0.5, 0.0) // Bottom
call testSliderH.setPivotPoint(0.5, 0.5) // Center
call testSliderH.refresh()
// 8. Create vertical slider template
set testSliderV = UIFrame.create(false, UIFrame.TYPE_V_SLIDER, UIFrame.Null, testSliderH.width/2.+5., 105., 0)
set testSliderV.name = "Radar V Slider"
set testSliderV.onAnyEvent = function FrameEvent
call testSliderV.setAnchorPoint(0.5, 0.0) // Bottom
call testSliderV.setPivotPoint(0.5, 0.0) // Bottom
call testSliderV.refresh()
// Add 10 random inventory items
set i = 0
loop
exitwhen i >= 10
loop
set r = GetRandomInt(0, 4)
set c = GetRandomInt(0, 3)
exitwhen not IsFilled[r][c]
endloop
set IsFilled[r][c] = true
call AddRandomItem(r, c)
set i = i + 1
endloop
endfunction
private function init takes nothing returns nothing
set LocalPlayerId = GetPlayerId(GetLocalPlayer())
call BJDebugMsg("Resolution = " + I2S(UIUtils.ResolutionWidth) + "x" + I2S(UIUtils.ResolutionHeight))
call TimerStart(CreateTimer(), 0, false, function createFrame)
endfunction
endscope
scope UpdateHealthbar initializer init
globals
unit array Foo
endglobals
private function update takes nothing returns nothing
set healthbarFrame.value = GetUnitState(Foo[LocalPlayerId], UNIT_STATE_LIFE)/GetUnitState(Foo[LocalPlayerId], UNIT_STATE_MAX_LIFE)
endfunction
private function init takes nothing returns nothing
set Foo[0] = gg_unit_hfoo_0004
set Foo[1] = gg_unit_hfoo_0002
set Foo[2] = gg_unit_hfoo_0005
call TimerStart(CreateTimer(), 0.1, true, function update)
endfunction
endscope
scope InventoryScaleSlider initializer init
globals
private UIFrame Scaler
private UIFrame StepSizer
endglobals
private function FrameEvent takes nothing returns boolean
local frameeventtype eventType = BlzGetTriggerFrameEvent()
if eventType == FRAMEEVENT_SLIDER_VALUE_CHANGED then
if UIFrame.TriggerComponent == Scaler then
set inventoryFrame.localScale = Scaler.value
call inventoryFrame.refresh()
else
set Scaler.stepSize = StepSizer.value
endif
endif
return false
endfunction
private function init2 takes nothing returns nothing
local UIFrame info
set Scaler = UIFrame.create(false, UIFrame.TYPE_H_SLIDER, inventoryFrame, 0.0, -15.0, 0)
set Scaler.name = "Inventory Scale Slider"
set Scaler.value = 1.0
set Scaler.onAnyEvent = function FrameEvent
call Scaler.setAnchorPoint(1.0, 0.0) // Bottom right
call Scaler.setPivotPoint(1.0, 1.0) // Top right
call Scaler.setMinMaxValue(0.5, 1.0)
call Scaler.refresh()
set info = UIFrame.create(true, UIFrame.TYPE_SIMPLE_TEXT, Scaler, 0.0, 0.0, 1)
set info.name = "Info Text"
set info.text = "|cffffcc00Inventory scale:|r"
call info.setAnchorPoint(0.0, 0.5) // Left
call info.setPivotPoint(1.0, 0.5) // Right
call info.setSize(175.0, 64.0)
call info.setTextAlignment(TEXT_JUSTIFY_RIGHT, TEXT_JUSTIFY_MIDDLE)
call info.refresh()
set StepSizer = UIFrame.create(false, UIFrame.TYPE_H_SLIDER, Scaler, 0, -15.0, 0)
set StepSizer.name = "Inventory Step Size Slider"
set StepSizer.onAnyEvent = function FrameEvent
call StepSizer.setAnchorPoint(1.0, 0.0) // Bottom right
call StepSizer.setPivotPoint(1.0, 0.5) // Right
call StepSizer.setMinMaxValue(0.0, 0.5)
call StepSizer.refresh()
set info = UIFrame.create(true, UIFrame.TYPE_SIMPLE_TEXT, StepSizer, 0.0, 0.0, 1)
set info.name = "Info Text"
set info.text = "|cffffcc00Step size:|r"
call info.setAnchorPoint(0.0, 0.5) // Left
call info.setPivotPoint(1.0, 0.5) // Right
call info.setSize(175.0, 64.0)
call info.setTextAlignment(TEXT_JUSTIFY_RIGHT, TEXT_JUSTIFY_MIDDLE)
call info.refresh()
endfunction
private function init takes nothing returns nothing
call TimerStart(CreateTimer(), 0.25, false, function init2)
endfunction
endscope
scope RadarDemo initializer init
globals
private UIFrame VLine
private UIFrame HLine
private real dltX
private real minX
private real dltY
private real minY
private unit array MT
endglobals
private function FrameEvent takes nothing returns boolean
local frameeventtype eventType = BlzGetTriggerFrameEvent()
if eventType == FRAMEEVENT_SLIDER_VALUE_CHANGED then
if UIFrame.TriggerComponent == testSliderV then
call HLine.move(0.0, testSliderV.height*testSliderV.value)
call HLine.refresh()
else
call VLine.move(testSliderH.width*testSliderH.value, 0.0)
call VLine.refresh()
endif
elseif eventType == FRAMEEVENT_CONTROL_CLICK then
call IssuePointOrder(MT[GetPlayerId(GetTriggerPlayer())], "attackground", minX+dltX*testSliderH.value, minY+dltY*testSliderV.value)
endif
return false
endfunction
private function init2 takes nothing returns nothing
local UIFrame frame
local UIFrame btn
// Create background
set frame = UIFrame.create(false, UIFrame.TYPE_SIMPLE_TEXTURE, UIFrame.Null, -5, testSliderH.screenPosY+15, 0)
set frame.name = "HVSlider Demo Background"
set frame.texture = "Replaceabletextures\\Teamcolor\\Teamcolor10.blp"
set frame.opacity = 128
call frame.setAnchorPoint(0.5, 0.0) // Bottom
call frame.setPivotPoint(0.5, 0.0) // Bottom
call frame.setSize(testSliderH.width, testSliderV.height)
call frame.refresh()
// Create vertical line
set VLine = UIFrame.create(false, UIFrame.TYPE_SIMPLE_TEXTURE, frame, 0.0, 0.0, 1)
set VLine.name = "HVSlider Demo VLine"
set VLine.texture = "Textures\\white.blp"
call VLine.setSize(1, testSliderV.height)
call VLine.refresh()
// Create horizontal line
set HLine = UIFrame.create(false, UIFrame.TYPE_SIMPLE_TEXTURE, frame, 0.0, 0.0, 1)
set HLine.name = "HVSlider Demo HLine"
set HLine.texture = "Textures\\white.blp"
call HLine.setSize(testSliderH.width, 1)
call HLine.refresh()
// Create attack button
set btn = UIFrame.create(false, UIFrame.TYPE_BUTTON, UIFrame.Null, testSliderH.width / 2, 100, 0)
set btn.name = "HVSlider Launch Button"
set btn.texture = "ReplaceableTextures\\CommandButtons\\BTNAttackGround.blp"
set btn.onAnyEvent = function FrameEvent
call btn.setAnchorPoint(0.5, 0.0) // Bottom
call btn.setPivotPoint(0.0, 1.0) // Top left
call btn.setSize(32.0, 32.0)
call btn.refresh()
// Register slider events
set testSliderH.onAnyEvent = function FrameEvent
set testSliderV.onAnyEvent = function FrameEvent
endfunction
private function init takes nothing returns nothing
set minX = GetRectMinX(bj_mapInitialPlayableArea)
set minY = GetRectMinY(bj_mapInitialPlayableArea)
set dltX = GetRectMaxX(bj_mapInitialPlayableArea)-minX
set dltY = GetRectMaxY(bj_mapInitialPlayableArea)-minY
set MT[0] = gg_unit_hmtm_0016
set MT[1] = gg_unit_hmtm_0017
set MT[2] = gg_unit_hmtm_0018
call TimerStart(CreateTimer(), 0.1, false, function init2)
endfunction
endscope
// This is an example of how to put command buttons to the center of screen
function modify takes nothing returns nothing
local integer i = 0
local integer count = 0
local real width = 49.0
local real x
local real y = 15.0*UIUtils.PXTODPI
loop
exitwhen i > 11
if BlzFrameIsVisible(DefaultFrame.CommandButton[i]) then
set count = count + 1
endif
set i = i + 1
endloop
set x = UIUtils.ResolutionWidth*0.5-(width+5.0)*(count-1)*0.5
set i = 0
loop
exitwhen i > 11
if BlzFrameIsVisible(DefaultFrame.CommandButton[i]) then
call BlzFrameClearAllPoints(DefaultFrame.CommandButton[i])
call BlzFrameSetAbsPoint(DefaultFrame.CommandButton[i], FRAMEPOINT_BOTTOM, UIUtils.GetScreenPosX(x), y)
set x = x + width + 5.0
endif
set i = i + 1
endloop
endfunction
function InitTrig_ModifyOriginFrameExample takes nothing returns nothing
set gg_trg_ModifyOriginFrameExample = CreateTrigger( )
call TriggerRegisterPlayerSelectionEventBJ( gg_trg_ModifyOriginFrameExample, Player(0), true )
call TriggerRegisterPlayerSelectionEventBJ( gg_trg_ModifyOriginFrameExample, Player(1), true )
call TriggerRegisterPlayerSelectionEventBJ( gg_trg_ModifyOriginFrameExample, Player(2), true )
call TriggerAddAction( gg_trg_ModifyOriginFrameExample, function modify )
endfunction
scope AddMessageFrame initializer init
globals
private UIFrame f
endglobals
// On resolution update
private function onResChange takes nothing returns boolean
// Refresh background points
call BlzFrameSetAllPoints(f.frame, DefaultFrame.UnitMsg)
call BJDebugMsg("Resolution Change:")
call BJDebugMsg("Resolution = " + I2S(UIUtils.ResolutionWidth) + "x" + I2S(UIUtils.ResolutionHeight))
return false
endfunction
private function init takes nothing returns nothing
// Add semi transparent background to the message frame
set f = UIFrame.create(false, UIFrame.TYPE_SIMPLE_TEXTURE, UIFrame.Null, 0, 0, 0)
set f.name = "Template Texture"
set f.texture = "Textures\\black32.blp"
set f.opacity = 128
call BlzFrameSetAllPoints(f.frame, DefaultFrame.UnitMsg)
call UIUtils.RegisterOnResolutionChangeEvent(function onResChange)
endfunction
endscope