Permalink
Browse files

add score board to gitignore, improve menucode modularity, add first …

…draft of score board implementation
  • Loading branch information...
1 parent b839eb8 commit 1cec28f6cb293c539a6fd4a225fdd7280eace3cb @ludamad committed Feb 21, 2013
Showing with 226 additions and 100 deletions.
  1. +1 −0 .gitignore
  2. +77 −0 res/start_menu/lobby_menu.lua
  3. +25 −0 res/start_menu/menu_utils.lua
  4. +84 −0 res/start_menu/scores_menu.lua
  5. +39 −100 res/start_menu/start_menu.lua
View
1 .gitignore
@@ -11,5 +11,6 @@ CMakeLists.txt.orig
*.wav
*.exe
*.zip
+*.score
stdout.txt
stderr.txt
View
77 res/start_menu/lobby_menu.lua
@@ -0,0 +1,77 @@
+require "InstanceGroup"
+require "InstanceBox"
+require "Sprite"
+require "TextLabel"
+require "utils"
+require "menu_utils"
+
+local PLAYER_COLOURS = {
+ COL_BABY_BLUE, COL_PALE_YELLOW, COL_PALE_RED,
+ COL_PALE_GREEN, COL_PALE_BLUE, COL_LIGHT_GRAY
+}
+
+local function lobby_joined_players_list_create()
+ local font = font_cached_load(settings.menu_font, 20)
+ local group = InstanceGroup.create()
+ group.size = {200, 400} -- For placement algorithms
+
+ group:add_instance(
+ TextLabel.create(font, {color=COL_WHITE, origin = CENTER_TOP}, "Players In Game:"),
+ {100, 30}
+ )
+
+ local lobby_list = { step = do_nothing }
+
+ function lobby_list:draw(xy)
+ local font = font_cached_load(settings.font, 10)
+ local x, y = unpack(xy)
+
+ for idx, player in ipairs(game.players) do
+ local color_idx = ( (idx -1) % #PLAYER_COLOURS ) + 1
+ local color = PLAYER_COLOURS[ color_idx ]
+
+ local text = "Player " .. idx .. ": "
+ if idx == 1 then -- Slot 1 always local player
+ text = text .. "You, "
+ end
+ text = text .. player.name .. " the " .. player.class_name
+
+ font:draw(
+ { color = color, origin = CENTER_TOP },
+ { x, y + (idx - 1) * 20 },
+ text
+ )
+ end
+ end
+
+ group:add_instance( lobby_list, {100, 70} )
+
+ return group
+end
+
+local function lobby_menu_create(on_start_click)
+ local menu = InstanceBox.create( { size = display.window_size } )
+ local logo = Sprite.image_create("res/interface/sprites/lanarts_logo.png")
+
+ menu:add_instance(
+ logo,
+ CENTER_TOP,
+ --[[Down 10 pixels]]
+ {0, 10}
+ )
+
+ menu:add_instance(
+ lobby_joined_players_list_create(),
+ CENTER_TOP,
+ {0, 10 + logo.size[2]}
+ )
+
+ menu:add_instance(
+ text_button_create("Start the Game!", on_start_click, text_button_params),
+ CENTER_BOTTOM,
+ --[[Up 40 pixels]]
+ {0, -40}
+ )
+
+ return menu
+end
View
25 res/start_menu/menu_utils.lua
@@ -0,0 +1,25 @@
+require "TextLabel"
+require "utils"
+
+
+function text_button_create(text, on_click, params)
+ local no_hover_color = params.color or COL_WHITE
+ local hover_color = params.hover_color or no_hover_color
+ local padding = params.click_box_padding or 5
+ local font = params.font
+
+ local label = TextLabel.create(font, { color=no_hover_color }, text)
+
+ function label:step(xy) -- Makeshift inheritance
+ TextLabel.step(self, xy)
+
+ local bbox = bbox_padded( xy, self.size, padding )
+ self.options.color = bbox_mouse_over( bbox ) and hover_color or no_hover_color
+
+ if mouse_left_pressed and bbox_mouse_over( bbox ) then
+ on_click()
+ end
+ end
+
+ return label
+end
View
84 res/start_menu/scores_menu.lua
@@ -0,0 +1,84 @@
+require "game_settings_menu"
+
+require "InstanceBox"
+require "Sprite"
+require "TextLabel"
+require "utils"
+require "config"
+
+local text_button_params = {
+ font = font_cached_load(settings.menu_font, 12),
+ color = COL_WHITE,
+ hover_color = COL_RED,
+ click_box_padding = 5
+}
+
+local function scores_menu_list_create()
+
+ local group = InstanceGroup.create()
+ group.size = {200, 400} -- For placement algorithms
+
+ group:add_instance(
+ TextLabel.create(
+ font_cached_load(settings.menu_font, 20),
+ {color=COL_WHITE, origin = CENTER_TOP},
+ "Highscore List:"
+ ),
+ {100, 30}
+ )
+
+ local scores_drawer = { step = do_nothing }
+
+ local scores = game.score_board_fetch()
+ local font = font_cached_load(settings.font, 10)
+ function scores_drawer:draw(xy)
+ local x, y = unpack(xy)
+
+ for idx, score_entry in ipairs(scores) do
+ local text_parts = {
+ idx .. ") ", score_entry.name,
+ "floor=", score_entry.deepest_floor,
+ "kills=", score_entry.kills,
+ "level=", score_entry.character_level,
+ "hardcore=", tostring(score_entry.hardcore)
+ }
+
+ font:draw(
+ { color = COL_WHITE, origin = CENTER_TOP },
+ { x, y + (idx - 1) * 20 },
+ table.concat(text_parts)
+ )
+ end
+ end
+
+ group:add_instance( scores_drawer, {100, 70} )
+
+ return group
+end
+
+function scores_menu_create(on_back_click)
+ local menu = InstanceBox.create( { size = display.window_size } )
+ local logo = Sprite.image_create("res/interface/sprites/lanarts_logo.png")
+
+ menu:add_instance(
+ logo,
+ CENTER_TOP,
+ --[[Down 10 pixels]]
+ {0, 10}
+ )
+
+ menu:add_instance(
+ scores_menu_list_create(),
+ CENTER_TOP,
+ {0, 10 + logo.size[2]}
+ )
+
+ menu:add_instance(
+ text_button_create("Back", on_back_click, text_button_params),
+ CENTER_BOTTOM,
+ --[[Up 40 pixels]]
+ {0, -40}
+ )
+
+ return menu
+end
View
139 res/start_menu/start_menu.lua
@@ -1,33 +1,23 @@
require "game_settings_menu"
+require "scores_menu"
require "InstanceBox"
require "Sprite"
require "TextLabel"
require "utils"
require "config"
+require "menu_utils"
-- START SCREEN --
-local function text_button_create(text, on_click)
- local font = font_cached_load(settings.menu_font, 20)
- local label = TextLabel.create(font, { color=COL_WHITE }, text)
- local padding = 5
-
- function label:step(xy) -- Makeshift inheritance
- TextLabel.step(self, xy)
-
- local bbox = bbox_padded( xy, self.size, padding )
- self.options.color = bbox_mouse_over( bbox ) and COL_RED or COL_WHITE
-
- if mouse_left_pressed and bbox_mouse_over( bbox ) then
- on_click()
- end
- end
-
- return label
-end
+local text_button_params = {
+ font = font_cached_load(settings.menu_font, 20),
+ color = COL_WHITE,
+ hover_color = COL_RED,
+ click_box_padding = 5
+}
-local function start_menu_create(on_start_click, on_load_click)
+local function start_menu_create(on_start_click, on_load_click, on_score_click)
local menu = InstanceBox.create( { size = display.window_size } )
menu:add_instance(
@@ -37,104 +27,43 @@ local function start_menu_create(on_start_click, on_load_click)
{0, 10}
)
+ local y_position = 100 -- Start down 100 pixels
menu:add_instance(
- text_button_create("Start a New Game", on_start_click),
+ text_button_create("Start a New Game", on_start_click, text_button_params),
CENTER,
- --[[Down 100 pixels]]
- {0, 100}
+ {0, y_position}
)
+ y_position = y_position + 50
+
if file_exists("savefile.save") then
menu:add_instance(
- text_button_create("Continue Game", on_load_click),
+ text_button_create("Continue Game", on_load_click, text_button_params),
CENTER,
- --[[Down 150 pixels]]
- {0, 150}
+ {0, y_position}
)
+ y_position = y_position + 50
end
+ menu:add_instance(
+ text_button_create("Highscores", on_score_click, text_button_params),
+ CENTER,
+ {0, y_position}
+ )
+ y_position = y_position + 50
+
+
function menu:step(xy) -- Makeshift inheritance
InstanceBox.step(self, xy)
if key_pressed('N') then
on_start_click()
+ elseif key_pressed('S') then
+ on_score_click()
end
end
return menu
end
--- LOBBY SCREEN --
-
-local PLAYER_COLOURS = {
- COL_BABY_BLUE, COL_PALE_YELLOW, COL_PALE_RED,
- COL_PALE_GREEN, COL_PALE_BLUE, COL_LIGHT_GRAY
-}
-
-local function lobby_joined_players_list_create()
- local font = font_cached_load(settings.menu_font, 20)
- local group = InstanceGroup.create()
- group.size = {200, 400}
-
- group:add_instance(
- TextLabel.create(font, {color=COL_WHITE, origin = CENTER_TOP}, "Players In Game:"),
- {100, 30}
- )
-
- local lobby_list = { step = do_nothing }
-
- function lobby_list:draw(xy)
- local font = font_cached_load(settings.font, 10)
- local x, y = unpack(xy)
-
- for idx, player in ipairs(game.players) do
- local color_idx = ( (idx -1) % #PLAYER_COLOURS ) + 1
- local color = PLAYER_COLOURS[ color_idx ]
-
- local text = "Player " .. idx .. ": "
- if idx == 1 then -- Slot 1 always local player
- text = text .. "You, "
- end
- text = text .. player.name .. " the " .. player.class_name
-
- font:draw(
- { color = color, origin = CENTER_TOP },
- { x, y + (idx - 1) * 20 },
- text
- )
- end
- end
-
- group:add_instance( lobby_list, {100, 70} )
-
- return group
-end
-
-local function lobby_menu_create(on_start_click)
- local menu = InstanceBox.create( { size = display.window_size } )
- local logo = Sprite.image_create("res/interface/sprites/lanarts_logo.png")
-
- menu:add_instance(
- logo,
- CENTER_TOP,
- --[[Down 10 pixels]]
- {0, 10}
- )
-
- menu:add_instance(
- lobby_joined_players_list_create(),
- CENTER_TOP,
- {0, 10 + logo.size[2]}
- )
-
- menu:add_instance(
- text_button_create("Start the Game!", on_start_click),
- CENTER_BOTTOM,
- --[[Up 40 pixels]]
- {0, -40}
- )
-
- return menu
-end
-
-- MAIN --
@@ -146,6 +75,7 @@ local exit_menu -- forward declare
local setup_start_menu -- forward declare
local setup_settings_menu -- forward declare
local setup_lobby_menu -- forward declare
+local setup_scores_menu -- forward declare
function exit_menu()
menu_state.menu = nil -- Signals event loop that menu is finished
@@ -171,15 +101,15 @@ function setup_start_menu()
end
menu_state.menu:add_instance(
- start_menu_create( --[[New Game Button]] setup_settings_menu, --[[Load Game Button]] on_load_click),
+ start_menu_create( --[[New Game Button]] setup_settings_menu, --[[Load Game Button]] on_load_click, --[[Highscores Button]] setup_scores_menu),
CENTER
)
end
function setup_settings_menu()
menu_state.menu = InstanceBox.create( { size = display.window_size } )
- function menu_state.continue()
+ menu_state.continue = function ()
if settings.class_type ~= -1 then
exit_menu()
end
@@ -200,6 +130,15 @@ function setup_lobby_menu()
)
end
+function setup_scores_menu()
+ menu_state.menu = InstanceBox.create( { size = display.window_size } )
+ menu_state.continue = setup_start_menu
+ menu_state.menu:add_instance(
+ scores_menu_create( --[[Back Button]] setup_start_menu ),
+ CENTER
+ )
+end
+
local function menu_loop(should_poll)
while game.input_capture() and not key_pressed(keys.ESCAPE) do
if key_pressed(keys.F9) then

0 comments on commit 1cec28f

Please sign in to comment.