Highlight moused-over inventory items

This commit is contained in:
2024-10-16 22:14:11 +01:00
parent cf0873d73b
commit d256bc0443
9 changed files with 214 additions and 148 deletions
+43
View File
@@ -6,8 +6,13 @@ module Dodge.SelectionSections (
setFirstPosSelectionSections,
selSecYint,
selSecSelSize,
inverseSelNumPos,
) where
import qualified Control.Foldl as L
import Dodge.ScreenPos
import Geometry.Data
import Dodge.Data.Config
import Control.Applicative
import Control.Lens
import qualified Data.IntMap.Strict as IM
@@ -124,6 +129,12 @@ ssLookupGE' i sss = do
selSecSelSize :: Int -> Int -> SelectionSections a -> Maybe Int
selSecSelSize i j sss = fmap length $ sss ^? sssSections . ix i . ssItems . ix j . siPictures
-- need to check that the vertical gap is correctly put in here
posSelSecYint :: Configuration -> ListDisplayParams -> Point2 -> Int
posSelSecYint cfig ldp (V2 _ y) = floor $ (y0 - y) / (20 / ldp ^. ldpScale + ldp ^. ldpVerticalGap)
where
V2 _ y0 = screenPosAbs cfig (ldp ^. ldpPos)
selSecYint :: Int -> Int -> SelectionSections a -> Maybe Int
selSecYint i j sss = do
ss <- sss ^? sssSections . ix i
@@ -136,5 +147,37 @@ selSecYint i j sss = do
where
secpos = sum . fmap (length . _ssShownItems) . fst $ IM.split i $ sss ^. sssSections
-- it is annoying that Control.Foldl doesn't seem to allow for scans to be done
-- at the same time as folds
inverseSelSecYint :: Int -> SelectionSections a -> Maybe (Int,Int)
inverseSelSecYint yint sss = do
((i,ss),othersss) <- IM.minViewWithKey (_sssSections sss)
let l = length $ _ssShownItems ss
if l <= yint
then inverseSelSecYint (yint - l) (sss & sssSections .~ othersss)
else do
let ls = L.postscan (L.premap _siHeight L.sum) (_ssItems ss)
j <- L.fold (L.findIndex (\x -> x - _ssOffset ss > yint)) ls
return (i,j)
--
-- ss <- sss ^? sssSections . ix i
-- return . (secpos +)
-- . subtract (ss ^. ssOffset)
-- . sum
-- . fmap _siHeight
-- . fst
-- $ IM.split j (ss ^. ssItems)
-- where
-- secpos = sum . fmap (length . _ssShownItems) . fst $ IM.split i $ sss ^. sssSections
inverseSelNumPos ::
Configuration ->
ListDisplayParams ->
SelectionSections a ->
Point2 ->
Maybe (Int,Int)
inverseSelNumPos cfig ldp sss pos = --Just (0,posSelSecYint cfig ldp pos)
inverseSelSecYint (posSelSecYint cfig ldp pos) sss
--getIthPos :: Int -> IM.IntMap (SelectionItem a) -> Int
--getIthPos i sm = sum . fmap _siHeight . fst $ IM.split i sm