Allow filtering of combinations with mouse click on inventory

This commit is contained in:
2024-11-04 00:07:37 +00:00
parent adca54c1ef
commit fafef1275b
11 changed files with 125 additions and 80 deletions
+7 -3
View File
@@ -3,6 +3,7 @@ module Dodge.SelectionSections (
nextInSectionSS,
ssLookupDown,
ssLookupGT,
ssTryLookup,
ssSetCursor,
-- setFirstPosSelectionSections,
selSecYint,
@@ -77,6 +78,12 @@ ssSetCursor f sss msel = fromMaybe msel $ do
(i, j, _) <- f sss
return $ Just (i, j)
ssTryLookup :: Maybe (Int,Int) -> IM.IntMap (SelectionSection a) -> Maybe (Int, Int, SelectionItem a)
ssTryLookup msel sss = fromMaybe (ssLookupMin sss) $ do
(i,j) <- msel
itm <- sss ^? ix i . ssItems . ix j
return $ Just (i,j,itm)
ssLookupMax :: IM.IntMap (SelectionSection a) -> Maybe (Int, Int, SelectionItem a)
ssLookupMax sss = do
(i, _) <- IM.lookupMax sss
@@ -193,8 +200,6 @@ selSecYint i j sss = do
where
secpos = sum . fmap (length . _ssShownItems) . fst $ IM.split i sss
-- it is annoying that Control.Foldl doesn't seem to allow for scans to be done
-- at the same time as folds
inverseSelSecYint :: Int -> IM.IntMap (SelectionSection a) -> Maybe (Int, Int)
inverseSelSecYint yint sss = do
((i, ss), othersss) <- IM.minViewWithKey sss
@@ -203,7 +208,6 @@ inverseSelSecYint yint sss = do
then inverseSelSecYint (yint - l) 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
(j,_) <- L.fold (L.find (\(_,x) -> x - _ssOffset ss > yint)) $ IM.toList ls
return (i, j)