Implement filter on nearby objects
This commit is contained in:
@@ -4,6 +4,7 @@ module Dodge.Update.Input (
|
||||
doInputScreenInput,
|
||||
doSubInvRegexInput,
|
||||
doInvRegexInput,
|
||||
doCloseRegexInput,
|
||||
) where
|
||||
|
||||
import Dodge.Inventory
|
||||
@@ -74,6 +75,34 @@ doSubInvRegexInput u
|
||||
&& ScancodeBackspace `M.lookup` pkeys == Just InitialPress
|
||||
pkeys = u ^. uvWorld . input . pressedKeys
|
||||
|
||||
doCloseRegexInput :: Universe -> Universe
|
||||
doCloseRegexInput u
|
||||
| backspacetonothing
|
||||
= u
|
||||
& uvWorld . cWorld . lWorld . creatures . ix 0 . crManipulation . closeRegex .~ Nothing
|
||||
& uvWorld . hud . hudElement . diSections %~
|
||||
( ssSetCursor (ssLookupGT 0 2)
|
||||
. (overSection (ssItems . at 2 .~ Nothing))
|
||||
)
|
||||
& uvWorld %~ setInvPosFromSS
|
||||
-- & uvWorld . hud . hudElement . diSections %~ setShownIntMap
|
||||
| endkeys || endmouse = u
|
||||
-- = u & uvWorld . hud . hudElement . diSections %~ initialSelPos
|
||||
-- | otherwise = u & uvWorld . hud . hudElement . diSections %~
|
||||
-- --overSection (doTextInputOver' u (ssRegex . regexString))
|
||||
-- overSection (id)
|
||||
| otherwise = u & doTextInputOver
|
||||
(uvWorld . cWorld . lWorld . creatures . ix 0 . crManipulation . closeRegex . _Just)
|
||||
-- & uvWorld . hud . hudElement . subInventory . subInvMap %~ setShownIntMap
|
||||
where
|
||||
endkeys = any
|
||||
( (== Just InitialPress) . (`M.lookup` pkeys))
|
||||
[ScancodeReturn,ScancodeEscape,ScancodeSlash]
|
||||
endmouse = Just True == (u ^? uvWorld . input . mouseButtons . ix ButtonLeft)
|
||||
backspacetonothing = u ^? uvWorld . cWorld . lWorld . creatures . ix 0 . crManipulation . closeRegex . _Just == Just ""
|
||||
&& ScancodeBackspace `M.lookup` pkeys == Just InitialPress
|
||||
pkeys = u ^. uvWorld . input . pressedKeys
|
||||
|
||||
doInvRegexInput :: Universe -> Universe
|
||||
doInvRegexInput u
|
||||
| backspacetonothing
|
||||
@@ -158,7 +187,8 @@ updateLongPressInGame uv sc = case sc of
|
||||
|
||||
updateBackspaceRegex :: World -> World
|
||||
updateBackspaceRegex w = case di ^? subInventory of
|
||||
Just NoSubInventory -> w & cWorld . lWorld . creatures . ix 0 . crManipulation %~ trybackspace
|
||||
Just NoSubInventory | invfocus -> w & cWorld . lWorld . creatures . ix 0 . crManipulation %~ trybackspace
|
||||
Just NoSubInventory | closefocus -> w & cWorld . lWorld . creatures . ix 0 . crManipulation %~ trybackspaceclose
|
||||
Just CombineInventory {} -> w & hud . hudElement . subInventory . subInvMap %~
|
||||
( ( smRegex %~ enternonzeroregex )
|
||||
. ( smSelPos ?~ 0 )
|
||||
@@ -166,21 +196,36 @@ updateBackspaceRegex w = case di ^? subInventory of
|
||||
)
|
||||
_ -> w
|
||||
where
|
||||
invfocus = fromMaybe False $ do
|
||||
i <- di ^? diSections . sssSelPos . _Just
|
||||
return $ i == (-1) || i == 0
|
||||
closefocus = fromMaybe False $ do
|
||||
i <- di ^? diSections . sssSelPos . _Just
|
||||
return $ i == 2 || i == 3
|
||||
trybackspace cm = case cm ^? invRegex . _Just of
|
||||
Just (_:_) -> cm & invRegex . _Just %~ init
|
||||
& manObject .~ InInventory SortInventory
|
||||
Just [] -> cm & invRegex .~ Nothing
|
||||
Nothing -> cm
|
||||
trybackspaceclose cm = case cm ^? closeRegex . _Just of
|
||||
Just (_:_) -> cm & closeRegex . _Just %~ init
|
||||
& manObject .~ InNearby SortNearby
|
||||
Just [] -> cm & closeRegex .~ Nothing
|
||||
Nothing -> cm
|
||||
di = w ^. hud . hudElement
|
||||
enternonzeroregex (Just (x:xs)) = Just (init (x:xs))
|
||||
enternonzeroregex smr = smr
|
||||
|
||||
updateEnterRegex :: World -> World
|
||||
updateEnterRegex w = case w ^? hud . hudElement . subInventory of
|
||||
Just NoSubInventory -> w & cWorld . lWorld . creatures . ix 0 . crManipulation %~
|
||||
Just NoSubInventory | invfocus -> w & cWorld . lWorld . creatures . ix 0 . crManipulation %~
|
||||
( ( invRegex %~ startregex )
|
||||
. ( manObject .~ InInventory SortInventory)
|
||||
)
|
||||
Just NoSubInventory | closefocus -> w & cWorld . lWorld . creatures . ix 0 . crManipulation %~
|
||||
( ( closeRegex %~ startregex )
|
||||
. ( manObject .~ InNearby SortNearby)
|
||||
)
|
||||
Just CombineInventory {} -> w & hud . hudElement . subInventory . subInvMap %~
|
||||
( setShownIntMap
|
||||
. (smSelPos ?~ 0 )
|
||||
@@ -188,6 +233,13 @@ updateEnterRegex w = case w ^? hud . hudElement . subInventory of
|
||||
)
|
||||
_ -> w
|
||||
where
|
||||
di = w ^. hud . hudElement
|
||||
invfocus = fromMaybe False $ do
|
||||
i <- di ^? diSections . sssSelPos . _Just
|
||||
return $ i == (-1) || i == 0
|
||||
closefocus = fromMaybe False $ do
|
||||
i <- di ^? diSections . sssSelPos . _Just
|
||||
return $ i == 2 || i == 3
|
||||
startregex Nothing = Just ""
|
||||
startregex x = x
|
||||
enterregex Nothing = Just ""
|
||||
|
||||
Reference in New Issue
Block a user