Unify terminal size determination

This commit is contained in:
2024-11-25 22:59:54 +00:00
parent 21aae232fc
commit 6aea049b80
3 changed files with 41 additions and 38 deletions
+17 -15
View File
@@ -4,7 +4,6 @@ module Dodge.Render.HUD (
drawHUD,
) where
import NewInt
import Control.Applicative
import Control.Lens
import Control.Monad
@@ -41,6 +40,7 @@ import Dodge.Terminal.Type
import Geometry
import qualified IntMapHelp as IM
import Justify
import NewInt
import Picture
import SDL (MouseButton (..))
@@ -59,7 +59,7 @@ drawInventory sss w cfig =
<> iextra
<> drawMouseOver cfig w
where
f = fmap (\(x,y,_) -> (x,y))
f = fmap (\(x, y, _) -> (x, y))
ldp = invDisplayParams w
curs = invCursorParams w
iextra = fromMaybe mempty $ do
@@ -116,9 +116,9 @@ drawMouseOver cfig w =
let idp = invDisplayParams w
return . translateScreenPos cfig (invDisplayParams w ^. ldpPos)
. color (withAlpha 0.1 white)
-- . color white
-- . color white
$ selSecDrawCursorAt 15 idp curs sss (j, i)
-- curs = BoundaryCursor [West]
-- curs = BoundaryCursor [West]
curs = BackdropCursor
combinvsel = do
(j, i) <-
@@ -133,11 +133,12 @@ drawMouseOver cfig w =
drawDragSelected :: Configuration -> World -> Maybe Picture
drawDragSelected cfig w = do
ys <- w ^? hud . hudElement . diSelection . _Just . _3
guard $ not (IS.null ys) &&
( case w ^? hud . hudElement . subInventory of
Just NoSubInventory -> True
_ -> False
)
guard $
not (IS.null ys)
&& ( case w ^? hud . hudElement . subInventory of
Just NoSubInventory -> True
_ -> False
)
(i, _, _) <- w ^? hud . hudElement . diSelection . _Just
sss <- w ^? hud . hudElement . diSections
let idp = invDisplayParams w
@@ -179,8 +180,9 @@ drawCombineInventory cfig sss w =
<> combineInventoryExtra sss msel cfig w
where
curs = BoundaryCursor [North, South, West]
msel = fmap (\(x,y,_) -> (x,y))
$ w ^? hud . hudElement . subInventory . ciSelection . _Just
msel =
fmap (\(x, y, _) -> (x, y)) $
w ^? hud . hudElement . subInventory . ciSelection . _Just
drawExamineInventory :: Configuration -> World -> Picture
drawExamineInventory cfig w =
@@ -228,7 +230,7 @@ yourAugmentedItem f x g w = case you w ^? crManipulation . manObject of
j <- w ^? hud . closeItems . ix i . unNInt
flit <- w ^? cWorld . lWorld . floorItems . unNIntMap . ix j
return . g $ Left flit
-- g . Left $ w ^?! hud . closeItems . ix i
-- g . Left $ w ^?! hud . closeItems . ix i
Just (SelCloseButton i) -> fromMaybe x $ do
j <- w ^? hud . closeButtons . ix i
flit <- w ^? cWorld . lWorld . buttons . ix j
@@ -245,7 +247,7 @@ drawRBOptions cfig w = fromMaybe mempty $ do
i <- w ^? rbOptions . opSel
let ae = getEquipmentAllocation w
sss <- w ^? hud . hudElement . diSections
(i', j,_) <- w ^? hud . hudElement . diSelection . _Just
(i', j, _) <- w ^? hud . hudElement . diSelection . _Just
curpos <- selSecYint i' j sss
let ytext = drawListElement 0 1 0 curpos . text
midstr = equipAllocString ae
@@ -356,11 +358,11 @@ combineInventoryExtra sss msel cfig w = fromMaybe mempty $ do
drawTerminalDisplay :: Int -> Configuration -> LWorld -> Picture
drawTerminalDisplay tid cfig w = fromMaybe mempty $ do
tm <- w ^? terminals . ix tid
let tsize = getMaxLinesTM (tm ^. tmType) + 1
return $
invHead cfig (_tmTitle tm ++ ":T" ++ show tid)
<> drawSelectionList secondColumnParams cfig (thesellist tm)
<> color (withAlpha 0.5 green) (drawSelectionListBackground secondColumnParams cfig 15)
-- when changing the 15, change isOverTerminalScreen
<> color (withAlpha 0.5 green) (drawSelectionListBackground secondColumnParams cfig tsize)
<> color (dark $ _tmExternalColor tm) (drawTitleBackground cfig)
where
toselitm (str, col) = SelectionItem [str] 1 True col 0 ()
+7 -6
View File
@@ -47,6 +47,7 @@ import Dodge.Shockwave.Update
import Dodge.SmoothScroll
import Dodge.SoundLogic
import Dodge.Spark
import Dodge.Terminal.Type
import Dodge.Tesla.Arc
import Dodge.TmTm
import Dodge.TractorBeam.Update
@@ -315,7 +316,8 @@ updateMouseContextGame :: Configuration -> Universe -> Universe
updateMouseContextGame cfig u = case u ^. uvWorld . input . mouseContext of
OverInvDrag i _ _ _ -> u & uvWorld . input . mouseContext .~ invdrag i
OverInvDragSelect{} -> u
_ -> u & uvWorld . input . mouseContext
_ ->
u & uvWorld . input . mouseContext
.~ fromMaybe aimcontext (overinv <|> overcomb <|> overterm)
where
w = u ^. uvWorld
@@ -332,7 +334,7 @@ updateMouseContextGame cfig u = case u ^. uvWorld . input . mouseContext of
return $ OverInvDrag i' (Just (i, j)) above bneath
overinv = do
sss <- w ^? hud . hudElement . diSections
selpos@(i,j) <- inverseSelNumPos cfig (invDisplayParams w) sss mpos
selpos@(i, j) <- inverseSelNumPos cfig (invDisplayParams w) sss mpos
case w ^? hud . hudElement . subInventory . ciSelection of
Just _ -> do
guard (i == 0)
@@ -384,7 +386,7 @@ getMenuMouseContext screen u = case screen ^. scOptions of
u ^? uvScreenLayers . _head . scSelectionList . ix yi . siIsSelectable
isOverTerminalScreen :: Configuration -> Terminal -> Point2 -> Bool
isOverTerminalScreen cfig _ (V2 x y) =
isOverTerminalScreen cfig tm (V2 x y) =
x <= xmax
&& x >= xmin - 5
&& y <= ymax + 5
@@ -392,9 +394,8 @@ isOverTerminalScreen cfig _ (V2 x y) =
where
ldp = secondColumnParams
V2 xmin ymax = screenPosAbs cfig (ldp ^. ldpPos)
s = 5 + 15 * (20 * ldp ^. ldpScale + ldp ^. ldpVerticalGap)
-- the 15 is the length of list in the terminal display, don't change
-- without changing drawTerminalDisplay
tsize = fromIntegral $ getMaxLinesTM (tm ^. tmType) + 1
s = 5 + tsize * (20 * ldp ^. ldpScale + ldp ^. ldpVerticalGap)
ymin = ymax - s
xmax = xmin + 555 -- HACK drawSelectionListBackground