Start adding filters to selection lists
This commit is contained in:
+19
-17
@@ -66,6 +66,8 @@ defaultSubInvSelectionList =
|
||||
{ _slItems = []
|
||||
, _slSelPos = Nothing
|
||||
, _slLength = 15
|
||||
, _slRegex = ""
|
||||
, _slRegexInput = False
|
||||
}
|
||||
|
||||
invDisplayParams :: World -> ListDisplayParams
|
||||
@@ -91,11 +93,11 @@ drawSubInventory subinv cfig w = case subinv of
|
||||
NoSubInventory -> drawNoSubInventory cfig w
|
||||
ExamineInventory mtweaki -> drawExamineInventory cfig mtweaki w
|
||||
DisplayTerminal tid -> displayTerminal tid cfig (w ^. cWorld . lWorld)
|
||||
CombineInventory mi ->
|
||||
CombineInventory mi regex x ->
|
||||
titledSub
|
||||
cfig
|
||||
"COMBINE"
|
||||
(combineListSelection w mi)
|
||||
("COMBINE")
|
||||
(combineListSelection w mi (T.unpack regex) x)
|
||||
<> combineInventoryExtra mi cfig w
|
||||
|
||||
titledSub :: Configuration -> String -> SelectionList a -> Picture
|
||||
@@ -115,7 +117,7 @@ drawExamineInventory cfig mtweaki w =
|
||||
itm = yourItem w
|
||||
f str =
|
||||
SelectionItem
|
||||
{ _siPictures = [text str]
|
||||
{ _siPictures = [str]
|
||||
, _siHeight = 1
|
||||
, _siIsSelectable = True
|
||||
, _siWidth = length str
|
||||
@@ -238,8 +240,8 @@ displayTerminal tid cfig w = fromMaybe mempty $ do
|
||||
, drawSelectionList secondColumnParams cfig (thesellist tm)
|
||||
]
|
||||
where
|
||||
toselitm (str, col) = SelectionItem [color col $ text str] 1 True (length str) col 0 ()
|
||||
thesellist tm = SelectionList (thelist tm) Nothing (length (thelist tm))
|
||||
toselitm (str, col) = SelectionItem [str] 1 True (length str) col 0 ()
|
||||
thesellist tm = SelectionList (thelist tm) Nothing (length (thelist tm)) "" False
|
||||
thelist tm =
|
||||
map toselitm . displayTermInput tm
|
||||
. reverse
|
||||
@@ -331,15 +333,17 @@ determineInvSelCursorWidth w = case _rbOptions w of
|
||||
47
|
||||
| otherwise -> topInvW
|
||||
|
||||
combineListSelection :: World -> Maybe Int -> SelectionList ()
|
||||
combineListSelection w mi =
|
||||
combineListSelection :: World -> Maybe Int -> String -> Bool -> SelectionList ()
|
||||
combineListSelection w mi regex x =
|
||||
defaultSubInvSelectionList
|
||||
& slItems .~ combineListSelectionItems w
|
||||
& slSelPos .~ mi
|
||||
& slRegex .~ regex
|
||||
& slRegexInput .~ x
|
||||
|
||||
combineListSelectionItems :: World -> [SelectionItem ()]
|
||||
combineListSelectionItems w = case combineListSelectionItems' w of
|
||||
[] -> [SelectionItem [text thetext] 1 False (length thetext) white 0 ()]
|
||||
[] -> [SelectionItem [thetext] 1 False (length thetext) white 0 ()]
|
||||
xs -> xs
|
||||
where
|
||||
thetext = "NO POSSIBLE COMBINATIONS"
|
||||
@@ -449,7 +453,7 @@ drawMapWall cfig thehud wl = color c . polygon $ map (cartePosToScreen cfig theh
|
||||
mainListCursor :: Color -> Int -> Configuration -> Picture
|
||||
mainListCursor c = openCursorAt 120 c 5 0
|
||||
|
||||
picsToSelectable :: Int -> [Picture] -> SelectionItem ()
|
||||
picsToSelectable :: Int -> [String] -> SelectionItem ()
|
||||
picsToSelectable wdth pics =
|
||||
SelectionItem
|
||||
{ _siPictures = pics
|
||||
@@ -462,17 +466,15 @@ picsToSelectable wdth pics =
|
||||
}
|
||||
|
||||
textSelItems :: [String] -> [SelectionItem ()]
|
||||
textSelItems = map (picsToSelectable 15 . (: []) . text)
|
||||
textSelItems = map (picsToSelectable 15 . (: []))
|
||||
|
||||
itemText :: Item -> [Picture]
|
||||
itemText :: Item -> [String]
|
||||
{-# INLINE itemText #-}
|
||||
itemText it = f $ case _itCurseStatus it of
|
||||
UndroppableIdentified -> map (color yellow . text) (itemDisplay it)
|
||||
-- <> color (withAlpha 0.9 thecolor) (polygon (rectNSEW 110 (-65) 885 (-90)))
|
||||
_ -> map (color thecolor . text) (itemDisplay it)
|
||||
UndroppableIdentified -> itemDisplay it
|
||||
_ -> itemDisplay it
|
||||
where
|
||||
thecolor = _itInvColor it
|
||||
f = take (itSlotsTaken it) . (++ replicate 10 (color (_itInvColor it) $ text "*"))
|
||||
f = take (itSlotsTaken it) . (++ replicate 10 "*")
|
||||
|
||||
openCursorAt ::
|
||||
-- | Width
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
module Dodge.Render.List where
|
||||
|
||||
--import Data.Foldable
|
||||
import Regex
|
||||
import Data.Maybe
|
||||
import Dodge.Base.WinScale
|
||||
import Dodge.Base.Window
|
||||
@@ -25,7 +26,16 @@ drawSelectionList ldps cfig sl =
|
||||
<> drawSelectionCursor ldps cfig sl
|
||||
|
||||
makeSelectionListPictures :: SelectionList a -> [Picture]
|
||||
makeSelectionListPictures sl = concatMap _siPictures $ _slItems sl
|
||||
makeSelectionListPictures sl = regex ++ concatMap f theitems
|
||||
where
|
||||
theitems = case sl ^. slRegex of
|
||||
"" -> _slItems sl
|
||||
str -> filter (doregex str) (_slItems sl)
|
||||
doregex str = regexList str . _siPictures
|
||||
regex = case sl ^. slRegex of
|
||||
"" | not (sl ^. slRegexInput) -> []
|
||||
str -> [text $ "SEARCH: " ++ str]
|
||||
f si = map (color (_siColor si) . text) $ _siPictures si
|
||||
--case sl ^. slSizeRestriction of
|
||||
-- SelectionSizeRestriction {} -> concatMap (_siPictures . fst) $ _slShownItems sl
|
||||
-- _ -> concatMap _siPictures $ _slItems sl
|
||||
@@ -47,7 +57,16 @@ drawCursorAt ldps cfig mi lis = fromMaybe mempty $ do
|
||||
_ -> 1
|
||||
|
||||
drawSelectionCursor :: ListDisplayParams -> Configuration -> SelectionList a -> Picture
|
||||
drawSelectionCursor ldps cfig sl = drawCursorAt ldps cfig (sl ^. slSelPos) (sl ^. slItems)
|
||||
drawSelectionCursor ldps cfig sl = drawCursorAt ldps cfig (f $ sl ^. slSelPos) (g $ sl ^. slItems)
|
||||
where
|
||||
-- the following is quite hacky
|
||||
f = case sl ^. slRegex of
|
||||
"" | not (sl ^. slRegexInput) -> id
|
||||
_ -> fmap (+1)
|
||||
g (x:xs) = case sl ^. slRegex of
|
||||
"" | not (sl ^. slRegexInput) -> (x:xs)
|
||||
_ -> ((x & siHeight .~ 1) : x : xs)
|
||||
g _ = []
|
||||
|
||||
-- given a list of pictures that are each the size of a "text" call, displays them as
|
||||
-- a list on the screen
|
||||
|
||||
Reference in New Issue
Block a user