Remove section-wide indentation
This commit is contained in:
@@ -1,21 +1,22 @@
|
||||
-- {-# OPTIONS_GHC -fno-full-laziness #-}
|
||||
{-# LANGUAGE TupleSections #-}
|
||||
|
||||
module Dodge.DisplayInventory (
|
||||
toggleCombineInv,
|
||||
updateInventoryPositioning,
|
||||
updateCombinePositioning,
|
||||
) where
|
||||
|
||||
import Data.Monoid
|
||||
import qualified Data.List as List
|
||||
import Dodge.CharacterEnums
|
||||
import Control.Applicative
|
||||
import Control.Lens
|
||||
import Control.Monad
|
||||
import Data.Bifunctor
|
||||
import qualified Data.IntMap.Strict as IM
|
||||
import qualified Data.List as List
|
||||
import Data.Maybe
|
||||
import Data.Monoid
|
||||
import Dodge.Base.You
|
||||
import Dodge.CharacterEnums
|
||||
import Dodge.Combine
|
||||
import Dodge.Data.Combine
|
||||
import Dodge.Data.Config
|
||||
@@ -32,17 +33,15 @@ import ListHelp
|
||||
import Picture.Base
|
||||
|
||||
toggleCombineInv :: Universe -> Universe
|
||||
toggleCombineInv uv = case uv ^? uvWorld . hud . hudElement . subInventory of
|
||||
Just CombineInventory{} ->
|
||||
uv & uvWorld . hud . hudElement . subInventory
|
||||
.~ NoSubInventory --MouseInvNothing
|
||||
_ -> uv & uvWorld %~ enterCombineInv (uv ^. uvConfig)
|
||||
toggleCombineInv uv = uv & case uv ^? uvWorld . hud . hudElement . subInventory of
|
||||
Just CombineInventory{} -> uvWorld . hud . hudElement . subInventory .~ NoSubInventory
|
||||
_ -> uvWorld %~ enterCombineInv (uv ^. uvConfig)
|
||||
|
||||
updateCombinePositioning :: Universe -> Universe
|
||||
updateCombinePositioning u =
|
||||
u & uvWorld . hud . hudElement . subInventory . ciSections
|
||||
updateCombinePositioning u = u
|
||||
& uvWorld . hud . hudElement . subInventory . ciSections
|
||||
%~ updateCombineSections (_uvWorld u) (_uvConfig u)
|
||||
& checkCombineSelectionExists
|
||||
& checkCombineSelectionExists
|
||||
|
||||
updateCombineSections ::
|
||||
World ->
|
||||
@@ -56,9 +55,7 @@ updateCombineSections w cfig =
|
||||
(getAvailableListLines secondColumnParams cfig)
|
||||
[(0, sclose), (-1, sfclose)]
|
||||
where
|
||||
filtcurs = case w ^? hud . hudElement . subInventory . ciSelection . _Just . _1 of
|
||||
Just (-1) -> [cFilledRect]
|
||||
_ -> [cWireRect]
|
||||
filtcurs = w ^? hud . hudElement . subInventory . ciSelection . _Just . _1 == Just (-1)
|
||||
(sfclose, sclose) =
|
||||
filterSectionsPair
|
||||
filtcurs
|
||||
@@ -108,7 +105,7 @@ checkCombineSelectionExists u = fromMaybe u $ do
|
||||
<|> Just (0, 0)
|
||||
Just $ case u ^? uvWorld . hud . hudElement . subInventory . ciSections . ix i . ssItems . ix j of
|
||||
Nothing ->
|
||||
u & uvWorld . hud . hudElement . subInventory . ciSelection ?~ (0,-1)
|
||||
u & uvWorld . hud . hudElement . subInventory . ciSelection ?~ (0, -1)
|
||||
& uvWorld . hud . hudElement . subInventory . ciSelection
|
||||
%~ scrollSelectionSections (-1) sss
|
||||
_ -> u
|
||||
@@ -128,32 +125,21 @@ updateDisplaySections w cfig =
|
||||
displaySectionsSizes
|
||||
mselpos
|
||||
(getAvailableListLines (invDisplayParams w) cfig)
|
||||
addorder
|
||||
[filtinv, filtclose, invx, youx, closex]
|
||||
where
|
||||
mselpos = w ^? hud . hudElement . diSelection . _Just
|
||||
addorder = case mselpos of
|
||||
Just (-1, _) -> reverse [filtinv, filtclose, invx, youx, closex]
|
||||
Just (0, _) -> reverse [filtinv, filtclose, invx, youx, closex]
|
||||
Just (1, _) -> reverse [filtinv, filtclose, invx, youx, closex]
|
||||
Just (2, _) -> reverse [filtinv, filtclose, closex, invx, youx]
|
||||
Just (3, _) -> reverse [filtinv, filtclose, closex, invx, youx]
|
||||
_ -> reverse [filtinv, filtclose, invx, closex, youx]
|
||||
invfiltcurs = case mselpos ^? _Just . _1 of
|
||||
Just (-1) -> [toEnum 219] -- filled rect
|
||||
_ -> [toEnum 128] -- wire rect
|
||||
invfiltcurs = mselpos ^? _Just . _1 == Just (-1)
|
||||
(sfinv, sinv) =
|
||||
filterSectionsPair invfiltcurs plainRegex invitems "INVENTORY" $
|
||||
w ^? hud . hudElement . diInvFilter . _Just
|
||||
(filtinv, invx) = ((-1, sfinv), (0, sinv))
|
||||
closefiltcurs = case mselpos ^? _Just . _1 of
|
||||
Just (2) -> [toEnum 219] -- filled rect
|
||||
_ -> [toEnum 128] -- wire rect
|
||||
closefiltcurs = mselpos ^? _Just . _1 == Just 2
|
||||
(sfclose, sclose) =
|
||||
filterSectionsPair closefiltcurs plainRegex closeitms "NEARBY" $
|
||||
w ^? hud . hudElement . diCloseFilter . _Just
|
||||
(filtclose, closex) = ((2, sfclose), (3, sclose))
|
||||
youx = (1, youitems)
|
||||
youitems = IM.singleton 0 $ SelectionItem [thetext] 1 True invDimColor 2 ()
|
||||
youitems = IM.singleton 0 $ SelectionItem [thetext] 1 True invDimColor 0 ()
|
||||
thetext = displayFreeSlots (crNumFreeSlots cr)
|
||||
closeitms =
|
||||
IM.fromDistinctAscList . zip [0 ..] $
|
||||
@@ -171,24 +157,23 @@ updateDisplaySections w cfig =
|
||||
cr = you w
|
||||
|
||||
filterSectionsPair ::
|
||||
String -> -- string at the end of the input
|
||||
Bool -> -- check for whether filter is in focus, changes string at the end
|
||||
(String -> SelectionItem a -> Bool) ->
|
||||
IM.IntMap (SelectionItem a) ->
|
||||
String ->
|
||||
Maybe String ->
|
||||
(IM.IntMap (SelectionItem a), IM.IntMap (SelectionItem a))
|
||||
filterSectionsPair endstr filtfn itms filtdescription mfilt =
|
||||
( filtsis
|
||||
, itms'
|
||||
)
|
||||
filterSectionsPair infocus filtfn itms filtdescription mfilt =
|
||||
(filtsis, itms')
|
||||
where
|
||||
filtcurs = if infocus then cFilledRect else cWireRect
|
||||
filtsis = fold $ do
|
||||
str <- mfilt
|
||||
return $
|
||||
IM.singleton
|
||||
0
|
||||
$ SelectionInfo
|
||||
[filtdescription ++ " FILTER/" ++ str ++ endstr, numfiltitems]
|
||||
[filtdescription ++ " FILTER/" ++ str ++ [filtcurs], numfiltitems]
|
||||
2
|
||||
True
|
||||
white
|
||||
@@ -234,22 +219,24 @@ doSectionSize ::
|
||||
IM.IntMap Int -> -- sections already sized
|
||||
IM.IntMap Int
|
||||
doSectionSize extraavailable mintaken is sss done = fromMaybe done $ do
|
||||
(v,others,k,ks) <- getsecusingis <|> getminsec
|
||||
(v, others, k, ks) <- getsecusingis <|> getminsec
|
||||
minv <- mintaken ^? ix k
|
||||
let extradesired = v - minv
|
||||
linesgiven = min extraavailable extradesired
|
||||
return $ doSectionSize (extraavailable - linesgiven) mintaken ks others $ done
|
||||
& at k ?~ linesgiven + minv
|
||||
return $
|
||||
doSectionSize (extraavailable - linesgiven) mintaken ks others $
|
||||
done
|
||||
& at k ?~ linesgiven + minv
|
||||
where
|
||||
getsecusingis = do
|
||||
(k,ks) <- List.uncons is
|
||||
let (my,s') = IM.updateLookupWithKey (\_ _ -> Nothing) k sss
|
||||
(k, ks) <- List.uncons is
|
||||
let (my, s') = IM.updateLookupWithKey (\_ _ -> Nothing) k sss
|
||||
y <- my
|
||||
return (y,s',k,ks)
|
||||
return (y, s', k, ks)
|
||||
getminsec = do
|
||||
((k,v),s') <- IM.minViewWithKey sss
|
||||
return (v,s',k,[])
|
||||
|
||||
((k, v), s') <- IM.minViewWithKey sss
|
||||
return (v, s', k, [])
|
||||
|
||||
updateSectionsPositioning ::
|
||||
(Int -> Int) -> -- for determining each sections minimum size
|
||||
Maybe (Int, Int) ->
|
||||
@@ -262,14 +249,18 @@ updateSectionsPositioning f mselpos allavailablelines lsss sss =
|
||||
where
|
||||
mss = IM.mapWithKey m sss
|
||||
m k _ = do
|
||||
(k',i) <- mselpos
|
||||
(k', i) <- mselpos
|
||||
guard $ k == k'
|
||||
return i
|
||||
ls = IM.fromList lsss
|
||||
h = IM.intersectionWith ($)
|
||||
lk = fromMaybe [] $ fmap ((:[]) . fst) mselpos
|
||||
ssizes = sectionsSizes allavailablelines f
|
||||
lk $ sectionsDesiredLines $ IM.intersectionWith (set ssItems) ls sss
|
||||
lk = fromMaybe [] $ fmap ((: []) . fst) mselpos
|
||||
ssizes =
|
||||
sectionsSizes
|
||||
allavailablelines
|
||||
f
|
||||
lk
|
||||
$ sectionsDesiredLines $ IM.intersectionWith (set ssItems) ls sss
|
||||
|
||||
updateSection ::
|
||||
IM.IntMap (SelectionItem a) ->
|
||||
@@ -297,28 +288,33 @@ updateSection sis mcsel availablelines ss =
|
||||
pos | pos == 0 || length allstrings <= availablelines -> 0
|
||||
pos | pos - 1 < oldoffset -> pos - 1
|
||||
pos | maxcsel == csel -> pos - availablelines + xselsize
|
||||
pos | pos + 1 + xselsize - availablelines > oldoffset ->
|
||||
pos
|
||||
| pos + 1 + xselsize - availablelines > oldoffset ->
|
||||
pos - availablelines + 1 + xselsize
|
||||
_ | length allstrings - oldoffset < availablelines ->
|
||||
_
|
||||
| length allstrings - oldoffset < availablelines ->
|
||||
length allstrings - availablelines
|
||||
_ -> oldoffset
|
||||
tweakfirst (x : xs)
|
||||
| offset > 0 =
|
||||
color moreupcolor (text (theindent ++ replicate 15 (toEnum 30))) :
|
||||
--color moreupcolor (text (theindent ++ replicate 15 (toEnum 30))) :
|
||||
color moreupcolor (text (replicate 15 (toEnum 30))) :
|
||||
xs
|
||||
| otherwise = x : xs
|
||||
| otherwise = x : xs
|
||||
tweakfirst [] = []
|
||||
moreupcolor = fromMaybe white $ allstrings ^? ix offset . _1
|
||||
shownitems
|
||||
| length shownstrings > availablelines =
|
||||
map h (take (availablelines - 1) shownstrings)
|
||||
++ [color moredowncolor . text $ theindent ++ replicate 15 (toEnum 31)]
|
||||
-- ++ [color moredowncolor . text $ theindent ++ replicate 15 (toEnum 31)]
|
||||
++ [color moredowncolor . text $ replicate 15 (toEnum 31)]
|
||||
| otherwise = map h shownstrings
|
||||
moredowncolor = fromMaybe white $ allstrings ^? ix (offset + availablelines - 1) . _1
|
||||
allstrings = listSelectionColorPicture sis
|
||||
shownstrings = drop offset allstrings
|
||||
h (_, str) = translate (fromIntegral (_ssIndent ss) * 100) 0 str
|
||||
theindent = replicate (_ssIndent ss) ' '
|
||||
--h (_, str) = translate (fromIntegral (_ssIndent ss) * 100) 0 str
|
||||
h (_, str) = str
|
||||
-- theindent = replicate (_ssIndent ss) ' '
|
||||
|
||||
listSelectionColorPicture :: Foldable t => t (SelectionItem a) -> [(Color, Picture)]
|
||||
listSelectionColorPicture = foldMap f
|
||||
@@ -351,11 +347,9 @@ enterCombineInv cfig w =
|
||||
filtsection =
|
||||
SelectionSection
|
||||
{ _ssItems = mempty
|
||||
-- , _ssMinSize = 0
|
||||
, _ssOffset = 0
|
||||
, -- , _ssMinSize = 0
|
||||
_ssOffset = 0
|
||||
, _ssShownItems = mempty
|
||||
, _ssIndent = 0
|
||||
, _ssDescriptor = "COMB FILTER"
|
||||
}
|
||||
combsection =
|
||||
updateSection
|
||||
@@ -364,11 +358,9 @@ enterCombineInv cfig w =
|
||||
availablelines
|
||||
SelectionSection
|
||||
{ _ssItems = cm
|
||||
-- , _ssMinSize = 5
|
||||
, _ssOffset = 0
|
||||
, -- , _ssMinSize = 5
|
||||
_ssOffset = 0
|
||||
, _ssShownItems = mempty
|
||||
, _ssIndent = 0
|
||||
, _ssDescriptor = "COMBINATIONS"
|
||||
}
|
||||
|
||||
regexList :: String -> [String] -> Bool
|
||||
|
||||
Reference in New Issue
Block a user