summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <nthirtyone@gmail.com>2017-04-06 19:22:26 +0200
committerAki <nthirtyone@gmail.com>2017-04-06 19:22:26 +0200
commit93d3257ff23331c308fb32940557911a29ca608b (patch)
treebb87d08d2ee168357513183764a3d869e1a8eedc
parent4cf1755d05a63452feca03d2e380b149fcaa76c2 (diff)
downloadroflnauts-93d3257ff23331c308fb32940557911a29ca608b.zip
roflnauts-93d3257ff23331c308fb32940557911a29ca608b.tar.gz
roflnauts-93d3257ff23331c308fb32940557911a29ca608b.tar.bz2
Menu cleaned-up and moved to /not/
Menu is now similar to new code Menu.load => Menu.open
-rw-r--r--config/menucredits.lua2
-rw-r--r--config/menuhost.lua4
-rw-r--r--config/menumain.lua6
-rw-r--r--config/menuselect.lua2
-rw-r--r--config/menusettings.lua2
-rw-r--r--main.lua2
-rw-r--r--not/Menu.lua (renamed from menu.lua)78
7 files changed, 50 insertions, 46 deletions
diff --git a/config/menucredits.lua b/config/menucredits.lua
index 9d38da4..0510333 100644
--- a/config/menucredits.lua
+++ b/config/menucredits.lua
@@ -11,7 +11,7 @@ return {
:setText("Go back")
:setPosition(bx,144)
:set("active", function (self)
- self.parent:load("menumain")
+ self.parent:open("menumain")
end)
,
element:new(menu)
diff --git a/config/menuhost.lua b/config/menuhost.lua
index 64ce0e7..ae5e3dd 100644
--- a/config/menuhost.lua
+++ b/config/menuhost.lua
@@ -29,14 +29,14 @@ return {
end)
:set("active", function (self)
MAP = map_selector:getFullSelection(true)[1][1] -- please, don't kill me for this, kek
- self.parent:load("menuselect")
+ self.parent:open("menuselect")
end)
,
button:new(menu)
:setText("Go back")
:setPosition(bx,117)
:set("active", function (self)
- self.parent:load("menumain")
+ self.parent:open("menumain")
end)
,
} \ No newline at end of file
diff --git a/config/menumain.lua b/config/menumain.lua
index 50b3d56..4e5ef1f 100644
--- a/config/menumain.lua
+++ b/config/menumain.lua
@@ -14,7 +14,7 @@ return {
:setText("Start")
:setPosition(bx, 80)
:set("active", function (self)
- self.parent:load("menuhost")
+ self.parent:open("menuhost")
end)
,
button:new(menu)
@@ -28,14 +28,14 @@ return {
:setText("Settings")
:setPosition(bx, 112)
:set("active", function (self)
- self.parent:load("menusettings")
+ self.parent:open("menusettings")
end)
,
button:new(menu)
:setText("Credits")
:setPosition(bx, 128)
:set("active", function (self)
- self.parent:load("menucredits")
+ self.parent:open("menucredits")
end)
,
button:new(menu)
diff --git a/config/menuselect.lua b/config/menuselect.lua
index 19f46ab..7b9f073 100644
--- a/config/menuselect.lua
+++ b/config/menuselect.lua
@@ -41,7 +41,7 @@ return {
:setText("Go back")
:setPosition(bx,150)
:set("active", function (self)
- self.parent:load("menuhost")
+ self.parent:open("menuhost")
end)
,
element:new(menu)
diff --git a/config/menusettings.lua b/config/menusettings.lua
index 1631e4f..19f952e 100644
--- a/config/menusettings.lua
+++ b/config/menusettings.lua
@@ -105,7 +105,7 @@ local a = {
:setText("Go back")
:setPosition(bx,144)
:set("active", function (self)
- self.parent:load("menumain")
+ self.parent:open("menumain")
end)
,
dimmer
diff --git a/main.lua b/main.lua
index bdee6a3..eed787f 100644
--- a/main.lua
+++ b/main.lua
@@ -26,7 +26,7 @@ end
-- Require
require "not.World"
require "camera"
-require "menu"
+require "not.Menu"
require "controller"
require "settings"
diff --git a/menu.lua b/not/Menu.lua
index 47e1b25..1be6f00 100644
--- a/menu.lua
+++ b/not/Menu.lua
@@ -1,24 +1,20 @@
--- `Menu` (Scene)
+--- `Menu`
-- It creates single screen of a menu
-- I do know that model I used here and in `World` loading configuration files is not flawless but I did not want to rewrite `World`s one but wanted to keep things similar at least in project scope.
-
-require "not.Music"
-
--- Here it begins
Menu = {
scale = getScale(),
- elements, --table
+ elements = --[[{not.Element}]]nil,
active = 1,
- music,
- sprite,
- background,
- asteroids,
- stars,
+ music = --[[not.Music]]nil,
+ sprite = --[[love.graphics.newImage]]nil,
+ background = --[[love.graphics.newImage]]nil,
+ asteroids = --[[love.graphics.newImage]]nil,
+ stars = --[[love.graphics.newImage]]nil,
asteroids_bounce = 0,
stars_frame = 1,
stars_delay = 0.8,
allowMove = true,
- quads = {
+ quads = { -- TODO: Could be moved to config file or perhaps QuadManager to manage all quads for animations etc.
button = {
normal = love.graphics.newQuad(0, 0, 58,15, 80,130),
active = love.graphics.newQuad(0, 0, 58,15, 80,130)
@@ -39,46 +35,54 @@ Menu = {
},
}
}
-function Menu:new(name)
- local o = {}
- setmetatable(o, self)
- self.__index = self
- self.sprite = love.graphics.newImage("assets/menu.png")
- self.background = love.graphics.newImage("assets/backgrounds/menu.png")
- self.asteroids = love.graphics.newImage("assets/asteroids.png")
- self.stars = love.graphics.newImage("assets/stars.png")
- o.elements = {}
- o:load(name)
- o.music = Music:new("menu.ogg")
+
+Menu.__index = Menu
+
+require "not.Music"
+
+function Menu:new (name)
+ local o = setmetatable({}, self)
+ -- Load statically.
+ if self.sprite == nil then
+ self.sprite = love.graphics.newImage("assets/menu.png")
+ self.background = love.graphics.newImage("assets/backgrounds/menu.png")
+ self.asteroids = love.graphics.newImage("assets/asteroids.png")
+ self.stars = love.graphics.newImage("assets/stars.png")
+ end
+ o:init(name)
return o
end
-function Menu:delete()
+
+function Menu:init (name)
+ self.music = Music:new("menu.ogg")
+ self:open(name)
+end
+
+function Menu:delete ()
self.music:delete()
end
--- Load menu from file
-function Menu:load(name)
- local name = "config/" .. (name or "menumain") .. ".lua"
- local menu = love.filesystem.load(name)
- self.active = 1
- self.elements = menu(self)
+function Menu:open (name)
+ local name = name or "menumain"
+ self.active = Menu.active --Menu.active is initial
+ self.elements = love.filesystem.load(string.format("config/%s.lua", name))(self)
self.elements[self.active]:focus()
end
-- Return reference to quads table and menu sprite
-function Menu:getSheet()
+function Menu:getSheet ()
return self.sprite, self.quads
end
-- Cycle elements
-function Menu:next()
+function Menu:next ()
self.elements[self.active]:blur()
self.active = (self.active%#self.elements)+1
if not self.elements[self.active]:focus() then
self:next()
end
end
-function Menu:previous()
+function Menu:previous ()
self.elements[self.active]:blur()
if self.active == 1 then
self.active = #self.elements
@@ -91,7 +95,7 @@ function Menu:previous()
end
-- LÖVE2D callbacks
-function Menu:update(dt)
+function Menu:update (dt)
for _,element in pairs(self.elements) do
element:update(dt)
end
@@ -107,7 +111,7 @@ function Menu:update(dt)
end
end
end
-function Menu:draw()
+function Menu:draw ()
local scale = self.scale
local scaler = getRealScale()
love.graphics.draw(self.background, 0, 0, 0, scaler, scaler)
@@ -120,7 +124,7 @@ function Menu:draw()
end
-- Controller callbacks
-function Menu:controlpressed(set, action, key)
+function Menu:controlpressed (set, action, key)
if self.allowMove then
if action == "down" then
self:next()
@@ -133,7 +137,7 @@ function Menu:controlpressed(set, action, key)
element:controlpressed(set, action, key)
end
end
-function Menu:controlreleased(set, action, key)
+function Menu:controlreleased (set, action, key)
for _,element in pairs(self.elements) do
element:controlreleased(set, action, key)
end