Files
loop/src/Dodge/Data/Input.hs
T
2025-05-31 15:28:30 +01:00

76 lines
2.3 KiB
Haskell

{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TemplateHaskell #-}
module Dodge.Data.Input where
import Control.Lens
import qualified Data.Map.Strict as M
import Geometry.Data
import SDL (MouseButton, Scancode)
import Data.Aeson
import Data.Aeson.TH
data PressType
= InitialPress
| ShortPress
| LongPress
deriving (Eq, Show)
data MouseContext
= NoMouseContext
| MouseAiming
| MouseInGame
| MouseMenuClick {_mcoMenuClick :: Int}
| MouseMenuCursor
| OverInvDrag {_mcoDragSection :: Int
, _mcoMaybeSelect :: Maybe (Int,Int)
, _mcoAboveSelect :: Maybe (Int,Int)
, _mcoBelowSelect :: Maybe (Int,Int)
}
| OverInvDragSelect { _mcoSecSelStart :: (Int,Int), _mcoSelEnd :: Maybe Int }
| OverInvSelect { _mcoInvSelect :: (Int,Int)}
| OverCombFiltInv { _mcoInvFilt :: (Int,Int)}
| OverCombSelect { _mcoCombSelect :: (Int,Int)}
| OverCombCombine { _mcoCombCombine :: (Int,Int)}
| OverCombFilter
| OverCombEscape
| OverTerminalReturn {_mcoTermID :: Int}
| OverTerminalEscape
| MouseGameRotate
deriving (Show)
data Input = Input
{ _mousePos :: Point2 -- in pixels, from the center of the screen
, _mouseContext :: MouseContext
, _mouseMoving :: Bool
, _pressedKeys :: M.Map Scancode PressType
, _mouseButtons :: M.Map MouseButton Int -- counts number of frames held down
, _mouseButtonsReleased :: M.Map MouseButton Int -- counts number of frames released
, _scrollAmount :: Int
, _smoothScrollAmount :: Int
, _clickPos :: M.Map MouseButton Point2 -- updates on initial mouse button press
, _heldPos :: M.Map MouseButton Point2 -- updates while mouse button is held, lags one frame
, _clickWorldPos :: M.Map MouseButton Point2 -- updates on initial mouse button press
, _heldWorldPos :: M.Map MouseButton Point2 -- updates while mouse button is held, lags one frame
, _textInput :: [Either TermSignal Char]
, _scrollTestFloat :: Float
, _scrollTestInt :: Int
}
data TermSignal
= TSescape
| TSreturn
| TSbackspace
| TSdelete
| TStab
| TSleft
| TSright
| TSup
| TSdown
makeLenses ''Input
makeLenses ''MouseContext
deriveJSON defaultOptions ''PressType