Permalink
Browse files

Lua refactoring, {lobby=>pregame}_menu, display=>Display

  • Loading branch information...
1 parent 5b129cf commit bbeeecafa244c50abb5871524d57229a003dff22 @ludamad committed Apr 3, 2013
@@ -42,10 +42,10 @@ local function graph_line(func, range, color, draw_area)
end
local function draw_function_create()
- local w,h = unpack(display.window_size)
+ local w,h = unpack(Display.window_size)
local function draw_function()
- draw_rectangle(COL_WHITE, {0,0, unpack(display.window_size)} )
+ draw_rectangle(COL_WHITE, {0,0, unpack(Display.window_size)} )
for F in values(functions_to_plot) do
graph_line(
F[1],
@@ -69,9 +69,9 @@ local function menu_loop()
setglobal("DEBUG_LAYOUTS", not DEBUG_LAYOUTS) -- flip on/off
end
- display.draw_start()
+ Display.draw_start()
draw_function()
- display.draw_finish()
+ Display.draw_finish()
io.flush()
Game.wait(10)
@@ -84,6 +84,6 @@ end
function main()
local WINDOW_SIZE = { 800, 800 }
- display.initialize("Lanarts Example", WINDOW_SIZE, false)
+ Display.initialize("Lanarts Example", WINDOW_SIZE, false)
menu_loop()
end
View
@@ -67,7 +67,7 @@ function game_overlay_draw()
fps_count = fps_count + frame_increase
if fps then
- local w,h = unpack( display.window_size )
+ local w,h = unpack( Display.window_size )
Fonts.small:draw( {origin=RIGHT_BOTTOM}, {w, h}, "FPS: " .. math.floor(fps) )
end
@@ -23,7 +23,7 @@ local function action_bar_hints_create()
end
local function help_overlay_create()
- local overlay = InstanceBox.create( {size = display.window_size} )
+ local overlay = InstanceBox.create( {size = Display.window_size} )
local action_bar = action_bar_hints_create()
overlay:add_instance( action_bar, LEFT_BOTTOM, --[[Up 16 pixels]] {0, -16})
View
@@ -11,10 +11,10 @@ function Engine.menu_start(...)
return start_menu_show(...)
end
-function Engine.lobby_menu_start(...)
- require "lobby_menu"
+function Engine.pregame_menu_start(...)
+ require "pregame_menu"
- return lobby_menu_show(...)
+ return pregame_menu_show(...)
end
function Engine.loading_screen_draw(...)
@@ -55,7 +55,7 @@ local function loading_screen_setup(...)
return cached_setup(...)
end
- local screen_box = InstanceBox.create( { size = display.window_size } )
+ local screen_box = InstanceBox.create( { size = Display.window_size } )
screen_box:add_instance( center_screen_setup(), CENTER )
@@ -68,11 +68,11 @@ end
-- Loading callback
function loading_screen_draw(...)
perf.timing_begin("system.loading_draw")
- display.draw_start()
+ Display.draw_start()
local screen = loading_screen_setup(...)
screen:draw( {0,0} )
- display.draw_finish()
+ Display.draw_finish()
perf.timing_end("system.loading_draw")
end
@@ -1,84 +0,0 @@
-require "InstanceGroup"
-require "InstanceBox"
-require "Sprite"
-require "TextLabel"
-require "utils"
-require "menu_utils"
-
-local text_button_params = {
- font = font_cached_load(settings.menu_font, 20),
- color = COL_WHITE,
- hover_color = COL_RED,
- click_box_padding = 5
-}
-
-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(World.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
-
-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
@@ -7,34 +7,6 @@ require "utils"
local score_menu_font = "res/fonts/MateSC-Regular.ttf"
--- Draw parts of text colored differently
-local function draw_colored_parts(font, origin, xy, ...)
- local rx, ry = 0, 0
-
- local parts = {...}
- local x_coords = {}
-
- -- First calculate relative positions
- for idx, part in ipairs(parts) do
- local color, text = unpack(part)
- local w, h = unpack( font:draw_size(text) )
- x_coords[idx] = rx
- rx = rx + w
- end
-
- local adjusted_origin = {0, origin[2]}
- local adjusted_x = xy[1] - rx * origin[1]
-
- -- Next draw according to origin
- for idx, part in ipairs(parts) do
- local color, text = unpack(part)
- local position = {adjusted_x + x_coords[idx], xy[2]}
- font:draw( { color = color, origin = adjusted_origin }, position, text)
- end
-
- return rx -- return final width for further chaining
-end
-
-- This is a hack.
-- Currently we cannot rely on the sprites being loaded, so we duplicate information from class_sprites.yaml here
-- This will be fixed in the coming move from YAML to Lua (allowing us to simply require 'class_sprite_data.lua')
@@ -198,7 +170,7 @@ local function scores_menu_body_create()
end
function scores_menu_create(on_back_click)
- local menu = InstanceBox.create( { size = display.window_size } )
+ local menu = InstanceBox.create( { size = Display.window_size } )
local logo_displacement = 0
-- Display the logo if we are >= 800x600 res
@@ -7,7 +7,7 @@ require "TextLabel"
require "utils"
require "game_loop"
require "menu_utils"
-require "lobby_menu"
+require "pregame_menu"
-- START SCREEN --
@@ -19,7 +19,7 @@ local text_button_params = {
}
local function start_menu_create(on_start_click, on_load_click, on_score_click)
- local menu = InstanceBox.create( { size = display.window_size } )
+ local menu = InstanceBox.create( { size = Display.window_size } )
menu:add_instance(
Sprite.image_create("res/interface/sprites/lanarts_logo.png"),
@@ -75,7 +75,7 @@ local menu_state = { exit_game = false }
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_pregame_menu -- forward declare
local setup_scores_menu -- forward declare
function exit_menu(exit_game)
@@ -87,7 +87,7 @@ function exit_menu(exit_game)
end
function setup_start_menu()
- menu_state.menu = InstanceBox.create( { size = display.window_size } )
+ menu_state.menu = InstanceBox.create( { size = Display.window_size } )
menu_state.back = function()
exit_menu(--[[Quit game]] true)
@@ -116,7 +116,7 @@ function setup_start_menu()
end
function setup_settings_menu()
- menu_state.menu = InstanceBox.create( { size = display.window_size } )
+ menu_state.menu = InstanceBox.create( { size = Display.window_size } )
menu_state.back = setup_start_menu
menu_state.continue = function ()
@@ -131,21 +131,21 @@ function setup_settings_menu()
)
end
-function setup_lobby_menu()
- menu_state.menu = InstanceBox.create( { size = display.window_size } )
+function setup_pregame_menu()
+ menu_state.menu = InstanceBox.create( { size = Display.window_size } )
menu_state.back = function()
exit_menu(--[[Quit game]] true)
end
menu_state.continue = exit_menu
menu_state.menu:add_instance(
- lobby_menu_create( --[[Start Game Button]] menu_state.continue ),
+ pregame_menu_create( --[[Start Game Button]] menu_state.continue ),
CENTER
)
end
function setup_scores_menu()
- menu_state.menu = InstanceBox.create( { size = display.window_size } )
+ menu_state.menu = InstanceBox.create( { size = Display.window_size } )
menu_state.back = setup_start_menu
menu_state.continue = nil
menu_state.menu:add_instance(
@@ -178,9 +178,9 @@ local function menu_loop(should_poll)
return not menu_state.exit_game
end
- display.draw_start()
+ Display.draw_start()
menu_state.menu:draw( {0, 0} )
- display.draw_finish()
+ Display.draw_finish()
Game.wait(10)
end
@@ -195,8 +195,8 @@ function start_menu_show()
end
-function lobby_menu_show()
- setup_lobby_menu()
+function pregame_menu_show()
+ setup_pregame_menu()
return menu_loop(--[[Poll connections]] true)
end
@@ -29,7 +29,7 @@ local function lanarts_explain_screen_create(click_back, click_forward)
CENTER
)
- local window = InstanceBox.create( { size = display.window_size} )
+ local window = InstanceBox.create( { size = Display.window_size} )
window:add_instance(
contents,
CENTER
@@ -57,7 +57,7 @@ function tutorial_menu_show(...)
function go_forward() update_screen(screen_idx + 1) end
while Game.input_capture() and not key_pressed(keys.ESCAPE) and screen do
- display.draw_start()
+ Display.draw_start()
screen:step( {0,0} )
if key_pressed(keys.ESCAPE) then
@@ -69,7 +69,7 @@ function tutorial_menu_show(...)
end
screen:draw( {0,0} )
- display.draw_finish()
+ Display.draw_finish()
Game.wait(100)
end
@@ -7,7 +7,7 @@ require "utils"
local winning_screen_font = "res/fonts/MateSC-Regular.ttf"
local function winning_screen_create()
- local box = InstanceBox.create( { size = display.window_size} )
+ local box = InstanceBox.create( { size = Display.window_size} )
local sprite = Sprite.image_create("res/menus/winning_screen.png")
box:add_instance(
@@ -48,7 +48,7 @@ local function winning_screen_create()
black_box_alpha = math.max(0, black_box_alpha - 0.05)
draw_rectangle(
with_alpha(COL_BLACK, black_box_alpha),
- bbox_create( {0,0}, display.window_size )
+ bbox_create( {0,0}, Display.window_size )
)
end
@@ -59,10 +59,10 @@ function winning_screen_show(...)
local screen = winning_screen_create()
while Game.input_capture() and not key_pressed(keys.ESCAPE) do
- display.draw_start()
+ Display.draw_start()
screen:step( {0,0} )
screen:draw( {0,0} )
- display.draw_finish()
+ Display.draw_finish()
Game.wait(100)
end
@@ -29,9 +29,9 @@ function main()
setglobal("DEBUG_LAYOUTS", not DEBUG_LAYOUTS) -- flip on/off
end
- display.draw_start()
+ Display.draw_start()
inv:draw( {100, 100} )
- display.draw_finish()
+ Display.draw_finish()
io.flush()
Game.wait(10)
Oops, something went wrong. Retry.

0 comments on commit bbeeeca

Please sign in to comment.