haskelloids/src/Menu.hs

73 lines
1.8 KiB
Haskell
Raw Normal View History

2017-02-20 19:51:33 +00:00
module Menu where
2017-12-16 18:06:36 +00:00
import Affection as A
2017-02-20 19:51:33 +00:00
import qualified SDL
import Debug.Trace
2017-12-16 18:06:36 +00:00
import Data.Maybe
import Control.Monad (when)
import Control.Monad.IO.Class (liftIO)
import qualified Data.Map as M
import NanoVG
-- internal imports
2017-02-20 19:51:33 +00:00
import Types
2017-12-16 18:06:36 +00:00
import Commons
2017-02-20 19:51:33 +00:00
2017-12-16 18:06:36 +00:00
handleMenuEvent :: (Affection UserData ()) -> [SDL.EventPayload] -> Affection UserData ()
handleMenuEvent loader es =
mapM_ (\e ->
case e of
SDL.KeyboardEvent dat ->
case SDL.keysymKeycode $ SDL.keyboardEventKeysym dat of
SDL.KeycodeSpace ->
when (SDL.keyboardEventKeyMotion dat == SDL.Pressed) $ do
ud <- getAffection
loader
_ -> return ()
SDL.WindowClosedEvent _ -> do
ad <- get
put ad
{ quitEvent = True
}
_ -> return ()
) es
2017-12-16 10:55:30 +00:00
loadMenu :: Affection UserData ()
loadMenu = do
2017-12-16 18:06:36 +00:00
liftIO $ logIO A.Debug "Loading Menu"
2017-12-16 10:55:30 +00:00
ud <- getAffection
2017-12-16 18:06:36 +00:00
mhaskImage <- liftIO $
createImage (nano ud) (FileName "assets/haskelloid.svg") 0
when (isNothing mhaskImage) $
liftIO $ logIO Error "Failed to load asset haskelloid"
hs <- newHaskelloids (fromJust mhaskImage)
2017-12-16 10:55:30 +00:00
putAffection ud
{ haskelloids = hs
, fade = FadeIn 1
, state = Menu
2017-12-16 18:06:36 +00:00
-- , shots = (shots ud)
-- { partSysParts = ParticleStorage Nothing [] }
2017-12-16 10:55:30 +00:00
}
updateMenu :: Double -> Affection UserData ()
updateMenu sec = do
ud <- getAffection
2017-12-16 18:06:36 +00:00
let nhs = map (updateHaskelloid sec) (haskelloids ud)
2017-12-16 10:55:30 +00:00
case fade ud of
FadeIn ttl -> do
putAffection ud
{ fade = if (ttl - sec) > 0 then FadeIn (ttl - sec) else FadeOut 1
, haskelloids = nhs
}
FadeOut ttl -> do
putAffection ud
{ fade = if (ttl - sec) > 0 then FadeOut (ttl - sec) else FadeIn 1
, haskelloids = nhs
}