-
Are you planning to upload your awesome spell or system to Hive? Please review the rules here.Dismiss Notice
-
Dismiss Notice
Triumph has risen from these uncharted shores. The 34th Modeling Contest Results are out!
-
Dismiss Notice
Awaken what lies in the heart of your swarm. The 17th Techtree Contest has arrived!
-
Dismiss Notice
The Hive Workshop is launching its first HD modelling contest. How HD should it be?
-
Dismiss Notice
Check out the Staff Job Openings thread.
Dismiss Notice
Hive 3 Remoosed BETA - NOW LIVE. Go check it out at BETA Hive Workshop! Post your feedback in this new forum BETA Feedback.
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.
MyResourceField
Submitted by
Tasyen
Introduction
MyResourceField is an UI-System allowing to create ResourceFields on the screen. Out of the Box it also creates a table of Resource Fields at a point of the world Frame, that tables position row and col count can be changed. Through it is quite easy to place loose ones anywhere on the screen.
With MyResourceField you will not be able to create ResourceBars that look like the default one.
How to Install
Copy the MyResourceField Trigger-Folder into your map.
Export
MyResourceField.fdf
MyResourceField.toc
Import them into your map keeping the war3mapimported folder prefix.
MyResourceField uses "ResourceBarFrame" as parent for its SIMPLEFRAMEs. if you do not show the default ResourceBar, you have to change this parentship, Inside function MyResourceFieldInit.
The Trigger MyResourceField will update all custom created ResourceFields 5 times a second. One could disable that trigger to stop the updating.
How to write to ResourceFields
MyResourceFieldValue is an String Array. The values of the arrayMembers is displayed in the ResourceFields. That array is splited into sections, Every player uses a part of it hence one needs 2 indexes to access it.
MyResourceFieldValue[PlayerIndex * MyResourceFieldPlayerSize() + resourceField Creation Index]
MyResourceFieldPlayerSize() is in the jass code at the top a function on default 100.
To write onto field 1 for player red one would have to write onto MyResourceFieldValue[101] cause Reds section starts at 100 and the first Field is 1; 100 + 1 = 101.
In this setting one can have maximum 100 custom Fields, if one wants more one needs to increase the value MyResourceFieldPlayerSize() returns and fit your MyResourceFieldValue access acording to that.
GUI Examples
This GUI Trigger changes the shown-data for a player killing an unit.
-
MyResourceField Change data
-
Events
-
Unit - A unit Dies
-
-
Conditions
-
Actions
-
-------- Player part of the array --------
-
-------- 100 should be the number choosen in function MyResourceFieldPlayerSize --------
-
Set PlayerIndex = (100 x (Player number of (Owner of (Killing unit))))
-
Set MyResourceFieldValue[(PlayerIndex + 1)] = (String(((Owner of (Killing unit)) Units Killed)))
-
Set MyResourceFieldValue[(PlayerIndex + 2)] = (String(((Owner of (Killing unit)) Heroes Killed)))
-
Set MyResourceFieldValue[(PlayerIndex + 3)] = (String(((Owner of (Killing unit)) Structures Razed)))
-
Set MyResourceFieldValue[(PlayerIndex + 4)] = (String(((Owner of (Killing unit)) Items Gained)))
-
Set MyResourceFieldValue[(PlayerIndex + 5)] = |cff6f2583I|r|cffff0000V|r
-
Set MyResourceFieldValue[(PlayerIndex + 6)] = 100%
-
Set MyResourceFieldValue[(PlayerIndex + 7)] = 523/893
-
Set MyResourceFieldValue[(PlayerIndex + 8)] = IIIII
-
-
-
This Trigger creates 3 loose ResourceFields somewhere on the screen. The coordinates are absolute and one should look into [JASS/AI] - UI: Positionate Frames when using this.
-
MyReosurceField CreateFreeOnes
-
Events
-
Time - Elapsed game time is 0.01 seconds
-
-
Conditions
-
Actions
-
-------- This Trigger should happen after 0.00s, to avoid colliding with the autogenerated fields. --------
-
-------- Set the X andY then run CreateFree to generate a ResourceField with its Bottom Left at that abs point --------
-
Set MyResourceFieldFreeX = 0.40
-
Set MyResourceFieldFreeY = 0.30
-
Trigger - Run MyResourceFieldCreateFree (ignoring conditions)
-
Set MyResourceFieldFreeX = 0.50
-
Set MyResourceFieldFreeY = 0.40
-
Trigger - Run MyResourceFieldCreateFree (ignoring conditions)
-
Set MyResourceFieldFreeX = 0.30
-
Set MyResourceFieldFreeY = 0.30
-
Trigger - Run MyResourceFieldCreateFree (ignoring conditions)
-
-
-
In this Init Trigger one defines Icons and Tooltips for MyResourceFields. MyResourceField supports chaninging Icons and tooltips during the game. As it also supports player specific Icons Tooltips. At the end of this trigger an example is shown Resource Filed 1 will show a claw for Player Red.
-
MyResourceFieldInit
-
Events
-
Map initialization
-
-
Conditions
-
Actions
-
-------- Icons of Custom Resource Fields --------
-
Set MyResourceFieldIcons[1] = ReplaceableTextures\CommandButtons\BTNSteelMelee.blp
-
Set MyResourceFieldIcons[2] = ReplaceableTextures\CommandButtons\BTNHumanArmorUpOne.blp
-
Set MyResourceFieldIcons[3] = ReplaceableTextures\CommandButtons\BTNPriestAdept.blp
-
Set MyResourceFieldIcons[4] = ReplaceableTextures\CommandButtons\BTNSorceressAdept.blp
-
Set MyResourceFieldIcons[5] = ReplaceableTextures\CommandButtons\BTNOrcMeleeUpOne.blp
-
Set MyResourceFieldIcons[6] = ReplaceableTextures\CommandButtons\BTNSteelArmor.blp
-
Set MyResourceFieldIcons[7] = ReplaceableTextures\CommandButtons\BTNLiquidFire.blp
-
Set MyResourceFieldIcons[8] = ReplaceableTextures\CommandButtons\BTNEnsnare.blp
-
-------- Tooltips --------
-
Set MyResourceFieldTooltipTitle[1] = Swords
-
Set MyResourceFieldTooltipTitle[2] = Shields
-
Set MyResourceFieldTooltipTitle[3] = Wands
-
Set MyResourceFieldTooltipTitle[4] = Books
-
Set MyResourceFieldTooltipText[1] = Swords are gained frequently by smiths
-
Set MyResourceFieldTooltipText[2] = Shields are needed by tanks
-
Set MyResourceFieldTooltipText[3] = Wands give spell dmg
-
Set MyResourceFieldTooltipText[4] = Books are requiered by Spellcasters
-
Set MyResourceFieldTooltipTitle[5] = Axes
-
Set MyResourceFieldTooltipTitle[6] = Bucklers
-
Set MyResourceFieldTooltipTitle[7] = Fire Bombs
-
Set MyResourceFieldTooltipTitle[8] = Nets
-
Set MyResourceFieldTooltipText[5] = Axes can hurt
-
Set MyResourceFieldTooltipText[6] = Not as heavy as shields
-
Set MyResourceFieldTooltipText[7] = Nice aoe damge
-
Set MyResourceFieldTooltipText[8] = No one wil escape our riders
-
-------- One could define player specific Icons and Tooltips by using an offset 100 * Number of Player (Red uses 1) --------
-
-------- The 100 is the playerArraySize, it should match MyResourceFieldPlayerSize() --------
-
-------- The next Line would Let player Red have unique Icon and tooltips for Resource 1 --------
-
Set MyResourceFieldIcons[101] = ReplaceableTextures\CommandButtons\BTNCreatureAttack.blp
-
Set MyResourceFieldTooltipTitle[101] = Claws
-
Set MyResourceFieldTooltipText[101] = Claws are found by creatures
-
-------- Default values for all Players. --------
-
-------- Without default values the ResourceFields will show no text. --------
-
Player Group - Pick every player in (All players) and do (Actions)
-
Loop - Actions
-
Set PlayerIndex = (100 x (Player number of (Picked player)))
-
For each (Integer A) from 1 to 8, do (Actions)
-
Loop - Actions
-
Set MyResourceFieldValue[(PlayerIndex + (Integer A))] = 0
-
-
-
-
-
-
-
-
When selecting Blutmagier show all for player red.
-
MyReosurceField CustomHiding Select
-
Events
-
Player - Player 1 (Red) Selects a unit
-
-
Conditions
-
(Triggering unit) Equal to Blutmagier 0000 <gen>
-
-
Actions
-
Set PlayerIndex = (100 x (Player number of (Triggering player)))
-
-------- Should all CustomResources be hidden for that player? --------
-
Set MyResourceFieldHideData[(Player number of (Triggering player))] = False
-
-------- hide ResourceField 1 for that player? --------
-
Set MyResourceFieldHideData[(PlayerIndex + 1)] = False
-
Trigger - Run MyResourceFieldHideTrigger (ignoring conditions)
-
-
When deselecting Blutmagier hide field 1 for player red.
-
MyReosurceField CustomHiding Deselect
-
Events
-
Player - Player 1 (Red) Deselects a unit
-
-
Conditions
-
(Triggering unit) Equal to Blutmagier 0000 <gen>
-
-
Actions
-
Set PlayerIndex = (100 x (Player number of (Triggering player)))
-
-------- Should all CustomResources be hidden for that player? --------
-
Set MyResourceFieldHideData[(Player number of (Triggering player))] = False
-
-------- hide ResourceField 1 for that player? --------
-
Set MyResourceFieldHideData[(PlayerIndex + 1)] = True
-
Trigger - Run MyResourceFieldHideTrigger (ignoring conditions)
-
-
-
-
MyResourceField Custom Tooltip Size
-
Events
-
Time - Elapsed game time is 1.00 seconds
-
-
Conditions
-
Actions
-
-------- Change the size of the TooltipBox of MyResourceField 1 to that value --------
-
Custom script: call BlzFrameSetSize(BlzGetFrameByName("MyResourceFieldBoxedText", 1), 0.285, 0.0365)
-
-
-
Definitions inside the jass code. They define some default behaviour.
Code (vJASS):
function MyResourceFieldPlayerSize takes nothing returns integer
return 100 //the array is splited into sections of size 100. Each section is used by one player. Player Red uses 101 to 200. Blue Takes 201 to 300, allows to have 100 MyResourceFields.
endfunction
//Allow and Pos the checkbox hidding the additional Bars.
function MyResourceFieldCreateCheckBox takes nothing returns boolean
return true //(true) create a checkbox to tooggle visiblity of the additional ResourceBarFrames
endfunction
function MyResourceFieldCheckBoxX takes nothing returns real
return 0.1 //abs point of checkbox
endfunction
function MyResourceFieldCheckBoxY takes nothing returns real
return 0.57
endfunction
function MyResourceFieldCheckBoxLabelText takes nothing returns string
return "Hide Resources"
endfunction
//Where is the tooltip of this Bars placed.
function MyResourceFieldTooltipX takes nothing returns real
return 0.8
endfunction
function MyResourceFieldTooltipY takes nothing returns real
return 0.16
endfunction
function MyResourceFieldTooltipPoint takes nothing returns framepointtype
return FRAMEPOINT_BOTTOMRIGHT //Which point of Tooltip is positionate to abs point MyResourceFieldTooltipX/MyResourceFieldTooltipY
endfunction
//Default Sizes of TooltipBoxes
//You could change a TooltipBox size after they were created with: x should be a number from 1 to udg_MyResourceFieldCount. udg_MyResourceFieldCount would be the last created.
//call BlzFrameSetSize(BlzGetFrameByName("MyResourceFieldBoxedText", x), xsize, 0)
function MyResourceFieldTooltipSizeX takes nothing returns real
return 0.285
endfunction
function MyResourceFieldAutoCreateCols takes nothing returns integer
return 3
endfunction
function MyResourceFieldAutoCreateColAddEachRow takes nothing returns integer
return 0 //rows after the first one gain this amount of cols. -values are valid
endfunction
function MyResourceFieldAutoCreateRows takes nothing returns integer
return 2 //0 or below will not create any Fields.
endfunction
function MyResourceFieldAnchor takes nothing returns framepointtype
//Poses the first Bar where in the world Frame?
//I suggest to use a y-offset when using any Bottom Point.
//return FRAMEPOINT_TOPLEFT
//return FRAMEPOINT_TOP
//return FRAMEPOINT_TOPRIGHT
//return FRAMEPOINT_BOTTOMLEFT
return FRAMEPOINT_BOTTOM
//return FRAMEPOINT_BOTTOMRIGHT
//return FRAMEPOINT_LEFT
//return FRAMEPOINT_RIGHT
//return FRAMEPOINT_CENTER
endfunction
function MyResourceFieldAnchor1OffsetX takes nothing returns real
return -0.15 //Offset the first bar by that amount from its FramePoint
endfunction
function MyResourceFieldAnchor1OffsetY takes nothing returns real
return 0.005
endfunction
function MyResourceFieldSizeX takes nothing returns real
return 0.064
endfunction
function MyResourceFieldSizeY takes nothing returns real
return 0.0218
endfunction
Lua
Code (Lua):
--MyResourceField 1.2a
--By Tasyen
do
local Settings = {}
Settings.PlayerSectionSize = 100 --the array is splited into sections of size 100. Each section is used by one . Player Red uses 101 to 200. Blue Takes 201 to 300, allows to have 100 MyResourceFields.
Settings.CreateCheckBox = true --(true) create a checkbox to tooggle visiblity of the additional ResourceBarFrames
Settings.CheckBoxX = 0.1 --abs point of checkbox
Settings.CheckBoxY = 0.57
Settings.CheckBoxText = "Hide Resources"
--Default Position of the TooltipBoxes its absolute
Settings.TooltipX = 0.8
Settings.TooltipY = 0.16
Settings.TooltipPoint = FRAMEPOINT_BOTTOMRIGHT
--Default Sizes of TooltipBoxes
Settings.TooltipSizeX = 0.285
Settings.TooltipSizeY = 0.06
--You could change a TooltipBox size after they were created with: x should be a number from 1 to udg_MyResourceFieldCount. udg_MyResourceFieldCount would be the last created.
--BlzFrameSetSize(BlzGetFrameByName("MyResourceFieldBoxedText", x), xsize, ysize)
Settings.AutoCreateCols = 3
Settings.AutoCreateRows = 2 --0 or below will not create any Fields.
Settings.AutoCreateColsAddEachRow = 0 --rows after the first one gain this amount of cols. -values are valid
--where to create the autocreated Fields, this point is relative to world Frame.
Settings.AutoCreatePoint = FRAMEPOINT_BOTTOM
--Offset from the relative point, to positionate the first autocreated field.
Settings.AutoCreatePointX = -0.15
Settings.AutoCreatePointY = 0.005
Settings.FieldSizeX = 0.064
Settings.FieldSizeY = 0.0218
--not really settings.
Settings.LastLineStart = 0 --which field to be relative to when starting a new row
local function UpdateBars()
local playerIndex
local index = 1
--share visiblity for tooltips to Resources
BlzFrameSetVisible(BlzGetFrameByName("MyResourceFieldBossF",0), BlzFrameIsVisible(BlzGetFrameByName("MyResourceFieldBossS",0)))
if Settings.CreateCheckBox then --Has checkbox enabled?
BlzFrameSetVisible(BlzGetFrameByName("MyResourceFieldCheckBox",0), not bj_cineModeAlreadyIn) --hide in cinematic
BlzFrameSetVisible(BlzGetFrameByName("MyResourceFieldCheckBoxLabel",0), not bj_cineModeAlreadyIn)
end
if not BlzFrameIsVisible(BlzGetFrameByName("SimpleReplayPanel",0)) then --not replay mode?
playerIndex = GetConvertedPlayerId(GetLocalPlayer()) * Settings.PlayerSectionSize
else
playerIndex = (R2I(BlzFrameGetValue(BlzGetFrameByName("ReplayVisionMenu",0))) + 1) * Settings.PlayerSectionSize
end
--Takes over all udg_MyResourceFieldValue data into the MyResourceFields also updates the title
--The outher Loop are the Bars, the inner Loop handles the tooltipTitle update
repeat
BlzFrameSetText(BlzGetFrameByName("MyResourceFieldText", index), udg_MyResourceFieldValue[playerIndex + index])
if udg_MyResourceFieldIcons[playerIndex + index] == "" then
BlzFrameSetTexture(BlzGetFrameByName("MyResourceFieldIcon", index), udg_MyResourceFieldIcons[index], 0 ,true)
else
BlzFrameSetTexture(BlzGetFrameByName("MyResourceFieldIcon", index), udg_MyResourceFieldIcons[playerIndex + index], 0 ,true)
end
if udg_MyResourceFieldTooltipText[playerIndex + index] == "" then
BlzFrameSetText(BlzGetFrameByName("MyResourceFieldBoxedTextValue", index), udg_MyResourceFieldTooltipText[index])
else
BlzFrameSetText(BlzGetFrameByName("MyResourceFieldBoxedTextValue", index), udg_MyResourceFieldTooltipText[playerIndex + index])
end
if udg_MyResourceFieldTooltipTitle[playerIndex + index] == "" then
BlzFrameSetText(BlzGetFrameByName("MyResourceFieldBoxedTextTitle", index), udg_MyResourceFieldTooltipTitle[index]..": "..udg_MyResourceFieldValue[playerIndex +index])
else
BlzFrameSetText(BlzGetFrameByName("MyResourceFieldBoxedTextTitle", index), udg_MyResourceFieldTooltipTitle[playerIndex + index]..": "..udg_MyResourceFieldValue[playerIndex + index])
end
index = index + 1
until index > udg_MyResourceFieldCount
end
local function CreateTooltip(targetFrameLeft, targetFrameRight, title, text, index)
local box = BlzGetFrameByName("MyResourceFieldBossF",0)
local fhHover = BlzCreateFrameByType("FRAME", "MyResourceHover", box, "", index)
local tooltipBox = BlzCreateFrame("MyResourceFieldBoxedText", box,0, index)
BlzFrameSetPoint(fhHover, FRAMEPOINT_BOTTOMLEFT, targetFrameLeft, FRAMEPOINT_BOTTOMLEFT, 0, 0)
BlzFrameSetPoint(fhHover, FRAMEPOINT_TOPRIGHT, targetFrameRight, FRAMEPOINT_TOPRIGHT, 0, 0)
BlzFrameSetTooltip(fhHover, tooltipBox)
BlzFrameSetAbsPoint(tooltipBox, Settings.TooltipPoint, Settings.TooltipX, Settings.TooltipY)
BlzFrameSetSize(tooltipBox, Settings.TooltipSizeX, Settings.TooltipSizeY)
BlzFrameSetText(BlzGetFrameByName("MyResourceFieldBoxedTextTitle", index), title)
BlzFrameSetText(BlzGetFrameByName("MyResourceFieldBoxedTextValue", index), text)
end
function CreateMyResourceFieldFree(x, y)
udg_MyResourceFieldCount = udg_MyResourceFieldCount + 1
local field = BlzCreateSimpleFrame("MyResourceField", BlzGetFrameByName("MyResourceFieldBossS",0), udg_MyResourceFieldCount)
BlzFrameSetAbsPoint(field, FRAMEPOINT_BOTTOMLEFT, x, y)
BlzFrameSetSize(field, Settings.FieldSizeX, Settings.FieldSizeY)
BlzFrameSetSize(BlzGetFrameByName("MyResourceFieldBackground", udg_MyResourceFieldCount), Settings.FieldSizeX, Settings.FieldSizeY + 0.0102)
CreateTooltip(BlzGetFrameByName("MyResourceFieldIcon", udg_MyResourceFieldCount), BlzGetFrameByName("MyResourceFieldText", udg_MyResourceFieldCount), udg_MyResourceFieldTooltipTitle[udg_MyResourceFieldCount], udg_MyResourceFieldTooltipText[udg_MyResourceFieldCount], udg_MyResourceFieldCount)
end
function CreateMyResourceField(newLine)
udg_MyResourceFieldCount = udg_MyResourceFieldCount + 1
local field = BlzCreateSimpleFrame("MyResourceField", BlzGetFrameByName("MyResourceFieldBossS",0), udg_MyResourceFieldCount)
if udg_MyResourceFieldCount == 1 then --if this is the first create one Pos it below the default one
BlzFrameSetPoint(field, Settings.AutoCreatePoint, BlzGetOriginFrame(ORIGIN_FRAME_WORLD_FRAME,0), Settings.AutoCreatePoint, Settings.AutoCreatePointX, Settings.AutoCreatePointY)
Settings.LastLineStart = 1
else
if not newLine then
if Settings.AutoCreatePoint == FRAMEPOINT_BOTTOMLEFT or Settings.AutoCreatePoint == FRAMEPOINT_TOPLEFT or Settings.AutoCreatePoint == FRAMEPOINT_LEFT or Settings.AutoCreatePoint == FRAMEPOINT_TOP or Settings.AutoCreatePoint == FRAMEPOINT_BOTTOM then
BlzFrameSetPoint(field, FRAMEPOINT_TOPLEFT, BlzGetFrameByName("MyResourceField", udg_MyResourceFieldCount - 1), FRAMEPOINT_TOPRIGHT, 0, 0)
elseif Settings.AutoCreatePoint == FRAMEPOINT_BOTTOMRIGHT or Settings.AutoCreatePoint == FRAMEPOINT_RIGHT or Settings.AutoCreatePoint == FRAMEPOINT_TOPRIGHT then
BlzFrameSetPoint(field, FRAMEPOINT_TOPRIGHT, BlzGetFrameByName("MyResourceField", udg_MyResourceFieldCount - 1), FRAMEPOINT_TOPLEFT, 0, 0)
else
BlzFrameSetPoint(field, FRAMEPOINT_TOPRIGHT, BlzGetFrameByName("MyResourceField", udg_MyResourceFieldCount - 1), FRAMEPOINT_TOPLEFT, 0, 0)
end
else
if Settings.AutoCreatePoint == FRAMEPOINT_TOPRIGHT or Settings.AutoCreatePoint == FRAMEPOINT_TOPLEFT or Settings.AutoCreatePoint == FRAMEPOINT_LEFT or Settings.AutoCreatePoint == FRAMEPOINT_TOP or Settings.AutoCreatePoint == FRAMEPOINT_RIGHT or Settings.AutoCreatePoint == FRAMEPOINT_CENTER then
BlzFrameSetPoint(field, FRAMEPOINT_TOPLEFT, BlzGetFrameByName("MyResourceField", Settings.LastLineStart), FRAMEPOINT_BOTTOMLEFT, 0, 0)
else
BlzFrameSetPoint(field, FRAMEPOINT_BOTTOMLEFT, BlzGetFrameByName("MyResourceField", Settings.LastLineStart), FRAMEPOINT_TOPLEFT, 0, 0)
end
Settings.LastLineStart = udg_MyResourceFieldCount
end
end
BlzFrameSetSize(field, Settings.FieldSizeX, Settings.FieldSizeY)
BlzFrameSetSize(BlzGetFrameByName("MyResourceFieldBackground", udg_MyResourceFieldCount), Settings.FieldSizeX, Settings.FieldSizeY + 0.0102)
CreateTooltip(BlzGetFrameByName("MyResourceFieldIcon", udg_MyResourceFieldCount), BlzGetFrameByName("MyResourceFieldText", udg_MyResourceFieldCount), udg_MyResourceFieldTooltipTitle[udg_MyResourceFieldCount], udg_MyResourceFieldTooltipText[udg_MyResourceFieldCount], udg_MyResourceFieldCount)
end
local function CustomHide()
local index = udg_MyResourceFieldCount
local playerIndex
local playerId
if not BlzFrameIsVisible(BlzGetFrameByName("SimpleReplayPanel",0)) then --not Replay Mode?
playerId = GetConvertedPlayerId(GetLocalPlayer())
else
playerId = R2I(BlzFrameGetValue(BlzGetFrameByName("ReplayVisionMenu",0))) + 1 --Replay Mode use the observed
end
playerIndex = playerId * Settings.PlayerSectionSize
--Wana hide all, yes -> hide the parent?
BlzFrameSetVisible(BlzGetFrameByName("MyResourceFieldBossSBest",0), not udg_MyResourceFieldHideData[playerId])
--Hide Specific Fields for that .
repeat
BlzFrameSetVisible(BlzGetFrameByName("MyResourceField", index), not udg_MyResourceFieldHideData[playerIndex + index])
BlzFrameSetVisible(BlzGetFrameByName("MyResourceHover", index), not udg_MyResourceFieldHideData[playerIndex + index])
index = index -1
until index == 0
end
local function CreateCheckBoxFunction()
local trig = CreateTrigger()
local fh = BlzCreateFrameByType("GLUECHECKBOX", "MyResourceFieldCheckBox", BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0),"QuestCheckBox",0)
local fhText = BlzCreateFrameByType("TEXT", "MyResourceFieldCheckBoxLabel", fh, "", 0)
BlzFrameSetAbsPoint(fh, FRAMEPOINT_TOPLEFT, Settings.CheckBoxX, Settings.CheckBoxY)
BlzFrameSetPoint(fhText, FRAMEPOINT_TOP, fh, FRAMEPOINT_BOTTOM, 0.0, 0.0)
BlzFrameSetEnable(fhText, false)
BlzFrameSetText(fhText, Settings.CheckBoxText)
BlzTriggerRegisterFrameEvent(trig, fh, FRAMEEVENT_CHECKBOX_CHECKED)
BlzTriggerRegisterFrameEvent(trig, fh, FRAMEEVENT_CHECKBOX_UNCHECKED)
TriggerAddAction(trig, function()
if GetTriggerPlayer() == GetLocalPlayer() then --only do something for the having pressed the checkbox
BlzFrameSetVisible(BlzGetFrameByName("MyResourceFieldBossF",0), BlzGetTriggerFrameEvent() == FRAMEEVENT_CHECKBOX_UNCHECKED)
BlzFrameSetVisible(BlzGetFrameByName("MyResourceFieldBossS",0), BlzGetTriggerFrameEvent() == FRAMEEVENT_CHECKBOX_UNCHECKED)
end
end
)
end
function MyResourceFieldInit()
BlzLoadTOCFile("war3mapImported\\MyResourceField.toc")
BlzCreateFrameByType("FRAME", "MyResourceFieldBossF", BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0),"",0) --Parent of Frames (tooltips stuff)
BlzCreateFrameByType("SIMPLEFRAME", "MyResourceFieldBossSBest", BlzGetFrameByName("ResourceBarFrame",0),"",0) --Upper Parent of the SimpleFrames it is used for the Hide Feature.
BlzCreateFrameByType("SIMPLEFRAME", "MyResourceFieldBossS", BlzGetFrameByName("MyResourceFieldBossSBest",0),"",0) --Parent of SimpleFrames (bar and its content)
--Transform the setup Trigger into updating the bars
TriggerClearActions(gg_trg_MyResourceField)
TriggerClearConditions(gg_trg_MyResourceField)
TriggerAddAction(gg_trg_MyResourceField, UpdateBars)
TriggerRegisterTimerEventPeriodic(gg_trg_MyResourceField , 0.2)
udg_MyResourceFieldCreateFree = CreateTrigger()
TriggerAddAction(udg_MyResourceFieldCreateFree, function() CreateMyResourceFieldFree(udg_MyResourceFieldFreeX, udg_MyResourceFieldFreeY) end)
udg_MyResourceFieldHideTrigger = CreateTrigger()
TriggerAddAction(udg_MyResourceFieldHideTrigger, CustomHide)
--AutoCreate as soon game started.
TimerStart(CreateTimer(),0.0,false, function()
local rows = 1
local cols
local colsExit = Settings.AutoCreateCols
if not BlzFrameIsVisible(BlzGetFrameByName("SimpleReplayPanel",0)) then
TriggerAddAction(gg_trg_MyResourceField, UpdateBars)
if Settings.CreateCheckBox then
CreateCheckBoxFunction()
end
else
TriggerAddAction(gg_trg_MyResourceField, UpdateBars)
end
if Settings.AutoCreateRows > 0 then
repeat
cols = 1
repeat
CreateMyResourceField(cols == 1)
cols = cols + 1
until cols > colsExit
rows = rows + 1
colsExit = colsExit + Settings.AutoCreateColsAddEachRow
until rows > Settings.AutoCreateRows or colsExit <= 0
end
DestroyTimer(GetExpiredTimer())
end
)
end
end
Jass
Code (vJASS):
//MyResourceField 1.2a
//By Tasyen
function MyResourceFieldPlayerSize takes nothing returns integer
return 100 //the array is splited into sections of size 100. Each section is used by one player. Player Red uses 101 to 200. Blue Takes 201 to 300, allows to have 100 MyResourceFields.
endfunction
//Allow and Pos the checkbox hidding the additional Bars.
function MyResourceFieldCreateCheckBox takes nothing returns boolean
return true //(true) create a checkbox to tooggle visiblity of the additional ResourceBarFrames
endfunction
function MyResourceFieldCheckBoxX takes nothing returns real
return 0.1 //abs point of checkbox
endfunction
function MyResourceFieldCheckBoxY takes nothing returns real
return 0.57
endfunction
function MyResourceFieldCheckBoxLabelText takes nothing returns string
return "Hide Resources"
endfunction
//Where is the tooltip of this Bars placed.
function MyResourceFieldTooltipX takes nothing returns real
return 0.8
endfunction
function MyResourceFieldTooltipY takes nothing returns real
return 0.16
endfunction
function MyResourceFieldTooltipPoint takes nothing returns framepointtype
return FRAMEPOINT_BOTTOMRIGHT //Which point of Tooltip is positionate to abs point MyResourceFieldTooltipX/MyResourceFieldTooltipY
endfunction
//Default Sizes of TooltipBoxes
//You could change a TooltipBox size after they were created with: x should be a number from 1 to udg_MyResourceFieldCount. udg_MyResourceFieldCount would be the last created.
//call BlzFrameSetSize(BlzGetFrameByName("MyResourceFieldBoxedText", x), xsize, ysize)
function MyResourceFieldTooltipSizeX takes nothing returns real
return 0.285
endfunction
function MyResourceFieldTooltipSizeY takes nothing returns real
return 0.06
endfunction
function MyResourceFieldAutoCreateCols takes nothing returns integer
return 3
endfunction
function MyResourceFieldAutoCreateColAddEachRow takes nothing returns integer
return 0 //rows after the first one gain this amount of cols. -values are valid
endfunction
function MyResourceFieldAutoCreateRows takes nothing returns integer
return 2 //0 or below will not create any Fields.
endfunction
function MyResourceFieldAnchor takes nothing returns framepointtype
//Poses the first Bar where in the world Frame?
//I suggest to use a y-offset when using any Bottom Point.
//return FRAMEPOINT_TOPLEFT
//return FRAMEPOINT_TOP
//return FRAMEPOINT_TOPRIGHT
//return FRAMEPOINT_BOTTOMLEFT
return FRAMEPOINT_BOTTOM
//return FRAMEPOINT_BOTTOMRIGHT
//return FRAMEPOINT_LEFT
//return FRAMEPOINT_RIGHT
//return FRAMEPOINT_CENTER
endfunction
function MyResourceFieldAnchor1OffsetX takes nothing returns real
return -0.15 //Offset the first bar by that amount from its FramePoint
endfunction
function MyResourceFieldAnchor1OffsetY takes nothing returns real
return 0.005
endfunction
function MyResourceFieldSizeX takes nothing returns real
return 0.064
endfunction
function MyResourceFieldSizeY takes nothing returns real
return 0.0218
endfunction
function MyResourceFieldCustomHiding takes nothing returns nothing
local integer index = udg_MyResourceFieldCount
local integer playerIndex
local integer playerId
if not BlzFrameIsVisible(BlzGetFrameByName("SimpleReplayPanel",0)) then //not Replay Mode?
set playerId = GetConvertedPlayerId(GetLocalPlayer())
else
set playerId = R2I(BlzFrameGetValue(BlzGetFrameByName("ReplayVisionMenu",0))) + 1 //Replay Mode use the player observed
endif
set playerIndex = playerId * MyResourceFieldPlayerSize()
//Wana hide all, yes -> hide the parent?
call BlzFrameSetVisible(BlzGetFrameByName("MyResourceFieldBossSBest",0), not udg_MyResourceFieldHideData[playerId])
//Hide Specific Fields for that player.
loop
call BlzFrameSetVisible(BlzGetFrameByName("MyResourceField", index), not udg_MyResourceFieldHideData[playerIndex + index])
call BlzFrameSetVisible(BlzGetFrameByName("MyResourceHover", index), not udg_MyResourceFieldHideData[playerIndex + index])
set index = index -1
exitwhen index == 0
endloop
endfunction
function MyResourceFieldUpdateBars takes nothing returns nothing
local integer playerIndex
local integer index = 1
//share visiblity for tooltips to Resources
call BlzFrameSetVisible(BlzGetFrameByName("MyResourceFieldBossF",0), BlzFrameIsVisible(BlzGetFrameByName("MyResourceFieldBossS",0)))
if MyResourceFieldCreateCheckBox() then //Has checkbox enabled?
call BlzFrameSetVisible(BlzGetFrameByName("MyResourceFieldCheckBox",0), not bj_cineModeAlreadyIn) //hide in cinematic
call BlzFrameSetVisible(BlzGetFrameByName("MyResourceFieldCheckBoxLabel",0), not bj_cineModeAlreadyIn)
endif
if not BlzFrameIsVisible(BlzGetFrameByName("SimpleReplayPanel",0)) then //not replay mode?
set playerIndex = GetConvertedPlayerId(GetLocalPlayer()) * MyResourceFieldPlayerSize()
else
set playerIndex = (R2I(BlzFrameGetValue(BlzGetFrameByName("ReplayVisionMenu",0))) + 1) * MyResourceFieldPlayerSize()
endif
//Takes over all udg_MyResourceFieldValue data into the MyResourceFields also updates the title
//The outher Loop are the Bars, the inner Loop handles the tooltipTitle update
loop
call BlzFrameSetText(BlzGetFrameByName("MyResourceFieldText", index), udg_MyResourceFieldValue[playerIndex + index])
if udg_MyResourceFieldIcons[playerIndex + index] == null or udg_MyResourceFieldIcons[playerIndex + index] == "" then
call BlzFrameSetTexture(BlzGetFrameByName("MyResourceFieldIcon", index), udg_MyResourceFieldIcons[index], 0 ,true)
else
call BlzFrameSetTexture(BlzGetFrameByName("MyResourceFieldIcon", index), udg_MyResourceFieldIcons[playerIndex + index], 0 ,true)
endif
if udg_MyResourceFieldTooltipText[playerIndex + index] == null then
call BlzFrameSetText(BlzGetFrameByName("MyResourceFieldBoxedTextValue", index), udg_MyResourceFieldTooltipText[index])
else
call BlzFrameSetText(BlzGetFrameByName("MyResourceFieldBoxedTextValue", index), udg_MyResourceFieldTooltipText[playerIndex + index])
endif
if udg_MyResourceFieldTooltipTitle[playerIndex + index] == null then
call BlzFrameSetText(BlzGetFrameByName("MyResourceFieldBoxedTextTitle", index), udg_MyResourceFieldTooltipTitle[index]+": "+udg_MyResourceFieldValue[playerIndex +index])
else
call BlzFrameSetText(BlzGetFrameByName("MyResourceFieldBoxedTextTitle", index), udg_MyResourceFieldTooltipTitle[playerIndex + index]+": "+udg_MyResourceFieldValue[playerIndex + index])
endif
set index = index + 1
exitwhen index > udg_MyResourceFieldCount
endloop
endfunction
function MyResourceFieldCreateTooltip takes framehandle targetFrameLeft, framehandle targetFrameRight, string title, string text, integer index returns nothing
local framehandle box = BlzGetFrameByName("MyResourceFieldBossF",0)
local framehandle fhHover = BlzCreateFrameByType("FRAME", "MyResourceHover", box, "", index)
local framehandle tooltipBox = BlzCreateFrame("MyResourceFieldBoxedText", box,0, index)
call BlzFrameSetPoint(fhHover, FRAMEPOINT_BOTTOMLEFT, targetFrameLeft, FRAMEPOINT_BOTTOMLEFT, 0, 0)
call BlzFrameSetPoint(fhHover, FRAMEPOINT_TOPRIGHT, targetFrameRight, FRAMEPOINT_TOPRIGHT, 0, 0)
call BlzFrameSetTooltip(fhHover, tooltipBox)
call BlzFrameSetAbsPoint(tooltipBox, MyResourceFieldTooltipPoint(), MyResourceFieldTooltipX(), MyResourceFieldTooltipY())
call BlzFrameSetSize(tooltipBox, MyResourceFieldTooltipSizeX(), MyResourceFieldTooltipSizeY())
call BlzFrameSetText(BlzGetFrameByName("MyResourceFieldBoxedTextTitle", index), title)
call BlzFrameSetText(BlzGetFrameByName("MyResourceFieldBoxedTextValue", index), text)
set box = null
set fhHover = null
set tooltipBox = null
endfunction
function CreateMyResourceFieldFree takes nothing returns nothing
local framehandle field = BlzCreateSimpleFrame("MyResourceField", BlzGetFrameByName("MyResourceFieldBossS",0), udg_MyResourceFieldCount + 1)
set udg_MyResourceFieldCount = udg_MyResourceFieldCount + 1
call BlzFrameSetAbsPoint(field, FRAMEPOINT_BOTTOMLEFT, udg_MyResourceFieldFreeX, udg_MyResourceFieldFreeY)
call BlzFrameSetSize(field, MyResourceFieldSizeX(), MyResourceFieldSizeY())
call BlzFrameSetSize(BlzGetFrameByName("MyResourceFieldBackground", udg_MyResourceFieldCount), MyResourceFieldSizeX(), MyResourceFieldSizeY() + 0.0102)
call MyResourceFieldCreateTooltip(BlzGetFrameByName("MyResourceFieldIcon", udg_MyResourceFieldCount), BlzGetFrameByName("MyResourceFieldText", udg_MyResourceFieldCount), udg_MyResourceFieldTooltipTitle[udg_MyResourceFieldCount], udg_MyResourceFieldTooltipText[udg_MyResourceFieldCount], udg_MyResourceFieldCount)
set field = null
endfunction
function CreateMyResourceField takes boolean newLine returns nothing
local framehandle field = BlzCreateSimpleFrame("MyResourceField", BlzGetFrameByName("MyResourceFieldBossS",0), udg_MyResourceFieldCount + 1)
set udg_MyResourceFieldCount = udg_MyResourceFieldCount + 1
if udg_MyResourceFieldCount == 1 then //if this is the first create one Pos it below the default one
call BlzFrameSetPoint(field, MyResourceFieldAnchor(), BlzGetOriginFrame(ORIGIN_FRAME_WORLD_FRAME,0), MyResourceFieldAnchor(), MyResourceFieldAnchor1OffsetX(), MyResourceFieldAnchor1OffsetY())
set udg_MyResourceFieldLastLineStart = 1
else
if not newLine then
if MyResourceFieldAnchor() == FRAMEPOINT_BOTTOMLEFT or MyResourceFieldAnchor() == FRAMEPOINT_TOPLEFT or MyResourceFieldAnchor() == FRAMEPOINT_LEFT or MyResourceFieldAnchor() == FRAMEPOINT_TOP or MyResourceFieldAnchor() == FRAMEPOINT_BOTTOM then
call BlzFrameSetPoint(field, FRAMEPOINT_TOPLEFT, BlzGetFrameByName("MyResourceField", udg_MyResourceFieldCount - 1), FRAMEPOINT_TOPRIGHT, 0, 0)
elseif MyResourceFieldAnchor() == FRAMEPOINT_BOTTOMRIGHT or MyResourceFieldAnchor() == FRAMEPOINT_RIGHT or MyResourceFieldAnchor() == FRAMEPOINT_TOPRIGHT then
call BlzFrameSetPoint(field, FRAMEPOINT_TOPRIGHT, BlzGetFrameByName("MyResourceField", udg_MyResourceFieldCount - 1), FRAMEPOINT_TOPLEFT, 0, 0)
else
call BlzFrameSetPoint(field, FRAMEPOINT_TOPRIGHT, BlzGetFrameByName("MyResourceField", udg_MyResourceFieldCount - 1), FRAMEPOINT_TOPLEFT, 0, 0)
endif
else
if MyResourceFieldAnchor() == FRAMEPOINT_TOPRIGHT or MyResourceFieldAnchor() == FRAMEPOINT_TOPLEFT or MyResourceFieldAnchor() == FRAMEPOINT_LEFT or MyResourceFieldAnchor() == FRAMEPOINT_TOP or MyResourceFieldAnchor() == FRAMEPOINT_RIGHT or MyResourceFieldAnchor() == FRAMEPOINT_CENTER then
call BlzFrameSetPoint(field, FRAMEPOINT_TOPLEFT, BlzGetFrameByName("MyResourceField", udg_MyResourceFieldLastLineStart), FRAMEPOINT_BOTTOMLEFT, 0, 0)
else
call BlzFrameSetPoint(field, FRAMEPOINT_BOTTOMLEFT, BlzGetFrameByName("MyResourceField", udg_MyResourceFieldLastLineStart), FRAMEPOINT_TOPLEFT, 0, 0)
endif
set udg_MyResourceFieldLastLineStart = udg_MyResourceFieldCount
endif
endif
call BlzFrameSetSize(field, MyResourceFieldSizeX(), MyResourceFieldSizeY())
call BlzFrameSetSize(BlzGetFrameByName("MyResourceFieldBackground", udg_MyResourceFieldCount), MyResourceFieldSizeX(), MyResourceFieldSizeY() + 0.0102)
call MyResourceFieldCreateTooltip(BlzGetFrameByName("MyResourceFieldIcon", udg_MyResourceFieldCount), BlzGetFrameByName("MyResourceFieldText", udg_MyResourceFieldCount), udg_MyResourceFieldTooltipTitle[udg_MyResourceFieldCount], udg_MyResourceFieldTooltipText[udg_MyResourceFieldCount], udg_MyResourceFieldCount)
set field = null
endfunction
function MyResourceFieldsCheckBox takes nothing returns nothing
if GetTriggerPlayer() == GetLocalPlayer() then //only do something for the player having pressed the checkbox
call BlzFrameSetVisible(BlzGetFrameByName("MyResourceFieldBossF",0), BlzGetTriggerFrameEvent() == FRAMEEVENT_CHECKBOX_UNCHECKED)
call BlzFrameSetVisible(BlzGetFrameByName("MyResourceFieldBossS",0), BlzGetTriggerFrameEvent() == FRAMEEVENT_CHECKBOX_UNCHECKED)
endif
endfunction
function MyResourceFieldCreateCheckBoxAction takes nothing returns nothing
local trigger trig = CreateTrigger()
local framehandle fh = BlzCreateFrameByType("GLUECHECKBOX", "MyResourceFieldCheckBox", BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0),"QuestCheckBox",0)
local framehandle fhText = BlzCreateFrameByType("TEXT", "MyResourceFieldCheckBoxLabel", fh, "", 0)
call BlzFrameSetAbsPoint(fh, FRAMEPOINT_TOPLEFT, MyResourceFieldCheckBoxX(), MyResourceFieldCheckBoxY())
call BlzFrameSetPoint(fhText, FRAMEPOINT_TOP, fh, FRAMEPOINT_BOTTOM, 0.0, 0.0)
call BlzFrameSetEnable(fhText, false)
call BlzFrameSetText(fhText, MyResourceFieldCheckBoxLabelText())
call BlzTriggerRegisterFrameEvent(trig, fh, FRAMEEVENT_CHECKBOX_CHECKED)
call BlzTriggerRegisterFrameEvent(trig, fh, FRAMEEVENT_CHECKBOX_UNCHECKED)
call TriggerAddAction(trig, function MyResourceFieldsCheckBox)
set fh = null
set fhText = null
set trig = null
endfunction
function MyResourceFieldInit takes nothing returns nothing
local integer rows = 1
local integer cols
local integer colsExit = MyResourceFieldAutoCreateCols()
if not BlzFrameIsVisible(BlzGetFrameByName("SimpleReplayPanel",0)) then
call TriggerAddAction( gg_trg_MyResourceField, function MyResourceFieldUpdateBars)
if MyResourceFieldCreateCheckBox() then
call MyResourceFieldCreateCheckBoxAction()
endif
else
call TriggerAddAction( gg_trg_MyResourceField, function MyResourceFieldUpdateBars)
endif
call BlzCreateFrameByType("FRAME", "MyResourceFieldBossF", BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0),"",0) //Parent of Frames (tooltips stuff)
call BlzCreateFrameByType("SIMPLEFRAME", "MyResourceFieldBossSBest", BlzGetFrameByName("ResourceBarFrame",0),"",0) //Upper Parent of the SimpleFrames it is used for the Hide Feature.
call BlzCreateFrameByType("SIMPLEFRAME", "MyResourceFieldBossS", BlzGetFrameByName("MyResourceFieldBossSBest",0),"",0) //Parent of SimpleFrames (bar and its content)
if MyResourceFieldAutoCreateRows()> 0 then
loop
set cols = 1
loop
call CreateMyResourceField(cols == 1)
set cols = cols + 1
exitwhen cols > colsExit
endloop
set rows = rows + 1
set colsExit = colsExit + MyResourceFieldAutoCreateColAddEachRow()
exitwhen rows > MyResourceFieldAutoCreateRows() or colsExit <= 0
endloop
endif
endfunction
//===========================================================================
function InitTrig_MyResourceField takes nothing returns nothing
set gg_trg_MyResourceField = CreateTrigger()
set udg_MyResourceFieldCreateFree = CreateTrigger()
set udg_MyResourceFieldHideTrigger = CreateTrigger()
call TriggerRegisterTimerEventPeriodic( gg_trg_MyResourceField , 0.2)
call TimerStart(CreateTimer(),0.0, false, function MyResourceFieldInit)
call TriggerAddAction(udg_MyResourceFieldCreateFree, function CreateMyResourceFieldFree)
call TriggerAddAction(udg_MyResourceFieldHideTrigger, function MyResourceFieldCustomHiding)
call BlzLoadTOCFile("war3mapImported\\MyResourceField.toc")
endfunction
Changelog
1.4b
Fix for Save&Load (v)jass
1.4aFix for Save&Load
Lua version calls itself
1.4Lua version calls itself
The value text font a little bit bigger.
Tooltips ySize is depends now on the the amount of displayed Text.
Tooltip won't take fight for mousecontrol anymore.
(Lua) Fixed some nonsense added in 1.3a, preventing the AutoCreate feature to work
1.3aTooltips ySize is depends now on the the amount of displayed Text.
Tooltip won't take fight for mousecontrol anymore.
(Lua) Fixed some nonsense added in 1.3a, preventing the AutoCreate feature to work
Possible desync fix in Lua Version
1.3Reduced the Font-Size inside the tooltip.
Reduced the timeout to update to 0.1 from 0.2.
The Field's tooltips now also works outside of the 4:3 Screen.
If you update(replace the system code and the imported fdf)
1.2aReduced the timeout to update to 0.1 from 0.2.
The Field's tooltips now also works outside of the 4:3 Screen.
If you update(replace the system code and the imported fdf)
Removed some unneeded code.
Added a Lua version.
V1.2Added a Lua version.
New feature: Show/Hide All MyResourceFields or specific ones for one player.
Added a demo trigger showing how to change the size of a tooltip box after it was created.
The Default TooltipBox size is now also a function at the top of jass code.
V1.1aAdded a demo trigger showing how to change the size of a tooltip box after it was created.
The Default TooltipBox size is now also a function at the top of jass code.
Checkbox creation does now consider the settings
V1.1Hides itself during Cinematics.
Outsourced the CheckboxLabelText into a function at top of the code.
Outsourced the CheckboxLabelText into a function at top of the code.
Contents
Page 1 of 2