Allow to hide today and holidays
parent
e1f7f23925
commit
efa5620db6
8
API.md
8
API.md
|
@ -112,14 +112,16 @@ used in `calendar.register_holiday`.
|
||||||
|
|
||||||
### `calendar.show_calendar(player_name, settings, wanted_months, wanted_years)`
|
### `calendar.show_calendar(player_name, settings, wanted_months, wanted_years)`
|
||||||
Display a graphical calendar to player. It shows the days of a single month
|
Display a graphical calendar to player. It shows the days of a single month
|
||||||
with one numbered box per day. Holidays and the current day are marked and
|
with one numbered box per day. Also, holidays and the current day can be marked and
|
||||||
have a tooltip.
|
get a tooltip.
|
||||||
|
|
||||||
* `player_name`: Named of player
|
* `player_name`: Named of player
|
||||||
* `settings`: Table to customize calendar:
|
* `settings`: Table to customize calendar:
|
||||||
* `ordinal`: If `true`, use ordinal numbers, otherwise, use cardinal numbers (default: `false`)
|
* `ordinal`: If `true`, use ordinal numbers, otherwise, use cardinal numbers (default: `false`)
|
||||||
* `show_weekdays`: If `true`, show weekdays and arrange the day boxes to weekdays (default: `true`)
|
* `show_weekdays`: If `true`, show weekdays and arrange the day boxes to weekdays (default: `true`)
|
||||||
* `show_controls`: If `true`, show buttons to change the month and year
|
* `show_today`: If `true`, mark today (default: `true`)
|
||||||
|
* `show_holiday`: If `true`, mark holidays (default: `true`)
|
||||||
|
* `show_controls`: If `true`, show buttons to change the month and year (default: `true`)
|
||||||
* `wanted_months`: Which cardinal calendar month to show (default: current one)
|
* `wanted_months`: Which cardinal calendar month to show (default: current one)
|
||||||
* `wanted_years`: Which cardinal calendar year to show (default: current one)
|
* `wanted_years`: Which cardinal calendar year to show (default: current one)
|
||||||
|
|
||||||
|
|
33
gui.lua
33
gui.lua
|
@ -14,22 +14,21 @@ local COLOR_TOOLTIP_TODAY = COLOR_DAYBOX_TODAY
|
||||||
|
|
||||||
local player_current_calendars = {}
|
local player_current_calendars = {}
|
||||||
|
|
||||||
local ORDINAL = true
|
local DEFAULT_SETTINGS = {
|
||||||
local SHOW_WEEKDAYS = true
|
ordinal = true,
|
||||||
local SHOW_CONTROLS = true
|
show_weekdays = true,
|
||||||
local DEFAULT_SETTINGS = { ordinal = ORDINAL, show_weekdays = SHOW_WEEKDAYS, show_controls = SHOW_CONTROLS }
|
show_today = true,
|
||||||
|
show_holidays = true,
|
||||||
|
show_controls = true,
|
||||||
|
}
|
||||||
|
|
||||||
function calendar.show_calendar(player_name, settings, wanted_months, wanted_years)
|
function calendar.show_calendar(player_name, settings, wanted_months, wanted_years)
|
||||||
local ordinal, show_weekdays, show_controls
|
|
||||||
if not settings then
|
if not settings then
|
||||||
settings = DEFAULT_SETTINGS
|
settings = DEFAULT_SETTINGS
|
||||||
end
|
end
|
||||||
ordinal = settings.ordinal
|
|
||||||
show_weekdays = settings.show_weekdays
|
|
||||||
show_controls = settings.show_controls
|
|
||||||
local days, months, years = calendar.get_date()
|
local days, months, years = calendar.get_date()
|
||||||
local total_days = minetest.get_day_count()
|
local total_days = minetest.get_day_count()
|
||||||
local ddays, dmonths, dyears = calendar.get_date(nil, ordinal)
|
local ddays, dmonths, dyears = calendar.get_date(nil, settings.ordinal)
|
||||||
local wanted_dmonths, wanted_dyears
|
local wanted_dmonths, wanted_dyears
|
||||||
if not wanted_months then
|
if not wanted_months then
|
||||||
wanted_months = months
|
wanted_months = months
|
||||||
|
@ -39,12 +38,12 @@ function calendar.show_calendar(player_name, settings, wanted_months, wanted_yea
|
||||||
end
|
end
|
||||||
wanted_dmonths = wanted_months
|
wanted_dmonths = wanted_months
|
||||||
wanted_dyears = wanted_years
|
wanted_dyears = wanted_years
|
||||||
if ordinal then
|
if settings.ordinal then
|
||||||
wanted_dmonths = wanted_dmonths + 1
|
wanted_dmonths = wanted_dmonths + 1
|
||||||
wanted_dyears = wanted_dyears + 1
|
wanted_dyears = wanted_dyears + 1
|
||||||
end
|
end
|
||||||
local formspec = ""
|
local formspec = ""
|
||||||
if ordinal then
|
if settings.ordinal then
|
||||||
formspec = formspec .. "label[0.5,0.5;"..F(S("Month @1, year @2", wanted_dmonths, wanted_dyears)).."]"
|
formspec = formspec .. "label[0.5,0.5;"..F(S("Month @1, year @2", wanted_dmonths, wanted_dyears)).."]"
|
||||||
else
|
else
|
||||||
formspec = formspec .. "label[0.5,0.5;"..F(S("@1 months, @2 years", wanted_dmonths, wanted_dyears)).."]"
|
formspec = formspec .. "label[0.5,0.5;"..F(S("@1 months, @2 years", wanted_dmonths, wanted_dyears)).."]"
|
||||||
|
@ -55,7 +54,7 @@ function calendar.show_calendar(player_name, settings, wanted_months, wanted_yea
|
||||||
tdays = tdays + wanted_months * calendar.MONTH_DAYS
|
tdays = tdays + wanted_months * calendar.MONTH_DAYS
|
||||||
local tdays_start = tdays
|
local tdays_start = tdays
|
||||||
local weekday, x, y
|
local weekday, x, y
|
||||||
if show_weekdays then
|
if settings.show_weekdays then
|
||||||
weekday = calendar.get_weekday(tdays)
|
weekday = calendar.get_weekday(tdays)
|
||||||
x, y = 0.75, 1.2
|
x, y = 0.75, 1.2
|
||||||
for w=1, #calendar.weekday_names_short do
|
for w=1, #calendar.weekday_names_short do
|
||||||
|
@ -75,14 +74,14 @@ function calendar.show_calendar(player_name, settings, wanted_months, wanted_yea
|
||||||
end
|
end
|
||||||
x = (weekday*1.1)- 0.5
|
x = (weekday*1.1)- 0.5
|
||||||
local pday = iday
|
local pday = iday
|
||||||
if ordinal then
|
if settings.ordinal then
|
||||||
pday = iday + 1
|
pday = iday + 1
|
||||||
end
|
end
|
||||||
local day_str = tostring(pday)
|
local day_str = tostring(pday)
|
||||||
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 = {}
|
||||||
if #holidays > 0 then
|
if settings.show_holidays and #holidays > 0 then
|
||||||
for h=1, #holidays do
|
for h=1, #holidays do
|
||||||
table.insert(tooltip_lines, minetest.colorize(COLOR_HOLIDAY, holidays[h].name))
|
table.insert(tooltip_lines, minetest.colorize(COLOR_HOLIDAY, holidays[h].name))
|
||||||
end
|
end
|
||||||
|
@ -90,7 +89,7 @@ function calendar.show_calendar(player_name, settings, wanted_months, wanted_yea
|
||||||
box_color = COLOR_DAYBOX_HOLIDAY
|
box_color = COLOR_DAYBOX_HOLIDAY
|
||||||
end
|
end
|
||||||
day_str = F(day_str)
|
day_str = F(day_str)
|
||||||
if tdays == total_days then
|
if settings.show_today and tdays == total_days then
|
||||||
formspec = formspec .. "box["..(x-0.05)..","..(y-0.05)..";1.1,1.1;"..COLOR_DAYBOX_TODAY.."]"
|
formspec = formspec .. "box["..(x-0.05)..","..(y-0.05)..";1.1,1.1;"..COLOR_DAYBOX_TODAY.."]"
|
||||||
table.insert(tooltip_lines, minetest.colorize(COLOR_TOOLTIP_TODAY, S("Today")))
|
table.insert(tooltip_lines, minetest.colorize(COLOR_TOOLTIP_TODAY, S("Today")))
|
||||||
end
|
end
|
||||||
|
@ -102,11 +101,11 @@ function calendar.show_calendar(player_name, settings, wanted_months, wanted_yea
|
||||||
tdays = tdays + 1
|
tdays = tdays + 1
|
||||||
end
|
end
|
||||||
y = y + 1.1
|
y = y + 1.1
|
||||||
if show_weekdays and calendar.get_weekday(tdays_start) <= calendar.get_weekday(tdays - 1) then
|
if settings.show_weekdays and calendar.get_weekday(tdays_start) <= calendar.get_weekday(tdays - 1) then
|
||||||
y = y + 1.1
|
y = y + 1.1
|
||||||
end
|
end
|
||||||
y = y + 0.1
|
y = y + 0.1
|
||||||
if show_controls then
|
if settings.show_controls then
|
||||||
if wanted_months > 0 or wanted_years > 0 then
|
if wanted_months > 0 or wanted_years > 0 then
|
||||||
formspec = formspec .. "button[0.5,"..y..";1,1;prev_year;<<]"
|
formspec = formspec .. "button[0.5,"..y..";1,1;prev_year;<<]"
|
||||||
.. "button[1.5,"..y..";1,1;prev_month;<]"
|
.. "button[1.5,"..y..";1,1;prev_month;<]"
|
||||||
|
|
Loading…
Reference in New Issue