Start adding mouse control of inventory

This commit is contained in:
2024-10-15 23:26:08 +01:00
parent e745238b8f
commit cf0873d73b
18 changed files with 333 additions and 269 deletions
+2 -1
View File
@@ -2,6 +2,7 @@
module Dodge.Render.HUD (
drawHUD,
selNumPos, -- this shoud probably be pushed back here
) where
import Control.Lens
@@ -70,7 +71,7 @@ drawInventory sss w cfig =
drawSubInventory :: SubInventory -> Configuration -> World -> Picture
drawSubInventory subinv cfig w = case subinv of
LockedInventory -> mempty -- topInvCursor col cursPos cfig w
NoSubInventory -> drawRBOptions cfig w
NoSubInventory{} -> drawRBOptions cfig w
ExamineInventory -> drawExamineInventory cfig w
DisplayTerminal tid -> displayTerminal tid cfig (w ^. cWorld . lWorld)
CombineInventory{_ciSections = sss} -> drawCombineInventory cfig sss w
+8 -3
View File
@@ -10,6 +10,7 @@ module Dodge.Render.List (
stackPicturesAt,
toTopLeft,
listCursorChooseBorderScale,
selSecDrawCursorAt,
) where
import Dodge.SelectionSections
@@ -84,9 +85,8 @@ stackPicturesAt = stackPicturesAtOff 0
stackPicturesAtOff :: Int -> [Picture] -> Picture
stackPicturesAtOff i = mconcat . zipWith (drawListElement 10 1 0) [i, i -1 ..]
selSecDrawCursor :: Int -> ListDisplayParams -> SelectionSections a -> Picture
selSecDrawCursor xsize ldp sss = fromMaybe mempty $ do
(i, j) <- sss ^? sssExtra . sssSelPos . _Just
selSecDrawCursorAt :: (Int,Int) -> Int -> ListDisplayParams -> SelectionSections a -> Picture
selSecDrawCursorAt (i,j) xsize ldp sss = fromMaybe mempty $ do
yint <- selSecYint i j sss
xint <- sss ^? sssSections . ix i . ssIndent
si <- sss ^? sssSections . ix i . ssItems . ix j
@@ -101,6 +101,11 @@ selSecDrawCursor xsize ldp sss = fromMaybe mempty $ do
xsize
(_siHeight si)
selSecDrawCursor :: Int -> ListDisplayParams -> SelectionSections a -> Picture
selSecDrawCursor xsize ldp sss = maybe mempty
(\x -> selSecDrawCursorAt x xsize ldp sss)
(sss ^? sssExtra . sssSelPos . _Just)
-- displays a cursor that should match up to list text pictures
listCursorChooseBorderScale ::
Float ->
+50 -14
View File
@@ -2,23 +2,27 @@ module Dodge.Render.ShapePicture (
worldSPic,
) where
import Data.Strict.Tuple
import NewInt
import Dodge.Render.List
import Dodge.Render.HUD
import Dodge.ListDisplayParams
import qualified Data.Map.Strict as M
import Control.Lens
import Control.Monad (guard)
import Data.Foldable
import Data.Maybe
import Data.Strict.Tuple
import Dodge.Base
import Dodge.Creature.Picture
import Dodge.Data.Universe
import Dodge.Debug.Picture
import Dodge.Draw
import Dodge.RadarBlip
import Dodge.Render.List
import Dodge.Render.Picture
import Geometry
import qualified IntMapHelp as IM
import NewInt
import Picture
import qualified SDL
import Shape
import ShapePicture
@@ -35,12 +39,40 @@ worldSPic cfig u =
<> foldup btSPic (filtOn _btPos _buttons)
<> foldup mcSPic (filtOn _mcPos _machines)
<> aimDelaySweep w
<> drawMouseSelection w
<> drawDISelections w cfig
<> drawDIMouseOver w cfig
where
w = _uvWorld u
foldup = foldMap'
filtOn f g = IM.filter (pointIsClose . f) (g (_lWorld (_cWorld w)))
pointIsClose = cullPoint cfig w
drawMouseSelection :: World -> SPic
drawMouseSelection w = fromMaybe mempty $ do
guard (SDL.ButtonLeft `M.member` (w ^. input . mouseButtons)
&& not (SDL.ButtonRight `M.member` (w ^. input . mouseButtons))
)
p <- w ^? input . clickPos . ix SDL.ButtonLeft
return $ noShape $ color (withAlpha 0.5 white)
$ setLayer FixedCoordLayer $ polygon $ reverse $ rectVV p (w ^. input . mousePos)
drawDIMouseOver :: World -> Configuration -> SPic
drawDIMouseOver w cfig = fromMaybe mempty $ do
i <- w ^? hud . hudElement . subInventory . nsMouseOver . _Just
sss <- w ^? hud . hudElement . diSections
let idp = invDisplayParams w
return . noShape . setLayer FixedCoordLayer . color white $ selSecDrawCursorAt (0,i) 10 idp sss
drawDISelections :: World -> Configuration -> SPic
drawDISelections w cfig = fromMaybe mempty $ do
(i,j) <- w ^? hud . hudElement . subInventory . nsSelected . _Just
sss <- w ^? hud . hudElement . diSections
let idp = invDisplayParams w
tp <- selNumPos cfig idp sss 0 i
bp <- selNumPos cfig idp sss 0 j
return . noShape . setLayer FixedCoordLayer . color red $ line [tp,bp]
aimDelaySweep :: World -> SPic
aimDelaySweep w = fromMaybe mempty $ do
cr <- w ^? cWorld . lWorld . creatures . ix 0
@@ -85,8 +117,8 @@ drawCreature cr = case _crType cr of
lampCrSPic :: Float -> SPic
lampCrSPic h =
colorSH blue (upperBox Small Typical h $ rectWH 5 5)
:!: setLayer BloomLayer (setDepth h . color white $ circleSolid 3)
colorSH blue (upperBox Small Typical h $ rectWH 5 5)
:!: setLayer BloomLayer (setDepth h . color white $ circleSolid 3)
picAtCrPos1 :: Picture -> Creature -> SPic
--{-# INLINE picAtCrPos #-}
@@ -125,19 +157,23 @@ extraPics cfig u =
<> foldMap drawBul (_bullets lw)
<> foldMap drawBlip (_radarBlips lw)
<> _flares lw
-- <> foldMap (dbArg (drawBeam . _bmDraw)) (_positronBeams $ _beams lw)
-- <> foldMap (dbArg (drawBeam . _bmDraw)) (_electronBeams $ _beams lw)
-- <> foldMap (dbArg (drawBeam . _bmDraw)) (_positronBeams $ _beams lw)
-- <> foldMap (dbArg (drawBeam . _bmDraw)) (_electronBeams $ _beams lw)
<> foldMap (dbArg (drawLightSource . _lsPict)) (_lightSources lw)
<> testPic cfig w
<> foldMap ppDraw (_pressPlates lw)
<> viewClipBounds cfig w
<> debugDraw cfig w
<> foldMap (`_debugPic` u) (_uvDebug u)
<> setLayer FixedCoordLayer
(toTopLeft cfig . translate (1.3* halfWidth cfig) 0
. drawList
. take 50 . drop (u ^. uvDebugMessageOffset)
. map text $ foldMap (`_debugMessage` u) (_uvDebug u))
<> setLayer
FixedCoordLayer
( toTopLeft cfig . translate (1.3 * halfWidth cfig) 0
. drawList
. take 50
. drop (u ^. uvDebugMessageOffset)
. map text
$ foldMap (`_debugMessage` u) (_uvDebug u)
)
where
w = u ^. uvWorld
lw = w ^. cWorld . lWorld
@@ -151,7 +187,8 @@ ppDraw c = uncurryV translate (_ppPos c) $ rotate (_ppRot c) (_ppPict c)
floorItemSPic :: FloorItem -> SPic
floorItemSPic flit =
uncurryV translateSPxy (_flItPos flit) $
rotateSP (_flItRot flit)
rotateSP
(_flItRot flit)
(itemSPic $ _flIt flit)
btSPic :: Button -> SPic
@@ -163,4 +200,3 @@ mcSPic :: Machine -> SPic
mcSPic mc =
uncurryV translateSPxy (_mcPos mc) $
rotateSP (_mcDir mc) (drawMachine mc)