mirror of
https://gitea.com/SweetSea-ButImNotSweet/tromi_mobile.git
synced 2025-01-08 17:33:09 +08:00
Do some preparation for touch config screen
This commit is contained in:
40
funcs.lua
40
funcs.lua
@@ -68,16 +68,43 @@ function formatBigNum(number)
|
|||||||
else
|
else
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local pos = Mod1(string.len(s), 3)
|
local pos = math.mod1(string.len(s), 3)
|
||||||
return string.sub(s, 1, pos)
|
return string.sub(s, 1, pos)
|
||||||
.. string.gsub(string.sub(s, pos+1), "(...)", ",%1")
|
.. string.gsub(string.sub(s, pos+1), "(...)", ",%1")
|
||||||
end
|
end
|
||||||
|
|
||||||
function Mod1(n, m)
|
function math.clamp(x, min, max)
|
||||||
-- returns a number congruent to n modulo m in the range [1;m] (as opposed to [0;m-1])
|
if max < min then
|
||||||
|
min, max = max, min
|
||||||
|
end
|
||||||
|
return x < min and min or (x > max and max or x)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Returns a number congruent to n modulo m in the range [1;m] (as opposed to [0;m-1])
|
||||||
|
function math.mod1(n, m)
|
||||||
return ((n-1) % m) + 1
|
return ((n-1) % m) + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---Round a number with specified unit
|
||||||
|
---@param n number
|
||||||
|
---@param u number # Default: 10
|
||||||
|
---@return number
|
||||||
|
function math.roundUnit(n,u)
|
||||||
|
local u = u or 10
|
||||||
|
return math.floor(n/u+.5)*u
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param t1 table
|
||||||
|
---@param t2 table
|
||||||
|
---@return table t
|
||||||
|
---Merge 2 tables into one<br>(**WARNING**: t2 can **overwrite** some value of t1 if both tables have some same keys!)
|
||||||
|
function table.merge(t1,t2)
|
||||||
|
local t
|
||||||
|
for k, v in pairs(t1) do t[k] = v end
|
||||||
|
for k, v in pairs(t2) do t[k] = v end
|
||||||
|
return t
|
||||||
|
end
|
||||||
|
|
||||||
function table.contains(table, element)
|
function table.contains(table, element)
|
||||||
for _, value in pairs(table) do
|
for _, value in pairs(table) do
|
||||||
if value == element then
|
if value == element then
|
||||||
@@ -107,13 +134,6 @@ function table.lowest(table)
|
|||||||
return lowest
|
return lowest
|
||||||
end
|
end
|
||||||
|
|
||||||
function math.clamp(x, min, max)
|
|
||||||
if max < min then
|
|
||||||
min, max = max, min
|
|
||||||
end
|
|
||||||
return x < min and min or (x > max and max or x)
|
|
||||||
end
|
|
||||||
|
|
||||||
function drawText(text, x, y, size, orientation, color)
|
function drawText(text, x, y, size, orientation, color)
|
||||||
if color == nil then color = {1, 1, 1, 1} end
|
if color == nil then color = {1, 1, 1, 1} end
|
||||||
love.graphics.setFont(FONT_tromi)
|
love.graphics.setFont(FONT_tromi)
|
||||||
|
|||||||
91
main.lua
91
main.lua
@@ -7,10 +7,9 @@ else
|
|||||||
end
|
end
|
||||||
|
|
||||||
require 'funcs'
|
require 'funcs'
|
||||||
DEBUG_showKey=false
|
DEBUG_showKey = false
|
||||||
|
|
||||||
PENTO_MODE = false
|
PENTO_MODE = false
|
||||||
|
|
||||||
SAVE_DIR = 'saves/'
|
SAVE_DIR = 'saves/'
|
||||||
REPLAY_DIR = 'saves/replays/'
|
REPLAY_DIR = 'saves/replays/'
|
||||||
if not love.filesystem.getInfo(REPLAY_DIR) then
|
if not love.filesystem.getInfo(REPLAY_DIR) then
|
||||||
@@ -19,6 +18,33 @@ end
|
|||||||
CONFIG_FILE = 'config.sav'
|
CONFIG_FILE = 'config.sav'
|
||||||
HIscoreFILE = 'hiscores.sav'
|
HIscoreFILE = 'hiscores.sav'
|
||||||
|
|
||||||
|
-- Text "LOADING..."
|
||||||
|
local loaded = {}
|
||||||
|
local last_loading
|
||||||
|
local loadedCounter = 0
|
||||||
|
--- Show the loading text while we are loading resources<br>
|
||||||
|
--- **WARNING**: should only be used while loading the game!
|
||||||
|
function ShowLoadingText(thing)
|
||||||
|
if last_loading then table.insert(loaded, last_loading) end
|
||||||
|
last_loading = thing
|
||||||
|
loadedCounter = loadedCounter + 1
|
||||||
|
|
||||||
|
love.graphics.replaceTransform(GLOBAL_TRANSFORM)
|
||||||
|
love.graphics.setFont(love.graphics.newFont(20))
|
||||||
|
love.graphics.clear()
|
||||||
|
|
||||||
|
drawText(
|
||||||
|
"Loading Tromi... ["..loadedCounter.." / 3]\nPlease wait, don't touch anywhere or press any key!\n\nLoading: "..thing,
|
||||||
|
10,0,1e99,"left"
|
||||||
|
)
|
||||||
|
for i, t in pairs(loaded) do
|
||||||
|
drawText("Loaded "..t,10,80+20*i,1e99,"left")
|
||||||
|
end
|
||||||
|
|
||||||
|
love.graphics.flushBatch()
|
||||||
|
love.graphics.present()
|
||||||
|
end
|
||||||
|
|
||||||
function love.load()
|
function love.load()
|
||||||
math.randomseed(os.time())
|
math.randomseed(os.time())
|
||||||
require "settings"
|
require "settings"
|
||||||
@@ -32,33 +58,6 @@ function love.load()
|
|||||||
GLOBAL_TRANSFORM = love.math.newTransform()
|
GLOBAL_TRANSFORM = love.math.newTransform()
|
||||||
love.resize(love.graphics.getWidth(), love.graphics.getHeight())
|
love.resize(love.graphics.getWidth(), love.graphics.getHeight())
|
||||||
|
|
||||||
-- Text "LOADING..."
|
|
||||||
local loaded = {}
|
|
||||||
local prev_thing
|
|
||||||
local loadedCounter = 0
|
|
||||||
--- Show the loading text while we are loading resources<br>
|
|
||||||
--- **WARNING**: should only be used while loading the game!
|
|
||||||
function ShowLoadingText(thing)
|
|
||||||
if prev_thing then table.insert(loaded, prev_thing) end
|
|
||||||
prev_thing = thing
|
|
||||||
loadedCounter = loadedCounter + 1
|
|
||||||
|
|
||||||
love.graphics.replaceTransform(GLOBAL_TRANSFORM)
|
|
||||||
love.graphics.setFont(love.graphics.newFont(20))
|
|
||||||
love.graphics.clear()
|
|
||||||
|
|
||||||
drawText(
|
|
||||||
"Loading Tromi... ["..loadedCounter.." / 3]\nPlease wait, don't touch anywhere or press any key!\n\nLoading: "..thing,
|
|
||||||
10,0,1e99,"left"
|
|
||||||
)
|
|
||||||
for i, t in pairs(loaded) do
|
|
||||||
drawText("Loaded "..t,10,80+20*i,1e99,"left")
|
|
||||||
end
|
|
||||||
|
|
||||||
love.graphics.flushBatch()
|
|
||||||
love.graphics.present()
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Now it's real time to load all stuffs!
|
-- Now it's real time to load all stuffs!
|
||||||
highscores = {}
|
highscores = {}
|
||||||
require "load" -- Most game's resources are loaded in here
|
require "load" -- Most game's resources are loaded in here
|
||||||
@@ -66,24 +65,24 @@ function love.load()
|
|||||||
require "game.vctrl" -- VCTRL
|
require "game.vctrl" -- VCTRL
|
||||||
|
|
||||||
SCENE = SETTINGS.firstTime and InputConfigScene(true) or TitleScene()
|
SCENE = SETTINGS.firstTime and InputConfigScene(true) or TitleScene()
|
||||||
VCTRL.toggle(love.system.getOS()=='Android')
|
VCTRL.toggle(love.system.getOS()=='Android' or true)
|
||||||
VCTRL.new{
|
VCTRL.new{
|
||||||
-- {type='button',x= 100,y=320,key= 'up',icon= 'up',r=35,iconSize=60,alpha=1},
|
-- {type='button',x= 100,y=320,key= 'up',icon= 'up',r=35,iconSize=60,alpha=0.75},
|
||||||
-- {type='button',x= 160,y=380,key='right',icon= 'right',r=35,iconSize=60,alpha=1},
|
-- {type='button',x= 160,y=380,key='right',icon= 'right',r=35,iconSize=60,alpha=0.75},
|
||||||
-- {type='button',x= 100,y=440,key= 'down',icon= 'down',r=35,iconSize=60,alpha=1},
|
-- {type='button',x= 100,y=440,key= 'down',icon= 'down',r=35,iconSize=60,alpha=0.75},
|
||||||
-- {type='button',x= 40,y=380,key= 'left',icon= 'left',r=35,iconSize=60,alpha=1},
|
-- {type='button',x= 40,y=380,key= 'left',icon= 'left',r=35,iconSize=60,alpha=0.75},
|
||||||
-- {type='button',x=640-100,y=320,key= 'f16',icon='rotate_right2',r=35,iconSize=60,alpha=1},
|
-- {type='button',x=640-100,y=320,key= 'f16',icon='rotate_right2',r=35,iconSize=60,alpha=0.75},
|
||||||
-- {type='button',x=640-160,y=380,key= 'f14',icon= 'rotate_left2',r=35,iconSize=60,alpha=1},
|
-- {type='button',x=640-160,y=380,key= 'f14',icon= 'rotate_left2',r=35,iconSize=60,alpha=0.75},
|
||||||
-- {type='button',x=640-100,y=440,key= 'f15',icon= 'rotate_right',r=35,iconSize=60,alpha=1},
|
-- {type='button',x=640-100,y=440,key= 'f15',icon= 'rotate_right',r=35,iconSize=60,alpha=0.75},
|
||||||
-- {type='button',x=640- 40,y=380,key= 'f13',icon= 'rotate_left',r=35,iconSize=60,alpha=1},
|
-- {type='button',x=640- 40,y=380,key= 'f13',icon= 'rotate_left',r=35,iconSize=60,alpha=0.75},
|
||||||
{type='button',x= 70,y=280,key= 'up',icon= 'up',r=45,iconSize=60,alpha=1},
|
{type='button',x= 70,y=280,key= 'up',icon= 'up',r=45,iconSize=60,alpha=0.75},
|
||||||
{type='button',x= 145,y=355,key='right',icon= 'right',r=45,iconSize=60,alpha=1},
|
{type='button',x= 145,y=355,key='right',icon= 'right',r=45,iconSize=60,alpha=0.75},
|
||||||
{type='button',x= 70,y=430,key= 'down',icon= 'down',r=45,iconSize=60,alpha=1},
|
{type='button',x= 70,y=430,key= 'down',icon= 'down',r=45,iconSize=60,alpha=0.75},
|
||||||
{type='button',x= -5,y=355,key= 'left',icon= 'left',r=45,iconSize=60,alpha=1},
|
{type='button',x= -5,y=355,key= 'left',icon= 'left',r=45,iconSize=60,alpha=0.75},
|
||||||
{type='button',x=640- 70,y=280,key= 'f16',icon='rotate_right2',r=45,iconSize=60,alpha=1},
|
{type='button',x=640- 70,y=280,key= 'f16',icon='rotate_right2',r=45,iconSize=60,alpha=0.75},
|
||||||
{type='button',x=640-145,y=355,key= 'f14',icon= 'rotate_left2',r=45,iconSize=60,alpha=1},
|
{type='button',x=640-145,y=355,key= 'f14',icon= 'rotate_left2',r=45,iconSize=60,alpha=0.75},
|
||||||
{type='button',x=640- 70,y=430,key= 'f15',icon= 'rotate_right',r=45,iconSize=60,alpha=1},
|
{type='button',x=640- 70,y=430,key= 'f15',icon= 'rotate_right',r=45,iconSize=60,alpha=0.75},
|
||||||
{type='button',x=640- -5,y=355,key= 'f13',icon= 'rotate_left',r=45,iconSize=60,alpha=1},
|
{type='button',x=640- -5,y=355,key= 'f13',icon= 'rotate_left',r=45,iconSize=60,alpha=0.75},
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -28,11 +28,11 @@ function ConfigScene:render()
|
|||||||
end
|
end
|
||||||
|
|
||||||
love.graphics.setColor(1, 1, 1, 0.5)
|
love.graphics.setColor(1, 1, 1, 0.5)
|
||||||
love.graphics.rectangle("fill", 75, 118 + 50 * self.menu_state, 300, 35)
|
love.graphics.rectangle("fill", 75, 118 + 50 * self.menu_state, 400, 35)
|
||||||
|
|
||||||
love.graphics.setColor(1, 1, 1, 1)
|
love.graphics.setColor(1, 1, 1, 1)
|
||||||
for i, screen in pairs(menu_screens) do
|
for i, screen in pairs(menu_screens) do
|
||||||
drawText(screen.title, 80, 120 + 50 * i, 300, "left")
|
drawText(screen.title, 80, 120 + 50 * i, 400, "left")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,21 +1,38 @@
|
|||||||
local TouchConfigScene = SCENE:extend()
|
local TouchConfigScene = SCENE:extend()
|
||||||
TouchConfigScene.title = "Touchscreen config\n(you can tap anywhere to select this)"
|
TouchConfigScene.title = "Touchscreen config\n(you can tap anywhere on touch screen to select this)"
|
||||||
|
|
||||||
|
local origin_touchPressed, origin_touchReleased, origin_touchMoved
|
||||||
|
local function onPressed(id, x, y)
|
||||||
|
if not VCTRL.press(x, y, id) then
|
||||||
|
-- TODO
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local function onMoved(id, _, _, dx, dy)
|
||||||
|
VCTRL.drag(dx, dy, id)
|
||||||
|
end
|
||||||
|
local function onReleased(id)
|
||||||
|
if not VCTRL.release(id) then
|
||||||
|
-- TODO
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function TouchConfigScene:new()
|
function TouchConfigScene:new()
|
||||||
-- TODO
|
-- TODO
|
||||||
|
-- Temproraily hijacking game's touch-related functions
|
||||||
|
origin_touchPressed, origin_touchReleased, origin_touchMoved = love.touchpressed, love.touchreleased, love.touchmoved
|
||||||
|
|
||||||
|
SETTINGS.input.keys = table.merge(SETTINGS.input.keys, SETTINGS.input.touch)
|
||||||
end
|
end
|
||||||
function TouchConfigScene:update()
|
function TouchConfigScene:update()
|
||||||
-- TODO
|
-- TODO
|
||||||
end
|
end
|
||||||
function TouchConfigScene:onInputPress(e)
|
|
||||||
end
|
|
||||||
|
|
||||||
function TouchConfigScene:onInputRelease(e)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
function TouchConfigScene:render()
|
function TouchConfigScene:render()
|
||||||
MainBackground()
|
MainBackground()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function TouchConfigScene:onQuit()
|
||||||
|
love.touchpressed, love.touchreleased, love.touchmoved = origin_touchPressed, origin_touchReleased, origin_touchMoved
|
||||||
|
end
|
||||||
|
|
||||||
return TouchConfigScene
|
return TouchConfigScene
|
||||||
@@ -8,10 +8,16 @@ local _defaultSettings = {
|
|||||||
fullscreen = false,
|
fullscreen = false,
|
||||||
music = true,
|
music = true,
|
||||||
|
|
||||||
|
---@class input
|
||||||
|
---@field keys table <string, string>
|
||||||
|
---@field joysticks table <string, string>
|
||||||
|
---@field mobile table <string, string>
|
||||||
input = {
|
input = {
|
||||||
keys = {},
|
keys = {},
|
||||||
|
joysticks = {},
|
||||||
mobile = { -- Should not be changed for any reason, used for mobile only
|
mobile = { -- Should not be changed for any reason, used for mobile only
|
||||||
enter = 'menu_decide',
|
enter = 'menu_decide',
|
||||||
|
acback = 'menu_back',
|
||||||
f13 = 'up',
|
f13 = 'up',
|
||||||
f14 = 'down',
|
f14 = 'down',
|
||||||
f15 = 'left',
|
f15 = 'left',
|
||||||
|
|||||||
Reference in New Issue
Block a user