--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