Miniwindows - Resizing HP Bars/windows

Posted by Xinefus on Fri 24 Apr 2020 05:02 PM — 3 posts, 15,578 views.

#0
Ref: a. https://www.gammon.com.au/forum/?id=9270
b. http://www.gammon.com.au/forum/bbshowpost.php?id=9097&page=2
c. https://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=14661


Hi!

Here I am again! I hope that all of you are doing well and staying healthy.

I've successfully implemented a chat capture miniwindow and it is working great, as seen on my post at ref c.

I've been reading and searching the forums for other info on implementing a HP Bar. I managed to get my prompt to spit out the things I want it to. Here is an example of that.
Quote:
Health[27/27] Energy[6/6] Charge<7/100> XP[14,937]
[Enemy Name][80%] Focus[0] Timer [0]


I've been able to use ref a. to help me get my hp/ep/charge/enemy name/enemyhp all on a nice little miniwindow.

1. What I am having trouble with is being able to size the miniwindow so that I can fit the text in front of the gauges. I don't need it to be dynamic, but I would like to be able to change it easily.

2. If I want a combination of gauges and just showing a value, how do I add that to a line in the miniwindow?
Ex: my xp is a running number, how can I just post this number on the miniwindow? XP: [number]. The same goes for the Focus and Timer.
I don't need a pretty gauge, I just want the number updated every tick.

3. How do I add/remove rows and have the box draw properly? I can't seem to figure that out... (I've been using the xml from ref a. as a basis)

I tried looking at InfoBox, but haven't been able to crack that nut yet. I want to be able to click and move the windows around, and so far the miniwindows that I've added work great.

Please let me know if I haven't been clear enough. Thanks a lot for your help!!
Amended on Sat 25 Apr 2020 09:07 AM by Xinefus
Australia Forum Administrator #1
On page 3 of that first link, there is a version that works out how much room to leave for the text. In particular, instead of a constant:


GAUGE_LEFT = 55


It uses a variable, which is worked out by taking the maximum of the description widths:


  -- work out how far in to start the gauge
  gauge_left = WindowTextWidth (win, font_id, "HP: ")
  gauge_left = math.max (gauge_left, WindowTextWidth (win, font_id, "Endurance: "))
  gauge_left = math.max (gauge_left, WindowTextWidth (win, font_id, "Guile: "))
  gauge_left = gauge_left + 5  -- allow gap from edge



Then elsewhere in the code, change GAUGE_LEFT to gauge_left.




The constant at the start:


WINDOW_WIDTH = 200


... controls how wide the overall window is (and therefore the width of the bars, less the width of the description).




Quote:

2. If I want a combination of gauges and just showing a value, how do I add that to a line in the miniwindow?


Instead of calling DoGauge, call another function (which you write) which does a couple of WindowText calls, instead of all the stuff to draw the box.

For example:


function DoText (sPrompt, current, max, Colour)

  if max <= 0 then 
    return 
  end -- no divide by zero
  
  -- fraction in range 0 to 1
  local Fraction = math.min (math.max (current / max, 0), 1) 
   
  local width = WindowTextWidth (win, font_id, sPrompt)
  
  WindowText (win, font_id, sPrompt, gauge_left - width, vertical, 0, 0, FONT_COLOUR)

  WindowText (win, font_id, string.format ("%i/%i (%0.2f%%)", current, max, Fraction * 100), gauge_left, vertical, 0, 0, Colour)
                                  
  vertical = vertical + font_height + 3
end -- function DoText


Now you can show XP as text, for example:


  DoGauge ("HP: ",    hp ,   max_hp,    ColourNameToRGB "darkgreen")
  DoText  ("XP: ",    xp,    max_xp,    ColourNameToRGB "darkblue")
  DoGauge ("Mana: ",  mana,  max_mana,  ColourNameToRGB "mediumblue")
  DoGauge ("Move: ",  move,  max_move,  ColourNameToRGB "gold")





Quote:

3. How do I add/remove rows and have the box draw properly? I can't seem to figure that out... (I've been using the xml from ref a. as a basis)


I don't understand that. Remove rows? If you want to omit a row, omit one of the lines shown above.
Amended on Sat 25 Apr 2020 02:29 AM by Nick Gammon
#2
Thanks Nick.

I am working this into my plugin. I am also trying to become more comfortable with InfoBox.

Thank you so much for all the help!