Fixed bug: options and demo menu not working in fused mode.

This commit is contained in:
yaw-man 2023-01-27 12:15:13 -04:00
parent 0a300b018c
commit 7a1533a6a7
7 changed files with 264 additions and 155 deletions

View File

@ -1,5 +1,6 @@
function love.conf( t ) function love.conf( t )
t.version = "11.4" t.version = "11.4"
t.identity = "Your Own Drum"
t.modules.joystick = false t.modules.joystick = false
t.modules.physics = false t.modules.physics = false

View File

@ -1,10 +1,12 @@
--UI for selecting a saved game. --UI for selecting a saved game.
local love = love local love = love
local loadGame = {}
local _Update = love.update local _Update = love.update
local _Draw = love.draw local _Draw = love.draw
local _MousePressed = love.mousepressed local _MousePressed = love.mousepressed
local _Resize = love.resize local _Resize = love.resize
local _KeyPressed = love.keypressed local _KeyPressed = love.keypressed
love.mouse.setRelativeMode( false )
local function RestoreMainState() local function RestoreMainState()
love.update = _Update love.update = _Update
@ -13,6 +15,7 @@ local function RestoreMainState()
love.keypressed = _KeyPressed love.keypressed = _KeyPressed
love.resize = _Resize love.resize = _Resize
love.mousemoved = nil love.mousemoved = nil
love.mouse.setRelativeMode( true )
end end
local selectedGame = 1 local selectedGame = 1
@ -23,6 +26,8 @@ local mouseX, mouseY = 0, 0
local w, h = love.graphics.getDimensions() local w, h = love.graphics.getDimensions()
local canvas = love.graphics.newCanvas( w, h * (1 + #gameList) / 10.0 ) local canvas = love.graphics.newCanvas( w, h * (1 + #gameList) / 10.0 )
local font = love.graphics.newFont( 36 ) local font = love.graphics.newFont( 36 )
local deleteIcon = love.graphics.newImage( "sitelenpona/ala.png" )
local playIcon = love.graphics.newImage( "sitelenpona/li.png" )
local OnClick local OnClick
@ -42,53 +47,63 @@ local function PopulateGameList()
scrollOffset = 0 scrollOffset = 0
gameList = assert( love.filesystem.getDirectoryItems( "demos" ) ) gameList = assert( love.filesystem.getDirectoryItems( "demos" ) )
canvas = love.graphics.newCanvas( w, h * (1 + #gameList) / 10.0 )
love.graphics.setCanvas( canvas ) love.graphics.setCanvas( canvas )
love.graphics.clear() love.graphics.clear()
love.graphics.setColor( 0.2, 0.2, 0.2, 0.5 ) love.graphics.setColor( 1, 1, 1, 1 )
love.graphics.setLineWidth( 3 ) love.graphics.setLineWidth( 3 )
for i, name in ipairs( gameList ) do for i, name in ipairs( gameList ) do
local x, y = 15, i * h / 10 local x, y = 15, i * h / 10
love.graphics.printf( gameList[i], font, x + 10, y, 0.75 * w, "left" ) love.graphics.printf( gameList[i], font, x + 10, y, 0.75 * w, "left" )
--love.graphics.rectangle( "line", x, y, w * 0.5, h / 10 - 12, 10, 10 ) love.graphics.draw( deleteIcon, DeleteLeft() - 8, y - 8, 0, 0.25, 0.25 )
love.graphics.rectangle( "line", DeleteLeft(), y, h / 10 - 12, h / 10 - 12, 10, 10 )
love.graphics.line( DeleteLeft() + 5, y + 5, DeleteRight() - 5, y + h / 10 - 17 )
end end
love.graphics.setCanvas() love.graphics.setCanvas()
end end
love.resize = function( newWidth, newHeight ) local resizeLoadMenu = function( newWidth, newHeight )
_Resize(newWidth, newHeight ) _Resize(newWidth, newHeight )
w, h = love.graphics.getDimensions() w, h = love.graphics.getDimensions()
canvas = love.graphics.newCanvas() canvas = love.graphics.newCanvas( w, h * (1 + #gameList) / 10.0 )
return PopulateGameList() return PopulateGameList()
end end
love.update = function() end local updateLoadMenu = function() end
love.draw = function()
local drawLoadGameMenu = function()
love.graphics.setColor( 1, 1, 1, 1 )
love.graphics.draw( canvas, 0, 15 - scrollOffset * h / 10 ) love.graphics.draw( canvas, 0, 15 - scrollOffset * h / 10 )
love.graphics.setColor( 0, 0, 0, 0.5 )
if deleteGame then
love.graphics.rectangle( "fill", DeleteLeft(), 15 + ( selectedGame - scrollOffset ) * h / 10, h / 10 - 12, h / 10 - 12, 10, 10 )
else
love.graphics.rectangle( "fill", 15, 15 + ( selectedGame - scrollOffset ) * h / 10, w * 0.75, h / 10 - 12, 10, 10 )
end
love.graphics.setColor( 1.0, 1.0, 1.0, 1.0 ) love.graphics.setColor( 1.0, 1.0, 1.0, 1.0 )
love.graphics.rectangle( "fill", 0, 0, w, 10 + h / 10 - 6 ) love.graphics.rectangle( "fill", 0, 0, w, 10 + h / 10 - 6 )
love.graphics.setColor( 91 / 255, 206 / 255, 250 / 255 ) love.graphics.setColor( 91 / 255, 206 / 255, 250 / 255 )--
love.graphics.print( "DEMOS."..( gameList[selectedGame] or "" ) ) love.graphics.print( "BACK")
if not selectedGame then return end
love.graphics.setColor( 1, 1, 1, 0.4 )
if deleteGame then
love.graphics.rectangle( "fill",
DeleteLeft(), 15 + ( selectedGame - scrollOffset ) * h / 10,
48, 48,
10, 10 )
else
love.graphics.rectangle( "fill", 15, 15 + ( selectedGame - scrollOffset ) * h / 10, w * 0.75,
--h / 10 - 12, 10, 10 )
48, 10, 10)
end end
love.mousemoved = function( x, y, dx, dy, istouch)
end
local mouseMoved = function( x, y, dx, dy, istouch)
deleteGame = ( x > DeleteLeft() ) deleteGame = ( x > DeleteLeft() )
selectedGame = math.max( math.min( #gameList, scrollOffset + math.floor( 10 * ( y - 15 ) / h ) ), 1) selectedGame = math.max( math.min( #gameList, scrollOffset + math.floor( 10 * ( y - 15 ) / h ) ), 1)
if y < 4 + h / 10 then selectedGame = nil end
end end
local KeyPress = function( key, code, isRepeat ) local KeyPress = function( key, code, isRepeat )
@ -96,6 +111,8 @@ local KeyPress = function( key, code, isRepeat )
return OnClick() return OnClick()
end end
if not selectedGame then selectedGame = 1 end
if code == "down" then if code == "down" then
if selectedGame < #gameList then if selectedGame < #gameList then
@ -106,7 +123,7 @@ local KeyPress = function( key, code, isRepeat )
end end
return return
end end
if key == "up" then if code == "up" then
if selectedGame > 9 then if selectedGame > 9 then
scrollOffset = scrollOffset - 1 scrollOffset = scrollOffset - 1
end end
@ -121,7 +138,8 @@ local KeyPress = function( key, code, isRepeat )
end end
OnClick = function( ) OnClick = function( x, y, button, istouch, presses )
if y and y < 4 + h / 10 then return RestoreMainState() end
if not selectedGame then return end if not selectedGame then return end
if #gameList < 1 then return end if #gameList < 1 then return end
@ -136,7 +154,19 @@ OnClick = function( )
end end
local wheelMoved = function(x, y)
scrollOffset = math.max( 0, math.min( #gameList, scrollOffset - y * 0.1 ) )
end
local function LoadGameMenu()
love.wheelmoved = wheelMoved
love.mousemoved = mouseMoved
love.draw = drawLoadGameMenu
love.update = updateLoadMenu
love.resize = resizeLoadMenu
PopulateGameList() PopulateGameList()
end
return OnClick, KeyPress return { OnClick = OnClick, KeyPress = KeyPress, LoadGameMenu = LoadGameMenu }

View File

@ -15,6 +15,7 @@ local Draw
local Update local Update
local ExtrapolateBeatScore local ExtrapolateBeatScore
local _ExtrapolateBeatScore local _ExtrapolateBeatScore
local mouseControl
local scores local scores
local state local state
@ -127,6 +128,7 @@ local function NewGame( demoName )
245 / 255, 169 / 255, 184 / 255, 1, 245 / 255, 169 / 255, 184 / 255, 1,
1,1,1,0) 1,1,1,0)
end end
mouseControl.Reset()
state.Reset() state.Reset()
marble.Reset() marble.Reset()
wave.Reset() wave.Reset()
@ -142,9 +144,10 @@ local function NewGame( demoName )
end end
function love.load() function love.load()
love.mouse.setRelativeMode( true )
UpdateWindowTransform( love.graphics.getDimensions() ) UpdateWindowTransform( love.graphics.getDimensions() )
options = {}
do--particle system setup do--particle system setup
@ -157,7 +160,8 @@ function love.load()
end end
options = assert( require( "options" ) )
mouseControl = assert( require "mousecontrols" )
sitelenpona = assert( require "sitelenpona" ) sitelenpona = assert( require "sitelenpona" )
text = assert( require "text" ) text = assert( require "text" )
marble = assert( require "marble" ) marble = assert( require "marble" )
@ -286,6 +290,8 @@ end
Draw = function() Draw = function()
local score = ExtrapolateBeatScore() local score = ExtrapolateBeatScore()
@ -352,11 +358,13 @@ end
_Update = Update _Update = Update
local function OptionsMenu() local function OptionsMenu()
dofile "options.lua" if not options then options = require( "options" ) end
return options.EnterMenu()
end end
local function LoadGame() -- Load game screen. local function LoadGame() -- Load game screen.
local Click, Press = assert( dofile "loadgame.lua" ) if not loadGame then loadGame = assert( require "loadgame" ) end
local Click, Press = assert(loadGame.OnClick), assert(loadGame.KeyPress)
love.mousepressed = function( x, y, button, istouch, presses) love.mousepressed = function( x, y, button, istouch, presses)
local demoName = Click( x, y, button, istouch, presses ) local demoName = Click( x, y, button, istouch, presses )
if demoName then return NewGame( demoName ) end if demoName then return NewGame( demoName ) end
@ -366,6 +374,8 @@ local function LoadGame() -- Load game screen.
local demoName = Press( key, code, isRepeat ) local demoName = Press( key, code, isRepeat )
if demoName then return NewGame( demoName ) end if demoName then return NewGame( demoName ) end
end end
loadGame.LoadGameMenu()
end end
function love.keypressed( key, code, isRepeat ) function love.keypressed( key, code, isRepeat )
@ -374,11 +384,21 @@ function love.keypressed( key, code, isRepeat )
if code == "return" then return LoadGame() end --Play demo. if code == "return" then return LoadGame() end --Play demo.
if code == "o" then return OptionsMenu() end if code == "o" then return OptionsMenu() end
if state.isDemo then return end if state.isDemo then return end
return marble.OnKey( state.tick )
return marble.OnKey(
love.keyboard.isScancodeDown( options.up.value ),
love.keyboard.isScancodeDown( options.left.value ),
love.keyboard.isScancodeDown( options.down.value ),
love.keyboard.isScancodeDown( options.right.value )
)
end end
function love.keyreleased( key, code ) function love.keyreleased( key, code )
return marble.OnKey( state.tick ) return marble.OnKey(
love.keyboard.isScancodeDown( options.up.value ),
love.keyboard.isScancodeDown( options.left.value ),
love.keyboard.isScancodeDown( options.down.value ),
love.keyboard.isScancodeDown( options.right.value ) )
end end
function love.resize( w, h ) function love.resize( w, h )
@ -386,6 +406,12 @@ function love.resize( w, h )
if marble then marble.Resize() end if marble then marble.Resize() end
end end
--TODO: make this feel better.
function love.mousemoved( x, y, dx, dy, number, istouch )
dx, dy = mouseControl.mousemoved( dx, dy )
if dx then return marble.SetAcceleration( dx, dy ) end
end
function love.mousepressed( x, y, button, istouch, presses ) function love.mousepressed( x, y, button, istouch, presses )
return NewGame() return NewGame()
end end

View File

@ -87,9 +87,10 @@ function marble.Update()
end end
function marble.OnKey( tick ) function marble.OnKey( w, a, s, d )
ddx = (love.keyboard.isScancodeDown( "d" ) and 1.0 or 0.0) - (love.keyboard.isScancodeDown( "a" ) and 1.0 or 0.0) --print( w, a, s, d )
ddy = (love.keyboard.isScancodeDown( "w" ) and 1.0 or 0.0) - (love.keyboard.isScancodeDown( "s" ) and 1.0 or 0.0) ddx = (d and 1.0 or 0.0) - (a and 1.0 or 0.0)
ddy = (w and 1.0 or 0.0) - (s and 1.0 or 0.0)
--print( tick, ddx, ddy ) --print( tick, ddx, ddy )
local n = math.sqrt( ddx * ddx + ddy * ddy ) local n = math.sqrt( ddx * ddx + ddy * ddy )

25
mousecontrols.lua Normal file
View File

@ -0,0 +1,25 @@
local mouseControl = {}
local love = love
local t = love.timer.getTime()
function mouseControl.Reset()
t = love.timer.getTime()
end
function mouseControl.mousemoved( dx, dy )
local dt = love.timer.getTime()
if dt - t < 1 / 1000.0 then return end
dt, t = dt - t, dt
dx, dy = dx * dt, -dy * dt
local norm = math.sqrt( dx * dx + dy * dy )
if norm > 1 then dx, dy = dx / norm, dy / norm end
if norm < 0.01 then return 0, 0 end
return dx, dy
end
return mouseControl

View File

@ -5,49 +5,49 @@ local update = love.update
local mousepressed = love.mousepressed local mousepressed = love.mousepressed
local keypressed = love.keypressed local keypressed = love.keypressed
local mousemoved = love.mousemoved local mousemoved = love.mousemoved
local ExitMenu
local function Restore() options = options or {}
love.mousemoved = mousemoved
love.keypressed = keypressed
love.mousepressed = mousepressed
love.update = update
love.draw = draw
end
local options = options local options = options
local optionList = {} local optionList = {}
local option
options.isHighContrast = false if not options.initialized then
options.keyBinds = {} options.initialized = true
local font = love.graphics.newFont( 32 )
local keyBindCallback = function(self, code) local keyBindCallback = function(self, code)
self.value = code self.value = code
options.keyBinds[self.name] = code
end end
options.optionValues = { options.optionValues = {
{ name = "options", { name = "options",
value = "back", value = "back",
callback = function(self) callback = function(self)
return Restore() return ExitMenu()
end end
}, },
{ name = "high contrast", { name = "high contrast",
value = false, value = false,
callback = function(self) callback = function(self, code)
self.value = true if code == "return" or code == "backspace" then return end
self.value = not( self.value )
end end
}, },
{ name = "volume", { name = "volume",
value = 1.0, value = 1.0,
callback = function(self, isIncreasing) callback = function(self, code)
local isIncreasing
if (code == "left" or code == "a") then isIncreasing = -1
elseif (code == "right" or code == "d") then isIncreasing = 1
else return false end
self.value = math.max( 0, math.min( 1, self.value = math.max( 0, math.min( 1,
self.value + (isIncreasing and 0.05 or -0.05 ))) self.value + (isIncreasing * 0.05 )))
return true
end end
}, },
{ name = "left", { name = "left",
@ -71,69 +71,86 @@ options.optionValues = {
} }
} }
do
local function SetKeyBind( dir, code ) for i, ov in ipairs( options.optionValues ) do
options[ ov.name ] = ov
end
end
end end
local optionIdx local optionIdx = 1
local isAwaitingKey = false
local font = love.graphics.newFont( 32 )
local function Draw() local function Draw()
love.graphics.setColor( 1,1,1,1 ) love.graphics.setColor( 1,1,1,1 )
for i, option in ipairs( options.optionValues ) do for i, option in ipairs( options.optionValues ) do
love.graphics.printf( option.name, font, 100, i * 50, 1000, "left") love.graphics.printf( option.name, font, 100, i * 50, 1000, "left")
love.graphics.printf( tostring( option.value ), font, -100, i * 50, love.graphics.getWidth(), "right") love.graphics.printf( tostring( option.value ), font, -100, i * 50, love.graphics.getWidth(), "right")
end
end
local function Update()
end end
local function ToggleSelectedOption() local w = love.graphics.getWidth()
love.graphics.setColor( 1,1,1,0.5 )
if isAwaitingKey then
love.graphics.rectangle( "fill", w - 200, optionIdx * 50, 100, 48, 10, 10 )
else
love.graphics.rectangle( "fill", 100, optionIdx * 50, 250, 48, 10, 10 )
end
end end
local function MousePress() local function SelectNextOption()
optionIdx = math.min( #options.optionValues, optionIdx + 1 )
option = options.optionValues[ optionIdx]
end end
local function SelectPreviousOption()
optionIdx = math.max( 1, optionIdx - 1 )
option = options.optionValues[ optionIdx]
end
local function KeyPress(key, code, isRepeat) local function KeyPress(key, code, isRepeat)
print( code )
if code == "backspace" then return Restore() end if code == "backspace" then return ExitMenu() end
if isAwaitingKey then
if code == "escape" then return end
isAwaitingKey = (options.optionValues[optionIdx]):callback( code )
end
if code == "return" and optionIdx then isAwaitingKey = true; return end
if code == "down" then return SelectNextOption() end if code == "down" then return SelectNextOption() end
if code == "up" then return SelectPreviousOption() end if code == "up" then return SelectPreviousOption() end
if code == "left" then return ShrinkOptionValue() end
if code == "right" then return GrowOptionValue() end
end end
local function EnterMenu()
draw = love.draw
update = love.update
mousepressed = love.mousepressed
keypressed = love.keypressed
mousemoved = love.mousemoved
love.draw = Draw love.draw = Draw
love.keypressed = KeyPress love.keypressed = KeyPress
love.update = function() end
--[[function love.draw()
love.graphics.print( "a" )
end end
function love.update() function ExitMenu()
love.mousemoved = mousemoved
end]] love.keypressed = keypressed
love.mousepressed = mousepressed
--[[love.mousepressed = function() love.update = update
love.draw = draw
end end
love.draw = function() options.EnterMenu = EnterMenu
options.ExitMenu = ExitMenu
end return options
love.update = function()
end
love.keypressed = function()
end
love.mousemoved = function()
end]]

View File

@ -9,6 +9,14 @@ function recorder.Reset()
for k, _ in ipairs( recorder ) do recorder[k] = nil end for k, _ in ipairs( recorder ) do recorder[k] = nil end
end end
function recorder.UpdateCts( ddx, ddy )
local xByte = 0
local yByte = 0
--i = i + 1
recorder[i] = love.data.pack( "data", "dd", ddx, ddy )
end
function recorder.Update( ddx, ddy ) function recorder.Update( ddx, ddy )
local byte = 0 local byte = 0
if ddx > 0.5 then byte = byte + 1 end if ddx > 0.5 then byte = byte + 1 end
@ -55,6 +63,7 @@ function recorder.NextTick( )
end end
function recorder.Save( ) function recorder.Save( )
if not love.filesystem.getInfo( "demos" ) then love.filesystem.createDirectory( "demos" ) end
return assert( love.filesystem.write( "demos/"..os.time()..".yod" , table.concat( recorder ) ) ) return assert( love.filesystem.write( "demos/"..os.time()..".yod" , table.concat( recorder ) ) )
end end