Add support for custom holiday colors

master
Wuzzy 2020-09-10 02:16:02 +02:00
parent f71c788fea
commit fb46fead56
2 changed files with 20 additions and 6 deletions

6
API.md
View File

@ -116,6 +116,8 @@ Holidays can be queried with `calendar.get_holidays`.
* `def`: Holiday definition. A table with these fields:
* `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
* Arguments when `type=="monthday"`:
* `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.
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
```
-- First day of every year

20
gui.lua
View File

@ -118,6 +118,7 @@ function calendar.show_calendar(player_name, settings, wanted_months, wanted_yea
pday = iday + 1
end
local day_str = tostring(pday)
local holiday_color
local box_color = COLOR_DAYBOX
local holidays = calendar.get_holidays(tdays)
local tooltip_lines = {}
@ -125,11 +126,18 @@ function calendar.show_calendar(player_name, settings, wanted_months, wanted_yea
local is_holiday = false
if settings.show_holidays and #holidays > 0 then
is_holiday = true
local text_color = COLOR_HOLIDAY
for h=1, #holidays do
table.insert(tooltip_lines, minetest.colorize(COLOR_HOLIDAY, holidays[h].name))
end
day_str = minetest.colorize(COLOR_HOLIDAY, day_str)
box_color = COLOR_DAYBOX_HOLIDAY
if holidays[h].text_color then
text_color = holidays[h].text_color
else
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
day_str = F(day_str)
-- 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.."]"
else
local day_num = pday
if is_holiday then
day_num = minetest.colorize(COLOR_HOLIDAY, pday)
if is_holiday and settings.show_holidays then
day_num = minetest.colorize(holiday_color, pday)
end
-- Fake button to display the day box. Clicking has no effect, this
-- fake button is only used to support tooltips as a workaround