Cleanup, hide item selection cursor when in terminal
This commit is contained in:
@@ -14,8 +14,8 @@ cardVec cp = case cp of
|
||||
East -> V2 1 0
|
||||
West -> V2 (-1) 0
|
||||
|
||||
cardEightVec :: CardinalEightPoint -> Point2
|
||||
cardEightVec cp = case cp of
|
||||
card8Vec :: Cardinal8 -> Point2
|
||||
card8Vec cp = case cp of
|
||||
North8 -> V2 0 1
|
||||
NorthEast8 -> V2 1 1
|
||||
East8 -> V2 1 0
|
||||
|
||||
@@ -24,7 +24,7 @@ data CardinalPointBetween
|
||||
| NorthWest
|
||||
deriving (Eq, Ord, Show, Bounded, Enum)
|
||||
|
||||
data CardinalEightPoint
|
||||
data Cardinal8
|
||||
= North8
|
||||
| NorthEast8
|
||||
| East8
|
||||
|
||||
@@ -10,7 +10,7 @@ import Dodge.Data.CardinalPoint
|
||||
import Dodge.Data.ScreenPos
|
||||
import Picture.Data
|
||||
|
||||
data ListDisplayParams = ListDisplayParams
|
||||
data LDParams = LDP -- List display parameters
|
||||
{ _ldpPos :: ScreenPos
|
||||
, _ldpScale :: Float
|
||||
, _ldpVerticalGap :: Float
|
||||
@@ -54,7 +54,7 @@ data SIDisplayMod
|
||||
= NoSIDisplayMod
|
||||
| HighlightSI
|
||||
|
||||
makeLenses ''ListDisplayParams
|
||||
makeLenses ''LDParams
|
||||
makeLenses ''SelectionItem
|
||||
makeLenses ''SelSection
|
||||
makeLenses ''SectionCursor
|
||||
|
||||
@@ -16,9 +16,8 @@ import Dodge.Data.World
|
||||
import Linear
|
||||
import SDL (MouseButton (..))
|
||||
|
||||
defaultLDP :: ListDisplayParams
|
||||
defaultLDP =
|
||||
ListDisplayParams
|
||||
defaultLDP :: LDParams
|
||||
defaultLDP = LDP
|
||||
{ _ldpVerticalGap = 0
|
||||
, _ldpScale = 1
|
||||
, _ldpPos =
|
||||
@@ -29,7 +28,7 @@ defaultLDP =
|
||||
, _ldpBorder = Nothing
|
||||
}
|
||||
|
||||
invDP :: ListDisplayParams
|
||||
invDP :: LDParams
|
||||
--invDP = defaultLDP & ldpPos . spPixelOff .~ V2 6 0
|
||||
invDP = defaultLDP & ldpPos . spPixelOff .~ V2 16 (-20)
|
||||
|
||||
@@ -40,7 +39,7 @@ invCursorParams w = BoundaryCursor $ case w ^? hud . subInventory of
|
||||
_ | ButtonRight `M.member` _mouseButtons (_input w) -> [North, South, East, West]
|
||||
_ -> [North, South, West]
|
||||
|
||||
secondColumnLDP :: ListDisplayParams
|
||||
secondColumnLDP :: LDParams
|
||||
secondColumnLDP = defaultLDP & ldpPos . spPixelOff .~ V2 subInvX (-20)
|
||||
|
||||
subInvX :: Float
|
||||
@@ -49,5 +48,5 @@ subInvX = 10 * fromIntegral topInvW + 170
|
||||
topInvW :: Int
|
||||
topInvW = 15
|
||||
|
||||
menuLDP :: ListDisplayParams
|
||||
menuLDP :: LDParams
|
||||
menuLDP = defaultLDP & ldpPos . spPixelOff .~ V2 11 (-70) & ldpScale .~ 2
|
||||
|
||||
+39
-54
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -7,7 +7,7 @@ import Dodge.Data.Universe
|
||||
import LensHelp
|
||||
import Linear
|
||||
|
||||
getAvailableListLines :: ListDisplayParams -> Config -> Int
|
||||
getAvailableListLines :: LDParams -> Config -> Int
|
||||
getAvailableListLines ldps cfig = floor ((dToBot - vgap) / itmHeight)
|
||||
where
|
||||
vgap = ldps ^. ldpVerticalGap
|
||||
|
||||
@@ -144,7 +144,7 @@ selSecSelSize :: Int -> Int -> IMSS a -> Maybe Int
|
||||
selSecSelSize i j = (^? ix i . ssItems . ix j . siHeight)
|
||||
|
||||
-- need to check that the vertical gap is correctly put in here
|
||||
posSelSecYint :: Config -> ListDisplayParams -> Float -> Int
|
||||
posSelSecYint :: Config -> LDParams -> Float -> Int
|
||||
posSelSecYint cfig ldp y = floor $ (y0 - y) / (20 / ldp ^. ldpScale + ldp ^. ldpVerticalGap)
|
||||
where
|
||||
V2 _ y0 = screenPosAbs cfig (ldp ^. ldpPos)
|
||||
@@ -175,12 +175,7 @@ inverseSelSecYint yint sss
|
||||
return $ NonInf (i, j)
|
||||
|
||||
inverseSelSecYintXPosCheck ::
|
||||
Config ->
|
||||
ListDisplayParams ->
|
||||
Float ->
|
||||
Int ->
|
||||
IMSS a ->
|
||||
Maybe (Int,Int)
|
||||
Config -> LDParams -> Float -> Int -> IMSS a -> Maybe (Int,Int)
|
||||
inverseSelSecYintXPosCheck cfig ldp x yint sss = do
|
||||
(i,j) <- inverseSelSecYint yint sss ^? nonInf
|
||||
let V2 x0 _ = screenPosAbs cfig (ldp ^. ldpPos)
|
||||
@@ -190,6 +185,6 @@ inverseSelSecYintXPosCheck cfig ldp x yint sss = do
|
||||
guard $ x - x1 < 160 && x > x1
|
||||
return (i,j)
|
||||
|
||||
inverseSelNumPos :: Config -> ListDisplayParams -> Point2 -> IMSS a -> Maybe (Int, Int)
|
||||
inverseSelNumPos :: Config -> LDParams -> Point2 -> IMSS a -> Maybe (Int, Int)
|
||||
inverseSelNumPos cfig ldp (V2 x y) =
|
||||
inverseSelSecYintXPosCheck cfig ldp x (posSelSecYint cfig ldp y)
|
||||
|
||||
@@ -13,7 +13,7 @@ import Dodge.ScreenPos
|
||||
import Dodge.SelectionSections
|
||||
import Picture.Base
|
||||
|
||||
drawSelectionSections :: IM.IntMap (SelSection a) -> ListDisplayParams -> Config -> Picture
|
||||
drawSelectionSections :: IM.IntMap (SelSection a) -> LDParams -> Config -> Picture
|
||||
drawSelectionSections sss ldp cfig =
|
||||
translateScreenPos cfig (ldp ^. ldpPos) $
|
||||
drawListYgapScaleYoff
|
||||
@@ -29,12 +29,7 @@ drawSelectionSections sss ldp cfig =
|
||||
)
|
||||
|
||||
drawSSCursor ::
|
||||
IM.IntMap (SelSection a) ->
|
||||
ListDisplayParams ->
|
||||
CursorDisplay ->
|
||||
Config ->
|
||||
Maybe (Int, Int) ->
|
||||
Picture
|
||||
IM.IntMap (SelSection a) -> LDParams -> CursorDisplay -> Config -> Maybe (Int, Int) -> Picture
|
||||
drawSSCursor sss ldp curs cfig =
|
||||
translateScreenPos cfig (ldp ^. ldpPos) .
|
||||
selSecDrawCursor ldp curs sss
|
||||
@@ -43,7 +38,7 @@ drawSSMultiCursor ::
|
||||
IM.IntMap (SelSection a) ->
|
||||
Maybe (Int, Int) ->
|
||||
Maybe Int ->
|
||||
ListDisplayParams ->
|
||||
LDParams ->
|
||||
CursorDisplay ->
|
||||
Config ->
|
||||
Picture
|
||||
|
||||
@@ -81,7 +81,7 @@ mouseClickOptionsList u = fromMaybe u $ do
|
||||
return $ f u & uvSoundQueue .:~ click1S
|
||||
_ -> Nothing
|
||||
|
||||
ldpSelection :: Config -> ListDisplayParams -> Point2 -> Maybe Int
|
||||
ldpSelection :: Config -> LDParams -> Point2 -> Maybe Int
|
||||
ldpSelection cfig ldp (V2 _ y)
|
||||
| yupper == ylower = Just yupper
|
||||
| otherwise = Nothing
|
||||
|
||||
Reference in New Issue
Block a user