Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Plugins ➜ Miniwindows - Resizing HP Bars/windows

Miniwindows - Resizing HP Bars/windows

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Xinefus   (106 posts)  Bio
Date Fri 24 Apr 2020 05:02 PM (UTC)

Amended on Sat 25 Apr 2020 09:07 AM (UTC) by Xinefus

Message
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!!
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #1 on Sat 25 Apr 2020 02:27 AM (UTC)

Amended on Sat 25 Apr 2020 02:29 AM (UTC) by Nick Gammon

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

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Xinefus   (106 posts)  Bio
Date Reply #2 on Sat 25 Apr 2020 11:08 AM (UTC)
Message
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!
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


11,013 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.