Add rp_formspec.refresh_formspec

master
Wuzzy 2022-08-12 22:20:57 +02:00
parent 2944b3ff8f
commit 6ef253a0da
4 changed files with 25 additions and 5 deletions

View File

@ -200,10 +200,7 @@ local function check_achievement_gotten(player, aname)
minetest.log("action", "[rp_achievements] " .. name .. " got achievement '"..aname.."'")
end
if rp_formspec.get_current_invpage(player) == "rp_achievements:achievements" then
local form = achievements.get_formspec(name)
player:set_inventory_formspec(form)
end
rp_formspec.refresh_invpage(player, "rp_achievements:achievements")
end
function achievements.trigger_subcondition(player, aname, subcondition)

View File

@ -113,9 +113,10 @@ The regular page then *becomes* an invpage by doing this.
### `rp_formspec.set_current_invpage(player, page)`
### `rp_formspec.set_current_invpage(player, invpage)`
Set the current invpage of `player` to the invpage with the name `page`.
If the player is already at this invpage, the invpage is refreshed.
@ -125,6 +126,19 @@ Returns the name of the current invpage of `player`.
### `rp_formspec.refresh_invpage(player, invpage)`
Regenerates the formspec for the `invpage` of player.
Call this whenever you need to report to `rp_formspec`
the formspec of an invpage had some changes (i.e. new
elements).
For example, on an achievements page, when the list
of achievments has changed.
Note: The invpage is automatically rebuilt when the current
invpage is selected manually.
### `rp_formspec.register_invtab(name, def)`
Registers an invtab and associates it with an invpage.

View File

@ -400,6 +400,13 @@ function rp_formspec.set_current_invpage(player, page)
current_invpage[pname] = page
end
function rp_formspec.refresh_invpage(player, invpage)
local current = rp_formspec.get_current_invpage(player)
if invpage == current then
rp_formspec.set_current_invpage(player, invpage)
end
end
function rp_formspec.get_current_invpage(player)
local pname = player:get_player_name()
return current_invpage[pname]

View File

@ -229,6 +229,8 @@ local function on_joinplayer(player)
minetest.log("action", "[rp_player_skins] Player "..name.." appears to be new, setting initial random skin")
player_skins.set_random_skin(name)
end
rp_formspec.refresh_invpage(player, "rp_player_skins:player_skins")
end
local function on_leaveplayer(player)