diff --git a/API.md b/API.md index 950af84..43b5b22 100644 --- a/API.md +++ b/API.md @@ -112,14 +112,16 @@ used in `calendar.register_holiday`. ### `calendar.show_calendar(player_name, settings, wanted_months, wanted_years)` 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 -have a tooltip. +with one numbered box per day. Also, holidays and the current day can be marked and +get a tooltip. * `player_name`: Named of player * `settings`: Table to customize calendar: * `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_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_years`: Which cardinal calendar year to show (default: current one) diff --git a/gui.lua b/gui.lua index ff9f6b5..464a591 100644 --- a/gui.lua +++ b/gui.lua @@ -14,22 +14,21 @@ local COLOR_TOOLTIP_TODAY = COLOR_DAYBOX_TODAY local player_current_calendars = {} -local ORDINAL = true -local SHOW_WEEKDAYS = true -local SHOW_CONTROLS = true -local DEFAULT_SETTINGS = { ordinal = ORDINAL, show_weekdays = SHOW_WEEKDAYS, show_controls = SHOW_CONTROLS } +local DEFAULT_SETTINGS = { + ordinal = true, + show_weekdays = true, + show_today = true, + show_holidays = true, + show_controls = true, +} function calendar.show_calendar(player_name, settings, wanted_months, wanted_years) - local ordinal, show_weekdays, show_controls if not settings then settings = DEFAULT_SETTINGS end - ordinal = settings.ordinal - show_weekdays = settings.show_weekdays - show_controls = settings.show_controls local days, months, years = calendar.get_date() 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 if not wanted_months then wanted_months = months @@ -39,12 +38,12 @@ function calendar.show_calendar(player_name, settings, wanted_months, wanted_yea end wanted_dmonths = wanted_months wanted_dyears = wanted_years - if ordinal then + if settings.ordinal then wanted_dmonths = wanted_dmonths + 1 wanted_dyears = wanted_dyears + 1 end 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)).."]" else 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 local tdays_start = tdays local weekday, x, y - if show_weekdays then + if settings.show_weekdays then weekday = calendar.get_weekday(tdays) x, y = 0.75, 1.2 for w=1, #calendar.weekday_names_short do @@ -75,14 +74,14 @@ function calendar.show_calendar(player_name, settings, wanted_months, wanted_yea end x = (weekday*1.1)- 0.5 local pday = iday - if ordinal then + if settings.ordinal then pday = iday + 1 end local day_str = tostring(pday) local box_color = COLOR_DAYBOX local holidays = calendar.get_holidays(tdays) local tooltip_lines = {} - if #holidays > 0 then + if settings.show_holidays and #holidays > 0 then for h=1, #holidays do table.insert(tooltip_lines, minetest.colorize(COLOR_HOLIDAY, holidays[h].name)) end @@ -90,7 +89,7 @@ function calendar.show_calendar(player_name, settings, wanted_months, wanted_yea box_color = COLOR_DAYBOX_HOLIDAY end 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.."]" table.insert(tooltip_lines, minetest.colorize(COLOR_TOOLTIP_TODAY, S("Today"))) end @@ -102,11 +101,11 @@ function calendar.show_calendar(player_name, settings, wanted_months, wanted_yea tdays = tdays + 1 end 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 end y = y + 0.1 - if show_controls then + if settings.show_controls then if wanted_months > 0 or wanted_years > 0 then formspec = formspec .. "button[0.5,"..y..";1,1;prev_year;<<]" .. "button[1.5,"..y..";1,1;prev_month;<]"