Compare commits

...

5 Commits

Author SHA1 Message Date
Wuzzy 35f4201dbd Version 1.1.1 2020-09-10 10:54:15 +02:00
Wuzzy c6e2848b56 Fix changable="months" mode 2020-09-10 10:54:05 +02:00
Wuzzy ef753f94a2 Version 1.1.0 2020-09-10 02:29:51 +02:00
Wuzzy fb46fead56 Add support for custom holiday colors 2020-09-10 02:21:32 +02:00
Wuzzy f71c788fea Version 1.0.0 2020-09-08 22:46:05 +02:00
3 changed files with 27 additions and 12 deletions

8
API.md
View File

@ -116,6 +116,8 @@ Holidays can be queried with `calendar.get_holidays`.
* `def`: Holiday definition. A table with these fields: * `def`: Holiday definition. A table with these fields:
* `name`: Human-readable holiday name * `name`: Human-readable holiday name
* `text_color` (optional): Custom text color of day/tooltip text
* `daybox_color` (optional): Custom text color of day box
* `type`: type of holiday, determines other arguments * `type`: type of holiday, determines other arguments
* Arguments when `type=="monthday"`: * Arguments when `type=="monthday"`:
* `days`: Cardinal month day on which the holiday occurs * `days`: Cardinal month day on which the holiday occurs
@ -126,6 +128,10 @@ Holidays can be queried with `calendar.get_holidays`.
return true if it's a holiday and false if not. return true if it's a holiday and false if not.
Try to keep your calculations as simple as possible Try to keep your calculations as simple as possible
When no colors are specified, a default green color is used. When multiple holidays fall
on the same day and the holidays use different colors, the day box will assume the color
of the first registered holiday (the order is not predictable).
#### Examples #### Examples
``` ```
-- First day of every year -- First day of every year
@ -171,7 +177,7 @@ get a tooltip.
* `show_holiday`: If `true`, mark holidays (default: `true`) * `show_holiday`: If `true`, mark holidays (default: `true`)
* `changable`: Which controls are available: * `changable`: Which controls are available:
* `"full"`: Can change year and month (default) * `"full"`: Can change year and month (default)
* `"months"`: Can change month only * `"months"`: Can change month within selected year only
* `"none"`: Can't change anything * `"none"`: Can't change anything
* `today_button`: Whether to show the 'Today' button (default: `true`) * `today_button`: Whether to show the 'Today' button (default: `true`)
Note: If `changable=="none"`, the 'Today' button is never shown Note: If `changable=="none"`, the 'Today' button is never shown

View File

@ -12,7 +12,7 @@ There are 7 weekdays from Monday to Sunday, starting at Monday.
The calendar starts at Day 1, Month 1 (January), Year 1. The calendar starts at Day 1, Month 1 (January), Year 1.
## Version ## Version
0.1.0 1.1.1
## Compability ## Compability
This mod is designed for Minetest 5.3.0, but there's a compability This mod is designed for Minetest 5.3.0, but there's a compability

29
gui.lua
View File

