And now it doesn't work :/
http://i1224.photobucket.com/albums/ee371/AvilonRayne/GuageFail.png
Empty gauge window. :(
<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])
sp, max_sp = tonumber (wildcards [3]), tonumber (wildcards [4])
ep, max_ep = tonumber (wildcards [5]), tonumber (wildcards [6])
draw_the_bars ()
end -- do_prompt
function do_prompt2 (name, line, wildcards)
hp = tonumber (wildcards [1])
sp = tonumber (wildcards [2])
ep = tonumber (wildcards [3])
draw_the_bars ()
end -- do_prompt2
function draw_the_bars ()
local hp_percent = hp / max_hp
local sp_percent = sp / max_sp
local ep_percent = ep / max_ep
-- 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_percent, ColourNameToRGB "darkgreen")
DoGauge ("SP: ", sp_percent, ColourNameToRGB "mediumblue")
DoGauge ("EP: ", ep_percent, ColourNameToRGB "gold")
WindowShow (win, true)
end -- draw_the_bars
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 = "Courier New" -- 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, 10)
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, "SP: "))
gauge_left = math.max (gauge_left, WindowTextWidth (win, font_id, "EP: "))
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 sp and max_sp and ep and max_ep then
do_prompt ("", "", { hp, max_hp, sp, max_sp, ep, max_ep } )
end -- if know hp, sp and ep
end -- OnPluginEnable
function OnPluginSaveState ()
-- save window current location for next time
movewindow.save_state (win)
SetVariable ("enabled", tostring (GetPluginInfo (GetPluginID (), 17)))
end -- OnPluginSaveState
]]>
</script>
|