Continue mouse context refactor

This commit is contained in:
2024-11-18 22:21:12 +00:00
parent 69fe28afe7
commit 5b709cd7ba
7 changed files with 186 additions and 165 deletions
+3 -1
View File
@@ -22,13 +22,15 @@ data MouseContext
| MouseInGame
| MouseMenuClick {_mcoMenuClick :: Int}
| MouseMenuCursor
| OverInvDrag
| OverInvDragSelect { _mcoSelStart :: (Int,Int), _mcoSelEnd :: (Int,Int) }
| OverInvSelect { _mcoInvSelect :: (Int,Int)}
| OverInvFilt { _mcoInvFilt :: (Int,Int)}
| OverCombSelect { _mcoCombSelect :: (Int,Int)}
| OverCombCombine { _mcoCombCombine :: (Int,Int)}
| OverCombFilter
| OverCombEscape
| OverTerminalReturn
| OverTerminalReturn {_mcoTermID :: Int}
| OverTerminalEscape
deriving (Show)
+9 -1
View File
@@ -84,13 +84,15 @@ mouseCursorType u = case u ^. uvWorld . input . mouseContext of
MouseMenuClick {} -> drawMenuClick 5
MouseMenuCursor -> drawMenuCursor 5
MouseInGame -> drawPlus 5
OverInvDrag -> drawDrag 5
OverInvDragSelect {} -> drawDragSelect 5
OverInvSelect {} -> drawSelect 5
OverInvFilt {} -> drawCombFilter 5
OverCombSelect {} -> drawSelect 5
OverCombFilter {} -> drawCombFilterJump 5
OverCombCombine {} -> drawGapPlus 5
OverCombEscape -> rotate (pi/4) $ drawPlus 5
OverTerminalReturn -> drawReturn 5
OverTerminalReturn {} -> drawReturn 5
OverTerminalEscape -> rotate (pi/4) $ drawPlus 5
where
w = u ^. uvWorld
@@ -149,6 +151,12 @@ drawCombFilterJump :: Float -> Picture
drawCombFilterJump x = rotate (0.25*pi)
$ fold [line [V2 0 0, V2 x 0], line [V2 0 0, V2 0 x]]
drawDragSelect :: Float -> Picture
drawDragSelect x = polygonWire $ rectWH (0.5 * x) x
drawDrag :: Float -> Picture
drawDrag x = line [V2 0 x,V2 0 (-x)]
drawSelect :: Float -> Picture
drawSelect x = polygonWire $ rectWH x (0.5 * x)
-- line [V2 (-x) 0, V2 0 0]
+6 -5
View File
@@ -273,16 +273,17 @@ commandFutureLines s tm w = fromMaybe [errline "^ Invalid command"] $ do
where
errline = makeColorTermLine red
terminalReturnEffect :: Terminal -> World -> World
terminalReturnEffect tm w = fromMaybe w $ do
terminalReturnEffect :: Int -> World -> World
terminalReturnEffect tmid w = fromMaybe w $ do
tm <- w ^? cWorld . lWorld . terminals. ix tmid
guard $ _tmStatus tm == TerminalReady
s <- w ^? cWorld . lWorld . terminals . ix (_tmID tm) . tmInput . tiText
s <- tm ^? tmInput . tiText
let pc = maybe "" (++ " ") $ tm ^? tmPartialCommand . _Just . tcString
return $
runTerminalString (pc ++ s) tm $
w
& cWorld . lWorld . terminals . ix (_tmID tm) . tmPartialCommand .~ Nothing
& cWorld . lWorld . terminals . ix (_tmID tm) . tmFutureLines
& cWorld . lWorld . terminals . ix tmid . tmPartialCommand .~ Nothing
& cWorld . lWorld . terminals . ix tmid . tmFutureLines
.~ [makeTermLine (pc ++ getPromptTM (tm ^. tmType) ++ s)]
runTerminalString :: String -> Terminal -> World -> World
+7 -5
View File
@@ -389,8 +389,9 @@ shiftInvItemsDown (_, i) x w = fromMaybe w $ do
g i' m = fst <$> IM.lookupGT i' m
updateMouseContext :: Configuration -> Universe -> Universe
updateMouseContext cfig u =
u & uvWorld . input . mouseContext
updateMouseContext cfig u = case u ^. uvWorld . input . mouseContext of
OverInvDrag -> u
_ -> u & uvWorld . input . mouseContext
.~ fromMaybe
aimcontext
(overmenu <|> overinv <|> overcomb <|> overterm)
@@ -440,9 +441,10 @@ updateMouseContext cfig u =
return $
if isOverTerminalScreen cfig tm mpos
then
if null $ tm ^. tmInput . tiText
then NoMouseContext
else OverTerminalReturn
fromMaybe NoMouseContext $ do
let s = tm ^. tmInput . tiText
guard $ not (null s) && _tmStatus tm == TerminalReady
return $ OverTerminalReturn tmid
else OverTerminalEscape
isOverTerminalScreen :: Configuration -> Terminal -> Point2 -> Bool
+7 -12
View File
@@ -88,20 +88,15 @@ updateUseInputInGame u = updateFunctionKeys $ case u ^. uvWorld . hud . hudEleme
& ciFilter .~ filts'
updateMouseClickInGame :: World -> World
updateMouseClickInGame w = if w ^? input . mouseButtons . ix ButtonLeft == Just 0
then updateMouseClickInGame' w
else w
updateMouseClickInGame w = case w ^? input . mouseButtons . ix ButtonLeft of
Just 0 -> updateMouseClickInGame' w
Just _ -> w
Nothing -> w
updateMouseClickInGame' :: World -> World
updateMouseClickInGame' w = case w ^. input . mouseContext of
OverTerminalReturn -> fromMaybe w $ do
tmid <- w ^? hud . hudElement . subInventory . termID
tm <- w ^? cWorld . lWorld . terminals . ix tmid
guard (_tmStatus tm == TerminalReady)
s <- tm ^? tmInput . tiText
return $ if null (words s) && null (_tmPartialCommand tm)
then w
else terminalReturnEffect tm w
OverInvSelect (i,j) -> w
OverTerminalReturn tmid -> terminalReturnEffect tmid w
OverTerminalEscape -> w
& hud . hudElement . subInventory .~ NoSubInventory MouseInvNothing
OverCombSelect x ->
@@ -183,7 +178,7 @@ updateKeysInTerminal tmid u =
pkeys = u ^. uvWorld . input . pressedKeys
checkEndStatus
| pkeys ^. at ScancodeReturn == Just InitialPress =
over uvWorld (\w -> terminalReturnEffect (w ^?! cWorld . lWorld . terminals . ix tmid) w)
over uvWorld (\w -> terminalReturnEffect tmid w)
| otherwise = id
updateKeyInGame :: Universe -> Scancode -> PressType -> Universe