|
|
|
@@ -1,7 +1,7 @@
|
|
|
|
|
{-# LANGUAGE TupleSections #-}
|
|
|
|
|
module Dodge.DisplayInventory
|
|
|
|
|
( makeDisplayInventory
|
|
|
|
|
, updateDisplayInventory
|
|
|
|
|
( updateDisplayInventory
|
|
|
|
|
, defaultDisplaySections
|
|
|
|
|
) where
|
|
|
|
|
|
|
|
|
|
import Data.Maybe
|
|
|
|
@@ -23,11 +23,25 @@ import Dodge.Data.World
|
|
|
|
|
|
|
|
|
|
updateDisplayInventory :: World -> Configuration -> SelectionSections () -> SelectionSections ()
|
|
|
|
|
updateDisplayInventory w cfig sss = sss
|
|
|
|
|
{ _sssSections = restrictsections
|
|
|
|
|
--{ _sssSections = restrictsections
|
|
|
|
|
{ _sssSections = sections
|
|
|
|
|
, _sssSelPos = mspos
|
|
|
|
|
, _sssMaxSize = availablelines
|
|
|
|
|
}
|
|
|
|
|
where
|
|
|
|
|
sections = case cr ^? crInvSel . isel of
|
|
|
|
|
Just (SelItem i _) -> updateSections availablelines (0,i) [invx ,youx, closex]
|
|
|
|
|
Just SelNothing -> updateSections availablelines (1,0) [invx ,youx, closex]
|
|
|
|
|
Just (SelCloseObject i) -> updateSections availablelines (2,i) [closex, invx ,youx]
|
|
|
|
|
_ -> error "wat"
|
|
|
|
|
invx = (0,(invsec, invitems))
|
|
|
|
|
youx = (1,(makeYouSection w, youitems))
|
|
|
|
|
closex = (2,(cosec, coitems))
|
|
|
|
|
youitems = IM.singleton 0 $ SelectionItem [thetext] 1 True (length thetext) invDimColor 2 ()
|
|
|
|
|
thetext = case nfreeslots of
|
|
|
|
|
0 -> " INVENTORY FULL"
|
|
|
|
|
1 -> " +1 FREE SLOT"
|
|
|
|
|
x -> " +" ++ show x ++ " FREE SLOTS"
|
|
|
|
|
mspos = do
|
|
|
|
|
mo <- cr ^? crInvSel . isel
|
|
|
|
|
case mo of
|
|
|
|
@@ -36,14 +50,12 @@ updateDisplayInventory w cfig sss = sss
|
|
|
|
|
SelCloseObject {} -> Just 2
|
|
|
|
|
availablelines = getAvailableListLines (invDisplayParams w) cfig
|
|
|
|
|
iavailablelines = availablelines - 6
|
|
|
|
|
--invsection = makeInventorySection iavailablelines oldoffset w
|
|
|
|
|
invsection = updateSection "MORE INV ITEMS" invpos invitems iavailablelines w invsec
|
|
|
|
|
invsection = updateSection invpos invitems iavailablelines invsec
|
|
|
|
|
invsectionlines = length $ _ssShownItems invsection
|
|
|
|
|
restrictsections = IM.fromList
|
|
|
|
|
[ (0, invsection )
|
|
|
|
|
, (1, makeYouSection w)
|
|
|
|
|
--, (2, makeCloseObjectsSection (availablelines - invsectionlines - 1) w)
|
|
|
|
|
, (2, updateSection "MORE CLOSE OBJECTS" copos coitems (availablelines - invsectionlines - 1) w cosec)
|
|
|
|
|
, (2, updateSection copos coitems (availablelines - invsectionlines - 1) cosec)
|
|
|
|
|
]
|
|
|
|
|
cosec = fromMaybe defaultCOSection $ sss ^? sssSections . ix 2
|
|
|
|
|
invsec = fromMaybe defaultInvSection $ sss ^? sssSections . ix 0
|
|
|
|
@@ -66,41 +78,30 @@ updateDisplayInventory w cfig sss = sss
|
|
|
|
|
SelNothing -> Nothing
|
|
|
|
|
SelCloseObject i -> Just i
|
|
|
|
|
|
|
|
|
|
updateSections :: Int -> (Int, Int) -> [(Int,(SelectionSection a,IM.IntMap (SelectionItem a)))]
|
|
|
|
|
-> IM.IntMap (SelectionSection a)
|
|
|
|
|
updateSections _ _ [] = mempty
|
|
|
|
|
updateSections allavailablelines (i,j) ((k,(x,y)):xs) = IM.insert k ss
|
|
|
|
|
$ updateSections (allavailablelines - length (_ssShownItems ss)) (i,j) xs
|
|
|
|
|
where
|
|
|
|
|
ss | i == k = updateSection (Just j) y availablelines x
|
|
|
|
|
| otherwise = updateSection Nothing y availablelines x
|
|
|
|
|
availablelines = allavailablelines - sum (map (_ssMinSize . fst . snd) xs)
|
|
|
|
|
|
|
|
|
|
defaultCOSection :: SelectionSection ()
|
|
|
|
|
defaultCOSection = SelectionSection mempty Nothing 5 1 0 NoSSRestriction [] 2
|
|
|
|
|
defaultCOSection = SelectionSection mempty Nothing 5 1 0 NoSSRestriction [] 2 "CLOSE OBJECTS"
|
|
|
|
|
|
|
|
|
|
defaultInvSection :: SelectionSection ()
|
|
|
|
|
defaultInvSection = SelectionSection mempty Nothing 5 0 0 NoSSRestriction [] 0
|
|
|
|
|
defaultInvSection = SelectionSection mempty Nothing 5 0 0 NoSSRestriction [] 0 "INVENTORY ITEMS"
|
|
|
|
|
|
|
|
|
|
makeDisplayInventory :: World -> Configuration -> SelectionSections ()
|
|
|
|
|
makeDisplayInventory w cfig = defaultDisplaySections
|
|
|
|
|
{ _sssSections = restrictsections
|
|
|
|
|
, _sssSelPos = mspos
|
|
|
|
|
, _sssMaxSize = availablelines
|
|
|
|
|
}
|
|
|
|
|
where
|
|
|
|
|
mspos = do
|
|
|
|
|
cr <- w ^? cWorld . lWorld . creatures . ix 0
|
|
|
|
|
mo <- cr ^? crInvSel . isel
|
|
|
|
|
case mo of
|
|
|
|
|
SelItem {} -> Just 0
|
|
|
|
|
SelNothing -> Just 1
|
|
|
|
|
SelCloseObject {} -> Just 2
|
|
|
|
|
availablelines = getAvailableListLines (invDisplayParams w) cfig
|
|
|
|
|
--iavailablelines = availablelines - 6
|
|
|
|
|
--invsection = makeInventorySection iavailablelines (Just 0) w
|
|
|
|
|
--invsectionlines = length $ _ssShownItems invsection
|
|
|
|
|
restrictsections = IM.fromList
|
|
|
|
|
[ (0, defaultInvSection )
|
|
|
|
|
, (1, makeYouSection w)
|
|
|
|
|
--, (2, makeCloseObjectsSection (availablelines - invsectionlines - 1) w)
|
|
|
|
|
, (2, defaultCOSection)
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
updateSection :: String -> Maybe Int -> IM.IntMap (SelectionItem ()) -> Int -> World
|
|
|
|
|
-> SelectionSection ()
|
|
|
|
|
-> SelectionSection ()
|
|
|
|
|
updateSection morestring mspos sis availablelines w ss = ss
|
|
|
|
|
updateSection
|
|
|
|
|
:: Maybe Int
|
|
|
|
|
-> IM.IntMap (SelectionItem a)
|
|
|
|
|
-> Int
|
|
|
|
|
-- -> World
|
|
|
|
|
-> SelectionSection a
|
|
|
|
|
-> SelectionSection a
|
|
|
|
|
updateSection mspos sis availablelines ss = ss
|
|
|
|
|
{ _ssItems = sis
|
|
|
|
|
, _ssCursor = scurs
|
|
|
|
|
, _ssRestriction = NoSSRestriction
|
|
|
|
@@ -109,21 +110,20 @@ updateSection morestring mspos sis availablelines w ss = ss
|
|
|
|
|
-- , _ssRegex = ""
|
|
|
|
|
-- , _ssRegexInput = False
|
|
|
|
|
, _ssMinSize = 5
|
|
|
|
|
-- , _ssOffset = 0
|
|
|
|
|
, _ssShownItems = shownitems
|
|
|
|
|
}
|
|
|
|
|
where
|
|
|
|
|
moldoffset = ss ^? ssOffset
|
|
|
|
|
oldoffset = ss ^. ssOffset
|
|
|
|
|
scurs = do
|
|
|
|
|
csel <- mspos
|
|
|
|
|
si <- sis ^? ix csel
|
|
|
|
|
let cpos = sum (fmap (length . _siPictures) . fst . IM.split csel $ sis)
|
|
|
|
|
csize <- selsize
|
|
|
|
|
ccolor <- selcolor
|
|
|
|
|
csize = length $ _siPictures si
|
|
|
|
|
ccolor = _siColor si
|
|
|
|
|
return $ SectionCursor (cpos - offset) csize ccolor
|
|
|
|
|
mcpos = do
|
|
|
|
|
csel <- mspos
|
|
|
|
|
return . sum $ fmap (length . _siPictures) . fst . IM.split csel $ sis
|
|
|
|
|
oldoffset = fromMaybe 0 moldoffset
|
|
|
|
|
xselsize = fromMaybe 1 selsize
|
|
|
|
|
offset = maybe 0 offset' mcpos
|
|
|
|
|
offset' jselpos
|
|
|
|
@@ -145,97 +145,20 @@ updateSection morestring mspos sis availablelines w ss = ss
|
|
|
|
|
allstrings :: [(Color,String)]
|
|
|
|
|
allstrings = foldMap g sis
|
|
|
|
|
mustrestrict = length allstrings > availablelines
|
|
|
|
|
shownstrings :: [(Color,String)]
|
|
|
|
|
shownstrings = drop offset allstrings
|
|
|
|
|
cr = you w
|
|
|
|
|
h (col,str) = color col . text $ str
|
|
|
|
|
--hdown (col,str) = textGrad col (withAlpha 0 col) str
|
|
|
|
|
--hup (col,str) = textGrad (withAlpha 0 col) col str
|
|
|
|
|
theindent = replicate (_ssIndent ss) ' '
|
|
|
|
|
hdown = color white . text $ theindent ++ ">>> " ++ morestring
|
|
|
|
|
hup = color white . text $ theindent ++ "<<< " ++ morestring
|
|
|
|
|
hdown = color white . text $ theindent ++ ">>> MORE " ++ _ssDescriptor ss
|
|
|
|
|
hup = color white . text $ theindent ++ "<<< MORE " ++ _ssDescriptor ss
|
|
|
|
|
g si = map (_siColor si ,) $ _siPictures si
|
|
|
|
|
islastitm = fromMaybe False $ do
|
|
|
|
|
i <- cr ^? crInvSel . isel . ispItem
|
|
|
|
|
k <- fmap fst $ IM.lookupMax (_crInv cr)
|
|
|
|
|
i <- mspos
|
|
|
|
|
k <- fst <$> IM.lookupMax sis
|
|
|
|
|
return $ k == i
|
|
|
|
|
selsize = do
|
|
|
|
|
i <- mspos
|
|
|
|
|
si <- sis ^? ix i
|
|
|
|
|
return . length $ _siPictures si
|
|
|
|
|
selcolor = do
|
|
|
|
|
i <- mspos
|
|
|
|
|
si <- sis ^? ix i
|
|
|
|
|
return $ _siColor si
|
|
|
|
|
|
|
|
|
|
--makeInventorySection :: Int -> Maybe Int -> World -> SelectionSection ()
|
|
|
|
|
--makeInventorySection iavailablelines moldoffset w = SelectionSection
|
|
|
|
|
-- { _ssItems = IM.mapWithKey (invSelectionItem' cr) inv
|
|
|
|
|
-- , _ssCursor = scurs
|
|
|
|
|
-- , _ssRestriction = NoSSRestriction
|
|
|
|
|
-- , _ssPriority = 0
|
|
|
|
|
-- , _ssOffset = offset
|
|
|
|
|
-- , _ssIndent = 0
|
|
|
|
|
---- , _ssRegex = ""
|
|
|
|
|
---- , _ssRegexInput = False
|
|
|
|
|
-- , _ssMinSize = 5
|
|
|
|
|
---- , _ssOffset = 0
|
|
|
|
|
-- , _ssShownItems = shownitems
|
|
|
|
|
-- }
|
|
|
|
|
-- where
|
|
|
|
|
-- scurs = do
|
|
|
|
|
-- cpos <- fmap (subtract offset) selpos
|
|
|
|
|
-- csize <- selsize
|
|
|
|
|
-- ccolor <- selcolor
|
|
|
|
|
-- return $ SectionCursor cpos csize ccolor
|
|
|
|
|
-- jselpos = fromMaybe 0 selpos
|
|
|
|
|
-- oldoffset = fromMaybe 0 moldoffset
|
|
|
|
|
-- xselsize = fromMaybe 1 selsize
|
|
|
|
|
-- offset
|
|
|
|
|
-- | jselpos == 0 || not mustrestrict = 0
|
|
|
|
|
-- | jselpos - 1 < oldoffset = jselpos - 1
|
|
|
|
|
-- | islastitm = jselpos - iavailablelines + xselsize
|
|
|
|
|
-- | jselpos + 1 + xselsize - iavailablelines > oldoffset = jselpos - iavailablelines + 1 + xselsize
|
|
|
|
|
-- | length allstrings - oldoffset < iavailablelines = length allstrings - iavailablelines
|
|
|
|
|
-- | otherwise = oldoffset
|
|
|
|
|
-- tweakfirst (x:xs)
|
|
|
|
|
-- | offset > 0 = hup : map h xs
|
|
|
|
|
-- | otherwise = map h (x:xs)
|
|
|
|
|
-- tweakfirst [] = []
|
|
|
|
|
-- shownitems
|
|
|
|
|
-- | length shownstrings > iavailablelines
|
|
|
|
|
-- = tweakfirst (take (iavailablelines - 1) shownstrings)
|
|
|
|
|
-- ++ [hdown]
|
|
|
|
|
-- | otherwise = tweakfirst shownstrings
|
|
|
|
|
-- allstrings :: [(Color,String)]
|
|
|
|
|
-- allstrings = foldMap (g . invSelectionItem cr ) (IM.toList inv)
|
|
|
|
|
-- mustrestrict = length allstrings > iavailablelines
|
|
|
|
|
-- shownstrings :: [(Color,String)]
|
|
|
|
|
-- shownstrings = drop offset allstrings
|
|
|
|
|
-- cr = you w
|
|
|
|
|
-- inv = _crInv cr
|
|
|
|
|
-- h (col,str) = color col . text $ str
|
|
|
|
|
-- --hdown (col,str) = textGrad col (withAlpha 0 col) str
|
|
|
|
|
-- --hup (col,str) = textGrad (withAlpha 0 col) col str
|
|
|
|
|
-- hdown = color white $ text ">>> MORE INV ITEMS"
|
|
|
|
|
-- hup = color white $ text "<<< MORE INV ITEMS"
|
|
|
|
|
-- g si = map (_siColor si ,) $ _siPictures si
|
|
|
|
|
-- islastitm = fromMaybe False $ do
|
|
|
|
|
-- i <- cr ^? crInvSel . isel . ispItem
|
|
|
|
|
-- k <- fmap fst $ IM.lookupMax (_crInv cr)
|
|
|
|
|
-- return $ k == i
|
|
|
|
|
-- selpos = do
|
|
|
|
|
-- i <- cr ^? crInvSel . isel . ispItem
|
|
|
|
|
-- return . sum . fmap itSlotsTaken . fst . IM.split i $ inv
|
|
|
|
|
-- selsize = do
|
|
|
|
|
-- i <- cr ^? crInvSel . isel . ispItem
|
|
|
|
|
-- itm <- inv ^? ix i
|
|
|
|
|
-- return $ itSlotsTaken itm
|
|
|
|
|
-- selcolor = do
|
|
|
|
|
-- i <- cr ^? crInvSel . isel . ispItem
|
|
|
|
|
-- itm <- inv ^? ix i
|
|
|
|
|
-- return $ _itInvColor itm
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
makeYouSection :: World -> SelectionSection ()
|
|
|
|
|
makeYouSection w = SelectionSection
|
|
|
|
@@ -250,6 +173,7 @@ makeYouSection w = SelectionSection
|
|
|
|
|
, _ssMinSize = 1
|
|
|
|
|
-- , _ssOffset = 0
|
|
|
|
|
, _ssShownItems = [color invDimColor $ text thetext]
|
|
|
|
|
, _ssDescriptor = "YOUR STATUS"
|
|
|
|
|
}
|
|
|
|
|
where
|
|
|
|
|
cr = you w
|
|
|
|
@@ -259,43 +183,3 @@ makeYouSection w = SelectionSection
|
|
|
|
|
1 -> " +1 FREE SLOT"
|
|
|
|
|
x -> " +" ++ show x ++ " FREE SLOTS"
|
|
|
|
|
|
|
|
|
|
--makeCloseObjectsSection :: Int -> World -> SelectionSection ()
|
|
|
|
|
--makeCloseObjectsSection cavailablelines w = SelectionSection
|
|
|
|
|
-- { _ssItems = IM.fromDistinctAscList . zip [0..]
|
|
|
|
|
-- $ map (closeObjectToSelectionItem nfreeslots) (w ^. hud . closeObjects)
|
|
|
|
|
-- , _ssCursor = scurs
|
|
|
|
|
-- , _ssPriority = 1
|
|
|
|
|
-- , _ssOffset = 0
|
|
|
|
|
-- , _ssIndent = 2
|
|
|
|
|
-- , _ssRestriction = NoSSRestriction
|
|
|
|
|
---- , _ssRegex = ""
|
|
|
|
|
---- , _ssRegexInput = False
|
|
|
|
|
-- , _ssMinSize = 5
|
|
|
|
|
---- , _ssOffset = 0
|
|
|
|
|
-- , _ssShownItems = foldMap (f . closeObjectToSelectionItem nfreeslots) (w ^. hud . closeObjects)
|
|
|
|
|
-- }
|
|
|
|
|
-- where
|
|
|
|
|
-- scurs = do
|
|
|
|
|
-- cpos <- selpos
|
|
|
|
|
-- csize <- selsize
|
|
|
|
|
-- ccolor <- selcolor
|
|
|
|
|
-- return $ SectionCursor cpos csize ccolor
|
|
|
|
|
-- f si = map (color (_siColor si) . text) $ _siPictures si
|
|
|
|
|
-- cr = you w
|
|
|
|
|
-- nfreeslots = crNumFreeSlots cr
|
|
|
|
|
-- selpos = do
|
|
|
|
|
-- i <- cr ^? crInvSel . isel . ispCloseObject
|
|
|
|
|
-- return . sum . map closeobjectsize . take i $ w ^. hud . closeObjects
|
|
|
|
|
-- selsize = do
|
|
|
|
|
-- i <- cr ^? crInvSel . isel . ispCloseObject
|
|
|
|
|
-- obj <- w ^? hud . closeObjects . ix i
|
|
|
|
|
-- return $ closeobjectsize obj
|
|
|
|
|
-- closeobjectsize co = maybe 1 itSlotsTaken (co ^? _Left . flIt)
|
|
|
|
|
-- selcolor = do
|
|
|
|
|
-- i <- cr ^? crInvSel . isel . ispCloseObject
|
|
|
|
|
-- obj <- w ^? hud . closeObjects . ix i
|
|
|
|
|
-- Just $ case obj of
|
|
|
|
|
-- Left flit -> _itInvColor $ _flIt flit
|
|
|
|
|
-- Right bt -> _btColor bt
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|