@ -118,6 +118,7 @@ function calendar.show_calendar(player_name, settings, wanted_months, wanted_yea
pday = iday + 1 pday = iday + 1
end end
local day_str = tostring(pday) local day_str = tostring(pday)
local holiday_color
local box_color = COLOR_DAYBOX local box_color = COLOR_DAYBOX
local holidays = calendar.get_holidays(tdays) local holidays = calendar.get_holidays(tdays)
local tooltip_lines = {} local tooltip_lines = {}
@ -125,11 +126,18 @@ function calendar.show_calendar(player_name, settings, wanted_months, wanted_yea
local is_holiday = false local is_holiday = false
if settings.show_holidays and #holidays > 0 then if settings.show_holidays and #holidays > 0 then
is_holiday = true is_holiday = true
local text_color = COLOR_HOLIDAY
for h=1, #holidays do for h=1, #holidays do
table.insert(tooltip_lines, minetest.colorize(COLOR_HOLIDAY, holidays[h].name)) if holidays[h].text_color then
end text_color = holidays[h].text_color
day_str = minetest.colorize(COLOR_HOLIDAY, day_str) else
box_color = COLOR_DAYBOX_HOLIDAY text_color = COLOR_HOLIDAY
end
table.insert(tooltip_lines, minetest.colorize(text_color, holidays[h].name))
end
holiday_color = holidays[1].text_color or COLOR_HOLIDAY
day_str = minetest.colorize(holiday_color, day_str)
box_color = holidays[1].daybox_color or COLOR_DAYBOX_HOLIDAY
end end
day_str = F(day_str) day_str = F(day_str)
-- Highlight today -- Highlight today
@ -146,8 +154,8 @@ function calendar.show_calendar(player_name, settings, wanted_months, wanted_yea
.. "label["..(x+0.15)..","..(y+0.075)..";"..day_str.."]" .. "label["..(x+0.15)..","..(y+0.075)..";"..day_str.."]"
else else
local day_num = pday local day_num = pday
if is_holiday then if is_holiday and settings.show_holidays then
day_num = minetest.colorize(COLOR_HOLIDAY, pday) day_num = minetest.colorize(holiday_color, pday)
end end
-- Fake button to display the day box. Clicking has no effect, this -- Fake button to display the day box. Clicking has no effect, this
-- fake button is only used to support tooltips as a workaround -- fake button is only used to support tooltips as a workaround
@ -175,8 +183,9 @@ function calendar.show_calendar(player_name, settings, wanted_months, wanted_yea
local chg_years = settings.changable == "full" local chg_years = settings.changable == "full"
-- Add controls -- Add controls
if chg_months then if chg_months then
if wanted_months > 0 or wanted_years > 0 then if wanted_months > 0 or wanted_years > 0 then
if chg_months or wanted_months > 0 then if (chg_years or wanted_months > 0) or (not chg_years and wanted_months > 0) then
formspec = formspec .. "button[1.5,"..y..";1,1;prev_month;<]" formspec = formspec .. "button[1.5,"..y..";1,1;prev_month;<]"
.. "tooltip[prev_month;"..F(S("Previous month")).."]" .. "tooltip[prev_month;"..F(S("Previous month")).."]"
end end
@ -189,7 +198,7 @@ function calendar.show_calendar(player_name, settings, wanted_months, wanted_yea
formspec = formspec .. "button[2.5,"..y..";2,1;today;"..F(S("Today")).."]" formspec = formspec .. "button[2.5,"..y..";2,1;today;"..F(S("Today")).."]"
end end
if chg_months or wanted_months < calendar.MONTHS - 1 then if (chg_years or wanted_months < calendar.MONTHS - 1) or (not chg_years and wanted_months < calendar.MONTHS - 1) then
formspec = formspec .. "button[4.5,"..y..";1,1;next_month;>]" formspec = formspec .. "button[4.5,"..y..";1,1;next_month;>]"
.. "tooltip[next_month;"..F(S("Next month")).."]" .. "tooltip[next_month;"..F(S("Next month")).."]"
end end
@ -248,7 +257,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
if fields.next_month then if fields.next_month then
cur_months = cur_months + 1 cur_months = cur_months + 1
if cur_months > calendar.MONTHS - 1 then if cur_months > calendar.MONTHS - 1 then
if settings.changable == "months" or settings.changable == "full" then if settings.changable == "full" then
cur_months = 0 cur_months = 0
cur_years = cur_years + 1 cur_years = cur_years + 1
else else
@ -259,7 +268,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
elseif fields.prev_month then elseif fields.prev_month then
cur_months = cur_months - 1 cur_months = cur_months - 1
if cur_months < 0 and cur_years > 0 then if cur_months < 0 and cur_years > 0 then
if settings.changable == "months" or settings.changable == "full" then if settings.changable == "full" then
cur_months = calendar.MONTHS - 1 cur_months = calendar.MONTHS - 1
cur_years = cur_years - 1 cur_years = cur_years - 1
else else