Add 8-way cardinal/intercardinal datatype

This commit is contained in:
2024-10-18 12:39:46 +01:00
parent d256bc0443
commit 8b6f5529ff
12 changed files with 267 additions and 157 deletions
+36 -5
View File
@@ -3,6 +3,7 @@
module Dodge.Render.HUD (
drawHUD,
selNumPos, -- this shoud probably be pushed back here
selNumPosCardinal, -- this shoud probably be pushed back here
) where
import Dodge.SelectionSections
@@ -30,7 +31,6 @@ import Dodge.Render.Connectors
import Dodge.Render.HUD.Carte
import Dodge.Render.List
import Dodge.ScreenPos
import Dodge.SelectionSections
import Dodge.SelectionSections.Draw
import Geometry
import qualified IntMapHelp as IM
@@ -80,13 +80,19 @@ drawDIMouseOver w = fromMaybe mempty $ do
let idp = invDisplayParams w
return . color (withAlpha 0.5 white) $ selSecDrawCursorAt (0,i) 10 idp sss
getMouseInvSel :: World -> Maybe ((Int,Int),(Int,Int))
getMouseInvSel w = case w ^? hud . hudElement . subInventory . nsSelected of
Just (MouseInvSelect s (Just e)) -> Just (s,e)
Just (MouseInvChosen s e) -> Just (s,e)
_ -> Nothing
drawDISelections :: World -> Configuration -> Picture
drawDISelections w cfig = fromMaybe mempty $ do
(i,j) <- w ^? hud . hudElement . subInventory . nsSelected . _Just
((i,j),(a,b)) <- getMouseInvSel w
sss <- w ^? hud . hudElement . diSections
let idp = invDisplayParams w
tp <- selNumPos cfig idp sss 0 i
bp <- selNumPos cfig idp sss 0 j
tp <- selNumPosCardinal NorthWest8 cfig idp sss i j
bp <- selNumPosCardinal SouthWest8 cfig idp sss a b
return . color red $ line [tp,bp]
@@ -353,12 +359,37 @@ selNumPos ::
Int ->
Int ->
Maybe Point2
selNumPos cfig ldp sss i j = do
selNumPos = selNumPosCardinal West8
--selNumPos cfig ldp sss i j = do
-- ipos <- selSecYint i j sss
-- size <- selSecSelSize i j sss
-- indent <- sss ^? sssSections . ix i . ssItems . ix j . siOffX
-- return $
-- screenPosAbs cfig (ldp ^. ldpPos)
-- + V2
-- (10 * s * fromIntegral indent)
-- (negate (20 * s + ygap) * (fromIntegral ipos + fromIntegral size * 0.5))
-- where
-- s = _ldpScale ldp
-- ygap = _ldpVerticalGap ldp
-- need to be able to determine a selection item's width for this
selNumPosCardinal ::
CardinalEightPoint ->
Configuration ->
ListDisplayParams ->
SelectionSections a ->
Int ->
Int ->
Maybe Point2
selNumPosCardinal card cfig ldp sss i j = do
ipos <- selSecYint i j sss
size <- selSecSelSize i j sss
indent <- sss ^? sssSections . ix i . ssItems . ix j . siOffX
let offset = cardEightVec card * V2 0 (fromIntegral size * 0.5 * 20 * s)
return $
screenPosAbs cfig (ldp ^. ldpPos)
+ offset
+ V2
(10 * s * fromIntegral indent)
(negate (20 * s + ygap) * (fromIntegral ipos + fromIntegral size * 0.5))