From 605add7e948be1a4694cc5568abfe8c9a912b566 Mon Sep 17 00:00:00 2001 From: Ishaan Bhardwaj Date: Fri, 18 Dec 2020 21:25:09 -0500 Subject: [PATCH] Added customizable DAS and ARR! (read comments) This only applies to modes that allow it. This feature does not apply to main modes (yet) --- SOURCES.md | 26 ++++++++ libs/simple-slider.lua | 138 +++++++++++++++++++++++++++++++++++++++++ main.lua | 3 + scene.lua | 1 + scene/title.lua | 1 + 5 files changed, 169 insertions(+) create mode 100644 libs/simple-slider.lua diff --git a/SOURCES.md b/SOURCES.md index 6424bcf..542092a 100644 --- a/SOURCES.md +++ b/SOURCES.md @@ -114,3 +114,29 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +simple-slider (https://love2d.org/forums/viewtopic.php?t=80711) +-------------------- + +Copyright (c) 2016 George Prosser + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/libs/simple-slider.lua b/libs/simple-slider.lua new file mode 100644 index 0000000..d234d99 --- /dev/null +++ b/libs/simple-slider.lua @@ -0,0 +1,138 @@ +--[[ +Copyright (c) 2016 George Prosser + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. +]] + +local slider = {} +slider.__index = slider + +function newSlider(x, y, length, value, min, max, setter, style) + local s = {} + s.value = (value - min) / (max - min) + s.min = min + s.max = max + s.setter = setter + s.x = x + s.y = y + s.length = length + + local p = style or {} + s.width = p.width or length * 0.1 + s.orientation = p.orientation or 'horizontal' + s.track = p.track or 'rectangle' + s.knob = p.knob or 'rectangle' + + s.grabbed = false + s.wasDown = true + s.ox = 0 + s.oy = 0 + + return setmetatable(s, slider) +end + +function slider:update(mouseX, mouseY, mouseDown) + local x = mouseX or love.mouse.getX() + local y = mouseY or love.mouse.getY() + local down = love.mouse.isDown(1) + if mouseDown ~= nil then + down = mouseDown + end + + local knobX = self.x + local knobY = self.y + if self.orientation == 'horizontal' then + knobX = self.x - self.length/2 + self.length * self.value + elseif self.orientation == 'vertical' then + knobY = self.y + self.length/2 - self.length * self.value + end + + local ox = x - knobX + local oy = y - knobY + + local dx = ox - self.ox + local dy = oy - self.oy + + if down then + if self.grabbed then + if self.orientation == 'horizontal' then + self.value = self.value + dx / self.length + elseif self.orientation == 'vertical' then + self.value = self.value - dy / self.length + end + elseif (x > knobX - self.width/2 and x < knobX + self.width/2 and y > knobY - self.width/2 and y < knobY + self.width/2) and not self.wasDown then + self.ox = ox + self.oy = oy + self.grabbed = true + end + else + self.grabbed = false + end + + self.value = math.max(0, math.min(1, self.value)) + + if self.setter ~= nil then + self.setter(self.min + self.value * (self.max - self.min)) + end + + self.wasDown = down +end + +function slider:draw() + if self.track == 'rectangle' then + if self.orientation == 'horizontal' then + love.graphics.rectangle('line', self.x - self.length/2 - self.width/2, self.y - self.width/2, self.length + self.width, self.width) + elseif self.orientation == 'vertical' then + love.graphics.rectangle('line', self.x - self.width/2, self.y - self.length/2 - self.width/2, self.width, self.length + self.width) + end + elseif self.track == 'line' then + if self.orientation == 'horizontal' then + love.graphics.line(self.x - self.length/2, self.y, self.x + self.length/2, self.y) + elseif self.orientation == 'vertical' then + love.graphics.line(self.x, self.y - self.length/2, self.x, self.y + self.length/2) + end + elseif self.track == 'roundrect' then + if self.orientation == 'horizontal' then + love.graphics.rectangle('line', self.x - self.length/2 - self.width/2, self.y - self.width/2, self.length + self.width, self.width, self.width/2, self.width) + elseif self.orientation == 'vertical' then + love.graphics.rectangle('line', self.x - self.width/2, self.y - self.length/2 - self.width/2, self.width, self.length + self.width, self.width, self.width/2) + end + end + + local knobX = self.x + local knobY = self.y + if self.orientation == 'horizontal' then + knobX = self.x - self.length/2 + self.length * self.value + elseif self.orientation == 'vertical' then + knobY = self.y + self.length/2 - self.length * self.value + end + + if self.knob == 'rectangle' then + love.graphics.rectangle('fill', knobX - self.width/2, knobY - self.width/2, self.width, self.width) + elseif self.knob == 'circle' then + love.graphics.circle('fill', knobX, knobY, self.width/2) + end +end + +function slider:getValue() + return self.min + self.value * (self.max - self.min) +end \ No newline at end of file diff --git a/main.lua b/main.lua index 393f7db..48772f9 100644 --- a/main.lua +++ b/main.lua @@ -15,6 +15,9 @@ function love.load() love.window.setMode(love.graphics.getWidth(), love.graphics.getHeight(), {resizable = true}); + if not config.das then config.das = 10 end + if not config.arr then config.arr = 2 end + if not config.gamesettings then config.gamesettings = {} config["das_last_key"] = false diff --git a/scene.lua b/scene.lua index 809a2df..fb66420 100644 --- a/scene.lua +++ b/scene.lua @@ -13,4 +13,5 @@ GameScene = require "scene.game" ModeSelectScene = require "scene.mode_select" InputConfigScene = require "scene.input_config" GameConfigScene = require "scene.game_config" +TuningScene = require "scene.tuning" TitleScene = require "scene.title" diff --git a/scene/title.lua b/scene/title.lua index 3c6b48a..72cf40e 100644 --- a/scene/title.lua +++ b/scene/title.lua @@ -4,6 +4,7 @@ local main_menu_screens = { ModeSelectScene, InputConfigScene, GameConfigScene, + TuningScene, ExitScene, }