Make combine and tweak menus servicable

This commit is contained in:
2021-12-04 00:27:22 +00:00
parent ecbc8eab35
commit 0114a2f9f2
14 changed files with 208 additions and 175 deletions
+28 -4
View File
@@ -1,13 +1,18 @@
{-# LANGUAGE TupleSections #-}
module Dodge.Inventory
( checkInvSlotsYou
, rmSelectedInvItem
, invSelPos
, invSelSize
, selNumPos
, selNumCol
, selNumSlots
, selNumMidHeight
, augmentedInvSizes
, rmInvItem
, updateCloseObjects
, closeObjScrollDir
, closeObjectCol
-- , swapInvDir
, changeInvSel
, changeSwapInvSel
@@ -22,12 +27,14 @@ import Dodge.Inventory.CloseObject
import Dodge.Inventory.CheckSlots
import Dodge.Inventory.ItemSpace
import Dodge.Base
import Dodge.Base.Window
import Dodge.Base.Collide
import Geometry
--import FoldableHelp
import Padding
import qualified IntMapHelp as IM
import ListHelp
import Color
import Data.Maybe
--import Data.List
@@ -69,7 +76,13 @@ closeObjectSize :: Either FloorItem Button -> Int
closeObjectSize e = case e of
Left flit -> itSlotsTaken $ _flIt flit
Right _ -> 1
closeObjectCol :: Either FloorItem Button -> Color
closeObjectCol e = case e of
Left flit -> _itInvColor $ _flIt flit
Right _ -> yellow
selNumSlots :: Int -> World -> Int
selNumSlots i w = fromMaybe 1 $ augmentedInvSizes w IM.!? i
selNumPos :: Int -> World -> Int
selNumPos i w = splitgap + (foldl' (+) 0 . fst $ IM.split i (augmentedInvSizes w))
@@ -78,6 +91,17 @@ selNumPos i w = splitgap + (foldl' (+) 0 . fst $ IM.split i (augmentedInvSizes w
| i < length (yourInv w) = 0
| otherwise = 1
selNumMidHeight :: Configuration -> World -> Int -> Point2
selNumMidHeight cfig w i = V2 (150 - hw) ( hh + bump - (20 * fromIntegral ipos + 7.5))
where
hh = halfHeight cfig
hw = halfWidth cfig
ipos = selNumPos i w
bump = negate $ 10 * fromIntegral (selNumSlots i w)
selNumCol :: Int -> World -> Color
selNumCol i w = fromMaybe white $ bimapAugmentInv _itInvColor closeObjectCol w IM.!? i
invSelPos :: World -> Int
invSelPos w = splitgap + (foldl' (+) 0 . fst $ IM.split invsel (augmentedInvSizes w))
where
@@ -156,12 +180,12 @@ bestCloseObjectIndex w = findIndex f $ _closeObjects w
selectedCloseObject :: World -> Maybe (Int,Either FloorItem Button)
selectedCloseObject w
| invsel >= length inv = Just $ selectNthCloseObject w (invsel - length inv)
| otherwise = selectNthCloseObject w <$> bestCloseObjectIndex w
| invsel >= length inv = selectNthCloseObject w (invsel - length inv)
| otherwise = selectNthCloseObject w =<< bestCloseObjectIndex w
where
invsel = _crInvSel cr
cr = you w
inv = _crInv cr
selectNthCloseObject :: World -> Int -> (Int,Either FloorItem Button)
selectNthCloseObject w n = (length (yourInv w) + n, _closeObjects w !! n)
selectNthCloseObject :: World -> Int -> Maybe (Int,Either FloorItem Button)
selectNthCloseObject w n = (length (yourInv w) + n,) <$> (_closeObjects w !? n)