retrofitting
This commit is contained in:
parent
5067551373
commit
0497c97475
6 changed files with 60 additions and 32 deletions
|
@ -46,7 +46,7 @@ init = do
|
||||||
, uuid = []
|
, uuid = []
|
||||||
, stateData = None
|
, stateData = None
|
||||||
, threadContext = Nothing
|
, threadContext = Nothing
|
||||||
, joystick = Nothing
|
, controls = NoController
|
||||||
, translation = defaultTranslation
|
, translation = defaultTranslation
|
||||||
, joyCache = []
|
, joyCache = []
|
||||||
}
|
}
|
||||||
|
|
14
src/Load.hs
14
src/Load.hs
|
@ -73,12 +73,22 @@ loadFork ws win glc nvg future progress = do
|
||||||
mcontrblue <- createImage nvg (FileName "assets/icons/controller_blue.png") 0
|
mcontrblue <- createImage nvg (FileName "assets/icons/controller_blue.png") 0
|
||||||
modifyMVar_ progress (return . (\(p, _) ->
|
modifyMVar_ progress (return . (\(p, _) ->
|
||||||
( p + increment
|
( p + increment
|
||||||
, "Loading icon \"conntroller_green\""
|
, "Loading icon \"controller_blue\""
|
||||||
)))
|
)))
|
||||||
mcontrgreen <- createImage nvg (FileName "assets/icons/controller_green.png") 0
|
mcontrgreen <- createImage nvg (FileName "assets/icons/controller_green.png") 0
|
||||||
modifyMVar_ progress (return . (\(p, _) ->
|
modifyMVar_ progress (return . (\(p, _) ->
|
||||||
( p + increment
|
( p + increment
|
||||||
, "Loading icon \"arrow\""
|
, "Loading icon \"controller_green\""
|
||||||
|
)))
|
||||||
|
mcontrblue <- createImage nvg (FileName "assets/icons/keyboard_blue.png") 0
|
||||||
|
modifyMVar_ progress (return . (\(p, _) ->
|
||||||
|
( p + increment
|
||||||
|
, "Loading icon \"keyboard_blue\""
|
||||||
|
)))
|
||||||
|
mcontrgreen <- createImage nvg (FileName "assets/icons/keyboard_green.png") 0
|
||||||
|
modifyMVar_ progress (return . (\(p, _) ->
|
||||||
|
( p + increment
|
||||||
|
, "Loading icon \"keyboard_green\""
|
||||||
)))
|
)))
|
||||||
marrow <- createImage nvg (FileName "assets/icons/arrow.png") 0
|
marrow <- createImage nvg (FileName "assets/icons/arrow.png") 0
|
||||||
modifyMVar_ progress (return . (\(p, _) ->
|
modifyMVar_ progress (return . (\(p, _) ->
|
||||||
|
|
|
@ -31,7 +31,7 @@ loadMenu = do
|
||||||
uu3 <- partSubscribe j emitJoyActionMessage
|
uu3 <- partSubscribe j emitJoyActionMessage
|
||||||
uu4 <- partSubscribe t handleActionMessages
|
uu4 <- partSubscribe t handleActionMessages
|
||||||
uu5 <- partSubscribe m handleClicks
|
uu5 <- partSubscribe m handleClicks
|
||||||
uu6 <- partSubscribe k emitKbdActionMessage
|
-- uu6 <- partSubscribe k emitKbdActionMessage
|
||||||
partUnSubscribe j (joyUUID ud)
|
partUnSubscribe j (joyUUID ud)
|
||||||
putAffection ud
|
putAffection ud
|
||||||
{ uuid = [ uu1, uu2, uu3, uu4, uu5 ]
|
{ uuid = [ uu1, uu2, uu3, uu4, uu5 ]
|
||||||
|
@ -44,27 +44,28 @@ loadMenu = do
|
||||||
joystickConnect :: JoystickMessage -> Affection UserData ()
|
joystickConnect :: JoystickMessage -> Affection UserData ()
|
||||||
joystickConnect msg = do
|
joystickConnect msg = do
|
||||||
ud <- getAffection
|
ud <- getAffection
|
||||||
when (isNothing $ joystick ud) $ do
|
when (controls ud == NoController) $ do
|
||||||
mjoy <- joystickAutoConnect msg
|
mjoy <- joystickAutoConnect msg
|
||||||
maybe (return ()) (\joy -> do
|
maybe (return ()) (\joy -> do
|
||||||
ident <- liftIO $ fromIntegral <$> SDL.getJoystickID joy
|
ident <- liftIO $ fromIntegral <$> SDL.getJoystickID joy
|
||||||
liftIO $ logIO A.Debug $ "Joystick connected: " ++ show ident
|
liftIO $ logIO A.Debug $ "Joystick connected: " ++ show ident
|
||||||
putAffection ud
|
putAffection ud
|
||||||
{ controls = Joystick
|
{ controls = Joystick joy
|
||||||
}
|
}
|
||||||
) mjoy
|
) mjoy
|
||||||
|
|
||||||
joystickDisconnect :: JoystickMessage -> Affection UserData ()
|
joystickDisconnect :: JoystickMessage -> Affection UserData ()
|
||||||
joystickDisconnect msg = do
|
joystickDisconnect msg = do
|
||||||
ud <- getAffection
|
ud <- getAffection
|
||||||
maybe (return ()) (\joy -> do
|
case controls ud of
|
||||||
njoys <- joystickAutoDisconnect [joy] msg
|
Joystick joy -> do
|
||||||
when (null njoys) $ do
|
njoys <- joystickAutoDisconnect [joy] msg
|
||||||
liftIO $ logIO A.Debug $ "Joystick disconnected"
|
when (null njoys) $ do
|
||||||
putAffection ud
|
liftIO $ logIO A.Debug $ "Joystick disconnected"
|
||||||
{ Controls = None
|
putAffection ud
|
||||||
}
|
{ controls = None
|
||||||
) (joystick ud)
|
}
|
||||||
|
_ -> return ()
|
||||||
|
|
||||||
handleActionMessages :: ActionMessage -> Affection UserData ()
|
handleActionMessages :: ActionMessage -> Affection UserData ()
|
||||||
handleActionMessages (ActionMessage Activate _) = do
|
handleActionMessages (ActionMessage Activate _) = do
|
||||||
|
@ -100,12 +101,16 @@ handleActionMessages (ActionMessage (LeftRight f) _) = do
|
||||||
|
|
||||||
handleClicks :: MouseMessage -> Affection UserData ()
|
handleClicks :: MouseMessage -> Affection UserData ()
|
||||||
handleClicks (MsgMouseButton _ _ SDL.Pressed _ SDL.ButtonLeft 1 pos@(V2 px py)) = do
|
handleClicks (MsgMouseButton _ _ SDL.Pressed _ SDL.ButtonLeft 1 pos@(V2 px py)) = do
|
||||||
rels@(V2 rx ry) <- liftIO $ fmap ((/ 2) . (+ 1)) <$> (relativizeMouseCoords pos)
|
ud <- getAffection
|
||||||
when (arrowUp rels || arrowDown rels) (adjustUpDown rels)
|
case controls ud of
|
||||||
when (arrowLeft rels || arrowRight rels) (adjustLeftRight rels)
|
Joystick -> do
|
||||||
when (buttonActivate rels) (adjustActivate)
|
rels@(V2 rx ry) <- liftIO $ fmap ((/ 2) . (+ 1)) <$> (relativizeMouseCoords pos)
|
||||||
when (buttonSwitchMap rels) (adjustSwitchMap)
|
when (arrowUp rels || arrowDown rels) (adjustUpDown rels)
|
||||||
when (buttonPlay rels) (enterGame)
|
when (arrowLeft rels || arrowRight rels) (adjustLeftRight rels)
|
||||||
|
when (buttonActivate rels) (adjustActivate)
|
||||||
|
when (buttonSwitchMap rels) (adjustSwitchMap)
|
||||||
|
when (buttonPlay rels) (enterGame)
|
||||||
|
_ -> return ()
|
||||||
where
|
where
|
||||||
adjustUpDown rels = do
|
adjustUpDown rels = do
|
||||||
if arrowUp rels
|
if arrowUp rels
|
||||||
|
@ -172,15 +177,26 @@ drawMenu = do
|
||||||
controller = controls ud
|
controller = controls ud
|
||||||
save ctx
|
save ctx
|
||||||
beginPath ctx
|
beginPath ctx
|
||||||
paint <- imagePattern ctx 600 620 80 80 0 (assetIcons ud M.!
|
cpaint <- imagePattern ctx 550 620 80 80 0 (assetIcons ud M.!
|
||||||
if isNothing controller
|
case controller of
|
||||||
then IconContrBlue
|
Joystick -> IconContrGreen
|
||||||
else IconContrGreen
|
_ -> IconContrBlue
|
||||||
) 1
|
) 1
|
||||||
rect ctx 600 620 80 80
|
rect ctx 600 620 80 80
|
||||||
fillPaint ctx paint
|
fillPaint ctx cpaint
|
||||||
|
endPath ctx
|
||||||
fill ctx
|
fill ctx
|
||||||
when (controller /= None) $ do
|
beginPath ctx
|
||||||
|
cpaint <- imagePattern ctx 650 620 80 80 0 (assetIcons ud M.!
|
||||||
|
case controller of
|
||||||
|
Keyboard -> IconKbdGreen
|
||||||
|
_ -> IconKbdBlue
|
||||||
|
) 1
|
||||||
|
rect ctx 600 620 80 80
|
||||||
|
fillPaint ctx cpaint
|
||||||
|
endPath ctx
|
||||||
|
fill ctx
|
||||||
|
when (controller /= NoController) $ do
|
||||||
let V2 vx vy = velocity $ stateData ud
|
let V2 vx vy = velocity $ stateData ud
|
||||||
beginPath ctx
|
beginPath ctx
|
||||||
roundedRect ctx 140 110 1000 500 25
|
roundedRect ctx 140 110 1000 500 25
|
||||||
|
@ -264,9 +280,9 @@ drawMenu = do
|
||||||
_ ->
|
_ ->
|
||||||
return ()
|
return ()
|
||||||
beginPath ctx
|
beginPath ctx
|
||||||
paint <- imagePattern ctx 0 0 100 100 0 (assetIcons ud M.! IconArrow) 1
|
apaint <- imagePattern ctx 0 0 100 100 0 (assetIcons ud M.! IconArrow) 1
|
||||||
rect ctx 0 0 100 100
|
rect ctx 0 0 100 100
|
||||||
fillPaint ctx paint
|
fillPaint ctx apaint
|
||||||
closePath ctx
|
closePath ctx
|
||||||
fill ctx
|
fill ctx
|
||||||
restore ctx
|
restore ctx
|
||||||
|
|
|
@ -3,6 +3,8 @@ module Types.ImgId where
|
||||||
data IconId
|
data IconId
|
||||||
= IconContrBlue
|
= IconContrBlue
|
||||||
| IconContrGreen
|
| IconContrGreen
|
||||||
|
| IconKbdBlue
|
||||||
|
| IconKbdGreen
|
||||||
| IconArrow
|
| IconArrow
|
||||||
deriving (Show, Eq, Ord, Enum)
|
deriving (Show, Eq, Ord, Enum)
|
||||||
|
|
||||||
|
|
|
@ -48,9 +48,9 @@ data UserData = UserData
|
||||||
}
|
}
|
||||||
|
|
||||||
data Controller
|
data Controller
|
||||||
= None
|
= NoController
|
||||||
| Keyboard
|
| Keyboard
|
||||||
| Joystick
|
| Joystick SDL.Joystick
|
||||||
deriving (Eq, Show)
|
deriving (Eq, Show)
|
||||||
|
|
||||||
data State
|
data State
|
||||||
|
|
|
@ -304,8 +304,8 @@ cacheJoypad msg = do
|
||||||
{ joyCache = msg : joyCache ud
|
{ joyCache = msg : joyCache ud
|
||||||
}
|
}
|
||||||
|
|
||||||
emitActionMessage :: JoystickMessage -> Affection UserData ()
|
emitJoyActionMessage :: JoystickMessage -> Affection UserData ()
|
||||||
emitActionMessage (MsgJoystickAxis time _ axis val) = do
|
emitJoyActionMessage (MsgJoystickAxis time _ axis val) = do
|
||||||
ud <- getAffection
|
ud <- getAffection
|
||||||
let Subsystems _ _ _ _ t = subsystems ud
|
let Subsystems _ _ _ _ t = subsystems ud
|
||||||
case (translation ud) Map.!? (AxisAction axis) of
|
case (translation ud) Map.!? (AxisAction axis) of
|
||||||
|
|
Loading…
Reference in a new issue