package Framehandle import NoWurst import Player import Vectors import Colors import ErrorHandling /* Custom frames can be defined in a frame definition file (*.fdf). These files need to be listed inside of a toc file and loaded using loadTOCFile() to be used. The toc file *must* always have an empty line at the end. Default .fdf files can be found in: war3.w3mod:ui\framedef\ui\ war3.w3mod:ui\framedef\glue\ Positioning: All frames are placed on the screen in a 4:3 box. (0, 0) is BOTTOM-LEFT corner of the box and (0.8, 0.6) is TOP-RIGHT corner of the box. Currently, there are exceptions. ORIGIN_FRAME_WORLD_FRAME and ORIGIN_FRAME_PORTRAIT are placed on the whole screen so they can go beyond the box' borders. This behaviour affects the frames' size as well. Keep it in mind, if the screen ratio is not 4:3, placing and sizing of ORIGIN_FRAME_WORLD_FRAME and ORIGIN_FRAME_PORTRAIT will not match other frames. Synch notes: A frame uses the default handlepool - it must not be created locally. All frameeventtype are synced events. If a player presses a button, the associated event will fire for all players. However, the frame's states are not synced; i.e you can change the text, value, position, visibility or state locally. *IMPORTANT:* Always get the framehandle outside of the local scope originframetype notes: ORIGIN_FRAME_GAME_UI --> Main parent frame ORIGIN_FRAME_WORLD_FRAME --> The game is displayed on this frame. ORIGIN_FRAME_HERO_BAR --> Parent of all HERO_BUTTONS, HeroButons share the same visiblity. ORIGIN_FRAME_HERO_BUTTON [0 to 6] --> The buttons of own/allied heroes on the left of the screen ORIGIN_FRAME_HERO_HP_BAR, ORIGIN_FRAME_HERO_MANA_BAR ORIGIN_FRAME_HERO_BUTTON_INDICATOR --> The glowing when a hero has skillpoints; They reappear when a hero gains a new skillpoint even if all originframes are hidden. ORIGIN_FRAME_ITEM_BUTTON [0 to 5] --> Items in the inventory. Reappear on unit's selection even if all originframes are hidden (when the parent's parent is shown) ORIGIN_FRAME_COMMAND_BUTTON [0 to 11] --> Buttons of the the command board. 0 is the (0,0) button, 11 is the (3,2) one. Reappear on unit's selection even if all originframes are hidden ORIGIN_FRAME_SYSTEM_BUTTON [0 to 3] --> Menu, allies, log, quest. ORIGIN_FRAME_PORTRAIT --> Portrait of the selected unit (this frame is not on the 4:3 screen but on the whole screen) ORIGIN_FRAME_MINIMAP ORIGIN_FRAME_MINIMAP_BUTTON [0 to 4] --> 0 is the button at top, 4 the one at the bottom. ORIGIN_FRAME_TOOLTIP ORIGIN_FRAME_UBERTOOLTIP --> Frame of the game's tooltips ORIGIN_FRAME_CHAT_MSG --> Frame of the game's messages (e.g. from DisplayTextToPlayer()) ORIGIN_FRAME_UNIT_MSG --> Frame of the UpKeep change warning message, below the clock */ public constant GAME_UI = BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0) public constant WORLD_UI = BlzGetOriginFrame(ORIGIN_FRAME_WORLD_FRAME, 0) public constant SCREEN_CENTER = vec2(0.4, 0.3) public constant SCREEN_TOPRIGHT = vec2(0.8, 0.6) public constant SCREEN_TOPLEFT = vec2(0.0, 0.6) public constant SCREEN_BOTTOMRIGHT = vec2(0.8, 0.0) public constant SCREEN_BOTTOMLEFT = vec2(0.0, 0.0) public constant SCREEN_RIGHT = vec2(0.8, 0.3) public constant SCREEN_LEFT = vec2(0.0, 0.3) public constant SCREEN_TOP = vec2(0.4, 0.6) public constant SCREEN_BOTTOM = vec2(0.4, 0.0) // These defines represent the whole 16:9 screen size. Only Frames of type 'SIMPLE' can be moved here. public constant WHOLE_SCREEN_TOPRIGHT = vec2( 0.95, 0.6) public constant WHOLE_SCREEN_TOPLEFT = vec2(-0.15, 0.6) public constant WHOLE_SCREEN_BOTTOMRIGHT = vec2( 0.95, 0.0) public constant WHOLE_SCREEN_BOTTOMLEFT = vec2(-0.15, 0.0) public constant WHOLE_SCREEN_RIGHT = vec2( 0.95, 0.3) public constant WHOLE_SCREEN_LEFT = vec2(-0.15, 0.3) public constant WHOLE_SCREEN_TOP = SCREEN_TOP public constant WHOLE_SCREEN_BOTTOM = SCREEN_BOTTOM constant BLZ_FRAMENAME_MAXLENGTH = 560 /** Returns whether the frame name length is valid or not */ function verifyFrameNameLength(string name) returns boolean if name.length() > BLZ_FRAMENAME_MAXLENGTH error("Trying to address frame with exceeding maximum frame name length (" + BLZ_FRAMENAME_MAXLENGTH.toString() + ") for: " + name) return false return true /** Returns the orgin frame of the given type */ public function getOriginFrame(originframetype frameType) returns framehandle return BlzGetOriginFrame(frameType, 0) /** Returns the orgin frame of the given type and index */ public function getOriginFrame(originframetype frameType, integer index) returns framehandle return BlzGetOriginFrame(frameType, index) /** Returns the framehandle of the given name and createContext index (children inherit the createContext value of their parent) */ public function getFrame(string name, integer createContext) returns framehandle verifyFrameNameLength(name) return BlzGetFrameByName(name, createContext) /** Returns the framehandle of the given name */ public function getFrame(string name) returns framehandle verifyFrameNameLength(name) return getFrame(name, 0) /** Creates a non simple frame of the given name (the name of the frame which must be defined in the imported fdf files) */ public function createFrame(string name) returns framehandle verifyFrameNameLength(name) return createFrame(name, GAME_UI, 0, 0) /** Creates a non simple frame: name: the name of the frame which must be defined in the imported fdf files. owner: the parent of the frame priority: unknown createContext: the unique id assigned to the frame and its children (useful for creating multiple frames of the same name) */ public function createFrame(string name, framehandle owner, integer priority, integer createContext) returns framehandle verifyFrameNameLength(name) return BlzCreateFrame(name, owner, priority, createContext) /** Creates a simple frame of the given name (the name of the frame which must be defined in the imported fdf files.) */ public function createSimpleFrame(string name) returns framehandle verifyFrameNameLength(name) return BlzCreateSimpleFrame(name, GAME_UI, 0) /** Creates a simple frame: name: the name of the frame which must be defined in the imported fdf files. owner: the parent of the frame createContext: the unique id assigned to the frame and its children (useful for creating multiple frames of the same name) */ public function createSimpleFrame(string name, framehandle owner, integer createContext) returns framehandle verifyFrameNameLength(name) return BlzCreateSimpleFrame(name, owner, createContext) /** Creates a frame by type: typeName: the name of the type (e.g. "SIMPLEFRAME", "MENU", "BUTTON") name: the name of the created frame owner: the parent of the frame inherits: the name of the frame frome which the created frame will be inhereting (which must be defined in the imported .fdf files) createContext: the unique id assigned to the frame and its children (useful for creating multiple frames of the same name) */ public function createFrame(string typeName, string name, framehandle owner, string inherits, integer createContext) returns framehandle verifyFrameNameLength(name) return BlzCreateFrameByType(typeName, name, owner, inherits, createContext) /** Removes a frame */ public function framehandle.remove() BlzDestroyFrame(this) /** Places the frame at the center of the screen */ public function framehandle.setCenter() BlzFrameSetAbsPoint(this, FRAMEPOINT_CENTER, SCREEN_CENTER.x, SCREEN_CENTER.y) /** Sets the frame position to an absolute x, y point on the screen. For the the x-axis, the value is between 0 and 0.8 For the the y-axis, the value is between 0 and 0.6 */ public function framehandle.setAbsPoint(framepointtype point, real x, real y) BlzFrameSetAbsPoint(this, point, x, y) /** Sets the frame position to an absolute x, y point on the screen. For the the x-axis, the value is between 0 and 0.8 For the the y-axis, the value is between 0 and 0.6 */ public function framehandle.setAbsPoint(framepointtype point, vec2 pos) BlzFrameSetAbsPoint(this, point, pos.x, pos.y) /** Sets the frame's anchor point position to the one of the given frame's anchor */ public function framehandle.setPoint(framepointtype point, framehandle relative, framepointtype relativePoint) BlzFrameSetPoint(this, point, relative, relativePoint, 0, 0) /** Sets the frame's anchor point position to the one of the given frame's anchor with an offset */ public function framehandle.setPoint(framepointtype point, framehandle relative, framepointtype relativePoint, vec2 offset) BlzFrameSetPoint(this, point, relative, relativePoint, offset.x, offset.y) /** Sets the frame's anchor point position to the one of the given frame's anchor with an offset */ public function framehandle.setPoint(framepointtype point, framehandle relative, framepointtype relativePoint, real offsetX, real offsetY) BlzFrameSetPoint(this, point, relative, relativePoint, offsetX, offsetY) /** Frees the frame from any relative or absolute anchor points */ public function framehandle.clearAllPoints() BlzFrameClearAllPoints(this) /** Copy all the anchor points of the given frame */ public function framehandle.setAllPoints(framehandle relative) BlzFrameSetAllPoints(this, relative) /** Shows or hides the frame */ public function framehandle.setVisible(bool flag) BlzFrameSetVisible(this, flag) /** Shows or hides the frame to the given player */ public function framehandle.setVisible(player p, bool flag) if localPlayer == p or p == null this.setVisible(flag) /** Shows the frame */ public function framehandle.show() this.setVisible(true) /** Shows the frame to the specific player */ public function framehandle.show(player p) this.setVisible(p, true) /** Hides the frame */ public function framehandle.hide() this.setVisible(false) /** Hides the frame to the specific player */ public function framehandle.hide(player p) this.setVisible(p, false) /** Returns whether the frame is visible or not */ public function framehandle.isVisible() returns bool return BlzFrameIsVisible(this) /** Returns whether the frame is visible or not for given player */ public function framehandle.isVisible(player p) returns boolean return localPlayer == p or p == null ? this.isVisible() : false /** Returns the frame's name */ public function framehandle.getName() returns string return BlzFrameGetName(this) /** Fires a click a event on the frame */ public function framehandle.click() BlzFrameClick(this) /** Returns the text value of the text frame */ public function framehandle.getText() returns string return BlzFrameGetText(this) /** Sets the text value of the text frame */ public function framehandle.setText(string text) BlzFrameSetText(this, text) /** Sets the text value of the text frame for the specific player*/ public function framehandle.setText(player p, string text) if localPlayer == p or p == null this.setText(text) /** Returns the maximum allowed text size of the text frame */ public function framehandle.getTextSizeLimit() returns integer return BlzFrameGetTextSizeLimit(this) /** Sets the maximum allowed text size of the text frame */ public function framehandle.setTextSizeLimit(integer size) BlzFrameSetTextSizeLimit(this, size) /** Sets the text color of the text frame */ public function framehandle.setTextColor(colorA color) BlzFrameSetTextColor(this, BlzConvertColor(color.alpha, color.red, color.green, color.blue)) /** Sets the text color of the text frame */ public function framehandle.setTextColor(integer color) BlzFrameSetTextColor(this, color) /** Enables or disables the user interaction for the frame */ public function framehandle.setFocus(bool flag) BlzFrameSetFocus(this, flag) /** Enables or disables the user interaction for the frame for given player */ public function framehandle.setFocus(player p, bool flag) if localPlayer == p or p == null this.setFocus(flag) /** Removes the focus from a given frame by disable and instantly enabling it. Mandatory for Frames of type 'SIMPLE' */ public function framehandle.unfocus() if this.isEnabled() this.disable() this.enable() else this.enable() this.disable() this.setFocus(false) /** Removes the focus from a given frame by disable and instantly enabling it for given player. Mandatory for Frames of type 'SIMPLE' */ public function framehandle.unfocus(player p) if this.isEnabled(p) this.disable(p) this.enable(p) else this.enable(p) this.disable(p) this.setFocus(p, false) /** Sets the model of the model frame */ public function framehandle.setModel(string modelFile, integer cameraIndex) BlzFrameSetModel(this, modelFile, cameraIndex) /** Returns the state of the frame */ public function framehandle.isEnabled() returns bool return BlzFrameGetEnable(this) /** Returns the state of the frame for given player */ public function framehandle.isEnabled(player p) returns boolean return localPlayer == p or p == null ? this.isEnabled() : false /** Enables or disables the frame */ public function framehandle.setEnabled(bool enabled) BlzFrameSetEnable(this, enabled) /** Enables the frame */ public function framehandle.enable() this.setEnabled(true) /** Disables the frame */ public function framehandle.disable() this.setEnabled(false) /** Enables the frame for the player p */ public function framehandle.enable(player p) if localPlayer == p or p == null this.enable() /** Disables the frame for the player p */ public function framehandle.disable(player p) if localPlayer == p or p == null this.disable() /** Returns the decimal alpha value of the frame (only for specific frames) */ public function framehandle.getAlpha() returns int return BlzFrameGetAlpha(this) /** Sets the decimal alpha value of the frame (only for specific frames) */ public function framehandle.setAlpha(integer alpha) BlzFrameSetAlpha(this, alpha) /** Sets the decimal alpha value of the frame (only for specific frames) to the given player */ public function framehandle.setAlpha(player p, integer alpha) if localPlayer == p or p == null this.setAlpha(alpha) /** Unknown */ public function framehandle.setSpriteAnimate(integer primaryProp, integer flags) BlzFrameSetSpriteAnimate(this, primaryProp, flags) /** Sets the texture of the frame texFile: the path of the texture flags: unknown blend: true to keep transparency */ public function framehandle.setTexture(string texFile, integer flag, bool blend) BlzFrameSetTexture(this, texFile, flag, blend) /** Sets the texture of the frame for the specific player texFile: the path of the texture flags: unknown blend: true to keep transparency */ public function framehandle.setTexture(player p, string texFile, integer flag, bool blend) if localPlayer == p or p == null this.setTexture(texFile, flag, blend) /** Sets the frame's scaling value. Frame's size, children frames and relative anchor points scale */ public function framehandle.setScale(real scale) BlzFrameSetScale(this, scale) /** Sets a frame's tooltip frame, if it has some tooltip subframe */ public function framehandle.setTooltip(framehandle tooltip) BlzFrameSetTooltip(this, tooltip) /** Forces the mouse cursor to stay (caged) inside of the frame */ public function framehandle.cageMouse(bool enable) BlzFrameCageMouse(this, enable) /** Returns the specific value of the frame (e.g. for sliders) */ public function framehandle.getValue() returns real return BlzFrameGetValue(this) /** Sets the specific value of the frame (e.g. for sliders) */ public function framehandle.setValue(real value) BlzFrameSetValue(this, value) /** Sets the specific minimum and maximum value of the frame (e.g. for sliders) */ public function framehandle.setMinMax(real minValue, real maxValue) BlzFrameSetMinMaxValue(this, minValue, maxValue) /** Sets the step size of the frame (e.g. for sliders) */ public function framehandle.setStepSize(real stepSize) BlzFrameSetStepSize(this, stepSize) /** Sets the width of the frame (sets the height to its current height) */ public function framehandle.setWidth(real width) BlzFrameSetSize(this, width, this.getHeight()) /** Sets the height of the frame (sets the width to its current width) */ public function framehandle.setHeight(real height) BlzFrameSetSize(this, this.getWidth(), height) /** Sets the width and height of the frame */ public function framehandle.setSize(real width, real height) BlzFrameSetSize(this, width, height) /** Sets the vertex color of the model frame */ public function framehandle.setVertexColor(color pcolor) BlzFrameSetVertexColor(this, BlzConvertColor(255, pcolor.red, pcolor.green, pcolor.blue)) /** Sets the vertex color of the model frame */ public function framehandle.setVertexColor(colorA color) BlzFrameSetVertexColor(this, BlzConvertColor(color.alpha, color.red, color.green, color.blue)) /** Sets the vertex color of the model frame */ public function framehandle.setVertexColor(integer color) BlzFrameSetVertexColor(this, color) /** If multiple frames cover each other, the one with the highest level will receive mouse events and will be drawn above the others. If several frames have the same level, the last created one is prioritized */ public function framehandle.setLevel(integer level) BlzFrameSetLevel(this, level) /** Searches for the frames parent frame. Should be used with caution as getting the parent of any top most frame will lead into a void crash */ public function framehandle.getParent() returns framehandle return BlzFrameGetParent(this) /** Sets the parent frame of the frame */ public function framehandle.setParent(framehandle parent) BlzFrameSetParent(this, parent) /** Returns the frame's height */ public function framehandle.getHeight() returns real return BlzFrameGetHeight(this) /** Returns the frame's width */ public function framehandle.getWidth() returns real return BlzFrameGetWidth(this) /** Sets the text font of the text frame */ public function framehandle.setFont(string fileName, real height, integer flags) BlzFrameSetFont(this, fileName, height, flags) /** Set the text alignment of the text frame */ public function framehandle.setTextAlignment(textaligntype vert, textaligntype horz) BlzFrameSetTextAlignment(this, vert, horz) /** Enables or disables auto positioning of ui elements */ public function enableUIAutoPosition(bool flag) BlzEnableUIAutoPosition(flag) /** Hides or shows all origin frames except ORIGIN_FRAME_WORLD_FRAME */ public function setOriginFramesVisible(bool flag) BlzHideOriginFrames(not flag) /** Hides all origin frames except ORIGIN_FRAME_WORLD_FRAME */ public function hideOriginFrames() setOriginFramesVisible(false) /** Shows all origin frames except ORIGIN_FRAME_WORLD_FRAME */ public function showOriginFrames() setOriginFramesVisible(true) /** Loads a toc file from the given path, to include custom fdf files from, returns true on success */ public function loadTOCFile(string tocFile) returns bool return BlzLoadTOCFile(tocFile) let mouseCage = createFrame("FRAME", "SetMousePositionCage", GAME_UI, null, 0) ..setSize(0.0001, 0.0001) /** Places the mouse cursor at the given point of the screen. Uses the same coodinate system as framehandles */ public function setMousePos(vec2 pos) mouseCage..clearAllPoints() ..setPoint(FRAMEPOINT_BOTTOMLEFT, GAME_UI, FRAMEPOINT_BOTTOMLEFT, pos) ..cageMouse(true) ..cageMouse(false) /** Places the mouse cursor in the center of the frame */ public function framehandle.setMousePos() mouseCage..clearAllPoints() ..setPoint(FRAMEPOINT_CENTER, this, FRAMEPOINT_CENTER) ..cageMouse(true) ..cageMouse(false) /** Places the mouse cursor at the given point of the screen. Uses the window's coordinate system (in pixels) where (0, 0) is top-left corner of the window and positive direction of Y axis is "down" */ public function setMousePos(integer x, integer y) BlzSetMousePos(x, y) public function enableCursor() BlzEnableCursor(true) public function disableCursor() BlzEnableCursor(false) public function setCursorEnabled(bool flag) BlzEnableCursor(flag) /** Get number of children frames of given frame. Only direct child frames are counted */ public function framehandle.getChildrenCount() returns int return BlzFrameGetChildrenCount(this) /** Get child frame handle from given index */ public function framehandle.getChild(int index) returns framehandle return BlzFrameGetChild(this, index)