-
Notifications
You must be signed in to change notification settings - Fork 15
/
Health_Bar_Miniwindow.xml
213 lines (152 loc) · 6.12 KB
/
Health_Bar_Miniwindow.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE muclient>
<muclient>
<plugin
name="Health_Bar_Miniwindow"
author="Nick Gammon"
id="48062dcd6b968c590df50f32"
language="Lua"
purpose="Shows stats in a mini window"
date_written="2010-02-14 09:00"
requires="4.40"
version="2.0"
save_state="y"
>
<description trim="y">
<![CDATA[
Install this plugin to show an info bar with HP, Mana,
and Movement points shown as a bar.
The window can be dragged to a new location with the mouse.
For Smaug your prompt needs to be set like this:
prompt <%h/%H hp %m/%M m %v/%V mv %x/%X xp>
fprompt <%h/%H hp %m/%M m %v/%V mv %x/%X xp>
]]>
</description>
</plugin>
<!-- Triggers -->
<triggers>
<trigger
enabled="y"
match="^\<(\d+)\s*\/(\d+)\s*hp (\d+)\s*\/(\d+)\s*m (\d+)\s*\/(\d+)\s*mv "
regexp="y"
script="do_prompt"
sequence="100"
>
</trigger>
</triggers>
<!-- Script -->
<script>
<![CDATA[
GAUGE_HEIGHT = 15
WINDOW_WIDTH = 300
WINDOW_HEIGHT = 65
NUMBER_OF_TICKS = 5
BACKGROUND_COLOUR = ColourNameToRGB "rosybrown"
FONT_COLOUR = ColourNameToRGB "darkred"
BORDER_COLOUR = ColourNameToRGB "#553333"
function DoGauge (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)
WindowRectOp (win, 2, gauge_left, vertical, WINDOW_WIDTH - 5, vertical + GAUGE_HEIGHT,
BACKGROUND_COLOUR) -- fill entire box
local gauge_width = (WINDOW_WIDTH - gauge_left - 5) * Fraction
-- box size must be > 0 or WindowGradient fills the whole thing
if math.floor (gauge_width) > 0 then
-- top half
WindowGradient (win, gauge_left, vertical, gauge_left + gauge_width, vertical + GAUGE_HEIGHT / 2,
0x000000,
Colour, 2)
-- bottom half
WindowGradient (win, gauge_left, vertical + GAUGE_HEIGHT / 2,
gauge_left + gauge_width, vertical + GAUGE_HEIGHT,
Colour,
0x000000,
2)
end -- non-zero
-- show ticks
local ticks_at = (WINDOW_WIDTH - gauge_left - 5) / (NUMBER_OF_TICKS + 1)
-- ticks
for i = 1, NUMBER_OF_TICKS do
WindowLine (win, gauge_left + (i * ticks_at), vertical,
gauge_left + (i * ticks_at), vertical + GAUGE_HEIGHT, ColourNameToRGB ("silver"), 0, 1)
end -- for
-- draw a box around it
WindowRectOp (win, 1, gauge_left, vertical, WINDOW_WIDTH - 5, vertical + GAUGE_HEIGHT,
ColourNameToRGB ("lightgrey")) -- frame entire box
-- mouse-over information: add hotspot if not there
if not WindowHotspotInfo(win, sPrompt, 1) then
WindowAddHotspot (win, sPrompt, gauge_left, vertical, WINDOW_WIDTH - 5, vertical + font_height,
"", "", "", "", "", "", 0, 0)
end -- if
-- store numeric values in case they mouse over it
WindowHotspotTooltip(win, sPrompt, string.format ("%s\t%i / %i (%i%%)",
sPrompt, current, max, Fraction * 100) )
vertical = vertical + font_height + 3
end -- function DoGauge
function do_prompt (name, line, wildcards)
hp, max_hp = tonumber (wildcards [1]), tonumber (wildcards [2])
mana, max_mana = tonumber (wildcards [3]), tonumber (wildcards [4])
move, max_move = tonumber (wildcards [5]), tonumber (wildcards [6])
-- fill entire box to clear it
check (WindowRectOp (win, 2, 0, 0, 0, 0, BACKGROUND_COLOUR)) -- fill entire box
-- Edge around box rectangle
check (WindowCircleOp (win, 3, 0, 0, 0, 0, BORDER_COLOUR, 0, 2, 0, 1))
vertical = 6 -- pixel to start at
DoGauge ("HP: ", hp , max_hp, ColourNameToRGB "darkgreen")
DoGauge ("Mana: ", mana, max_mana, ColourNameToRGB "mediumblue")
DoGauge ("Move: ", move, max_move, ColourNameToRGB "gold")
WindowShow (win, true)
end -- function do_prompt
function OnPluginInstall ()
win = GetPluginID ()
font_id = "fn"
require "movewindow" -- load the movewindow.lua module
-- install the window movement handler, get back the window position
windowinfo = movewindow.install (win, 7) -- default to 7 (on right, center top/bottom)
font_name = "Fixedsys" -- the font
-- make miniwindow so I can grab the font info
WindowCreate (win,
windowinfo.window_left,
windowinfo.window_top,
WINDOW_WIDTH,
WINDOW_HEIGHT,
windowinfo.window_mode,
windowinfo.window_flags,
BACKGROUND_COLOUR)
-- add the drag handler so they can move the window around
movewindow.add_drag_handler (win, 0, 0, 0, 0)
WindowFont (win, font_id, font_name, 9)
font_height = WindowFontInfo (win, font_id, 1) -- height
-- 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, "Mana: "))
gauge_left = math.max (gauge_left, WindowTextWidth (win, font_id, "Move: "))
gauge_left = gauge_left + 5 -- allow gap from edge
if GetVariable ("enabled") == "false" then
ColourNote ("yellow", "", "Warning: Plugin " .. GetPluginName ().. " is currently disabled.")
check (EnablePlugin(GetPluginID (), false))
end -- they didn't enable us last time
end -- OnPluginInstall
function OnPluginDisable ()
WindowShow (win, false)
end -- OnPluginDisable
function OnPluginEnable ()
WindowShow (win, true)
-- draw gauge again if possible
if hp and max_hp and mana and max_mana and move and max_move then
do_prompt ("", "", { hp, max_hp, mana, max_mana, move, max_move } )
end -- if know hp, endurance and guile
end -- OnPluginEnable
function OnPluginSaveState ()
-- save window current location for next time
movewindow.save_state (win)
SetVariable ("enabled", tostring (GetPluginInfo (GetPluginID (), 17)))
end -- OnPluginSaveState
]]>
</script>
</muclient>