Commit before reorganising/removing SSSExtra
This commit is contained in:
@@ -1,16 +1,11 @@
|
||||
--{-# LANGUAGE TupleSections #-}
|
||||
|
||||
--{-# OPTIONS_GHC -fno-full-laziness #-}
|
||||
|
||||
module Dodge.DisplayInventory (
|
||||
toggleCombineInv,
|
||||
updateInventoryPositioning,
|
||||
updateCombinePositioning,
|
||||
) where
|
||||
|
||||
import Dodge.Data.DoubleTree
|
||||
import Control.Lens
|
||||
import Dodge.Inventory.SelectionList
|
||||
import Control.Monad
|
||||
import qualified Data.IntMap.Strict as IM
|
||||
import Data.Maybe
|
||||
@@ -18,20 +13,22 @@ import Dodge.Base.You
|
||||
import Dodge.Combine
|
||||
import Dodge.Data.Combine
|
||||
import Dodge.Data.Config
|
||||
import Dodge.Data.DoubleTree
|
||||
import Dodge.Data.SelectionList
|
||||
import Dodge.Data.Universe
|
||||
import Dodge.Inventory.CheckSlots
|
||||
import Dodge.Inventory.SelectionList
|
||||
import Dodge.Item.Grammar
|
||||
import Dodge.ListDisplayParams
|
||||
import Dodge.SelectionList
|
||||
import Dodge.Item.Grammar
|
||||
import ListHelp
|
||||
import Picture.Base
|
||||
import Regex
|
||||
|
||||
toggleCombineInv :: Universe -> Universe
|
||||
toggleCombineInv uv = case uv ^? uvWorld . hud . hudElement . subInventory of
|
||||
Just CombineInventory{} -> uv & uvWorld . hud . hudElement . subInventory
|
||||
.~ NoSubInventory MouseInvNothing Nothing
|
||||
Just CombineInventory{} ->
|
||||
uv & uvWorld . hud . hudElement . subInventory
|
||||
.~ NoSubInventory MouseInvNothing Nothing
|
||||
_ -> uv & uvWorld %~ enterCombineInv (uv ^. uvConfig)
|
||||
|
||||
updateCombinePositioning :: Universe -> Universe
|
||||
@@ -40,8 +37,8 @@ updateCombinePositioning u =
|
||||
%~ updateCombineSections (_uvWorld u) (_uvConfig u)
|
||||
|
||||
updateCombineSections :: World -> Configuration -> SelectionSections CombinableItem -> SelectionSections CombinableItem
|
||||
updateCombineSections w cfig sss =
|
||||
sss & sssSections
|
||||
updateCombineSections w cfig =
|
||||
sssSections
|
||||
%~ updateSectionsPositioning
|
||||
mselpos
|
||||
availablelines
|
||||
@@ -55,7 +52,8 @@ updateCombineSections w cfig sss =
|
||||
invitms <- w ^? hud . hudElement . diSections . sssSections . ix 0 . ssItems
|
||||
return $ IM.filter (flip (andOrRegex $ regexCombs invitms) str) allcombs
|
||||
showncombs
|
||||
| null filtcombs = IM.singleton 0 $ SelectionInfo ["No possible combinations"] 1 False white 0
|
||||
| null filtcombs = IM.singleton 0
|
||||
$ SelectionInfo ["No possible combinations"] 1 False white 0
|
||||
| otherwise = filtcombs
|
||||
filtinv = fromMaybe mempty $ do
|
||||
str <- mstr
|
||||
@@ -77,7 +75,7 @@ regexCombs inv ci str = case str of
|
||||
return $ regexList str' $ _siPictures si'
|
||||
|
||||
andOrRegex :: (a -> String -> Bool) -> a -> String -> Bool
|
||||
andOrRegex f x str = all (orRegex f x) (wordsBy '&' str)
|
||||
andOrRegex f x = all (orRegex f x) . wordsBy '&'
|
||||
|
||||
orRegex :: (a -> String -> Bool) -> a -> String -> Bool
|
||||
orRegex f x str = case words str of
|
||||
@@ -89,11 +87,11 @@ updateInventoryPositioning u =
|
||||
u & uvWorld . hud . hudElement . diSections
|
||||
%~ updateDisplaySections (_uvWorld u) (_uvConfig u)
|
||||
|
||||
updateDisplaySections
|
||||
:: World
|
||||
-> Configuration
|
||||
-> SelectionSections ()
|
||||
-> SelectionSections ()
|
||||
updateDisplaySections ::
|
||||
World ->
|
||||
Configuration ->
|
||||
SelectionSections () ->
|
||||
SelectionSections ()
|
||||
updateDisplaySections w cfig sss =
|
||||
sss & sssSections
|
||||
%~ updateSectionsPositioning
|
||||
@@ -117,8 +115,10 @@ updateDisplaySections w cfig sss =
|
||||
coitems' =
|
||||
IM.fromDistinctAscList . zip [0 ..] $
|
||||
map closeObjectToSelectionItem (w ^. hud . closeObjects)
|
||||
invitems' = IM.mapWithKey (\k (y,x) -> invSelectionItem cr k (x ^. locLDT . ldtValue) y)
|
||||
invlocs
|
||||
invitems' =
|
||||
IM.mapWithKey
|
||||
(\k (y, x) -> invSelectionItem cr k (x ^. locLDT . ldtValue) y)
|
||||
invlocs
|
||||
cr = you w
|
||||
invlocs = allInvLocs $ _crInv (you w)
|
||||
nfreeslots = crNumFreeSlots cr
|
||||
@@ -203,15 +203,20 @@ updateSection sis mcsel availablelines ss =
|
||||
si <- sis ^? ix csel
|
||||
let xselsize = length $ _siPictures si
|
||||
return $ case sum $ fmap (length . _siPictures) . fst . IM.split csel $ sis of
|
||||
pos | pos == 0 || length allstrings <= availablelines ->
|
||||
pos
|
||||
| pos == 0 || length allstrings <= availablelines ->
|
||||
0
|
||||
pos | pos - 1 < oldoffset ->
|
||||
pos
|
||||
| pos - 1 < oldoffset ->
|
||||
pos - 1
|
||||
pos | maxcsel == csel ->
|
||||
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)
|
||||
@@ -232,13 +237,13 @@ updateSection sis mcsel availablelines ss =
|
||||
h (_, str) = translate (fromIntegral (_ssIndent ss) * 100) 0 str
|
||||
theindent = replicate (_ssIndent ss) ' '
|
||||
|
||||
listSelectionColorPicture :: Foldable t => t (SelectionItem a) -> [(Color,Picture)]
|
||||
listSelectionColorPicture = foldMap f
|
||||
listSelectionColorPicture :: Foldable t => t (SelectionItem a) -> [(Color, Picture)]
|
||||
listSelectionColorPicture = foldMap f
|
||||
where
|
||||
f si = map g (_siPictures si)
|
||||
where
|
||||
where
|
||||
indent = 100 * fromIntegral (_siOffX si)
|
||||
g str = (_siColor si,translate indent 0 . color (_siColor si) $ text str)
|
||||
g str = (_siColor si, translate indent 0 . color (_siColor si) $ text str)
|
||||
|
||||
enterCombineInv :: Configuration -> World -> World
|
||||
enterCombineInv cfig w = w & hud . hudElement . subInventory .~ CombineInventory sss selpos
|
||||
@@ -269,17 +274,22 @@ enterCombineInv cfig w = w & hud . hudElement . subInventory .~ CombineInventory
|
||||
, _ssIndent = 0
|
||||
, _ssDescriptor = "COMB FILTER"
|
||||
}
|
||||
combsection = updateSection cm (Just 0) availablelines SelectionSection
|
||||
{ _ssItems = cm
|
||||
, _ssCursor = do
|
||||
(_, si) <- IM.lookupMin cm
|
||||
return $ SectionCursor 0 (_siHeight si) (_siColor si)
|
||||
, _ssMinSize = 5
|
||||
, _ssOffset = 0
|
||||
, _ssShownItems = mempty
|
||||
, _ssIndent = 0
|
||||
, _ssDescriptor = "COMBINATIONS"
|
||||
}
|
||||
combsection =
|
||||
updateSection
|
||||
cm
|
||||
(Just 0)
|
||||
availablelines
|
||||
SelectionSection
|
||||
{ _ssItems = cm
|
||||
, _ssCursor = do
|
||||
(_, si) <- IM.lookupMin cm
|
||||
return $ SectionCursor 0 (_siHeight si) (_siColor si)
|
||||
, _ssMinSize = 5
|
||||
, _ssOffset = 0
|
||||
, _ssShownItems = mempty
|
||||
, _ssIndent = 0
|
||||
, _ssDescriptor = "COMBINATIONS"
|
||||
}
|
||||
|
||||
regexList :: String -> [String] -> Bool
|
||||
regexList x = any (isInfixOf x)
|
||||
|
||||
@@ -7,11 +7,9 @@ module Dodge.InputFocus (
|
||||
inInputFocus,
|
||||
regexScope,
|
||||
regexFocus,
|
||||
-- , inputFocus'
|
||||
) where
|
||||
|
||||
import Control.Monad
|
||||
--import Data.IntMap.Strict (IntMap)
|
||||
import Data.Maybe
|
||||
import Dodge.Data.SelectionList
|
||||
import Dodge.Data.World
|
||||
@@ -27,8 +25,7 @@ inTermFocus w = fromMaybe False $ do
|
||||
regexScope ::
|
||||
(Applicative f) =>
|
||||
World ->
|
||||
Maybe
|
||||
((SSSExtra -> f SSSExtra) -> HUDElement -> f HUDElement, Int)
|
||||
Maybe ((SSSExtra -> f SSSExtra) -> HUDElement -> f HUDElement, Int)
|
||||
regexScope w = case w ^? hud . hudElement . subInventory of
|
||||
Just NoSubInventory{} -> case he ^? diSelection . _Just of
|
||||
Just (-1, _) -> di (-1)
|
||||
|
||||
Reference in New Issue
Block a user