diff options
author | Fernando Carmona Varo <ferkiwi@gmail.com> | 2015-11-07 09:56:53 +0100 |
---|---|---|
committer | Fernando Carmona Varo <ferkiwi@gmail.com> | 2015-11-07 09:56:53 +0100 |
commit | 6b5cbd4939b4f461e89f2c2ce79640aeae72a0c7 (patch) | |
tree | beb412b0e9d69d7a2fa9fa55dc1080f95105f705 | |
parent | 4c03a0e5880e44e920007ead8212025858a1fb21 (diff) |
Added game selection interface for myhighscores
-rwxr-xr-x | myhighscore/scoreboard.lua | 42 |
1 files changed, 31 insertions, 11 deletions
diff --git a/myhighscore/scoreboard.lua b/myhighscore/scoreboard.lua index 2de154b..d8f687e 100755 --- a/myhighscore/scoreboard.lua +++ b/myhighscore/scoreboard.lua @@ -13,9 +13,9 @@ local game_name = "the game" local game_player_name = "the player" local game_player_score = "648138" -local function get_formspec_for_game(name) - local def = myhighscore.registered_games[name] - local scores = myhighscore.scores[name] or {} +local function show_formspec_for_game(playername, gamename) + local def = myhighscore.registered_games[gamename] + local scores = myhighscore.scores[gamename] or {} -- Obtain a comma separated list of scores to display local scorelist = "" for _,score in pairs(scores) do @@ -23,14 +23,13 @@ local function get_formspec_for_game(name) "\t\t\t\t " .." ".. score.score .."," end - return "size[6,8;]".. + minetest.show_formspec(playername, "myhighscores:score_" .. gamename, "size[6,8;]".. "background[0,0;6,8;myhighscore_form_bg.png]".. "label[1,0.5;HIGH SCORES FOR "..def.description.."]".. "label[1.25,1.5;PLAYER]".. "label[3.5,1.5;SCORE]".. "textlist[0.5,2;5,5;;"..scorelist.."]".. - "button[1,7;2,1;back;Back]".. - "button_exit[3,7;2,1;exit;Exit]" + "button_exit[3,7;2,1;exit;Exit]") end @@ -61,15 +60,36 @@ minetest.register_node("myhighscore:score_board", { }, on_construct = function(pos) local meta = minetest.env:get_meta(pos) - meta:set_string("formspec", button_form) meta:set_string("infotext", "High Scores") + + local textlist = "" + for game,def in pairs(myhighscore.registered_games) do + textlist = textlist .." ".. minetest.formspec_escape(def.description) .. "," + end + + meta:set_string("formspec", "size[6,8;]".. + "background[0,0;6,8;myhighscore_form_bg.png]".. + "label[2,0.5;HIGH SCORES]".. + "label[1.3,1;Choose a game for its score]".. + "textlist[0.5,1.6;5,5;gameid;"..textlist.."]".. + "button_exit[2,7;2,1;exit;Exit]") + end, on_receive_fields = function(pos, formname, fields, sender) local meta = minetest.env:get_meta(pos) - if fields['game'] then - meta:set_string('formspec', get_formspec_for_game("pacmine")) - elseif fields["back"] then - meta:set_string('formspec', button_form) + local playername = sender:get_player_name() + if fields.gameid then + local event = minetest.explode_textlist_event(fields.gameid) + print(dump(fields) .. " " .. dump(event)) + -- find which game it is + local i, game = 0, nil + repeat + game = next(myhighscore.registered_games, game) + i = i + 1 + until not game or i == event.index + if game then + show_formspec_for_game(playername, game) + end end end, }) |