summaryrefslogtreecommitdiff
path: root/myhighscore/scoreboard.lua
blob: 38e659e9a80406c51d98f5e269bddda34a5841c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75




local button_form = "size[6,8;]"..
				"background[0,0;6,8;myhighscore_form_bg.png]"..
				"label[1,0.5;HIGH SCORES]"..
				"button[1,1;4,1;game;label]"..
				"button_exit[4,7;1,2;exit;Exit]"

--place holders
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 {}
	-- Obtain a comma separated list of scores to display
	local scorelist = ""
	for _,score in pairs(scores) do
		scorelist = scorelist .. minetest.formspec_escape(score.player) ..
			"\t\t\t\t " .. score.score ..","
	end

	return "size[6,8;]"..
		"background[0,0;6,8;myhighscore_form_bg.png]"..
		"label[1,0.5;HIGH SCORES FOR "..def.description.."]"..
		"label[1,1.5;PLAYER]"..
		"label[3.5,1.5;SCORE]"..
		"textlist[0.5,2;5,5;;"..scorelist.."]"..
		"button[2,7;1,2;back;Back]"..
		"button_exit[4,7;1,2;exit;Exit]"
end


minetest.register_node("myhighscore:score_board", {
	description = "Score Board",
	tiles = {
			"myhighscore_top.png",
			"myhighscore_back.png",
			"myhighscore_side.png^[transformFX",
			"myhighscore_side.png",
			"myhighscore_back.png",
			"myhighscore_front.png",
			},
	drawtype = "nodebox",
	paramtype = "light",
	paramtype2 = "facedir",
	groups = {cracky = 1},
	node_box = {
		type = "fixed",
		fixed = {
			{-0.375, -0.5, -0.5, 0.375, -0.1875, 0.5},
			{-0.375, -0.5, 0.1875, 0.375, 0.5, 0.5},
			{-0.1875, -0.5, -0.3125, -0.125, 0, -0.25},
			{-0.375, -0.5, 0, -0.3125, 0.5, 0.5},
			{0.3125, -0.5, 0, 0.375, 0.5, 0.5},
			{-0.375, 0.4375, 0, 0.375, 0.5, 0.5},
		}
	},
	on_construct = function(pos)
		local meta = minetest.env:get_meta(pos)
		meta:set_string("formspec", button_form)
		meta:set_string("infotext", "High Scores")
	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)
		end
	end,
})