Refactored settings menus

pull/13/head
Ishaan Bhardwaj 2020-12-20 09:45:49 -05:00
parent 130c2ea403
commit 87b88f4b42
8 changed files with 93 additions and 19 deletions

View File

@ -28,13 +28,13 @@ sounds = {
function playSE(sound, subsound)
if subsound == nil then
sounds[sound]:setVolume(0.5)
sounds[sound]:setVolume(config.sfx_volume)
if sounds[sound]:isPlaying() then
sounds[sound]:stop()
end
sounds[sound]:play()
else
sounds[sound][subsound]:setVolume(0.6)
sounds[sound][subsound]:setVolume(config.sfx_volume)
if sounds[sound][subsound]:isPlaying() then
sounds[sound][subsound]:stop()
end
@ -44,13 +44,13 @@ end
function playSEOnce(sound, subsound)
if subsound == nil then
sounds[sound]:setVolume(0.5)
sounds[sound]:setVolume(config.sfx_volume)
if sounds[sound]:isPlaying() then
return
end
sounds[sound]:play()
else
sounds[sound][subsound]:setVolume(0.5)
sounds[sound][subsound]:setVolume(config.sfx_volume)
if sounds[sound][subsound]:isPlaying() then
return
end

View File

@ -9,17 +9,18 @@ function love.load()
require "load.save"
loadSave()
require "scene"
config["side_next"] = false
config["reverse_rotate"] = true
--config["side_next"] = false
--config["reverse_rotate"] = true
config["fullscreen"] = false
love.window.setMode(love.graphics.getWidth(), love.graphics.getHeight(), {resizable = true});
if config.secret == nil then config.secret = false
elseif config.secret == true then playSE("welcome") end
if not config.das then config.das = 10 end
if not config.arr then config.arr = 2 end
if not config.sfx_volume then config.sfx_volume = 0.5 end
if config.secret == nil then config.secret = false
elseif config.secret == true then playSE("welcome") end
if not config.gamesettings then
config.gamesettings = {}

View File

@ -14,4 +14,5 @@ ModeSelectScene = require "scene.mode_select"
InputConfigScene = require "scene.input_config"
GameConfigScene = require "scene.game_config"
TuningScene = require "scene.tuning"
SettingsScene = require "scene.settings"
TitleScene = require "scene.title"

View File

@ -3,14 +3,14 @@ local ConfigScene = Scene:extend()
ConfigScene.title = "Game Settings"
require 'load.save'
require 'libs.simple-slider'
ConfigScene.options = {
-- this serves as reference to what the options' values mean i guess?
{"manlock", "Manual locking",{"Per ruleset","Per gamemode","Harddrop", "Softdrop"}},
{"manlock", "Manual Locking",{"Per ruleset","Per gamemode","Harddrop", "Softdrop"}},
{"piece_colour", "Piece Colours", {"Per ruleset","Arika" ,"TTC"}},
{"world_reverse","A Button Rotation", {"Left" ,"Auto" ,"Right"}},
{"display_gamemode", "Display Gamemode", {"On", "Off"}},
{"next_se", "Next Piece SFX", {"On", "Off"}},
{"das_last_key", "DAS Switch", {"Default", "Instant"}},
{"smooth_movement", "Smooth Piece Drop", {"On", "Off"}},
{"synchroes_allowed", "Synchroes", {"Per ruleset", "On", "Off"}},
@ -27,10 +27,13 @@ function ConfigScene:new()
details = "In menus",
state = "Changing game settings",
})
self.sfxSlider = newSlider(290, 375, 400, config.sfx_volume * 100, 0, 100, function(v) config.sfx_volume = v / 100 end, {width=20})
end
function ConfigScene:update()
config["das_last_key"] = config.gamesettings.das_last_key == 2
self.sfxSlider:update()
end
function ConfigScene:render()
@ -40,6 +43,9 @@ function ConfigScene:render()
0, 0, 0,
0.5, 0.5
)
love.graphics.setFont(font_3x5_3)
love.graphics.print("Master Volume: " .. math.floor(self.sfxSlider:getValue()) .. "%", 80, 325)
love.graphics.setFont(font_3x5_4)
love.graphics.print("GAME SETTINGS", 80, 40)
@ -56,13 +62,16 @@ function ConfigScene:render()
love.graphics.printf(setting, 100 + 110 * j, 100 + i * 20, 100, "center")
end
end
love.graphics.setColor(1, 1, 1, 0.75)
self.sfxSlider:draw()
end
function ConfigScene:onInputPress(e)
if e.input == "menu_decide" or e.scancode == "return" then
playSE("mode_decide")
saveConfig()
scene = TitleScene()
scene = SettingsScene()
elseif e.input == "up" or e.scancode == "up" then
playSE("cursor")
self.highlight = Mod1(self.highlight-1, optioncount)
@ -79,7 +88,7 @@ function ConfigScene:onInputPress(e)
config.gamesettings[option[1]] = Mod1(config.gamesettings[option[1]]+1, #option[3])
elseif e.input == "menu_back" or e.scancode == "delete" or e.scancode == "backspace" then
loadSave()
scene = TitleScene()
scene = SettingsScene()
end
end

View File

@ -82,7 +82,7 @@ function ConfigScene:onInputPress(e)
-- function keys, escape, and tab are reserved and can't be remapped
if e.scancode == "escape" and config.input then
-- cancel only if there was an input config already
scene = TitleScene()
scene = SettingsScene()
elseif self.input_state > table.getn(configurable_inputs) then
if e.scancode == "return" then
-- save new input, then load next scene

65
scene/settings.lua Normal file
View File

@ -0,0 +1,65 @@
local SettingsScene = Scene:extend()
SettingsScene.title = "Settings"
local menu_screens = {
InputConfigScene,
GameConfigScene,
TuningScene
}
function SettingsScene:new()
self.menu_state = 1
DiscordRPC:update({
details = "In menus",
state = "Changing settings",
})
end
function SettingsScene:update() end
function SettingsScene:render()
love.graphics.setColor(1, 1, 1, 1)
love.graphics.draw(
backgrounds["game_config"],
0, 0, 0,
0.5, 0.5
)
love.graphics.setFont(font_3x5_4)
love.graphics.print("SETTINGS", 80, 40)
love.graphics.setFont(font_3x5_2)
love.graphics.print("Here, you can change some settings that change\nthe look and feel of the game.", 80, 90)
love.graphics.setColor(1, 1, 1, 0.5)
love.graphics.rectangle("fill", 75, 118 + 50 * self.menu_state, 200, 33)
love.graphics.setFont(font_3x5_3)
love.graphics.setColor(1, 1, 1, 1)
for i, screen in pairs(menu_screens) do
love.graphics.printf(screen.title, 80, 120 + 50 * i, 200, "left")
end
end
function SettingsScene:changeOption(rel)
local len = table.getn(menu_screens)
self.menu_state = (self.menu_state + len + rel - 1) % len + 1
end
function SettingsScene:onInputPress(e)
if e.input == "menu_decide" or e.scancode == "return" then
playSE("main_decide")
scene = menu_screens[self.menu_state]()
elseif e.input == "up" or e.scancode == "up" then
self:changeOption(-1)
playSE("cursor")
elseif e.input == "down" or e.scancode == "down" then
self:changeOption(1)
playSE("cursor")
elseif e.input == "menu_back" or e.scancode == "backspace" or e.scancode == "delete" then
scene = TitleScene()
end
end
return SettingsScene

View File

@ -5,9 +5,7 @@ TitleScene.restart_message = false
local main_menu_screens = {
ModeSelectScene,
InputConfigScene,
GameConfigScene,
TuningScene,
SettingsScene,
ExitScene,
}

View File

@ -47,10 +47,10 @@ function TuningScene:onInputPress(e)
if e.input == "menu_decide" or e.scancode == "return" then
playSE("mode_decide")
saveConfig()
scene = TitleScene()
scene = SettingsScene()
elseif e.input == "menu_back" or e.scancode == "delete" or e.scancode == "backspace" then
loadSave()
scene = TitleScene()
scene = SettingsScene()
end
end