mirror of
https://github.com/bryanthaboi/gen1recomp.git
synced 2026-08-25 23:11:15 +02:00
Add controller support to Skin Studio
This commit is contained in:
@@ -722,7 +722,7 @@ function love.gamepadpressed(joystick, button)
|
|||||||
end
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if Studio then return end
|
if Studio then return Studio.gamepadpressed(joystick, button) end
|
||||||
if Importer then return Importer:gamepadpressed(joystick, button) end
|
if Importer then return Importer:gamepadpressed(joystick, button) end
|
||||||
if not Game then return end
|
if not Game then return end
|
||||||
Game:gamepadpressed(joystick, button)
|
Game:gamepadpressed(joystick, button)
|
||||||
@@ -742,7 +742,7 @@ function love.gamepadreleased(joystick, button)
|
|||||||
end
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if Studio then return end
|
if Studio then return Studio.gamepadreleased(joystick, button) end
|
||||||
if Importer then return Importer:gamepadreleased(joystick, button) end
|
if Importer then return Importer:gamepadreleased(joystick, button) end
|
||||||
if not Game then return end
|
if not Game then return end
|
||||||
Game:gamepadreleased(joystick, button)
|
Game:gamepadreleased(joystick, button)
|
||||||
@@ -762,7 +762,7 @@ function love.gamepadaxis(joystick, axis, value)
|
|||||||
end
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if Studio then return end
|
if Studio then return Studio.gamepadaxis(joystick, axis, value) end
|
||||||
if Importer then return Importer:gamepadaxis(joystick, axis, value) end
|
if Importer then return Importer:gamepadaxis(joystick, axis, value) end
|
||||||
if not Game then return end
|
if not Game then return end
|
||||||
Game:gamepadaxis(joystick, axis, value)
|
Game:gamepadaxis(joystick, axis, value)
|
||||||
@@ -782,7 +782,7 @@ function love.joystickpressed(joystick, button)
|
|||||||
end
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if Studio then return end
|
if Studio then return Studio.joystickpressed(joystick, button) end
|
||||||
if Importer then return Importer:joystickpressed(joystick, button) end
|
if Importer then return Importer:joystickpressed(joystick, button) end
|
||||||
if not Game then return end
|
if not Game then return end
|
||||||
Game:joystickpressed(joystick, button)
|
Game:joystickpressed(joystick, button)
|
||||||
@@ -802,7 +802,7 @@ function love.joystickreleased(joystick, button)
|
|||||||
end
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if Studio then return end
|
if Studio then return Studio.joystickreleased(joystick, button) end
|
||||||
if Importer then return Importer:joystickreleased(joystick, button) end
|
if Importer then return Importer:joystickreleased(joystick, button) end
|
||||||
if not Game then return end
|
if not Game then return end
|
||||||
Game:joystickreleased(joystick, button)
|
Game:joystickreleased(joystick, button)
|
||||||
@@ -822,7 +822,7 @@ function love.joystickaxis(joystick, axis, value)
|
|||||||
end
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if Studio then return end
|
if Studio then return Studio.joystickaxis(joystick, axis, value) end
|
||||||
if Importer then return Importer:joystickaxis(joystick, axis, value) end
|
if Importer then return Importer:joystickaxis(joystick, axis, value) end
|
||||||
if not Game then return end
|
if not Game then return end
|
||||||
Game:joystickaxis(joystick, axis, value)
|
Game:joystickaxis(joystick, axis, value)
|
||||||
@@ -842,7 +842,7 @@ function love.joystickhat(joystick, hat, direction)
|
|||||||
end
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if Studio then return end
|
if Studio then return Studio.joystickhat(joystick, hat, direction) end
|
||||||
if Importer then return Importer:joystickhat(joystick, hat, direction) end
|
if Importer then return Importer:joystickhat(joystick, hat, direction) end
|
||||||
if not Game then return end
|
if not Game then return end
|
||||||
Game:joystickhat(joystick, hat, direction)
|
Game:joystickhat(joystick, hat, direction)
|
||||||
|
|||||||
+80
-4
@@ -6,6 +6,8 @@ local TouchControls = require("src.core.TouchControls")
|
|||||||
local SaveData = require("src.core.SaveData")
|
local SaveData = require("src.core.SaveData")
|
||||||
local FilePicker = require("src.core.FilePicker")
|
local FilePicker = require("src.core.FilePicker")
|
||||||
local SafeArea = require("src.core.SafeArea")
|
local SafeArea = require("src.core.SafeArea")
|
||||||
|
local GamepadMap = require("src.core.GamepadMap")
|
||||||
|
local PadCursor = require("src.ui.PadCursor")
|
||||||
|
|
||||||
local Studio = {}
|
local Studio = {}
|
||||||
|
|
||||||
@@ -501,6 +503,7 @@ function Studio.load(opts)
|
|||||||
Studio.thumbs = {}
|
Studio.thumbs = {}
|
||||||
Studio.pointerX, Studio.pointerY = nil, nil
|
Studio.pointerX, Studio.pointerY = nil, nil
|
||||||
Studio.pointerDown, Studio.touchId = false, nil
|
Studio.pointerDown, Studio.touchId = false, nil
|
||||||
|
PadCursor.reset()
|
||||||
-- Studio always opens on the library. Creating and choosing a skin are
|
-- Studio always opens on the library. Creating and choosing a skin are
|
||||||
-- first-class tasks, not controls buried inside the editor workspace.
|
-- first-class tasks, not controls buried inside the editor workspace.
|
||||||
Studio.mode = "library"
|
Studio.mode = "library"
|
||||||
@@ -758,6 +761,7 @@ function Studio.unload()
|
|||||||
Studio.undoStack, Studio.redoStack = {}, {}
|
Studio.undoStack, Studio.redoStack = {}, {}
|
||||||
Studio.pointerX, Studio.pointerY = nil, nil
|
Studio.pointerX, Studio.pointerY = nil, nil
|
||||||
Studio.pointerDown, Studio.touchId = false, nil
|
Studio.pointerDown, Studio.touchId = false, nil
|
||||||
|
PadCursor.reset()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- The Studio is a real touch editor on Android and iOS. Keeping this here,
|
-- The Studio is a real touch editor on Android and iOS. Keeping this here,
|
||||||
@@ -2678,7 +2682,12 @@ function Studio.draw()
|
|||||||
local f = Studio._frame
|
local f = Studio._frame
|
||||||
Kit.layout(f.w, f.h)
|
Kit.layout(f.w, f.h)
|
||||||
local mx, my = love.mouse.getPosition()
|
local mx, my = love.mouse.getPosition()
|
||||||
if Studio.pointerX ~= nil then mx, my = Studio.pointerX, Studio.pointerY end
|
local px, py, padActive = PadCursor.pointer()
|
||||||
|
if padActive then
|
||||||
|
mx, my = px, py
|
||||||
|
elseif Studio.pointerX ~= nil then
|
||||||
|
mx, my = Studio.pointerX, Studio.pointerY
|
||||||
|
end
|
||||||
Kit.beginFrame(mx, my, Studio.clicked, Studio.wheel)
|
Kit.beginFrame(mx, my, Studio.clicked, Studio.wheel)
|
||||||
Studio.clicked, Studio.wheel = false, 0
|
Studio.clicked, Studio.wheel = false, 0
|
||||||
Theme.fill(0, 0, W, H, PAL.bg, 1)
|
Theme.fill(0, 0, W, H, PAL.bg, 1)
|
||||||
@@ -2691,19 +2700,26 @@ function Studio.draw()
|
|||||||
Kit.blockClicks = false
|
Kit.blockClicks = false
|
||||||
Studio.drawOverlay(f.w, f.h)
|
Studio.drawOverlay(f.w, f.h)
|
||||||
Kit.endFrame()
|
Kit.endFrame()
|
||||||
|
PadCursor.draw()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- ---------------------------------------------------------------- input
|
-- ---------------------------------------------------------------- input
|
||||||
|
|
||||||
function Studio.update()
|
function Studio.update(dt)
|
||||||
|
PadCursor.update(dt or 0)
|
||||||
|
local x, y, active = PadCursor.pointer()
|
||||||
|
if active and Studio.pointerDown then Studio.mousemoved(x, y) end
|
||||||
|
local wheel = PadCursor.takeWheel()
|
||||||
|
if wheel ~= 0 then Studio.wheelmoved(0, wheel) end
|
||||||
if not Studio.pendingPlay then return end
|
if not Studio.pendingPlay then return end
|
||||||
Studio.pendingPlay = false
|
Studio.pendingPlay = false
|
||||||
local onPlay, version, canvas = Studio.onPlay, Studio.version, Studio.canvas()
|
local onPlay, version, canvas = Studio.onPlay, Studio.version, Studio.canvas()
|
||||||
if onPlay then onPlay(version, canvas) end
|
if onPlay then onPlay(version, canvas) end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Studio.mousepressed(x, y, button)
|
function Studio.mousepressed(x, y, button, fromPad)
|
||||||
if button ~= 1 then return end
|
if button ~= 1 then return end
|
||||||
|
if not fromPad then PadCursor.yieldToPointer() end
|
||||||
Studio.pointerX, Studio.pointerY = x, y
|
Studio.pointerX, Studio.pointerY = x, y
|
||||||
Studio.pointerDown = true
|
Studio.pointerDown = true
|
||||||
Studio.clicked = true
|
Studio.clicked = true
|
||||||
@@ -2760,6 +2776,65 @@ function Studio.touchpressed(id, x, y)
|
|||||||
return Studio.mousepressed(x, y, 1)
|
return Studio.mousepressed(x, y, 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function closeFromPad()
|
||||||
|
if Studio.confirm then
|
||||||
|
Studio.confirmNo()
|
||||||
|
elseif Studio.modal then
|
||||||
|
Studio.closeModal()
|
||||||
|
elseif Studio.mode == "editor" then
|
||||||
|
Studio.backToLibrary()
|
||||||
|
elseif Studio.onClose then
|
||||||
|
Studio.onClose()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function handlePadAction(action)
|
||||||
|
if action == "a" then
|
||||||
|
local x, y = PadCursor.pointer()
|
||||||
|
Studio.mousepressed(x, y, 1, true)
|
||||||
|
elseif action == "b" then
|
||||||
|
closeFromPad()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Studio.gamepadpressed(joystick, button)
|
||||||
|
handlePadAction(PadCursor.gamepadpressed(joystick, button))
|
||||||
|
end
|
||||||
|
|
||||||
|
function Studio.gamepadreleased(joystick, button)
|
||||||
|
PadCursor.gamepadreleased(joystick, button)
|
||||||
|
if GamepadMap.mapGamepadButton(button) == "a" then
|
||||||
|
local x, y = PadCursor.pointer()
|
||||||
|
Studio.mousereleased(x, y, 1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Studio.gamepadaxis(joystick, axis, value)
|
||||||
|
PadCursor.gamepadaxis(joystick, axis, value)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Studio.joystickpressed(joystick, button)
|
||||||
|
handlePadAction(PadCursor.joystickpressed(joystick, button))
|
||||||
|
end
|
||||||
|
|
||||||
|
function Studio.joystickreleased(joystick, button)
|
||||||
|
PadCursor.joystickreleased(joystick, button)
|
||||||
|
if GamepadMap.ignoreRawForJoystick(joystick) then return end
|
||||||
|
local padButton = GamepadMap.mapRawToGamepadButton(button)
|
||||||
|
if padButton and GamepadMap.mapGamepadButton(padButton) == "a" then
|
||||||
|
local x, y = PadCursor.pointer()
|
||||||
|
Studio.mousereleased(x, y, 1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Studio.joystickaxis(joystick, axis, value)
|
||||||
|
PadCursor.joystickaxis(joystick, axis, value)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Studio.joystickhat(joystick, hat, direction)
|
||||||
|
PadCursor.joystickhat(joystick, hat, direction)
|
||||||
|
end
|
||||||
|
|
||||||
function Studio.touchmoved(id, x, y)
|
function Studio.touchmoved(id, x, y)
|
||||||
if Studio.touchId ~= id then return end
|
if Studio.touchId ~= id then return end
|
||||||
return Studio.mousemoved(x, y)
|
return Studio.mousemoved(x, y)
|
||||||
@@ -2774,7 +2849,8 @@ end
|
|||||||
function Studio.wheelmoved(_, dy)
|
function Studio.wheelmoved(_, dy)
|
||||||
if Studio.mode == "editor" and not Studio.modalUp() and dy and dy ~= 0 then
|
if Studio.mode == "editor" and not Studio.modalUp() and dy and dy ~= 0 then
|
||||||
local work = Studio.canvasWorkspace
|
local work = Studio.canvasWorkspace
|
||||||
local mx, my = Studio.pointerX, Studio.pointerY
|
local mx, my, active = PadCursor.pointer()
|
||||||
|
if not active then mx, my = Studio.pointerX, Studio.pointerY end
|
||||||
if (not mx or not my) and love and love.mouse and love.mouse.getPosition then
|
if (not mx or not my) and love and love.mouse and love.mouse.getPosition then
|
||||||
mx, my = love.mouse.getPosition()
|
mx, my = love.mouse.getPosition()
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user