Partially working scrolling below list to floor items
This commit is contained in:
+89
-7
@@ -1,14 +1,20 @@
|
||||
module Dodge.Inventory
|
||||
( checkInvSlotsYou
|
||||
, rmSelectedInvItem
|
||||
, invSelPos
|
||||
, invSelSize
|
||||
, selNumPos
|
||||
, augmentedInvSizes
|
||||
, rmInvItem
|
||||
, updateCloseObjects
|
||||
, closeObjScrollDir
|
||||
, swapInvDir
|
||||
, changeInvPos
|
||||
, changeSwapInvPos
|
||||
, changeInvCloseObjectsPos
|
||||
, crNumFreeSlots
|
||||
, crInvSize
|
||||
, selectedCloseObject
|
||||
)
|
||||
where
|
||||
import Dodge.Data
|
||||
@@ -18,9 +24,10 @@ import Geometry
|
||||
--import FoldableHelp
|
||||
import Padding
|
||||
import qualified IntMapHelp as IM
|
||||
import ListHelp
|
||||
|
||||
--import Data.Maybe
|
||||
import Data.List
|
||||
import Data.Maybe
|
||||
--import Data.List
|
||||
--import System.Random
|
||||
import Control.Lens
|
||||
|
||||
@@ -66,9 +73,40 @@ rmSelectedInvItem
|
||||
-> World
|
||||
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 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
|
||||
ypos = _crPos $ you w
|
||||
objs = map Left (IM.elems $ _floorItems w) ++ activeButtons
|
||||
@@ -94,7 +132,8 @@ closeObjScrollDir x
|
||||
swapInvDir :: Int -> World -> World
|
||||
swapInvDir k w
|
||||
| n == 0 = w
|
||||
| otherwise = w & creatures . ix (_yourID w) %~ updatecreature
|
||||
| i < n = w & creatures . ix (_yourID w) %~ updatecreature
|
||||
| otherwise = w
|
||||
where
|
||||
updatecreature = ( crInv %~ IM.swapKeys (i `mod` n) swapi )
|
||||
. (crLeftInvSel . _Just %~ updateLeftInvSel)
|
||||
@@ -103,14 +142,41 @@ swapInvDir k w
|
||||
| swapi == li = i
|
||||
| otherwise = li
|
||||
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 i 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
|
||||
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 i w
|
||||
@@ -118,3 +184,19 @@ changeInvCloseObjectsPos i w
|
||||
| otherwise = w & creatures . ix (_yourID w) . crInvSel %~ (`mod` n) . subtract i
|
||||
where
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user