Add support for custom holiday colors
parent
f71c788fea
commit
fb46fead56
6
API.md
6
API.md
|
@ -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
|
||||||
|
|
20
gui.lua
20
gui.lua
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue