Continue hud/mouse refactor

This commit is contained in:
2024-11-16 15:06:05 +00:00
parent 0621709f7b
commit 5efc9220e0
6 changed files with 184 additions and 226 deletions
+3
View File
@@ -19,13 +19,16 @@ data PressType
data MouseContext
= NoMouseContext
| MouseAiming
| MouseClick
| OverInvSelect { _mcoInvSelect :: (Int,Int)}
| OverInvFilt { _mcoInvFilt :: (Int,Int)}
| OverCombSelect { _mcoCombSelect :: (Int,Int)}
| OverCombCombine { _mcoCombCombine :: (Int,Int)}
| OverCombFilter
| OverCombEscape
| OverTerminalReturn
| OverTerminalEscape
deriving (Show)
data Input = Input
{ _mousePos :: Point2 -- in pixels, from the center of the screen
+27 -24
View File
@@ -2,7 +2,6 @@ module Dodge.Render.Picture (
fixedCoordPictures,
) where
import Dodge.CharacterEnums
import Control.Lens
import Control.Monad
import Data.Maybe
@@ -79,14 +78,16 @@ drawMouseCursor u =
mouseCursorType :: Universe -> Picture
mouseCursorType u = case u ^. uvWorld . input . mouseContext of
NoMouseContext -> drawPlus 5
NoMouseContext -> drawEmptySet 5
MouseAiming -> rotate a (drawPlus 5)
MouseClick -> drawPlus 5
OverInvSelect {} -> drawSelect 5
OverInvFilt {} -> drawCombFilter 5
OverCombSelect {} -> drawSelect 5
OverCombFilter {} -> drawCombFilterJump 5
OverCombCombine {} -> drawGapPlus 5
OverTerminalReturn -> drawReturn
OverCombEscape -> rotate (pi/4) $ drawPlus 5
OverTerminalReturn -> drawReturn 5
OverTerminalEscape -> rotate (pi/4) $ drawPlus 5
where
w = u ^. uvWorld
@@ -96,22 +97,22 @@ mouseCursorType u = case u ^. uvWorld . input . mouseContext of
argV (mouseWorldPos (w ^. input) (w ^. wCam) -.- cpos)
- w ^. wCam . camRot
determineTermCursor :: Int -> Universe -> Picture
determineTermCursor tmid u = fromMaybe (drawPlus 5) $ do
return drawReturn
drawReturn :: Picture
drawReturn = fold
[line [V2 0 0, V2 3 3]
,line [V2 0 0, V2 3 (-3)]
,line [V2 0 0, V2 6 0]
,line [V2 6 0, V2 6 10]
drawEmptySet :: Float -> Picture
drawEmptySet x = fold
[line [V2 x x,V2 (-x) (-x)]
,circle x
]
--drawReturn = scale 0.1 0.1 . translate (-50) (-100) $ text [toEnum 153]
drawWireRectCursor :: Picture
drawWireRectCursor = scale 0.1 0.1 $ text [cWireRect]
--drawReturn = text "ASDF"
drawReturn :: Float -> Picture
drawReturn x = fold
[line [V2 0 0, V2 y y]
,line [V2 0 0, V2 y (-y)]
,line [V2 0 0, V2 (2*y) 0]
,line [V2 (2*y) 0, V2 (2*y) (2*x)]
]
where
y = 0.7 * x
--drawReturn = scale 0.1 0.1 . translate (-50) (-100) $ text [toEnum 153]
drawPlus :: Float -> Picture
drawPlus x = fold [line [V2 (- x) 0, V2 x 0], line [V2 0 (- x), V2 0 x]]
@@ -121,13 +122,15 @@ drawCombFilterJump x = rotate (0.25*pi)
$ fold [line [V2 0 0, V2 x 0], line [V2 0 0, V2 0 x]]
drawSelect :: Float -> Picture
drawSelect x = line
[ V2 x x
, V2 0 x
, V2 0 (-x)
, V2 x (-x)
] <>
line [V2 (-x) 0, V2 0 0]
drawSelect x = polygonWire $ rectWH x (0.5 * x)
-- line [V2 (-x) 0, V2 0 0]
--drawSelect x = line
-- [ V2 x x
-- , V2 0 x
-- , V2 0 (-x)
-- , V2 x (-x)
-- ] <>
-- line [V2 (-x) 0, V2 0 0]
drawCombFilter :: Float -> Picture
drawCombFilter x = rotate (0.25*pi)
+8 -11
View File
@@ -301,9 +301,9 @@ checkTermDist w = fromMaybe w $ do
w & hud . hudElement . subInventory
.~ NoSubInventory MouseInvNothing
-- for other mouse effects, see yourControl
updateMouseInventoryEffects :: Configuration -> World -> World
updateMouseInventoryEffects cfig w = w
---- for other mouse effects, see yourControl
--updateMouseInventoryEffects :: Configuration -> World -> World
--updateMouseInventoryEffects cfig w = w
updateMouseInventorySelection :: Configuration -> World -> World
updateMouseInventorySelection cfig w = fromMaybe w $ do
@@ -407,14 +407,11 @@ updateMouseContext cfig w =
sss <- w ^? hud . hudElement . subInventory . ciSections
msel <- w ^? hud . hudElement . subInventory . ciSelection . _Just
let mpossel = inverseSelNumPos cfig secondColumnParams sss (w ^. input . mousePos)
case mpossel of
Nothing -> usecsel msel
Just (-1,_) -> return OverCombFilter
Just x | x == msel -> return $ OverCombCombine x
Just x -> return $ OverCombSelect x
-- fmap OverCombCombine $ inverseSelNumPos cfig secondColumnParams sss (w ^. input . mousePos)
usecsel (-1,_) = return OverCombFilter
usecsel x = return $ OverCombCombine x
return $ case mpossel of
Nothing -> OverCombEscape
Just (-1,_) -> OverCombFilter
Just x | x == msel -> OverCombCombine x
Just x -> OverCombSelect x
overterm = do
tmid <- w ^? hud . hudElement . subInventory . termID
guard True
+12 -8
View File
@@ -43,7 +43,7 @@ updateUseInputInGame u = updateFunctionKeys $ case u ^. uvWorld . hud . hudEleme
u & uvWorld . cWorld . lWorld . terminals . ix tmid . tmInput . tiFocus
%~ const True
CombineInventory{_ciSections = sss, _ciSelection = msel}
| lbinitialpress -> u & uvWorld %~ updateCombineInvClick msel sss
| lbinitialpress -> u & uvWorld %~ updateCombineInvClick sss
| inSubInvRegex (u ^. uvWorld) ->
u
& uvWorld . hud . hudElement . subInventory
@@ -103,11 +103,10 @@ updateFunctionKey uv sc InitialPress = case sc of
updateFunctionKey uv _ _ = uv
updateCombineInvClick ::
Maybe (Int, Int) ->
IM.IntMap (SelectionSection CombinableItem) ->
World ->
World
updateCombineInvClick msel sss w = fromMaybe trydocombination $ do
updateCombineInvClick sss w = fromMaybe trydocombination $ do
(i,j) <- w ^? input . mouseContext . mcoInvFilt
guard $ i == 0
str <- fmap (take 5) $ w
@@ -123,9 +122,15 @@ updateCombineInvClick msel sss w = fromMaybe trydocombination $ do
& worldEventFlags . at CombineInventoryChange ?~ ()
OverCombFilter -> w & hud . hudElement . subInventory . ciFilter .~ Nothing
& worldEventFlags . at CombineInventoryChange ?~ ()
OverCombCombine (i,j) -> (worldEventFlags . at InventoryChange ?~ ()) . maybeExitCombine $
tryCombine sss msel w
OverCombCombine (i,j) ->
(worldEventFlags . at InventoryChange ?~ ()) . maybeExitCombine $
tryCombine sss (i,j) w
& worldEventFlags . at CombineInventoryChange ?~ ()
OverCombEscape -> w
& worldEventFlags . at InventoryChange ?~ ()
& hud . hudElement . subInventory .~ NoSubInventory MouseInvNothing
x -> error $ "while combining this mouse context should not be possible: "
++ show x
-- x@(Just (i,_))
-- | x /= msel -> w & hud . hudElement . subInventory . ciSelection .~ x
@@ -352,11 +357,10 @@ toggleTweakInv w = case w ^? hud . hudElement . subInventory of
tryCombine ::
IM.IntMap (SelectionSection CombinableItem) ->
Maybe (Int, Int) ->
(Int, Int) ->
World ->
World
tryCombine sss msel w = fromMaybe w $ do
(i, j) <- msel
tryCombine sss (i,j) w = fromMaybe w $ do
CombinableItem is it _ <- sss ^? ix i . ssItems . ix j . siPayload
p <- w ^? cWorld . lWorld . creatures . ix 0 . crPos
return $