From fb46fead5682db23a09f6d8561fd0a313380b1dc Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Thu, 10 Sep 2020 02:16:02 +0200 Subject: [PATCH] Add support for custom holiday colors --- API.md | 6 ++++++ gui.lua | 20 ++++++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/API.md b/API.md index 3e1a24f..e1df05e 100644 --- a/API.md +++ b/API.md @@ -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 diff --git a/gui.lua b/gui.lua index fecb5e1..0a68dbb 100644 --- a/gui.lua +++ b/gui.lua @@ -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