From c6e2848b56e5305b29bef90d4bc409c6b258fce3 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Thu, 10 Sep 2020 10:52:37 +0200 Subject: [PATCH] Fix changable="months" mode --- API.md | 2 +- gui.lua | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/API.md b/API.md index e1df05e..0f2120e 100644 --- a/API.md +++ b/API.md @@ -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 diff --git a/gui.lua b/gui.lua index 0a68dbb..843e900 100644 --- a/gui.lua +++ b/gui.lua @@ -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