@ -6,7 +6,7 @@
<!-- Plugin "Aardwolf_Clock" generated by Plugin Wizard -->
<muclient >
<plugin name= "Aardwolf_Clock" author= "Crowley, with help from Fiendish" id= "28a36788fa20aa062e760ee2" language= "Lua" purpose= "Displays a realtime clock based on Aardwolf game time" save_state= "y" date_written= "2018-05-15 11:43:22" requires= "4.90" version= " 4 .00">
<plugin name= "Aardwolf_Clock" author= "Crowley, with help from Fiendish" id= "28a36788fa20aa062e760ee2" language= "Lua" purpose= "Displays a realtime clock based on Aardwolf game time" save_state= "y" date_written= "2018-05-15 11:43:22" requires= "4.90" version= " 5 .00">
</plugin>
@ -46,6 +46,8 @@ require 'themed_miniwindows'
async_ok, async = pcall (require, "async")
local s = 0
clock_seasons = {
Sun = {138, 3, 19, 1, "Light"},
Scourge = {162, 9, 18, 2, "Disease"},
@ -100,65 +102,15 @@ font = "f"
checked_time = false
footer_text = {}
font_name = GetAlphaOption("output_font_name")
font_size = GetOption("output_font_height")
font_families = utils.getfontfamilies()
if font_families["Monoid"] then
font_name = "Monoid"
font_size = 8
elseif font_families["Dina"] then
font_name = "Dina"
font_size = 8
elseif font_families["Lucida Sans Console"] then
font_name = "Lucida Sans Console"
font_size = 10
else
font_name = "Consolas"
font_size = 10
if not GetVariable("showTitleBar") then
SetVariable("showTitleBar", "true")
end
clockWin = ThemedBasicWindow(
win, -- id
0, -- default_left_position
0, -- default_top_position
0, -- default_width
0, -- default_height
"AardClock", -- title
"center", -- title alignment
false, -- is_temporary
1, -- resizer_type
nil, -- do_while_resizing
nil, -- do_after_resizing
nil, -- do_on_delete
fontName, -- title_font_name
fontSize, -- title_font_size
true -- defer_showing
)
require 'tprint'
--tprint(clockWin)
WindowFont(win, font, clockWin.title_font_name, clockWin.title_font_size, true)
title_height = WindowFontInfo(win, font, 1) + 5
WindowFont(win, font, font_name, font_size, true)
font_height = WindowFontInfo(win, font, 1)
font_width = WindowTextWidth(win, font, " ", 1)
window_width = (20 * font_width) + 11
cx = math.floor((window_width-5)/2) + 3
cy = cx + font_height + title_height
function round(v)
local r = 0
if type(v) == 'number' then
i, f = math.modf(v)
if f >0.5 then
r = i + 1
else
r = i
end
end
return r
if not GetVariable("showDigital") then
SetVariable("showDigital", "false")
end
function findPos(t)
@ -184,20 +136,128 @@ function findPos(t)
return {posx = x - offset, posy = y}
end
PLUGIN_VERSION = GetPluginInfo(GetPluginID(), 19)
PLUGIN_NAME = GetPluginInfo(GetPluginID(), 1)
function createWindow()
clockWin = ThemedBasicWindow(
win, -- id
0, -- default_left_position
0, -- default_top_position
0, -- default_width
0, -- default_height
GetVariable("showTitleBar") == "true" and "AardClock" or nil, -- title
"center", -- title alignment
false, -- is_temporary
1, -- resizer_type
nil, -- do_while_resizing
nil, -- do_after_resizing
nil, -- do_on_delete
fontName, -- title_font_name
fontSize, -- title_font_size
true -- defer_showing
)
table.insert(clockWin.menu_table, "Show title bar")
table.insert(clockWin.menu_table, "Hide title bar")
table.insert(clockWin.menu_table, "Compact mode")
table.insert(clockWin.menu_table, "Full mode")
table.insert(
clockWin.menu_handlers,
function()
showTitleBar()
end
)
table.insert(
clockWin.menu_handlers,
function()
hideTitleBar()
end
)
table.insert(
clockWin.menu_handlers,
function()
showDigital()
end
)
table.insert(
clockWin.menu_handlers,
function()
showAnalog()
end
)
WindowFont(win, font, clockWin.title_font_name, clockWin.title_font_size, true)
title_height = (GetVariable("showTitleBar") == "true" and (WindowFontInfo(win, font, 1) + 5)) or 0
WindowFont(win, font, font_name, font_size, true)
font_height = WindowFontInfo(win, font, 1)
font_width = WindowTextWidth(win, font, " ", 1)
window_width = (20 * font_width) + 11
cx = math.floor((window_width-5)/2) + 3
cy = cx + font_height + title_height
clock_numbers = {}
for i = 1,12 do
table.insert(clock_numbers, {text = i, pos = findPos(i)})
end
endy = GetVariable("showDigital") == "false" and clock_numbers[6].pos.posy or (#footer_text + 5) * font_height
starty = GetVariable("showDigital") == "false" and clock_numbers[12].pos.posy or 0
window_height = font_height + title_height + 5 + endy + starty + (font_height * (#footer_text + 2))
clockWin:resize(window_width, window_height)
end
createWindow()
function showDigital()
SetVariable("showDigital", "true")
SaveState()
clockWin:hide()
createWindow()
Execute("aardclock time")
end
clock_numbers = {}
for i = 1,12 do
table.insert(clock_numbers, {text = i, pos = findPos(i)})
function showAnalog()
SetVariable("showDigital", "false")
SaveState()
clockWin:hide()
createWindow()
Execute("aardclock time")
end
endy = clock_numbers[6].pos.posy
starty = clock_numbers[12].pos.posy
window_height = font_height + title_height + 5 + endy + starty + (font_height * (#footer_text + 2)) -- font_height * 10
function showTitleBar()
SetVariable("showTitleBar", "true")
SaveState()
clockWin:hide()
createWindow()
Execute("aardclock time")
end
function hideTitleBar()
SetVariable("showTitleBar", "false")
SaveState()
clockWin:hide()
createWindow()
Execute("aardclock time")
end
require 'tprint'
function round(v)
local r = 0
if type(v) == 'number' then
i, f = math.modf(v)
if f >0.5 then
r = i + 1
else
r = i
end
end
return r
end
PLUGIN_VERSION = GetPluginInfo(GetPluginID(), 19)
PLUGIN_NAME = GetPluginInfo(GetPluginID(), 1)
clockWin:resize(window_width, window_height)
bgDay = 'khaki'
bgNight = 'navy'
@ -242,8 +302,10 @@ function drawFace()
clockWin:blank()
WindowDrawImage(win, "background", 0, 0, (WindowInfo(win, 3) or 0), (WindowInfo(win, 4) or 0), miniwin.image_stretch)
local addPos = GetVariable("showDigital") == "false" and clock_numbers[6].pos.posy or 10
local x = 5
local y = clock_numbers[6].pos.posy + title_height + font_height * 2
local y = (title_height + font_height * 2) + addPos
WindowText(win, font, seasonEnd, center(seasonEnd), font_height/2 + title_height, 0, 0, ColourNameToRGB(textColour))
@ -252,36 +314,45 @@ function drawFace()
WindowText(win, font, sunr, x, title_height + font_height*1.5, 0, 0, ColourNameToRGB(textColour))
local cdiml, cdimt = font_width, title_height + font_height*2.5
local cdimr, cdimb = cdiml + font_width*2, cdimt + (font_width*2)
local cdiml, cdimt = font_width, title_height + font_height*2.5
local cdimr, cdimb = cdiml + font_width*2, cdimt + (font_width*2)
WindowCircleOp(win, 1, cdiml, cdimt, cdimr, cdimb, ColourNameToRGB("yellow"), 2, 1, ColourNameToRGB("yellow"), 0)
cdiml = (WindowInfo(win, 3) - 5) - font_width*3
cdimr = cdiml + font_width*2
WindowCircleOp(win, 1, cdiml, cdimt, cdimr, cdimb, ColourNameToRGB("yellow"), 2, 1, ColourNameToRGB("yellow"), 0)
WindowText(win, font, suns, ((WindowInfo(win, 3) -5) - font_width*4), title_height + font_height*1.5, 0, 0, ColourNameToRGB(textColour) )
cdiml = (WindowInfo(win, 3) - 5) - font_width*3
cdimr = cdiml + font_width*2
WindowCircleOp(win, 1, cdiml, cdimt, cdimr, cdimb, ColourNameToRGB("orangered"), 2, 1, ColourNameToRGB("orangered"), 0)
WindowText(win, font, suns, ((WindowInfo(win, 3) -5) - font_width*4), title_height + font_height*1.5, 0, 0, ColourNameToRGB(textColour) )
sqdim = circleDraw(cx, cy, 68 )
WindowCircleOp(win, 1, cdiml, cdimt, cdimr, cdimb, ColourNameToRGB("orangered"), 2, 1, ColourNameToRGB("orangered"), 0)
if GetVariable("showDigital") == "false" then
sqdim = circleDraw(cx, cy, 68 )
WindowCircleOp(win, 1, sqdim.l, sqdim.t, sqdim.r, sqdim.b, ColourNameToRGB(handColour), 0, 1, 0, 1 )
WindowCircleOp(win, 1, sqdim.l, sqdim.t, sqdim.r, sqdim.b, ColourNameToRGB(handColour), 0, 1, 0, 1 )
sqdim = circleDraw(cx, cy, 70 )
sqdim = circleDraw(cx, cy, 70 )
WindowCircleOp(win, 1, sqdim.l, sqdim.t, sqdim.r, sqdim.b, ColourNameToRGB(handColour), 0, 1, 0, 1 )
WindowCircleOp(win, 1, sqdim.l, sqdim.t, sqdim.r, sqdim.b, ColourNameToRGB(handColour), 0, 1, 0, 1)
sqdim = circleDraw(cx, cy, 7 1)
sqdim = circleDraw(cx, cy, 7 1)
WindowCircleOp(win, 1, sqdim.l, sqdim.t, sqdim.r, sqdim.b, ColourNameToRGB(handColour), 0, 1, 0, 1)
WindowCircleOp(win, 1, sqdim.l, sqdim.t, sqdim.r, sqdim.b, ColourNameToRGB(handColour), 0, 1, 0, 1 )
sqdim = circleDraw(cx, cy, 72 )
sqdim = circleDraw(cx, cy, 72 )
WindowCircleOp(win, 1, sqdim.l, sqdim.t, sqdim.r, sqdim.b, ColourNameToRGB(handColour), 0, 1, 0, 1 )
WindowCircleOp(win, 1, sqdim.l, sqdim.t, sqdim.r, sqdim.b, ColourNameToRGB(handColour), 0, 1, 0, 1)
for _,v in ipairs(clock_numbers) do
WindowText(win, font, v.text, v.pos.posx, v.pos.posy, 0, 0, ColourNameToRGB(textColour))
end
end
for _,v in ipairs(clock_numbers) do
WindowText(win, font, v.text, v.pos.posx, v.pos.posy, 0, 0, ColourNameToRGB(textColour))
if GetVariable("showDigital") == "true" then
dTime = string.format("%s:%02d%s", tostring(hourTime), math.floor(s)*2, postTime)
else
dTime = hourTime .. postTime
end
WindowText(win, font, (dTime or ""), center((dTime or "")), y, 0, 0, ColourNameToRGB(textColour))
@ -292,10 +363,16 @@ function drawFace()
y = y + font_height
WindowText(win, font, string.format("[ %s ]", footer_text.DamType), center(string.format("[ %s ]", footer_text.DamType)), y, 0, 0, ColourNameToRGB(textColour))
if GetVariable("showDigital") == "true" then
y = y + font_height
WindowText(win, font, "[ Next tick: " .. 30 - math.floor(s) .. " ]", center("[ Next tick: " .. 30 - math.floor(s) .. " ]"), y, 0, 0, ColourNameToRGB(textColour))
--clockWin:resize(window_width, y+font_height)
end
WindowRectOp(win, 4, 1, 1, WindowInfo(win, 3)-1, WindowInfo(win, 4)-1, ColourNameToRGB("black"), ColourNameToRGB("black")) -- 9, 15 + 0x1000 + 0x4000)
clockWin:dress_window()
Redraw()
--clockWin:resize(window_width, window_height )
Redraw()
end
function center(t)
@ -323,10 +400,11 @@ function OnPluginBroadcast (msg, id, name, text)
end
if rTime >= 12 then
dTime = hourTime .. "pm"
postTime = "pm"
else
dTime = hourTime .. "am"
postTime = "am"
end
checkColours()
ResetTimer("clockTimer")
last_tick = os.clock()
@ -383,10 +461,10 @@ function getTime(name, line, args)
hourTime = tonumber(args[1])
if args[2] == "a" then
rTime = tonumber(args[1])
dTime = hourTime .. "am"
postTime = "am"
else
rTime = tonumber(args[1]) + 12
dTime = hourTime .. "pm"
postTime = "pm"
end
end
@ -411,20 +489,20 @@ function updateTime()
local rH, rM = math.floor(mins_left/60), math.floor(mins_left%60)
seasonEnd = seasonEnd .. rH .. "h " .. rM .. "m"
--clockWin.title = seasonEnd
end
function onTimer()
if checked_time then
last_tick = last_tick or os.clock()
local s = os.clock() - last_tick
s = os.clock() - last_tick
updateTime()
clockWin:blank()
drawFace()
drawHand(math.min(30, s), 60, 30)
hourHandTime = hourTime + s/30
drawHand(hourHandTime, 45, 12)
--clockWin:dress_window()
if GetVariable("showDigital") == "false" then
drawHand(math.min(30, s), 60, 30)
hourHandTime = hourTime + s/30
drawHand(hourHandTime, 45, 12)
end
Redraw()
end
end