Partially working scrolling below list to floor items

This commit is contained in:
2021-12-01 00:04:54 +00:00
parent 42d7ca3ba8
commit 0ed260c9b7
4 changed files with 99 additions and 56 deletions
+1 -1
View File
@@ -110,7 +110,7 @@ wheelEvent y w = case (_carteDisplay w, _inventoryMode w) of
Nothing -> closeObjScrollDir y w Nothing -> closeObjScrollDir y w
Just f -> w & creatures . ix 0 . crInv . ix (_crInvSel $ you w) %~ f y (you w) Just f -> w & creatures . ix 0 . crInv . ix (_crInvSel $ you w) %~ f y (you w)
| lbDown -> w & cameraZoom +~ y | lbDown -> w & cameraZoom +~ y
| invKeyDown -> swapInvDir yi $ stopSoundFrom (CrReloadSound 0) $ changeInvPos yi w | invKeyDown -> stopSoundFrom (CrReloadSound 0) $ changeSwapInvPos yi w
| otherwise -> stopSoundFrom (CrReloadSound 0) $ changeInvCloseObjectsPos yi w | otherwise -> stopSoundFrom (CrReloadSound 0) $ changeInvCloseObjectsPos yi w
(_, TweakInventory) (_, TweakInventory)
| invKeyDown && rbDown -> w & moveTweakSel yi | invKeyDown && rbDown -> w & moveTweakSel yi
+89 -7
View File
@@ -1,14 +1,20 @@
module Dodge.Inventory module Dodge.Inventory
( checkInvSlotsYou ( checkInvSlotsYou
, rmSelectedInvItem , rmSelectedInvItem
, invSelPos
, invSelSize
, selNumPos
, augmentedInvSizes
, rmInvItem , rmInvItem
, updateCloseObjects , updateCloseObjects
, closeObjScrollDir , closeObjScrollDir
, swapInvDir , swapInvDir
, changeInvPos , changeInvPos
, changeSwapInvPos
, changeInvCloseObjectsPos , changeInvCloseObjectsPos
, crNumFreeSlots , crNumFreeSlots
, crInvSize , crInvSize
, selectedCloseObject
) )
where where
import Dodge.Data import Dodge.Data
@@ -18,9 +24,10 @@ import Geometry
--import FoldableHelp --import FoldableHelp
import Padding import Padding
import qualified IntMapHelp as IM import qualified IntMapHelp as IM
import ListHelp
--import Data.Maybe import Data.Maybe
import Data.List --import Data.List
--import System.Random --import System.Random
import Control.Lens import Control.Lens
@@ -66,9 +73,40 @@ rmSelectedInvItem
-> World -> World
rmSelectedInvItem cid w = rmInvItem cid (_crInvSel (_creatures w IM.! cid)) w rmSelectedInvItem cid w = rmInvItem cid (_crInvSel (_creatures w IM.! cid)) w
augmentedInvSizes :: World -> IM.IntMap Int
augmentedInvSizes w = IM.union (fmap _itInvSize $ yourInv w)
(IM.fromAscList $ zip [length (yourInv w) ..] $ map closeObjectSize $ _closeObjects w)
invSelSize :: Int -> World -> Int
invSelSize i w = fromMaybe 1 $ augmentedInvSizes w IM.!? i
closeObjectSize :: Either FloorItem Button -> Int
closeObjectSize e = case e of
Left flit -> _itInvSize $ _flIt flit
Right _ -> 1
selNumPos :: Int -> World -> Int
selNumPos i w = splitgap + (foldl' (+) 0 . fst $ IM.split i (augmentedInvSizes w))
where
splitgap
| yourInvSel w < length (yourInv w) = 0
| otherwise = 1
invSelPos :: World -> Int
invSelPos w = splitgap + (foldl' (+) 0 . fst $ IM.split invsel (augmentedInvSizes w))
where
invsel = yourInvSel w
splitgap
| yourInvSel w < length (yourInv w) = 0
| otherwise = 1
updateCloseObjects :: World -> World updateCloseObjects :: World -> World
updateCloseObjects w = w & closeObjects .~ unionBy eTest oldCloseFiltered currentClose updateCloseObjects w = w & closeObjects .~ unionBy eTest oldCloseFiltered currentClose
where & creatures . ix 0 . crInvSel %~ updateinvsel
where
updateinvsel curinvsel
| length (augmentedInvSizes w) <= curinvsel = length (augmentedInvSizes w) - 1
| otherwise = curinvsel
filt = filter $ \obj -> dist ypos (pos obj) < 40 && hasLOS ypos (pos obj) w filt = filter $ \obj -> dist ypos (pos obj) < 40 && hasLOS ypos (pos obj) w
ypos = _crPos $ you w ypos = _crPos $ you w
objs = map Left (IM.elems $ _floorItems w) ++ activeButtons objs = map Left (IM.elems $ _floorItems w) ++ activeButtons
@@ -94,7 +132,8 @@ closeObjScrollDir x
swapInvDir :: Int -> World -> World swapInvDir :: Int -> World -> World
swapInvDir k w swapInvDir k w
| n == 0 = w | n == 0 = w
| otherwise = w & creatures . ix (_yourID w) %~ updatecreature | i < n = w & creatures . ix (_yourID w) %~ updatecreature
| otherwise = w
where where
updatecreature = ( crInv %~ IM.swapKeys (i `mod` n) swapi ) updatecreature = ( crInv %~ IM.swapKeys (i `mod` n) swapi )
. (crLeftInvSel . _Just %~ updateLeftInvSel) . (crLeftInvSel . _Just %~ updateLeftInvSel)
@@ -103,14 +142,41 @@ swapInvDir k w
| swapi == li = i | swapi == li = i
| otherwise = li | otherwise = li
i = _crInvSel $ you w i = _crInvSel $ you w
n = length $ IM.keys $ _crInv $ _creatures w IM.! _yourID w n = length $ _crInv $ _creatures w IM.! _yourID w
--numCO = length $ _closeObjects w
changeInvPos :: Int -> World -> World changeInvPos :: Int -> World -> World
changeInvPos i w changeInvPos i w
| n == 0 = w | n == 0 = w
| otherwise = w & creatures . ix (_yourID w) . crInvSel %~ (`mod` n) . subtract i | yourInvSel w < n = w & creatures . ix (_yourID w) . crInvSel %~ (`mod` n) . subtract i
| otherwise = w & creatures . ix (_yourID w) . crInvSel %~ ((+n) . (`mod` numCO) . subtract (i+n))
where where
n = length $ IM.keys $ _crInv $ _creatures w IM.! _yourID w n = length $ _crInv $ _creatures w IM.! _yourID w
numCO = length $ _closeObjects w
changeSwapInvPos :: Int -> World -> World
changeSwapInvPos k w
| n == 0 = w
| yourInvSel w < n = w
& creatures . ix (_yourID w) %~ updatecreature
& creatures . ix (_yourID w) . crInvSel %~ (`mod` n) . subtract k
-- | otherwise = w & creatures . ix (_yourID w) . crInvSel %~ ((+n) . (`mod` numCO) . subtract (k+n))
| otherwise = w & creatures . ix (_yourID w) . crInvSel .~ ico'
& closeObjects %~ listSwapIndices (i - n) (ico' - n)
where
updatecreature = ( crInv %~ IM.swapKeys (i `mod` n) swapi )
. (crLeftInvSel . _Just %~ updateLeftInvSel)
swapi = (i - k) `mod` n
updateLeftInvSel li | i == li = swapi
| swapi == li = i
| otherwise = li
i = _crInvSel $ you w
ico' = ( (i - (k+n)) `mod` numCO ) + n
n = length $ _crInv $ _creatures w IM.! _yourID w
numCO = length $ _closeObjects w
listSwapIndices :: Int -> Int -> [a] -> [a]
listSwapIndices i j xs = insertOver i (xs !! j) . insertOver j (xs !! i) $ xs
changeInvCloseObjectsPos :: Int -> World -> World changeInvCloseObjectsPos :: Int -> World -> World
changeInvCloseObjectsPos i w changeInvCloseObjectsPos i w
@@ -118,3 +184,19 @@ changeInvCloseObjectsPos i w
| otherwise = w & creatures . ix (_yourID w) . crInvSel %~ (`mod` n) . subtract i | otherwise = w & creatures . ix (_yourID w) . crInvSel %~ (`mod` n) . subtract i
where where
n = (length $ IM.keys $ _crInv $ _creatures w IM.! _yourID w) + length (_closeObjects w) n = (length $ IM.keys $ _crInv $ _creatures w IM.! _yourID w) + length (_closeObjects w)
bestCloseObjectIndex :: World -> Maybe Int
bestCloseObjectIndex w = Nothing
selectedCloseObject :: World -> Maybe (Int,Either FloorItem Button)
selectedCloseObject w
| invsel >= length inv = Just $ selectNthCloseObject w (invsel - length inv)
| otherwise = fmap (selectNthCloseObject w) $ bestCloseObjectIndex w
where
invsel = _crInvSel cr
cr = you w
inv = _crInv cr
invsize = crInvSize (you w)
selectNthCloseObject :: World -> Int -> (Int,Either FloorItem Button)
selectNthCloseObject w n = (length (yourInv w) + n, _closeObjects w !! n)
+5 -48
View File
@@ -51,37 +51,6 @@ subInventoryDisplay cfig w = case _inventoryMode w of
col = itCol it col = itCol it
cursPos = invSelPos w cursPos = invSelPos w
--crInvSelSize :: Creature -> Int
--crInvSelSize cr = fromMaybe 1 $ fmap _itInvSize $ _crInv cr IM.!? _crInvSel cr
--crInvSelPos :: Creature -> Int
--crInvSelPos cr = foldl' (+) 0 . fmap _itInvSize . fst $ IM.split (_crInvSel cr) (_crInv cr)
invSelPos :: World -> Int
invSelPos w = splitgap + (foldl' (+) 0 . fst $ IM.split invsel (augmentedInvSizes w))
where
invsel = yourInvSel w
splitgap
| yourInvSel w < length (yourInv w) = 0
| otherwise = 1
augmentedInvSizes :: World -> IM.IntMap Int
augmentedInvSizes w = IM.union (fmap _itInvSize $ yourInv w)
(IM.fromAscList $ zip [length (yourInv w) ..] $ map closeObjectSize $ _closeObjects w)
--augmentedInvSizesWithGap :: World -> IM.IntMap Int
--augmentedInvSizesWithGap w = IM.union (safeUpdateMax (Just . (+1)) $ fmap _itInvSize $ yourInv w)
-- (IM.fromAscList $ zip [length (yourInv w) ..] $ (map closeObjectSize $ _closeObjects w))
--
--safeUpdateMax :: (a -> Maybe a) -> IM.IntMap a -> IM.IntMap a
--safeUpdateMax f m
-- | IM.null m = m
-- | otherwise = IM.updateMax f m
closeObjectSize :: Either FloorItem Button -> Int
closeObjectSize e = case e of
Left flit -> _itInvSize $ _flIt flit
Right bt -> 1
cursorsZ :: Configuration -> Int -> Maybe Item -> Picture cursorsZ :: Configuration -> Int -> Maybe Item -> Picture
cursorsZ cfig ipos it = case it ^? _Just . itTweaks . tweakSel of cursorsZ cfig ipos it = case it ^? _Just . itTweaks . tweakSel of
Nothing -> f $ zConnect sp (V2 (155- hw) ( hh - 77.5)) Nothing -> f $ zConnect sp (V2 (155- hw) ( hh - 77.5))
@@ -133,10 +102,14 @@ displayInv :: Int -> Configuration -> World -> Picture
displayInv n cfig w = listTextPicturesAt 0 0 cfig invlist displayInv n cfig w = listTextPicturesAt 0 0 cfig invlist
<> equipcursor <> equipcursor
<> selcursor <> selcursor
<> closeobjectcursor
where where
selcursor selcursor
| IM.null inv && null (_closeObjects w) = mempty | IM.null inv && null (_closeObjects w) = mempty
| otherwise = listCursorAt 0 0 cfig curpos white curx cury | otherwise = listCursorAt 0 0 cfig curpos white curx cury
closeobjectcursor = case selectedCloseObject w of
Nothing -> mempty
Just (i,_) -> listCursorAt 50 0 cfig (selNumPos i w) blue 15 (invSelSize i w)
inv = _crInv cr inv = _crInv cr
invlist = (concatMap itemToTextPictures $ IM.elems inv) invlist = (concatMap itemToTextPictures $ IM.elems inv)
++ displayFreeSlots ++ concatMap (closeObjectToTextPictures nfreeslots) (_closeObjects w) ++ displayFreeSlots ++ concatMap (closeObjectToTextPictures nfreeslots) (_closeObjects w)
@@ -147,11 +120,10 @@ displayInv n cfig w = listTextPicturesAt 0 0 cfig invlist
x -> [color invDimColor . text $ " +" ++ show x ++ " FREE SLOTS"] x -> [color invDimColor . text $ " +" ++ show x ++ " FREE SLOTS"]
curpos = invSelPos w curpos = invSelPos w
curx = 10 curx = 10
--cury = crInvSelSize $ you w
cury = fromMaybe 1 $ augmentedInvSizes w IM.!? _crInvSel (you w) cury = fromMaybe 1 $ augmentedInvSizes w IM.!? _crInvSel (you w)
equipcursor = case _crLeftInvSel cr of equipcursor = case _crLeftInvSel cr of
Nothing -> mempty Nothing -> mempty
Just invid -> openCursorAt 20 yellow 0 0 invid cfig Just invid -> openCursorAt 20 yellow 0 0 (selNumPos invid w) cfig
cr = _creatures w IM.! n cr = _creatures w IM.! n
invDimColor :: Color invDimColor :: Color
invDimColor = greyN 0.7 invDimColor = greyN 0.7
@@ -201,21 +173,6 @@ mapWall cfig w wl =
(x,y) = _wlLine wl (x,y) = _wlLine wl
c = _wlColor wl c = _wlColor wl
bestCloseObjectIndex :: World -> Maybe Int
bestCloseObjectIndex w = Nothing
selectedCloseObject :: World -> Maybe (Int,Either FloorItem Button)
selectedCloseObject w
| invsel > length inv = Just $ selectNthCloseObject w (invsel - length inv)
| otherwise = fmap (selectNthCloseObject w) $ bestCloseObjectIndex w
where
invsel = _crInvSel cr
cr = you w
inv = _crInv cr
invsize = crInvSize (you w)
selectNthCloseObject :: World -> Int -> (Int,Either FloorItem Button)
selectNthCloseObject w n = undefined
selectedCloseObjectLink :: Configuration -> World -> Picture selectedCloseObjectLink :: Configuration -> World -> Picture
selectedCloseObjectLink cfig w = mempty selectedCloseObjectLink cfig w = mempty
+4
View File
@@ -1,9 +1,13 @@
module ListHelp module ListHelp
(module Data.List (module Data.List
,initOrNull ,initOrNull
, insertOver
)where )where
import Data.List import Data.List
initOrNull :: [a] -> [a] initOrNull :: [a] -> [a]
initOrNull [] = [] initOrNull [] = []
initOrNull xs = init xs initOrNull xs = init xs
insertOver :: Int -> a -> [a] -> [a]
insertOver i x xs = take i xs ++ x : drop (i+1) xs