Unify backspace in regex code
This commit is contained in:
@@ -7,11 +7,11 @@ module Dodge.DisplayInventory (
|
||||
updateCombinePositioning,
|
||||
) where
|
||||
|
||||
import Data.IntMap.Merge.Strict
|
||||
import Control.Applicative
|
||||
import Control.Lens
|
||||
import Control.Monad
|
||||
import Data.Bifunctor
|
||||
import Data.IntMap.Merge.Strict
|
||||
import qualified Data.IntMap.Strict as IM
|
||||
import Data.Maybe
|
||||
import Data.Monoid
|
||||
@@ -33,15 +33,17 @@ import qualified ListHelp as List
|
||||
import Picture.Base
|
||||
|
||||
toggleCombineInv :: Universe -> Universe
|
||||
toggleCombineInv uv = uv & case uv ^? uvWorld . hud . hudElement . subInventory of
|
||||
Just CombineInventory{} -> uvWorld . hud . hudElement . subInventory .~ NoSubInventory
|
||||
_ -> 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
|
||||
%~ updateCombineSections (_uvWorld u) (_uvConfig u)
|
||||
& checkCombineSelectionExists
|
||||
updateCombinePositioning u =
|
||||
u
|
||||
& uvWorld . hud . hudElement . subInventory . ciSections
|
||||
%~ updateCombineSections (_uvWorld u) (_uvConfig u)
|
||||
& checkCombineSelectionExists
|
||||
|
||||
updateCombineSections ::
|
||||
World ->
|
||||
@@ -52,7 +54,7 @@ updateCombineSections w cfig =
|
||||
updateSectionsPositioning
|
||||
(const 5)
|
||||
(const 0)
|
||||
(fmap (\(x,y,_) -> (x,y)) $ w ^? hud . hudElement . subInventory . ciSelection . _Just)
|
||||
(fmap (\(x, y, _) -> (x, y)) $ w ^? hud . hudElement . subInventory . ciSelection . _Just)
|
||||
(getAvailableListLines secondColumnParams cfig)
|
||||
[(0, sclose), (-1, sfclose)]
|
||||
where
|
||||
@@ -90,14 +92,15 @@ updateInventoryPositioning u =
|
||||
%~ updateDisplaySections (_uvWorld u) (_uvConfig u)
|
||||
& checkInventorySelectionExists
|
||||
|
||||
-- this is possibly not completely correct
|
||||
checkInventorySelectionExists :: Universe -> Universe
|
||||
checkInventorySelectionExists u = case u ^? uvWorld . hud . hudElement . diSections . ix i . ssItems . ix j of
|
||||
checkInventorySelectionExists u =
|
||||
case u ^? uvWorld . hud . hudElement . diSections . ix i . ssItems . ix j of
|
||||
Nothing -> u & uvWorld %~ scrollAugNextInSection
|
||||
_ -> u
|
||||
where
|
||||
(i,j,_) = fromMaybe (0,-1,mempty)
|
||||
$ u ^? uvWorld . hud . hudElement . diSelection . _Just
|
||||
(i, j, _) =
|
||||
fromMaybe (1, -1, mempty) $
|
||||
u ^? uvWorld . hud . hudElement . diSelection . _Just
|
||||
|
||||
checkCombineSelectionExists :: Universe -> Universe
|
||||
checkCombineSelectionExists u = fromMaybe u $ do
|
||||
@@ -107,7 +110,7 @@ checkCombineSelectionExists u = fromMaybe u $ do
|
||||
<|> Just (0, 0, mempty)
|
||||
Just $ case u ^? uvWorld . hud . hudElement . subInventory . ciSections . ix i . ssItems . ix j of
|
||||
Nothing ->
|
||||
u & uvWorld . hud . hudElement . subInventory . ciSelection ?~ (0, -1,mempty)
|
||||
u & uvWorld . hud . hudElement . subInventory . ciSelection ?~ (0, -1, mempty)
|
||||
& uvWorld . hud . hudElement . subInventory . ciSelection
|
||||
%~ scrollSelectionSections (-1) sss
|
||||
_ -> u
|
||||
@@ -135,10 +138,18 @@ updateDisplaySections w cfig =
|
||||
displayIndents
|
||||
mselpos
|
||||
(getAvailableListLines (invDisplayParams w) cfig)
|
||||
[statushead,statusdisplay,invhead,invx,youx, nearbyhead, closex
|
||||
,interfaceshead,interfaces]
|
||||
[ statushead
|
||||
, statusdisplay
|
||||
, invhead
|
||||
, invx
|
||||
, youx
|
||||
, nearbyhead
|
||||
, closex
|
||||
, interfaceshead
|
||||
, interfaces
|
||||
]
|
||||
where
|
||||
mselpos = fmap (\(x,y,_) -> (x,y)) $ w ^? hud . hudElement . diSelection . _Just
|
||||
mselpos = fmap (\(x, y, _) -> (x, y)) $ w ^? hud . hudElement . diSelection . _Just
|
||||
invfiltcurs = mselpos ^? _Just . _1 == Just (-1)
|
||||
(sfinv, sinv) =
|
||||
filterSectionsPair invfiltcurs plainRegex invitems "INVENTORY" $
|
||||
@@ -149,18 +160,19 @@ updateDisplaySections w cfig =
|
||||
filterSectionsPair closefiltcurs plainRegex closeitms "NEARBY ITEMS" $
|
||||
w ^? hud . hudElement . diCloseFilter . _Just
|
||||
(filtclose, closex) = ((2, sfclose), (3, sclose))
|
||||
nearbyhead = if null sfclose
|
||||
then if null sclose then (2,mempty) else makehead "NEARBY ITEMS" 2
|
||||
else filtclose
|
||||
nearbyhead =
|
||||
if null sfclose
|
||||
then if null sclose then (2, mempty) else makehead "NEARBY ITEMS" 2
|
||||
else filtclose
|
||||
youx = (1, youitems)
|
||||
interfaceshead = if null btitems then (4,mempty) else makehead "NEARBY INTERFACES" 4
|
||||
interfaces = (5,btitems)
|
||||
interfaceshead = if null btitems then (4, mempty) else makehead "NEARBY INTERFACES" 4
|
||||
interfaces = (5, btitems)
|
||||
btitems =
|
||||
IM.fromDistinctAscList . zip [0 ..] $
|
||||
mapMaybe (closeButtonToSelectionItem w) (w ^. hud . closeButtons)
|
||||
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)
|
||||
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)
|
||||
invhead = if null sfinv then makehead "INVENTORY" (-1) else filtinv
|
||||
youitems = IM.singleton 0 $ SelectionItem [thetext] 1 True invDimColor 2 ()
|
||||
thetext = displayFreeSlots (crNumFreeSlots cr)
|
||||
@@ -312,9 +324,11 @@ updateSection indent mcsel sis availablelines oldoffset =
|
||||
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)
|
||||
@@ -349,15 +363,18 @@ enterCombineInv cfig w =
|
||||
, _ciSelection = selpos
|
||||
, _ciFilter = Nothing
|
||||
}
|
||||
& hud . hudElement . diInvFilter .~ Nothing
|
||||
& hud . hudElement . diInvFilter
|
||||
.~ Nothing
|
||||
where
|
||||
cm' = IM.fromDistinctAscList . zip [0 ..] $ combineList w
|
||||
cm | null cm' = IM.singleton 0
|
||||
$ SelectionInfo ["No possible combinations"] 1 False white 0
|
||||
cm
|
||||
| null cm' =
|
||||
IM.singleton 0 $
|
||||
SelectionInfo ["No possible combinations"] 1 False white 0
|
||||
| otherwise = cm'
|
||||
selpos
|
||||
| null cm' = Nothing
|
||||
| otherwise = Just (0, 0,mempty)
|
||||
| otherwise = Just (0, 0, mempty)
|
||||
filtsection =
|
||||
SelectionSection
|
||||
{ _ssItems = mempty
|
||||
|
||||
@@ -446,41 +446,27 @@ updateBackspaceRegex :: World -> World
|
||||
updateBackspaceRegex w = case di ^? subInventory of
|
||||
Just NoSubInventory{}
|
||||
| secfocus (-1) 0 ->
|
||||
w & hud . hudElement %~ trybackspace (-1)
|
||||
w & hud . hudElement %~ trybackspace (-1) diInvFilter diInvFilter diSelection
|
||||
& worldEventFlags . at InventoryChange ?~ ()
|
||||
Just NoSubInventory{}
|
||||
| secfocus 2 3 ->
|
||||
w & hud . hudElement %~ trybackspace'' 2
|
||||
w & hud . hudElement %~ trybackspace 2 diCloseFilter diCloseFilter diSelection
|
||||
& worldEventFlags . at InventoryChange ?~ ()
|
||||
Just CombineInventory{} ->
|
||||
w & hud . hudElement . subInventory %~ trybackspace' (-1)
|
||||
w & hud . hudElement . subInventory %~ trybackspace (-1) ciFilter ciFilter ciSelection
|
||||
& worldEventFlags . at InventoryChange ?~ ()
|
||||
_ -> w
|
||||
where
|
||||
secfocus a b = fromMaybe False $ do
|
||||
i <- di ^? diSelection . _Just . _1
|
||||
return $ i == a || i == b
|
||||
trybackspace x he = fromMaybe he $ do
|
||||
str <- he ^? diInvFilter . _Just
|
||||
trybackspace x filtget filtset selset he = fromMaybe he $ do
|
||||
str <- he ^? filtget . _Just
|
||||
return $ case str of
|
||||
(_ : _) ->
|
||||
he & diInvFilter . _Just %~ init
|
||||
& diSelection ?~ (x, 0,mempty)
|
||||
[] -> he & diInvFilter .~ Nothing
|
||||
trybackspace'' x he = fromMaybe he $ do
|
||||
str <- he ^? diCloseFilter . _Just
|
||||
return $ case str of
|
||||
(_ : _) ->
|
||||
he & diCloseFilter . _Just %~ init
|
||||
& diSelection ?~ (x, 0,mempty)
|
||||
[] -> he & diCloseFilter .~ Nothing
|
||||
trybackspace' x ci = fromMaybe ci $ do
|
||||
str <- ci ^? ciFilter . _Just
|
||||
return $ case str of
|
||||
(_ : _) ->
|
||||
ci & ciFilter . _Just %~ init
|
||||
& ciSelection ?~ (x, 0,mempty)
|
||||
[] -> ci & ciFilter .~ Nothing
|
||||
he & filtset . _Just %~ init
|
||||
& selset ?~ (x, 0,mempty)
|
||||
[] -> he & filtset .~ Nothing
|
||||
di = w ^. hud . hudElement
|
||||
|
||||
updateEnterRegex :: World -> World
|
||||
|
||||
Reference in New Issue
Block a user