• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

MyResourceField

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

Change Data

Create Free Ones

Init

CustomHide

Change TooltipBox Size

Definitions

Code


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.
JASS:
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:
--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:
//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.4a
Fix for Save&Load
Lua version calls itself​
1.4
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.3a
Possible desync fix in Lua Version​
1.3
Reduced 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.2a
Removed some unneeded code.
Added a Lua version.​
V1.2
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.1a
Checkbox creation does now consider the settings​
V1.1
Hides itself during Cinematics.
Outsourced the CheckboxLabelText into a function at top of the code.​
Previews
Contents

MyResourceField 1.4b (Map)

MyResourceField 1.4b Lua (Map)

Reviews
MyPad
This is an interesting bundle that can be very useful, and has already used in some approved resources. Approved This might be considered for a High Quality Status, possibly DC. Just got to need a bit of code cleanup and get rid of that if-else smell.
The UI natives are already complex enough as they are. Making this just shows how juicy the new wc3 natives can be, and how one can complement the UI display of wc3, or supersede it, making a completely new game.

Kudos to you!

With this, will MyResourceBar be deprecated? This is more generic, and appears to fulfil the purpose of the resource above as well.
 

SpasMaster

Hosted Project: SC
Level 23
Joined
Jan 29, 2010
Messages
1,969
Very glad you put this out.

I only encountered 2 issues so far:

1) The Toggle Checkbox is visible during Cinematic Mode, which kinda annoying:

HideStats.png



2) Once more during Cinematic Mode, while moving your mouse, if you happen to land on where the stats window is supposed to be, the tooltips will appear:

2.png



Here are the solutions I have in mind:
• For the first issue - perhaps a boolean variable that we can set to True or False to enable/disable the checkbox? That way, as soon as a cinematic starts/ends, one would be able to enable/disable the checkbox.
• For the second issue - once more a boolean that either has the checkbox ticked or not by default. If it's ticked by default (aka, Resources hidden by default), there will be nothing to mouse over during cinematics.
 
Uploaded V1.2.
One can now hide all MyResourceFields or single ones player specific, by setting up a boolean array (MyResourceFieldHideData) and using a Trigger (MyResourceFieldHideTrigger). MyResourceFieldHideData is a hide feature when one sets a field to true, it will not be shown, use false to show it.
When MyResourceFieldHideTrigger runs it reads MyResourceFieldHideData: a true at a playerIndex (GUI-Indexing) will hide all custom created MyResourceFields. Setting true at 100 * PlayerIndex + 1 will hide the 1.MyResourceField for that player. 100 should match the return value of function MyResourceFieldPlayerSize. For Player Red that would result into MyResourceFieldHideData[101] = true; to hide Field 1.
When one never uses MyResourceFieldHideTrigger, it won't have any effect.
There is now an further parent for the simpleframes named "MyResourceFieldBossSBest" which made that feature easier to create without coliding with the checkbox feature.​

Added a demo GUI Trigger; showing how to change the size of a tooltip box after it was created.

Moved the default size values of tooltipboxes into functions at top of the jass code.
 
Did you import the two files inside the demo Map to your map?
war3mapImported\MyResourceField.fdf
war3mapImported\MyResourceField.toc
After you placed them were they were. You have to tell MyResorceField what to display.
Example Trigger for the default resources of the linked system.
JASS:
function Trig_Show_Resources_Actions takes nothing returns nothing
    local integer playerId = GetPlayerId(GetLocalPlayer())
    set udg_PlayerIndex = ( 100 * GetConvertedPlayerId(GetLocalPlayer()) )
    set udg_MyResourceFieldValue[udg_PlayerIndex + 1] = I2S(PlayerResource[playerId][Wood])
    set udg_MyResourceFieldValue[udg_PlayerIndex + 2] = I2S(PlayerResource[playerId][Food])
    set udg_MyResourceFieldValue[udg_PlayerIndex + 3] = I2S(PlayerResource[playerId][Stone])
    set udg_MyResourceFieldValue[udg_PlayerIndex + 4] = I2S(PlayerResource[playerId][Gold])
endfunction
//===========================================================================
function InitTrig_Show_Resources takes nothing returns nothing
    set gg_trg_Show_Resources = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Show_Resources, 1.00 )
    call TriggerAddAction( gg_trg_Show_Resources, function Trig_Show_Resources_Actions )
endfunction
 
Hey @Tasyen, really great system.

I considered giving it a try, as I need to create a new resource bar called Faith. I used these triggers at the Init:
  • MyResourceFieldInit
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Player Group - Pick every player in (All players) and do (Actions)
        • Loop - Actions
          • Set PlayerIndex = (100 x (Player number of (Picked player)))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Race of (Picked player)) Equal to Human
              • And - All (Conditions) are true
                • Conditions
                  • ((Picked player) handicap) Equal to 90.00
            • Then - Actions
              • Set MyResourceFieldIcons[(PlayerIndex + 1)] = ReplaceableTextures\CommandButtons\PASSpell_Holy_PrayerOfHealing02.blp
              • Set MyResourceFieldTooltipTitle[(PlayerIndex + 1)] = Faith
              • Set MyResourceFieldTooltipText[(PlayerIndex + 1)] = Each point of Faith increases all Seraphic Union units health by 1 and improve Heroes' ultimates.
              • Set MyResourceFieldValue[(PlayerIndex + 1)] = 0
            • Else - Actions
I've edited it a bit so that it would only create one custom resource bar. However, the results shows 6 resource bars instead:

6frames.png


I only need one. Can you help me out here?
 
