mirror of
https://gitea.com/SweetSea-ButImNotSweet/tromi_mobile.git
synced 2025-01-08 17:33:09 +08:00
Add ``.gitignore``
Update ``.vscode\settings.json``
Main file changed a bit
Replace every single ``io.open`` into ``fs.read()``
Add ``input.waiting2trigger`` as buffer for too quick inputs
Replace ``binser`` with ``bitser``
Add the missing buffer logical code in training mode
Add a debug connector
Not a big update
Update VirtualControl.lua
Update in vctrl system
Trimming some unnecessary empty lines in classic library
Update virtual control stuff
Replace ``table.getn`` with ``#`` and ``scene`` with ``SCENE``
Renaming and moving some modules
Removing unnecessary ``local mino = {...}``
Add loading screen
Update loading screen
Apply replay patch
Not showing virtual control on computer
Adding touch screen configuration scene (placeholder)
Fix loading screen
update virtual control texture
Do some preparation for touch config screen
Quick patch
Compress background
Not important uodates
Small changes on how virtual key call action
Add ``SCENE:onInputMove``
Apply V2.2 patch
Clean up unnecessary imports
Test
.
Remove a redudant global variable
Small change
Split up alpha number
Sorting code
Update storeInput function
Optimize replay storing, saving and reading
Add VCTRL.export (for saving feature)
Remove unnecessary imports
Redesign loading screen
Replace loading screen
Make a simple BUTTON module
Update BUTTON module
Update button module
Add new callback
Add new callback
TEST
Update simple-button module
Update simple button module
Set default draw function for button
Add scene type notation
TEST
Not important updates
Design a error screen
Small update
Remove error key
Update
TEST
TEST
Test
TEST
TEST
Update button module
TEST
TEST
TEST
TEST
TEST
TEST
TEST
TEST
test
TEST
TEST
TEST
test
TEST
test
Fix a bug in VCTRL module that affect to SCENE:onInputRelease
Moving VCTRL related calls and adding buttons for name entry screen
Add type notation
Update modules
Final update for touch configuration scene
Fix 2 buttons can be highlighted at the same time in simple-button module
Narrow the safe border
Remove id = b (it was there for test)
Update of touch configuration scene
Add touch gesture for replay and input configuration scene
Add buttons for Replay, add MENU to go out after finishing game or in 20G Training mode
TEST
Fix some bugs (TEST)
Fix lỗi giữa đêm
Fix bug again
It should work imo
TEST
Fix SCENE:onInputMove{type="touch"} is not working
Fix bug once again (DONE!)
Temproraily allowing save
Fix settings module
Fix VCTRL.exportAll()
Fix VCTRL.exportAll returns userdata
Reverse a change
Fix forgetting to import virtual control settings
Fix grid drawing
Fix bugs related to the first time launching game
Add README file
Add README file
Update README and add LICENSE files
Update README
Add TV remote code
Disable debug code
Fix Android code
Small fix
Rename LICENSE to COPYING
Moving scene.lua to modules folder
Add new libraries
Make a new FILE API and add a simple error screen in case most thing went down
Change special code, add a way to skip keys
Update icon + README file
Rename screenshot file
Update README
Updating README file
Replace loading screen
Update README
Update virtual control texture
Fix virtual button method
Update README
Add icon font
Add importing and exporting replays
Update touch control
Update conf.lua
Replacing font, to avoid license issue
convert indents to spaces
Update font related stuff
Replace font
Updating README file
Update virtual control texture
153 lines
5.2 KiB
Lua
153 lines
5.2 KiB
Lua
--[[
|
|
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
|
|
|
|
---@type table
|
|
---@class slider.style
|
|
---@field width? number
|
|
---@field orientatio? 'horizontal'|'vertical'
|
|
---@field track? 'rectangle'|'line'|'roundrect'
|
|
---@field knob? 'rectangle'|'circle'
|
|
|
|
---@param x number
|
|
---@param y number
|
|
---@param length number
|
|
---@param value number
|
|
---@param min number
|
|
---@param max number
|
|
---@param setter? function
|
|
---@param style? slider.style
|
|
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 |