Fix show_calendar default interpretation
parent
f8601bf6ca
commit
56545f370f
34
gui.lua
34
gui.lua
|
@ -9,20 +9,33 @@ local COLOR_TOOLTIP_TODAY = COLOR_DAYBOX_TODAY
|
|||
|
||||
local player_current_calendars = {}
|
||||
|
||||
ORDINAL = true
|
||||
SHOW_WEEKDAYS = true
|
||||
SHOW_TODAY = true
|
||||
SHOWHOLIDAYS = true
|
||||
SHOW_CONTROLS = true
|
||||
|
||||
local DEFAULT_SETTINGS = {
|
||||
ordinal = true,
|
||||
show_weekdays = true,
|
||||
show_today = true,
|
||||
show_holidays = true,
|
||||
show_controls = true,
|
||||
ordinal = ORDINAL,
|
||||
show_weekdays = SHOW_WEEKDAYS,
|
||||
show_today = SHOW_TODAY,
|
||||
show_holidays = SHOW_HOLIDAYS,
|
||||
show_controls = SHOW_CONTROLS,
|
||||
}
|
||||
|
||||
local SHOW_AREA_TOOLTIPS = minetest.features.formspec_version_element
|
||||
|
||||
function calendar.show_calendar(player_name, settings, wanted_months, wanted_years, caption_format)
|
||||
-- Get settings, use defaults if needed
|
||||
if not settings then
|
||||
settings = DEFAULT_SETTINGS
|
||||
end
|
||||
for k,v in pairs(DEFAULT_SETTINGS) do
|
||||
if settings[k] == nil then
|
||||
settings[k] = v
|
||||
end
|
||||
end
|
||||
|
||||
local days, months, years = calendar.get_date()
|
||||
local total_days = minetest.get_day_count()
|
||||
local ddays, dmonths, dyears = calendar.get_date(nil, settings.ordinal)
|
||||
|
@ -43,6 +56,8 @@ function calendar.show_calendar(player_name, settings, wanted_months, wanted_yea
|
|||
local tdays = 0
|
||||
tdays = tdays + wanted_years * (calendar.MONTHS * calendar.MONTH_DAYS)
|
||||
tdays = tdays + wanted_months * calendar.MONTH_DAYS
|
||||
|
||||
-- Render caption
|
||||
local formspec = ""
|
||||
local caption = ""
|
||||
if caption_format then
|
||||
|
@ -64,6 +79,7 @@ function calendar.show_calendar(player_name, settings, wanted_months, wanted_yea
|
|||
formspec = formspec .. "label[0.5,0.5;"..F(caption).."]"
|
||||
end
|
||||
|
||||
-- Render weekday names
|
||||
local tdays_start = tdays
|
||||
local weekday, x, y
|
||||
if settings.show_weekdays then
|
||||
|
@ -77,6 +93,7 @@ function calendar.show_calendar(player_name, settings, wanted_months, wanted_yea
|
|||
weekday = 0
|
||||
end
|
||||
|
||||
-- Render day boxes, day numbers and highlights
|
||||
x, y = 0.5, 1.7
|
||||
for iday=0, calendar.MONTH_DAYS - 1 do
|
||||
weekday = weekday + 1
|
||||
|
@ -93,6 +110,7 @@ function calendar.show_calendar(player_name, settings, wanted_months, wanted_yea
|
|||
local box_color = COLOR_DAYBOX
|
||||
local holidays = calendar.get_holidays(tdays)
|
||||
local tooltip_lines = {}
|
||||
-- Highlight holiday
|
||||
if settings.show_holidays and #holidays > 0 then
|
||||
if SHOW_AREA_TOOLTIPS then
|
||||
for h=1, #holidays do
|
||||
|
@ -103,6 +121,7 @@ function calendar.show_calendar(player_name, settings, wanted_months, wanted_yea
|
|||
box_color = COLOR_DAYBOX_HOLIDAY
|
||||
end
|
||||
day_str = F(day_str)
|
||||
-- Highlight today
|
||||
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.."]"
|
||||
if SHOW_AREA_TOOLTIPS then
|
||||
|
@ -121,6 +140,7 @@ function calendar.show_calendar(player_name, settings, wanted_months, wanted_yea
|
|||
y = y + 1.1
|
||||
end
|
||||
y = y + 0.1
|
||||
-- Add controls
|
||||
if settings.show_controls then
|
||||
if wanted_months > 0 or wanted_years > 0 then
|
||||
formspec = formspec .. "button[0.5,"..y..";1,1;prev_year;<<]"
|
||||
|
@ -136,13 +156,15 @@ function calendar.show_calendar(player_name, settings, wanted_months, wanted_yea
|
|||
end
|
||||
local size_x = math.max(calendar.WEEK_DAYS+2, 7)
|
||||
local size_y = y+1.5
|
||||
|
||||
-- Formspec config
|
||||
if minetest.features.formspec_version_element then
|
||||
formspec = "formspec_version[3]" .. formspec
|
||||
end
|
||||
formspec = "size["..size_x..","..size_y.."]" .. formspec
|
||||
minetest.show_formspec(player_name, "calendar:calendar", formspec)
|
||||
|
||||
player_current_calendars[player_name] = { years = wanted_years, months = wanted_months }
|
||||
player_current_calendars[player_name] = { years = wanted_years, months = wanted_months, settings = settings, caption_format = caption_format }
|
||||
end
|
||||
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
|
|
Loading…
Reference in New Issue