Fix changable="months" mode

master
Wuzzy 2020-09-10 10:52:37 +02:00
parent ef753f94a2
commit c6e2848b56
2 changed files with 6 additions and 5 deletions

2
API.md
View File

@ -177,7 +177,7 @@ get a tooltip.
* `show_holiday`: If `true`, mark holidays (default: `true`)
* `changable`: Which controls are available:
* `"full"`: Can change year and month (default)
* `"months"`: Can change month only
* `"months"`: Can change month within selected year only
* `"none"`: Can't change anything
* `today_button`: Whether to show the 'Today' button (default: `true`)
Note: If `changable=="none"`, the 'Today' button is never shown

View File

@ -183,8 +183,9 @@ function calendar.show_calendar(player_name, settings, wanted_months, wanted_yea
local chg_years = settings.changable == "full"
-- Add controls
if chg_months then
if wanted_months > 0 or wanted_years > 0 then
if chg_months or wanted_months > 0 then
if (chg_years or wanted_months > 0) or (not chg_years and wanted_months > 0) then
formspec = formspec .. "button[1.5,"..y..";1,1;prev_month;<]"
.. "tooltip[prev_month;"..F(S("Previous month")).."]"
end
@ -197,7 +198,7 @@ function calendar.show_calendar(player_name, settings, wanted_months, wanted_yea
formspec = formspec .. "button[2.5,"..y..";2,1;today;"..F(S("Today")).."]"
end
if chg_months or wanted_months < calendar.MONTHS - 1 then
if (chg_years or wanted_months < calendar.MONTHS - 1) or (not chg_years and wanted_months < calendar.MONTHS - 1) then
formspec = formspec .. "button[4.5,"..y..";1,1;next_month;>]"
.. "tooltip[next_month;"..F(S("Next month")).."]"
end
@ -256,7 +257,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
if fields.next_month then
cur_months = cur_months + 1
if cur_months > calendar.MONTHS - 1 then
if settings.changable == "months" or settings.changable == "full" then
if settings.changable == "full" then
cur_months = 0
cur_years = cur_years + 1
else
@ -267,7 +268,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
elseif fields.prev_month then
cur_months = cur_months - 1
if cur_months < 0 and cur_years > 0 then
if settings.changable == "months" or settings.changable == "full" then
if settings.changable == "full" then
cur_months = calendar.MONTHS - 1
cur_years = cur_years - 1
else