Update Aardwolf_Clock.xml

New features
master
AardCrowley 10 months ago committed by GitHub
parent f9b424faf8
commit 1a62c10b52
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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,29 +102,48 @@ 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
if not GetVariable("showDigital") then
SetVariable("showDigital", "false")
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
function createWindow()
clockWin = ThemedBasicWindow(
win, -- id
0, -- default_left_position
0, -- default_top_position
0, -- default_width
0, -- default_height
"AardClock", -- title
GetVariable("showTitleBar") == "true" and "AardClock" or nil, -- title
"center", -- title alignment
false, -- is_temporary
1, -- resizer_type
@ -133,12 +154,37 @@ clockWin = ThemedBasicWindow(
fontSize, -- title_font_size
true -- defer_showing
)
require 'tprint'
--tprint(clockWin)
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 = 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)
font_height = WindowFontInfo(win, font, 1)
@ -148,6 +194,54 @@ 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
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)
local r = 0
if type(v) == 'number' then
@ -161,43 +255,9 @@ function round(v)
return r
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_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'
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))
@ -266,6 +328,8 @@ function drawFace()
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)
sqdim = circleDraw(cx, cy, 70)
@ -283,6 +347,13 @@ function drawFace()
for _,v in ipairs(clock_numbers) do
WindowText(win, font, v.text, v.pos.posx, v.pos.posy, 0, 0, ColourNameToRGB(textColour))
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))
y = y + font_height
@ -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()
--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()
if GetVariable("showDigital") == "false" then
drawHand(math.min(30, s), 60, 30)
hourHandTime = hourTime + s/30
drawHand(hourHandTime, 45, 12)
--clockWin:dress_window()
end
Redraw()
end
end

Loading…
Cancel
Save