summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <nthirtyone@gmail.com>2016-12-20 06:02:05 +0100
committerAki <nthirtyone@gmail.com>2016-12-20 06:02:05 +0100
commit73bcd524906c51d43b22b3ea68c64b38f130bea6 (patch)
tree998fe4fd04f901e411e366f4acdf142afe302a88
parent941d0214a4a1b499190f4f3c6133b5e512d897fe (diff)
downloadroflnauts-73bcd524906c51d43b22b3ea68c64b38f130bea6.zip
roflnauts-73bcd524906c51d43b22b3ea68c64b38f130bea6.tar.gz
roflnauts-73bcd524906c51d43b22b3ea68c64b38f130bea6.tar.bz2
I have no idea why I have put everything in one commit
-rw-r--r--config/menusettings.lua96
-rw-r--r--main.lua3
-rw-r--r--menu.lua19
-rw-r--r--settings.lua46
4 files changed, 151 insertions, 13 deletions
diff --git a/config/menusettings.lua b/config/menusettings.lua
index 380828d..1b19e84 100644
--- a/config/menusettings.lua
+++ b/config/menusettings.lua
@@ -2,16 +2,106 @@ local menu = ...
local button = require "button"
local selector = require "selector"
+local element = require "element"
local width, height = love.graphics.getWidth()/getRealScale(), love.graphics.getHeight()/getRealScale()
local bx = width/2-29
-return {
+local keys = {"Left", "Right", "Up", "Down", "Attack", "Jump"}
+
+local dimmer = element:new(menu)
+ :setPosition(width/2, 15)
+ :set("visible", false)
+ :set("currentControl", "Left")
+ :set("draw", function (self, scale)
+ if self.visible then
+ love.graphics.setColor(0, 0, 0, 210)
+ love.graphics.rectangle("fill",0,0,width*getRealScale(),height*getRealScale())
+ love.graphics.setColor(120, 255, 120, 255)
+ love.graphics.printf("Press new key for: \n> " .. self.currentControl .. " <", (width/2-110)*scale, (height/2-4)*scale, 220, "center", 0, scale, scale)
+ love.graphics.setColor(255, 255, 255, 255)
+ end
+ end)
+
+-- CHANGER functions
+local isEnabled = function (self)
+ if Controller.getSets()[self.setNumber()] and not self.inProgress then
+ return true
+ else
+ return false
+ end
+end
+local startChange = function (self)
+ dimmer:set("visible", true):set("currentControl", "Left")
+ self.parent.allowMove = false
+ self.inProgress = true
+ self.currentKey = 0
+ self.newSet = {}
+end
+local controlreleased = function(self, set, action, key)
+ if self.inProgress then
+ if self.currentKey > 0 and self.currentKey < 7 then
+ table.insert(self.newSet, key)
+ dimmer:set("currentControl", keys[self.currentKey+1])
+ end
+ if self.currentKey > 5 then
+ dimmer:set("visible", false)
+ self.parent.allowMove = true
+ self.inProgress = false
+ table.insert(self.newSet, Controller.sets[self.setNumber()][7])
+ print(self.newSet[7])
+ Settings.change(self.setNumber(), self.newSet[1], self.newSet[2], self.newSet[3], self.newSet[4], self.newSet[5], self.newSet[6], self.newSet[7])
+ else
+ self.currentKey = self.currentKey + 1
+ end
+ end
+end
+
+local a = {
+ button:new(menu)
+ :setText("Keyboard 1")
+ :setPosition(bx,80)
+ :set("setNumber", function () return 1 end)
+ :set("isEnabled", isEnabled)
+ :set("controlreleased", controlreleased)
+ :set("stopChange", stopChange)
+ :set("active", startChange)
+ ,
+ button:new(menu)
+ :setText("Keyboard 2")
+ :setPosition(bx,96)
+ :set("setNumber", function () return 2 end)
+ :set("isEnabled", isEnabled)
+ :set("controlreleased", controlreleased)
+ :set("stopChange", stopChange)
+ :set("active", startChange)
+ ,
+ button:new(menu)
+ :setText("Gamepad 1")
+ :setPosition(bx,112)
+ :set("setNumber", function () return 3 end)
+ :set("isEnabled", isEnabled)
+ :set("controlreleased", controlreleased)
+ :set("stopChange", stopChange)
+ :set("active", startChange)
+ ,
+ button:new(menu)
+ :setText("Gamepad 2")
+ :setPosition(bx,128)
+ :set("setNumber", function () return 4 end)
+ :set("isEnabled", isEnabled)
+ :set("controlreleased", controlreleased)
+ :set("stopChange", stopChange)
+ :set("active", startChange)
+ ,
button:new(menu)
:setText("Go back")
- :setPosition(bx,117)
+ :setPosition(bx,144)
:set("active", function (self)
self.parent:load("menumain")
end)
,
-} \ No newline at end of file
+ dimmer
+}
+
+return a \ No newline at end of file
diff --git a/main.lua b/main.lua
index 3e28d90..deff1a1 100644
--- a/main.lua
+++ b/main.lua
@@ -74,6 +74,9 @@ function love.draw()
love.graphics.print("Current FPS: "..tostring(love.timer.getFPS()), 10, 10+9*scale, 0, scale, scale)
end
end
+function love.quit()
+ Settings.save()
+end
-- Pass input to Controller
function love.gamepadaxis(joystick, axis, value) Controller.gamepadaxis(joystick, axis, value) end
function love.gamepadpressed(joystick, key) Controller.gamepadpressed(joystick, key) end
diff --git a/menu.lua b/menu.lua
index e24bc64..b72ea09 100644
--- a/menu.lua
+++ b/menu.lua
@@ -12,6 +12,7 @@ Menu = {
music,
sprite,
background,
+ allowMove = true,
quads = {
button = {
normal = love.graphics.newQuad(0, 0, 58,15, 80,130),
@@ -95,14 +96,20 @@ end
-- Controller callbacks
function Menu:controlpressed(set, action, key)
- if action == "down" then
- self:next()
- end
- if action == "up" then
- self:previous()
+ if self.allowMove then
+ if action == "down" then
+ self:next()
+ end
+ if action == "up" then
+ self:previous()
+ end
end
for _,element in pairs(self.elements) do
element:controlpressed(set, action, key)
end
end
-function Menu:controlreleased(set, action, key) end \ No newline at end of file
+function Menu:controlreleased(set, action, key)
+ for _,element in pairs(self.elements) do
+ element:controlreleased(set, action, key)
+ end
+end \ No newline at end of file
diff --git a/settings.lua b/settings.lua
index 93432a0..ad8b8e5 100644
--- a/settings.lua
+++ b/settings.lua
@@ -1,5 +1,5 @@
Settings = {}
-
+Settings.current = {}
function Settings.load()
if Controller then
if not love.filesystem.exists("settings") then
@@ -10,12 +10,15 @@ function Settings.load()
new:close() def:close()
end
local getSettings = love.filesystem.load("settings")
- for _,set in pairs(getSettings()) do
+ Settings.current = getSettings()
+ local joysticksList = love.joystick.getJoysticks() -- local list for editing
+ for _,set in pairs(Settings.current) do
local isJoystick = set[7]
local joystick
if isJoystick then
- joystick = love.joystick.getJoysticks()[1]
- -- Add first free joystick from joysticks list
+ -- take and remove first joystick from list
+ joystick = joysticksList[1]
+ table.remove(joysticksList, 1)
end
if not isJoystick or joystick then
Controller.registerSet(set[1], set[2], set[3], set[4], set[5], set[6], joystick)
@@ -23,3 +26,38 @@ function Settings.load()
end
end
end
+function Settings.save()
+ local new = love.filesystem.newFile("settings")
+ local sets = Settings.current
+ local string = "return {\n"
+ for i,set in pairs(sets) do
+ string = string .. "\t{"
+ for j,word in pairs(set) do
+ if j ~= 7 then
+ string = string .. "\"" .. word .. "\", "
+ else
+ if word then
+ string = string .. "true"
+ else
+ string = string .. "false"
+ end
+ end
+ end
+ string = string .. "},\n"
+ end
+ string = string .. "}"
+ new:open("w")
+ new:write(string)
+ new:close()
+end
+function Settings.change(n, left, right, up, down, attack, jump, joystick)
+ local bool
+ if joystick then
+ bool = true
+ else
+ bool = false
+ end
+ Settings.current[n] = {left, right, up, down, attack, jump, bool}
+ table.remove(Controller.sets, n)
+ Controller.registerSet(left, right, up, down, attack, jump, joystick)
+end \ No newline at end of file