@ -6,7 +6,7 @@
<!-- Plugin "Aardwolf_Clock" generated by Plugin Wizard -->
<!-- Plugin "Aardwolf_Clock" generated by Plugin Wizard -->
<muclient >
<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>
</plugin>
@ -46,6 +46,8 @@ require 'themed_miniwindows'
async_ok, async = pcall (require, "async")
async_ok, async = pcall (require, "async")
local s = 0
clock_seasons = {
clock_seasons = {
Sun = {138, 3, 19, 1, "Light"},
Sun = {138, 3, 19, 1, "Light"},
Scourge = {162, 9, 18, 2, "Disease"},
Scourge = {162, 9, 18, 2, "Disease"},
@ -100,29 +102,48 @@ font = "f"
checked_time = false
checked_time = false
footer_text = {}
footer_text = {}
font_name = GetAlphaOption("output_font_name")
font_size = GetOption("output_font_height")
font_families = utils.getfontfamilies()
if not GetVariable("showTitleBar") then
if font_families["Monoid"] then
SetVariable("showTitleBar", "true")
font_name = "Monoid"
end
font_size = 8
elseif font_families["Dina"] then
if not GetVariable("showDigital") then
font_name = "Dina"
SetVariable("showDigital", "false")
font_size = 8
end
elseif font_families["Lucida Sans Console"] then
font_name = "Lucida Sans Console"
function findPos(t)
font_size = 10
local spt = 12.0
else
local r = 62
font_name = "Consolas"
local offset = 0
font_size = 10
if t > 6 then
offset = font_width
elseif t< = 6 then
offset = font_width/2
end
local a = 2 * math.pi * (spt-t) / spt
local diff = 0.9 -- default 0.9
local s = math.sin(a)
local c = math.cos(a)
local x = 1 + round(cx - diff * r * s)
local y = 10 + round(cy - diff * r * c)
return {posx = x - offset, posy = y}
end
end
function createWindow()
clockWin = ThemedBasicWindow(
clockWin = ThemedBasicWindow(
win, -- id
win, -- id
0, -- default_left_position
0, -- default_left_position
0, -- default_top_position
0, -- default_top_position
0, -- default_width
0, -- default_width
0, -- default_height
0, -- default_height
"AardClock", -- title
GetVariable("showTitleBar") == "true" and "AardClock" or nil , -- title
"center", -- title alignment
"center", -- title alignment
false, -- is_temporary
false, -- is_temporary
1, -- resizer_type
1, -- resizer_type
@ -133,12 +154,37 @@ clockWin = ThemedBasicWindow(
fontSize, -- title_font_size
fontSize, -- title_font_size
true -- defer_showing
true -- defer_showing
)
)
table.insert(clockWin.menu_table, "Show title bar")
require 'tprint'
table.insert(clockWin.menu_table, "Hide title bar")
--tprint(clockWin)
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)
WindowFont(win, font, clockWin.title_font_name, clockWin.title_font_size, true)
title_height = WindowFontInfo(win, font, 1) + 5
title_height = (GetVariable("showTitleBar") == "true" and ( WindowFontInfo(win, font, 1) + 5)) or 0
WindowFont(win, font, font_name, font_size, true)
WindowFont(win, font, font_name, font_size, true)
font_height = WindowFontInfo(win, font, 1)
font_height = WindowFontInfo(win, font, 1)
@ -148,6 +194,54 @@ window_width = (20 * font_width) + 11
cx = math.floor((window_width-5)/2) + 3
cx = math.floor((window_width-5)/2) + 3
cy = cx + font_height + title_height
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
function showAnalog()
SetVariable("showDigital", "false")
SaveState()
clockWin:hide()
createWindow()
Execute("aardclock time")
end
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)
function round(v)
local r = 0
local r = 0
if type(v) == 'number' then
if type(v) == 'number' then
@ -161,43 +255,9 @@ function round(v)
return r
return r
end
end
function findPos(t)
local spt = 12.0
local r = 62
local offset = 0
if t > 6 then
offset = font_width
elseif t< = 6 then
offset = font_width/2
end
local a = 2 * math.pi * (spt-t) / spt
local diff = 0.9 -- default 0.9
local s = math.sin(a)
local c = math.cos(a)
local x = 1 + round(cx - diff * r * s)
local y = 10 + round(cy - diff * r * c)
return {posx = x - offset, posy = y}
end
PLUGIN_VERSION = GetPluginInfo(GetPluginID(), 19)
PLUGIN_VERSION = GetPluginInfo(GetPluginID(), 19)
PLUGIN_NAME = GetPluginInfo(GetPluginID(), 1)
PLUGIN_NAME = GetPluginInfo(GetPluginID(), 1)
clock_numbers = {}
for i = 1,12 do
table.insert(clock_numbers, {text = i, pos = findPos(i)})
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
clockWin:resize(window_width, window_height)
bgDay = 'khaki'
bgDay = 'khaki'
bgNight = 'navy'
bgNight = 'navy'
@ -242,8 +302,10 @@ function drawFace()
clockWin:blank()
clockWin:blank()
WindowDrawImage(win, "background", 0, 0, (WindowInfo(win, 3) or 0), (WindowInfo(win, 4) or 0), miniwin.image_stretch)
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 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))
WindowText(win, font, seasonEnd, center(seasonEnd), font_height/2 + title_height, 0, 0, ColourNameToRGB(textColour))
@ -266,6 +328,8 @@ function drawFace()
sqdim = circleDraw(cx, cy, 68)
sqdim = circleDraw(cx, cy, 68)
if GetVariable("showDigital") == "false" then
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)
@ -283,6 +347,13 @@ function drawFace()
for _,v in ipairs(clock_numbers) do
for _,v in ipairs(clock_numbers) do
WindowText(win, font, v.text, v.pos.posx, v.pos.posy, 0, 0, ColourNameToRGB(textColour))
WindowText(win, font, v.text, v.pos.posx, v.pos.posy, 0, 0, ColourNameToRGB(textColour))
end
end
end
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))
WindowText(win, font, (dTime or ""), center((dTime or "")), y, 0, 0, ColourNameToRGB(textColour))
y = y + font_height
y = y + font_height
@ -292,10 +363,16 @@ function drawFace()
y = y + font_height
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))
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)
WindowRectOp(win, 4, 1, 1, WindowInfo(win, 3)-1, WindowInfo(win, 4)-1, ColourNameToRGB("black"), ColourNameToRGB("black")) -- 9, 15 + 0x1000 + 0x4000)
clockWin:dress_window()
clockWin:dress_window()
--clockWin:resize(window_width, window_height)
Redraw()
Redraw()
end
end
function center(t)
function center(t)
@ -323,10 +400,11 @@ function OnPluginBroadcast (msg, id, name, text)
end
end
if rTime >= 12 then
if rTime >= 12 then
dTime = hourTime .. "pm"
postTime = "pm"
else
else
dTime = hourTime .. "am"
postTime = "am"
end
end
checkColours()
checkColours()
ResetTimer("clockTimer")
ResetTimer("clockTimer")
last_tick = os.clock()
last_tick = os.clock()
@ -383,10 +461,10 @@ function getTime(name, line, args)
hourTime = tonumber(args[1])
hourTime = tonumber(args[1])
if args[2] == "a" then
if args[2] == "a" then
rTime = tonumber(args[1])
rTime = tonumber(args[1])
dTime = hourTime .. "am"
postTime = "am"
else
else
rTime = tonumber(args[1]) + 12
rTime = tonumber(args[1]) + 12
dTime = hourTime .. "pm"
postTime = "pm"
end
end
end
end
@ -411,20 +489,20 @@ function updateTime()
local rH, rM = math.floor(mins_left/60), math.floor(mins_left%60)
local rH, rM = math.floor(mins_left/60), math.floor(mins_left%60)
seasonEnd = seasonEnd .. rH .. "h " .. rM .. "m"
seasonEnd = seasonEnd .. rH .. "h " .. rM .. "m"
--clockWin.title = seasonEnd
end
end
function onTimer()
function onTimer()
if checked_time then
if checked_time then
last_tick = last_tick or os.clock()
last_tick = last_tick or os.clock()
local s = os.clock() - last_tick
s = os.clock() - last_tick
updateTime()
updateTime()
clockWin:blank()
clockWin:blank()
drawFace()
drawFace()
if GetVariable("showDigital") == "false" then
drawHand(math.min(30, s), 60, 30)
drawHand(math.min(30, s), 60, 30)
hourHandTime = hourTime + s/30
hourHandTime = hourTime + s/30
drawHand(hourHandTime, 45, 12)
drawHand(hourHandTime, 45, 12)
--clockWin:dr ess_wi ndow()
end
Redraw()
Redraw()
end
end
end
end