Cleanup, hide item selection cursor when in terminal

This commit is contained in:
2025-12-24 13:45:38 +00:00
parent 6becda01d5
commit 8cd2625548
11 changed files with 262 additions and 295 deletions
+39 -54
View File
@@ -2,11 +2,11 @@
module Dodge.Render.HUD (drawHUD) where
import Data.List (elemIndex)
import Control.Applicative
import Control.Lens
import Control.Monad
import qualified Data.IntSet as IS
import Data.List (elemIndex)
import qualified Data.Map.Strict as M
import Data.Maybe
import qualified Data.Vector as V
@@ -57,9 +57,14 @@ drawHUD cfig w = case w ^. hud of
drawInventory sections w cfig subinv
<> drawSubInventory subinv cfig w
drawInventory :: IM.IntMap (SelSection ()) -> World -> Config -> SubInventory -> Picture
drawInventory :: IMSS () -> World -> Config -> SubInventory -> Picture
drawInventory sss w cfig = \case
-- DisplayTerminal {} -> mempty
DisplayTerminal {} ->
drawSelectionSections sss invDP cfig
-- <> drawSSCursor sss invDP curs cfig (f $ w ^? hud . diSelection . _Just)
-- <> drawRootCursor w sss (f $ w ^? hud . diSelection . _Just) invDP cfig
<> itemconnections
<> drawMouseOver cfig w
_ ->
drawSelectionSections sss invDP cfig
<> drawSSCursor sss invDP curs cfig (f $ w ^? hud . diSelection . _Just)
@@ -77,12 +82,7 @@ drawInventory sss w cfig = \case
_ -> return . drawItemConnections sss cfig $ invAdj inv
drawRootCursor ::
World ->
IM.IntMap (SelSection ()) ->
Maybe (Int, Int) ->
ListDisplayParams ->
Config ->
Picture
World -> IMSS () -> Maybe (Int, Int) -> LDParams -> Config -> Picture
drawRootCursor w sss msel ldp cfig = fromMaybe mempty $ do
cr <- w ^? cWorld . lWorld . creatures . ix 0
guard $ crIsAiming cr
@@ -169,7 +169,6 @@ drawDragSelecting cfig w = do
drawSubInventory :: SubInventory -> Config -> World -> Picture
drawSubInventory subinv cfig w = case subinv of
-- LockedInventory -> mempty -- topInvCursor col cursPos cfig w
NoSubInventory{} -> drawRBOptions cfig w
ExamineInventory -> drawExamineInventory cfig w
DisplayTerminal tid -> (drawTerminalDisplay w cfig tid)
@@ -185,7 +184,7 @@ drawMapperInventory itid w = fold $ do
where
f = worldPosToScreen (w ^. wCam)
drawCombineInventory :: Config -> IM.IntMap (SelSection CombItem) -> World -> Picture
drawCombineInventory :: Config -> IMSS CombItem -> World -> Picture
drawCombineInventory cfig sss w =
drawSelectionSections sss secondColumnLDP cfig
<> drawSSCursor sss secondColumnLDP curs cfig msel
@@ -319,16 +318,13 @@ equipAllocString = \case
RemoveEquipment{} -> "TAKE OFF"
drawItemConnections ::
IM.IntMap (SelSection ()) ->
Config ->
IM.IntMap (Maybe (Int, Int), [Int], [Int]) ->
Picture
IMSS () -> Config -> IM.IntMap (Maybe (Int, Int), [Int], [Int]) -> Picture
drawItemConnections sss cfig =
translate (negate 5) 0
. IM.foldMapWithKey (drawItemChildrenConnect sss cfig)
. fmap (\(_, a, b) -> a <> b)
drawItemChildrenConnect :: IM.IntMap (SelSection ()) -> Config -> Int -> [Int] -> Picture
drawItemChildrenConnect :: IMSS () -> Config -> Int -> [Int] -> Picture
drawItemChildrenConnect sss cfig i is = fromMaybe mempty $ do
p <- snum i
let ps = mapMaybe snum is
@@ -337,7 +333,7 @@ drawItemChildrenConnect sss cfig i is = fromMaybe mempty $ do
snum = selNumPos cfig invDP sss 0
combineInventoryExtra ::
IM.IntMap (SelSection CombItem) -> Maybe (Int, Int) -> Config -> World -> Picture
IMSS CombItem -> Maybe (Int, Int) -> Config -> World -> Picture
combineInventoryExtra sss msel cfig w = fold $ do
(i, j) <- msel
si <- sss ^? ix i . ssItems . ix j
@@ -345,13 +341,13 @@ combineInventoryExtra sss msel cfig w = fold $ do
lnks <- si ^? siPayload . _Just . ciInvIDs
return (lnkMidPosInvSelsCol cfig w j col lnks) <> Just (foldMap invcursor lnks)
where
invcursor i =
translateScreenPos cfig (invDP ^. ldpPos) $
selSecDrawCursor
invDP
(BoundaryCursor [North, South, East, West])
(w ^. hud . diSections)
(Just (0, i))
invcursor i =
translateScreenPos cfig (invDP ^. ldpPos) $
selSecDrawCursor
invDP
(BoundaryCursor [North, South, East, West])
(w ^. hud . diSections)
(Just (0, i))
drawTerminalDisplay :: World -> Config -> Int -> Picture
drawTerminalDisplay w cfig tid = fold $ do
@@ -370,8 +366,9 @@ drawTerminalDisplay w cfig tid = fold $ do
TerminalLineRead -> (++ [(spincurs, termTextColor)])
TerminalTextInput s -> (++ [(getPromptTM ++ s ++ [cFilledRect], white)])
TerminalPressTo s -> (++ [(s, white)])
return $ drawSelectionList (secondColumnLDP & ldpBorder ?~ (49, 16)) cfig f
<> drawTerminalCursorLink w cfig tm
return $
drawSelectionList (secondColumnLDP & ldpBorder ?~ (49, 16)) cfig f
<> drawTerminalCursorLink w cfig tm
where
-- <> tm ^. tmButtonID
@@ -389,15 +386,20 @@ drawTerminalDisplay w cfig tid = fold $ do
drawTerminalCursorLink :: World -> Config -> Terminal -> Picture
drawTerminalCursorLink w cfig tm = fold $ do
j <- elemIndex (tm ^. tmButtonID) $ w ^. hud . closeButtons
lp <- selNumPos cfig invDP (w^. hud . diSections) 5 j
lp <- selNumPos cfig invDP (w ^. hud . diSections) 5 j
let rp = screenPosAbs cfig (secondColumnLDP ^. ldpPos) - V2 5 10
lcol <- selSecSelCol 5 j (w ^. hud . diSections)
return $ translateScreenPos cfig (invDP ^. ldpPos)
(selSecDrawCursor invDP
(BoundaryCursor [North,South,East,West])
(w ^. hud . diSections)
(Just (5,j)))
<> lConnectCol (lp + V2 155 0) rp lcol white white
return $
translateScreenPos
cfig
(invDP ^. ldpPos)
( selSecDrawCursor
invDP
(BoundaryCursor [North, South, East, West])
(w ^. hud . diSections)
(Just (5, j))
)
<> lConnectCol (lp + V2 155 0) rp lcol white white
lnkMidPosInvSelsCol :: Config -> World -> Int -> Color -> [Int] -> Picture
lnkMidPosInvSelsCol cfig w i col = fromMaybe mempty . foldMap f
@@ -459,13 +461,7 @@ invHead cfig =
-- textSelItems = map (picsToSelectable . (: []))
-- would be nice to add parameter to orient this with NSEW, cf cursor
selNumPos ::
Config ->
ListDisplayParams ->
IMSS a ->
Int ->
Int ->
Maybe Point2
selNumPos :: Config -> LDParams -> IMSS a -> Int -> Int -> Maybe Point2
selNumPos = selNumPosCardinal West8
-- selNumPos cfig ldp sss i j = do
@@ -483,26 +479,15 @@ selNumPos = selNumPosCardinal West8
-- need to be able to determine a selection item's width for this
selNumPosCardinal ::
CardinalEightPoint ->
Config ->
ListDisplayParams ->
IM.IntMap (SelSection a) ->
Int ->
Int ->
Maybe Point2
Cardinal8 -> Config -> LDParams -> IMSS a -> Int -> Int -> Maybe Point2
selNumPosCardinal card cfig ldp sss i j = do
ipos <- selSecYint i j sss
-- size <- selSecSelSize i j sss
ysize <- fromIntegral <$> sss ^? ix i . ssItems . ix j . siHeight
xsize <- fromIntegral <$> sss ^? ix i . ssItems . ix j . siWidth
itmindent <- fromIntegral <$> sss ^? ix i . ssItems . ix j . siOffX
sindent <- fromIntegral <$> sss ^? ix i . ssIndent
let indent = itmindent + sindent
let offset =
cardEightVec card
* V2
(xsize * 0.5 * 10 * s)
(ysize * 0.5 * 20 * s)
let offset = s *^ (card8Vec card * V2 (xsize * 5) (ysize * 10))
return $
screenPosAbs cfig (ldp ^. ldpPos)
+ offset
@@ -513,5 +498,5 @@ selNumPosCardinal card cfig ldp sss i j = do
s = _ldpScale ldp
ygap = _ldpVerticalGap ldp
selSecSelCol :: Int -> Int -> IM.IntMap (SelSection a) -> Maybe Color
selSecSelCol :: Int -> Int -> IMSS a -> Maybe Color
selSecSelCol i j = (^? ix i . ssItems . ix j . siColor)
+5 -18
View File
@@ -33,7 +33,7 @@ import LensHelp
import ListHelp
import Picture
drawSelectionList :: ListDisplayParams -> Config -> [SelectionItem a] -> Picture
drawSelectionList :: LDParams -> Config -> [SelectionItem a] -> Picture
drawSelectionList ldps cfig sl =
translateScreenPos cfig (ldps ^. ldpPos) $
drawListYgapScaleYoff ygap sf 0 (makeSelectionListPictures sl)
@@ -57,7 +57,7 @@ drawTitleBackground cfig =
$ rectNSWE 70 0 0 560
drawSelectionListBackground ::
ListDisplayParams ->
LDParams ->
Config ->
Int -> -- list length
Picture
@@ -77,12 +77,7 @@ makeSelectionListPictures = concatMap f
-- note this does not take into account any selectionsection indent
drawCursorAt ::
Maybe Int ->
[SelectionItem a] ->
ListDisplayParams ->
Int ->
CursorDisplay ->
Picture
Maybe Int -> [SelectionItem a] -> LDParams -> Int -> CursorDisplay -> Picture
drawCursorAt mi lis ldps width curs = fromMaybe mempty $ do
i <- mi
selit <- lis !? i
@@ -110,11 +105,7 @@ stackPicturesAtOff :: Int -> [Picture] -> Picture
stackPicturesAtOff i = mconcat . zipWith (drawListElement 10 1 0) [i, i - 1 ..]
selSecDrawCursorAt ::
ListDisplayParams ->
CursorDisplay ->
IM.IntMap (SelSection a) ->
(Int, Int) ->
Picture
LDParams -> CursorDisplay -> IM.IntMap (SelSection a) -> (Int, Int) -> Picture
selSecDrawCursorAt ldp curs sss (i, j) = fold $ do
yint <- selSecYint i j sss
sindent <- sss ^? ix i . ssIndent
@@ -131,11 +122,7 @@ selSecDrawCursorAt ldp curs sss (i, j) = fold $ do
(_siHeight si)
selSecDrawCursor ::
ListDisplayParams ->
CursorDisplay ->
IM.IntMap (SelSection a) ->
Maybe (Int, Int) ->
Picture
LDParams -> CursorDisplay -> IM.IntMap (SelSection a) -> Maybe (Int, Int) -> Picture
selSecDrawCursor ldp curs = maybe mempty . selSecDrawCursorAt ldp curs
-- displays a cursor that should match up to list text pictures