Refactor close objects hud display
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
-- {-# OPTIONS_GHC -fno-full-laziness #-}
|
||||
{-# LANGUAGE TupleSections #-}
|
||||
--{-# LANGUAGE TupleSections #-}
|
||||
|
||||
module Dodge.DisplayInventory (
|
||||
toggleCombineInv,
|
||||
@@ -52,10 +52,10 @@ updateCombineSections ::
|
||||
updateCombineSections w cfig =
|
||||
updateSectionsPositioning
|
||||
(const 5)
|
||||
(const 0)
|
||||
(w ^? hud . hudElement . subInventory . ciSelection . _Just)
|
||||
(getAvailableListLines secondColumnParams cfig)
|
||||
[(0, sclose), (-1, sfclose)]
|
||||
(IM.fromAscList [(-1,0),(0,0)])
|
||||
where
|
||||
filtcurs = w ^? hud . hudElement . subInventory . ciSelection . _Just . _1 == Just (-1)
|
||||
(sfclose, sclose) =
|
||||
@@ -117,6 +117,13 @@ displaySectionsSizes 0 = 10
|
||||
displaySectionsSizes 3 = 10
|
||||
displaySectionsSizes _ = 3
|
||||
|
||||
displayIndents :: Int -> Int
|
||||
displayIndents (-3) = 2
|
||||
displayIndents 0 = 2
|
||||
displayIndents 3 = 2
|
||||
displayIndents 5 = 2
|
||||
displayIndents _ = 0
|
||||
|
||||
updateDisplaySections ::
|
||||
World ->
|
||||
Configuration ->
|
||||
@@ -125,10 +132,10 @@ updateDisplaySections ::
|
||||
updateDisplaySections w cfig =
|
||||
updateSectionsPositioning
|
||||
displaySectionsSizes
|
||||
displayIndents
|
||||
mselpos
|
||||
(getAvailableListLines (invDisplayParams w) cfig)
|
||||
[statushead,statusdisplay,invhead,invx,youx, nearbyhead, closex]
|
||||
(IM.fromAscList [(-4,0),(-3,2),(-2,0),(-1,0),(0,2),(1,0),(2,0),(3,2)])
|
||||
where
|
||||
mselpos = w ^? hud . hudElement . diSelection . _Just
|
||||
invfiltcurs = mselpos ^? _Just . _1 == Just (-1)
|
||||
@@ -147,21 +154,19 @@ updateDisplaySections w cfig =
|
||||
youx = (1, youitems)
|
||||
makehead str i = (i,IM.singleton 0 $ SelectionInfo [str] 1 False white 0)
|
||||
statushead = (-4,IM.singleton 0 $ SelectionInfo ["STATUS"] 1 False white 0)
|
||||
statusdisplay = (-3,IM.singleton 0 $ SelectionInfo ["HEALTH "++show (_crHP cr)] 1 False white 0)
|
||||
statusdisplay = (-3,IM.singleton 0 $ SelectionInfo ["HEALTH: "++show (_crHP cr)] 1 False white 0)
|
||||
invhead = if null sfinv then makehead "INVENTORY" (-2) else filtinv
|
||||
youitems = IM.singleton 0 $ SelectionItem [thetext] 1 True invDimColor 2 ()
|
||||
thetext = displayFreeSlots (crNumFreeSlots cr)
|
||||
closeitms =
|
||||
IM.fromDistinctAscList . zip [0 ..] $
|
||||
map closeObjectToSelectionItem (w ^. hud . closeObjects)
|
||||
map closeItemToSelectionItem (w ^. hud . closeItems)
|
||||
invitems =
|
||||
IM.mapWithKey
|
||||
(\k (indent, x) -> invSelectionItem indent cr k (x ^. locLDT . ldtValue))
|
||||
(fmap (first removeindentiffiltering) . allInvLocs $ _crInv cr)
|
||||
-- this clearly deserves refactoring, also check if drawInventory/iextra
|
||||
-- needs it at the same time
|
||||
removeindentiffiltering =
|
||||
if maybe False isFilteringInv (w ^? hud . hudElement . diSections)
|
||||
if maybe False (not . null) (w ^? hud . hudElement . diInvFilter . _Just)
|
||||
then const 0
|
||||
else id
|
||||
cr = you w
|
||||
@@ -218,7 +223,7 @@ sectionsSizes ::
|
||||
IM.IntMap Int
|
||||
sectionsSizes x f is sss = doSectionSize extraavailable mintaken is sss mempty
|
||||
where
|
||||
mintaken = IM.mapWithKey (\k y -> min (f k) y) sss
|
||||
mintaken = IM.mapWithKey (min . f) sss
|
||||
extraavailable = x - sum mintaken
|
||||
|
||||
doSectionSize ::
|
||||
@@ -249,26 +254,25 @@ doSectionSize extraavailable mintaken is sss done = fromMaybe done $ do
|
||||
|
||||
updateSectionsPositioning ::
|
||||
(Int -> Int) -> -- for determining each sections minimum size
|
||||
(Int -> Int) -> -- for determining each sections indent
|
||||
Maybe (Int, Int) ->
|
||||
Int ->
|
||||
[(Int, IM.IntMap (SelectionItem a))] ->
|
||||
IM.IntMap Int ->
|
||||
IM.IntMap (SelectionSection a) ->
|
||||
IM.IntMap (SelectionSection a)
|
||||
updateSectionsPositioning f mselpos allavailablelines lsss indents sss =
|
||||
IM.intersectionWith updateSection ls mss `h` ssizes `g` offsets `h` indents
|
||||
updateSectionsPositioning f h mselpos allavailablelines lsss sss =
|
||||
IM.intersectionWithKey (\k -> updateSection (h k) (m k)) ls ssizes `g` offsets
|
||||
where
|
||||
offsets = fmap _ssOffset sss
|
||||
mss = IM.mapWithKey m ssizes
|
||||
m k _ = do
|
||||
m k = do
|
||||
(k', i) <- mselpos
|
||||
guard $ k == k'
|
||||
return i
|
||||
ls = IM.fromList lsss
|
||||
h = IM.intersectionWith ($)
|
||||
-- h = IM.intersectionWith ($)
|
||||
-- defaults non-existing offsets to 0
|
||||
g = merge (mapMissing (const ($ 0))) dropMissing (zipWithMatched (const ($)))
|
||||
lk = fromMaybe [] $ fmap ((: []) . fst) mselpos
|
||||
lk = maybe [] ((: []) . fst) mselpos
|
||||
ssizes =
|
||||
sectionsSizes
|
||||
allavailablelines
|
||||
@@ -277,13 +281,13 @@ updateSectionsPositioning f mselpos allavailablelines lsss indents sss =
|
||||
$ sectionsDesiredLines ls
|
||||
|
||||
updateSection ::
|
||||
IM.IntMap (SelectionItem a) ->
|
||||
Maybe Int ->
|
||||
Int ->
|
||||
Maybe Int ->
|
||||
IM.IntMap (SelectionItem a) ->
|
||||
Int ->
|
||||
Int ->
|
||||
SelectionSection a
|
||||
updateSection sis mcsel availablelines oldoffset indent =
|
||||
updateSection indent mcsel sis availablelines oldoffset =
|
||||
SelectionSection
|
||||
{ _ssItems = sis
|
||||
, _ssOffset = offset
|
||||
@@ -363,10 +367,10 @@ enterCombineInv cfig w =
|
||||
}
|
||||
combsection =
|
||||
updateSection
|
||||
cm
|
||||
(Just 0)
|
||||
availablelines
|
||||
0
|
||||
(Just 0)
|
||||
cm
|
||||
availablelines
|
||||
0
|
||||
|
||||
regexList :: String -> [String] -> Bool
|
||||
|
||||
Reference in New Issue
Block a user