Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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