Updated to V1.3.
Changed the FrameType of the Fields from SIMPLEFRAME to SIMPLEBUTTON. Now the tooltip-Hovering works outside of the 4:3 Screen. The Tooltip display is still a Frame hence the update is applied by frequently checking for an empty invisible Tooltip and the Tooltip-display has to be inside the 4:3 Screen. There is now only one TooltipBox, which is updated based on the current shown SimpleFrame-Tooltip.

Reduced the font-Size of the Tooltip-Text and Title.
Update timeout 0.2 -> 0.1
 
Last edited:
Level 13
Joined
Jul 15, 2007
Messages
763
Had a look at this and test map seems to be a bit bugged? Or are things meant to be all over the place?

I'm on the latest version of reforged.

edit: using my limited knowledge of UI stuff I managed to get things sorted. Just seems the X/Y anchoring stuff is off in the demo...
 

Attachments

  • upload_2020-9-26_17-16-12.png
    upload_2020-9-26_17-16-12.png
    3.6 MB · Views: 112
Last edited:
Updated to V1.4. Contains a changed fdf, means if you update you should import the new one.
Made the value text font a little bit bigger.
The Tooltips ySize is depends now on the the amount of displayed Text.
The tooltip won't take fight for mousecontrol anymore.
(Lua) Fixed some nonsense added in 1.3a preventing the AutoCreate feature to work
 
Updated to 1.4a
The System works now after Save&Load. Custom Free Fields need another event (Game is Loaded) and a short wait as first action to make sure that they are recreated in the same order.
The Lua version now calls itself, no need from the GUI trigger to start it anymore.

Recently someone told me that one of my UI systems broke when the game was saved and later loaded. I did some research about that and found out that custom created Frames and Frame modifications are not save nor loaded and that using references to the now broken custom Frames can crash the game. This applies to V1.31, V1.32.8 and V1.32.9 PTR.

I added a custom FrameLoader Trigger that redoes the whole system's Frame creation when the game is Loaded.
 
the (v)jass version was updated to 1.4b
I assumed the TOC-File would be probably saved&Loaded, it was done in the trigger init phase. Which is wrong, after the game was Saved, Closed, Restarted and Loaded the TOCs content was forgotten and no Frames were recreated.
Therefore Pushed the TOC-Loading to the top of the Frame creation function.
 
Level 4
Joined
Mar 8, 2020
Messages
14
the (v)jass version was updated to 1.4b
I assumed the TOC-File would be probably saved&Loaded, it was done in the trigger init phase. Which is wrong, after the game was Saved, Closed, Restarted and Loaded the TOCs content was forgotten and no Frames were recreated.
Therefore Pushed the TOC-Loading to the top of the Frame creation function.
How do I make the fields 1 row of 4 resources exactly below the standard resources?
 

Attachments

  • Inked161511-bb82bbd0d0863c84e6628e029b8743dd_LI.jpg
    Inked161511-bb82bbd0d0863c84e6628e029b8743dd_LI.jpg
    855.3 KB · Views: 53
How do I make the fields 1 row of 4 resources exactly below the standard resources?
If you only want a second Resourcebar MyResourceBar is a better fit.

Or you change the returned values of the AutoCreate functions in MyResourceField (I guess you use the jass version).
MyResourceFieldAutoCreateCols
return 5
MyResourceFieldAutoCreateRows
return 1

MyResourceFieldAnchor
return FRAMEPOINT_TOPRIGHT

and something for
MyResourceFieldAnchor1OffsetX
return 0.0
MyResourceFieldAnchor1OffsetY
return 0.0
 
Level 3
Joined
Aug 22, 2018
Messages
25
For some reason, this seems to make my map replay not work properly,

Like they would go out of sync and the replay would actually show different stuff than the actual game.
 
Level 8
Joined
Aug 5, 2014
Messages
190
Hello, may question may be off-topic, but i wonder it is possible somehow display required custom resources for unit in its tooltip? This system the only one around here to solve the problem to display custom resources in most native way possible, but is there a way to place custom price with resource icon and stuff near units standart prices similar way?
 
Hello, may question may be off-topic, but i wonder it is possible somehow display required custom resources for unit in its tooltip? This system the only one around here to solve the problem to display custom resources in most native way possible, but is there a way to place custom price with resource icon and stuff near units standart prices similar way?
Short: No/MakeOwn

There is no good native stuff that allows to interact with the current displayed tooltip's content nor is there anything that tells you what unit/item/ability currently is hovered.
One first would need to setup a command button hover system and a database to know what is hovered. Then one could use custom frames to add custom tooltip infos over the default tooltip box. Or screw the default and make an own custom tooltip box

For the command buttons hovering, I shared a system. Even when using it, one still needs a way to know what the button points to.
 
Level 8
Joined
Aug 5, 2014
Messages
190
Short: No/MakeOwn

There is no good native stuff that allows to interact with the current displayed tooltip's content nor is there anything that tells you what unit/item/ability currently is hovered.
One first would need to setup a command button hover system and a database to know what is hovered. Then one could use custom frames to add custom tooltip infos over the default tooltip box. Or screw the default and make an own custom tooltip box

For the command buttons hovering, I shared a system. Even when using it, one still needs a way to know what the button points to.
Well, thank you! If it allows even just add custom info overlay on standart ui tooltip it suits me well. As additional preparations for establishing data base or another checks to specify over what my cursor is currently howering is manageable. Its shame that there is no example for that system, and i need to inspect code itself, but its far better than nothing as it gives me needed opportunity.
 
Top