Move inventory filter to different section of selection list
This commit is contained in:
+51
-44
@@ -6,7 +6,7 @@ module Dodge.Update.Input (
|
||||
doInvRegexInput,
|
||||
) where
|
||||
|
||||
import Color
|
||||
import Dodge.Inventory
|
||||
import Data.Maybe
|
||||
import Dodge.DisplayInventory
|
||||
import SelectionIntMap
|
||||
@@ -19,7 +19,6 @@ import Dodge.Creature.Action
|
||||
import Dodge.Data.Universe
|
||||
import Dodge.Debug.Terminal
|
||||
import Dodge.Event.Test
|
||||
import Dodge.Inventory
|
||||
import Dodge.Menu
|
||||
import Dodge.Reloading
|
||||
import Dodge.Save
|
||||
@@ -28,14 +27,14 @@ import Dodge.WorldPos
|
||||
import LensHelp
|
||||
import SDL
|
||||
|
||||
doTextInputOver' :: Universe -> ASetter' a String -> a -> a
|
||||
doTextInputOver' u p x = x & p %~ (++ map toUpper thetext)
|
||||
& checkBackspace
|
||||
where
|
||||
thetext = u ^. uvWorld . input . textInput
|
||||
checkBackspace
|
||||
| backspaceInputted u = p %~ doBackspace
|
||||
| otherwise = id
|
||||
--doTextInputOver' :: Universe -> ASetter' a String -> a -> a
|
||||
--doTextInputOver' u p x = x & p %~ (++ map toUpper thetext)
|
||||
-- & checkBackspace
|
||||
-- where
|
||||
-- thetext = u ^. uvWorld . input . textInput
|
||||
-- checkBackspace
|
||||
-- | backspaceInputted u = p %~ doBackspace
|
||||
-- | otherwise = id
|
||||
|
||||
doTextInputOver :: ASetter' Universe String -> Universe -> Universe
|
||||
doTextInputOver p u = u & p %~ (++ map toUpper thetext)
|
||||
@@ -78,24 +77,28 @@ doSubInvRegexInput u
|
||||
doInvRegexInput :: Universe -> Universe
|
||||
doInvRegexInput u
|
||||
| backspacetonothing
|
||||
= u & uvWorld . hud . hudElement . diSections %~ overSection
|
||||
( ( ssRegex .~ EmptyRegex )
|
||||
. ( ssItems . at (-1) .~ Nothing)
|
||||
= u
|
||||
& uvWorld . cWorld . lWorld . creatures . ix 0 . crManipulation . invRegex .~ Nothing
|
||||
& uvWorld . hud . hudElement . diSections %~
|
||||
( ssSetCursor (ssLookupGT 0 (-1))
|
||||
. (overSection (ssItems . at (-1) .~ Nothing))
|
||||
)
|
||||
-- . initialSelPos )
|
||||
& 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))
|
||||
-- | otherwise = u & doTextInputOver (uvWorld . hud . hudElement . subInventory . subInvMap . smRegex . _Just)
|
||||
-- | otherwise = u & uvWorld . hud . hudElement . diSections %~
|
||||
-- --overSection (doTextInputOver' u (ssRegex . regexString))
|
||||
-- overSection (id)
|
||||
| otherwise = u & doTextInputOver
|
||||
(uvWorld . cWorld . lWorld . creatures . ix 0 . crManipulation . invRegex . _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 . hud . hudElement . subInventory . subInvMap . smRegex . _Just == Just ""
|
||||
backspacetonothing = u ^? uvWorld . cWorld . lWorld . creatures . ix 0 . crManipulation . invRegex . _Just == Just ""
|
||||
&& ScancodeBackspace `M.lookup` pkeys == Just InitialPress
|
||||
pkeys = u ^. uvWorld . input . pressedKeys
|
||||
|
||||
@@ -143,8 +146,8 @@ updateInitialPressInGame uv sc = case sc of
|
||||
ScancodeX -> uv & uvWorld %~ toggleTweakInv
|
||||
ScancodeC -> over uvWorld toggleCombineInv uv
|
||||
-- the following should be put in a more sensible place
|
||||
ScancodeSlash -> uv & uvWorld . hud . hudElement %~ updateEnterRegex
|
||||
ScancodeBackspace -> uv & uvWorld . hud . hudElement %~ updateBackspaceRegex
|
||||
ScancodeSlash -> uv & uvWorld %~ updateEnterRegex
|
||||
ScancodeBackspace -> uv & uvWorld %~ updateBackspaceRegex
|
||||
_ -> uv
|
||||
|
||||
updateLongPressInGame :: Universe -> Scancode -> Universe
|
||||
@@ -153,36 +156,40 @@ updateLongPressInGame uv sc = case sc of
|
||||
ScancodeSpace -> over uvWorld spaceAction uv
|
||||
_ -> uv
|
||||
|
||||
updateBackspaceRegex :: HUDElement -> HUDElement
|
||||
updateBackspaceRegex di = case di ^? subInventory of
|
||||
Just NoSubInventory -> di & diSections %~ overSection
|
||||
( (ssRegex %~ backssregex)
|
||||
. (ssCursor ?~ SectionCursor (-1) 0 1 white)
|
||||
)
|
||||
Just CombineInventory {} -> di
|
||||
& subInventory . subInvMap . smRegex %~ enternonzeroregex
|
||||
& subInventory . subInvMap . smSelPos ?~ 0
|
||||
& subInventory . subInvMap %~ setShownIntMap
|
||||
_ -> di
|
||||
updateBackspaceRegex :: World -> World
|
||||
updateBackspaceRegex w = case di ^? subInventory of
|
||||
Just NoSubInventory -> w & cWorld . lWorld . creatures . ix 0 . crManipulation %~ trybackspace
|
||||
Just CombineInventory {} -> w & hud . hudElement . subInventory . subInvMap %~
|
||||
( ( smRegex %~ enternonzeroregex )
|
||||
. ( smSelPos ?~ 0 )
|
||||
. ( setShownIntMap )
|
||||
)
|
||||
_ -> w
|
||||
where
|
||||
trybackspace cm = case cm ^? invRegex . _Just of
|
||||
Just (_:_) -> cm & invRegex . _Just %~ init
|
||||
& manObject .~ InInventory SortInventory
|
||||
Just [] -> cm & invRegex .~ Nothing
|
||||
Nothing -> cm
|
||||
di = w ^. hud . hudElement
|
||||
enternonzeroregex (Just (x:xs)) = Just (init (x:xs))
|
||||
enternonzeroregex smr = smr
|
||||
backssregex (Regex (x:xs)) = Regex (init (x:xs))
|
||||
backssregex x = x
|
||||
|
||||
updateEnterRegex :: HUDElement -> HUDElement
|
||||
updateEnterRegex di = case di ^? subInventory of
|
||||
Just NoSubInventory -> di & diSections %~ overSection
|
||||
( (ssRegex %~ enterssregex)
|
||||
updateEnterRegex :: World -> World
|
||||
updateEnterRegex w = case w ^? hud . hudElement . subInventory of
|
||||
Just NoSubInventory -> w & cWorld . lWorld . creatures . ix 0 . crManipulation %~
|
||||
( ( invRegex %~ startregex )
|
||||
. ( manObject .~ InInventory SortInventory)
|
||||
)
|
||||
Just CombineInventory {} -> di
|
||||
& subInventory . subInvMap . smRegex %~ enterregex
|
||||
& subInventory . subInvMap . smSelPos ?~ 0
|
||||
& subInventory . subInvMap %~ setShownIntMap
|
||||
_ -> di
|
||||
Just CombineInventory {} -> w & hud . hudElement . subInventory . subInvMap %~
|
||||
( setShownIntMap
|
||||
. (smSelPos ?~ 0 )
|
||||
. ( smRegex %~ enterregex)
|
||||
)
|
||||
_ -> w
|
||||
where
|
||||
enterssregex EmptyRegex = Regex ""
|
||||
enterssregex x = x
|
||||
startregex Nothing = Just ""
|
||||
startregex x = x
|
||||
enterregex Nothing = Just ""
|
||||
enterregex (Just str) = Just str
|
||||
|
||||
|
||||
Reference in New Issue
Block a user