Pressing return on regex jumps to item
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
{-# LANGUAGE TupleSections #-}
|
{-# LANGUAGE TupleSections #-}
|
||||||
|
|
||||||
module Dodge.Inventory (
|
module Dodge.Inventory (
|
||||||
|
ssLookupDown,
|
||||||
ssLookupGT,
|
ssLookupGT,
|
||||||
ssSetCursor,
|
ssSetCursor,
|
||||||
firstPosSelectionSections,
|
firstPosSelectionSections,
|
||||||
|
|||||||
+76
-42
@@ -6,20 +6,20 @@ module Dodge.Update.Input (
|
|||||||
doRegexInput,
|
doRegexInput,
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Data.Monoid (First)
|
import qualified Data.IntMap.Strict as IM
|
||||||
import Dodge.Inventory
|
|
||||||
import Data.Maybe
|
|
||||||
import Dodge.DisplayInventory
|
|
||||||
import SelectionIntMap
|
|
||||||
import qualified Data.Map.Strict as M
|
|
||||||
import Data.Char
|
import Data.Char
|
||||||
|
import qualified Data.Map.Strict as M
|
||||||
|
import Data.Maybe
|
||||||
|
import Data.Monoid (First)
|
||||||
import Dodge.Base.You
|
import Dodge.Base.You
|
||||||
import Dodge.Button.Event
|
import Dodge.Button.Event
|
||||||
import Dodge.Combine
|
import Dodge.Combine
|
||||||
import Dodge.Creature.Action
|
import Dodge.Creature.Action
|
||||||
import Dodge.Data.Universe
|
import Dodge.Data.Universe
|
||||||
import Dodge.Debug.Terminal
|
import Dodge.Debug.Terminal
|
||||||
|
import Dodge.DisplayInventory
|
||||||
import Dodge.Event.Test
|
import Dodge.Event.Test
|
||||||
|
import Dodge.Inventory
|
||||||
import Dodge.Menu
|
import Dodge.Menu
|
||||||
import Dodge.Reloading
|
import Dodge.Reloading
|
||||||
import Dodge.Save
|
import Dodge.Save
|
||||||
@@ -27,6 +27,7 @@ import Dodge.Terminal.LeftButton
|
|||||||
import Dodge.WorldPos
|
import Dodge.WorldPos
|
||||||
import LensHelp
|
import LensHelp
|
||||||
import SDL
|
import SDL
|
||||||
|
import SelectionIntMap
|
||||||
|
|
||||||
--doTextInputOver' :: Universe -> ASetter' a String -> a -> a
|
--doTextInputOver' :: Universe -> ASetter' a String -> a -> a
|
||||||
--doTextInputOver' u p x = x & p %~ (++ map toUpper thetext)
|
--doTextInputOver' u p x = x & p %~ (++ map toUpper thetext)
|
||||||
@@ -38,7 +39,8 @@ import SDL
|
|||||||
-- | otherwise = id
|
-- | otherwise = id
|
||||||
|
|
||||||
doTextInputOver :: ASetter' Universe String -> Universe -> Universe
|
doTextInputOver :: ASetter' Universe String -> Universe -> Universe
|
||||||
doTextInputOver p u = u & p %~ (++ map toUpper thetext)
|
doTextInputOver p u =
|
||||||
|
u & p %~ (++ map toUpper thetext)
|
||||||
& checkBackspace
|
& checkBackspace
|
||||||
where
|
where
|
||||||
thetext = u ^. uvWorld . input . textInput
|
thetext = u ^. uvWorld . input . textInput
|
||||||
@@ -58,49 +60,71 @@ backspaceInputted u = case u ^. uvWorld . input . pressedKeys . at ScancodeBacks
|
|||||||
|
|
||||||
doSubInvRegexInput :: Universe -> Universe
|
doSubInvRegexInput :: Universe -> Universe
|
||||||
doSubInvRegexInput u
|
doSubInvRegexInput u
|
||||||
| backspacetonothing
|
| backspacetonothing =
|
||||||
= u & uvWorld . hud . hudElement . subInventory . subInvMap . smRegex .~ Nothing
|
u & uvWorld . hud . hudElement . subInventory . subInvMap . smRegex .~ Nothing
|
||||||
& uvWorld . hud . hudElement . subInventory . subInvMap %~ initialSelPos
|
& uvWorld . hud . hudElement . subInventory . subInvMap %~ initialSelPos
|
||||||
& uvWorld . hud . hudElement . subInventory . subInvMap %~ setShownIntMap
|
& uvWorld . hud . hudElement . subInventory . subInvMap %~ setShownIntMap
|
||||||
| endkeys || endmouse
|
| endkeys || endmouse =
|
||||||
= u & uvWorld . hud . hudElement . subInventory . subInvMap %~ initialSelPos
|
u & uvWorld . hud . hudElement . subInventory . subInvMap %~ initialSelPos
|
||||||
| otherwise = u & doTextInputOver (uvWorld . hud . hudElement . subInventory . subInvMap . smRegex . _Just)
|
| otherwise =
|
||||||
|
u & doTextInputOver (uvWorld . hud . hudElement . subInventory . subInvMap . smRegex . _Just)
|
||||||
& uvWorld . hud . hudElement . subInventory . subInvMap %~ setShownIntMap
|
& uvWorld . hud . hudElement . subInventory . subInvMap %~ setShownIntMap
|
||||||
where
|
where
|
||||||
endkeys = any
|
endkeys =
|
||||||
|
any
|
||||||
((== Just InitialPress) . (`M.lookup` pkeys))
|
((== Just InitialPress) . (`M.lookup` pkeys))
|
||||||
[ScancodeReturn, ScancodeEscape, ScancodeSlash]
|
[ScancodeReturn, ScancodeEscape, ScancodeSlash]
|
||||||
endmouse = Just True == (u ^? uvWorld . input . mouseButtons . ix ButtonLeft)
|
endmouse = Just True == (u ^? uvWorld . input . mouseButtons . ix ButtonLeft)
|
||||||
backspacetonothing = u ^? uvWorld . hud . hudElement . subInventory . subInvMap . smRegex . _Just == Just ""
|
backspacetonothing =
|
||||||
|
u ^? uvWorld . hud . hudElement . subInventory . subInvMap . smRegex . _Just == Just ""
|
||||||
&& ScancodeBackspace `M.lookup` pkeys == Just InitialPress
|
&& ScancodeBackspace `M.lookup` pkeys == Just InitialPress
|
||||||
pkeys = u ^. uvWorld . input . pressedKeys
|
pkeys = u ^. uvWorld . input . pressedKeys
|
||||||
|
|
||||||
doRegexInput :: Int
|
doRegexInput ::
|
||||||
-> ((Maybe String -> Identity (Maybe String))
|
Int ->
|
||||||
-> Manipulation -> Identity Manipulation)
|
( (Maybe String -> Identity (Maybe String)) ->
|
||||||
-> ((Maybe String
|
Manipulation ->
|
||||||
-> Const (First String) (Maybe String))
|
Identity Manipulation
|
||||||
-> Manipulation -> Const (First String) Manipulation)
|
) ->
|
||||||
-> Universe
|
( ( Maybe String ->
|
||||||
-> Universe
|
Const (First String) (Maybe String)
|
||||||
|
) ->
|
||||||
|
Manipulation ->
|
||||||
|
Const (First String) Manipulation
|
||||||
|
) ->
|
||||||
|
Universe ->
|
||||||
|
Universe
|
||||||
doRegexInput i crregex crregex' u
|
doRegexInput i crregex crregex' u
|
||||||
| backspacetonothing
|
| backspacetonothing =
|
||||||
= u
|
u
|
||||||
& uvWorld . cWorld . lWorld . creatures . ix 0 . crManipulation . crregex .~ Nothing
|
& uvWorld . cWorld . lWorld . creatures . ix 0 . crManipulation . crregex .~ Nothing
|
||||||
& uvWorld . hud . hudElement . diSections %~
|
& uvWorld . hud . hudElement . diSections
|
||||||
( ssSetCursor (ssLookupGT i 0)
|
%~ ( ssSetCursor (ssLookupGT i 0)
|
||||||
. (overSection (ssItems . at i .~ Nothing))
|
. (overSection (ssItems . at i .~ Nothing))
|
||||||
)
|
)
|
||||||
& uvWorld %~ setInvPosFromSS
|
& uvWorld %~ setInvPosFromSS
|
||||||
| endkeys || endmouse = u
|
| endkeys || endmouse = u
|
||||||
| otherwise = u & doTextInputOver
|
& uvWorld . cWorld . lWorld . creatures . ix 0 . crManipulation . crregex .~ Nothing
|
||||||
|
& uvWorld . hud . hudElement . diSections
|
||||||
|
%~ ( ssSetCursor (ssLookupDown (i+1) (j-1))
|
||||||
|
. (overSection (ssItems . at i .~ Nothing))
|
||||||
|
)
|
||||||
|
& uvWorld %~ setInvPosFromSS
|
||||||
|
| otherwise =
|
||||||
|
u
|
||||||
|
& doTextInputOver
|
||||||
(uvWorld . cWorld . lWorld . creatures . ix 0 . crManipulation . crregex . _Just)
|
(uvWorld . cWorld . lWorld . creatures . ix 0 . crManipulation . crregex . _Just)
|
||||||
where
|
where
|
||||||
endkeys = any
|
j = fromMaybe 0 $ do
|
||||||
|
itms <- u ^? uvWorld . hud . hudElement . diSections . sssSections . ix (i+1) . ssItems
|
||||||
|
fmap fst $ IM.lookupMin itms
|
||||||
|
endkeys =
|
||||||
|
any
|
||||||
((== Just InitialPress) . (`M.lookup` pkeys))
|
((== Just InitialPress) . (`M.lookup` pkeys))
|
||||||
[ScancodeReturn, ScancodeEscape, ScancodeSlash]
|
[ScancodeReturn, ScancodeEscape, ScancodeSlash]
|
||||||
endmouse = Just True == (u ^? uvWorld . input . mouseButtons . ix ButtonLeft)
|
endmouse = Just True == (u ^? uvWorld . input . mouseButtons . ix ButtonLeft)
|
||||||
backspacetonothing = u ^? uvWorld . cWorld . lWorld . creatures . ix 0 . crManipulation . crregex' . _Just == Just ""
|
backspacetonothing =
|
||||||
|
u ^? uvWorld . cWorld . lWorld . creatures . ix 0 . crManipulation . crregex' . _Just == Just ""
|
||||||
&& ScancodeBackspace `M.lookup` pkeys == Just InitialPress
|
&& ScancodeBackspace `M.lookup` pkeys == Just InitialPress
|
||||||
pkeys = u ^. uvWorld . input . pressedKeys
|
pkeys = u ^. uvWorld . input . pressedKeys
|
||||||
|
|
||||||
@@ -111,7 +135,8 @@ doInputScreenInput s u =
|
|||||||
where
|
where
|
||||||
pkeys = u ^. uvWorld . input . pressedKeys
|
pkeys = u ^. uvWorld . input . pressedKeys
|
||||||
checkEndStatus
|
checkEndStatus
|
||||||
| ScancodeReturn `M.member` pkeys = (uvScreenLayers %~ tail)
|
| ScancodeReturn `M.member` pkeys =
|
||||||
|
(uvScreenLayers %~ tail)
|
||||||
. applyTerminalString (words s)
|
. applyTerminalString (words s)
|
||||||
| ScancodeEscape `M.member` pkeys = uvScreenLayers %~ tail
|
| ScancodeEscape `M.member` pkeys = uvScreenLayers %~ tail
|
||||||
| otherwise = id
|
| otherwise = id
|
||||||
@@ -162,8 +187,9 @@ updateBackspaceRegex :: World -> World
|
|||||||
updateBackspaceRegex w = case di ^? subInventory of
|
updateBackspaceRegex w = case di ^? subInventory of
|
||||||
Just NoSubInventory | invfocus -> 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 NoSubInventory | closefocus -> w & cWorld . lWorld . creatures . ix 0 . crManipulation %~ trybackspaceclose
|
||||||
Just CombineInventory {} -> w & hud . hudElement . subInventory . subInvMap %~
|
Just CombineInventory{} ->
|
||||||
( ( smRegex %~ enternonzeroregex )
|
w & hud . hudElement . subInventory . subInvMap
|
||||||
|
%~ ( (smRegex %~ enternonzeroregex)
|
||||||
. (smSelPos ?~ 0)
|
. (smSelPos ?~ 0)
|
||||||
. (setShownIntMap)
|
. (setShownIntMap)
|
||||||
)
|
)
|
||||||
@@ -176,12 +202,14 @@ updateBackspaceRegex w = case di ^? subInventory of
|
|||||||
i <- di ^? diSections . sssSelPos . _Just
|
i <- di ^? diSections . sssSelPos . _Just
|
||||||
return $ i == 2 || i == 3
|
return $ i == 2 || i == 3
|
||||||
trybackspace cm = case cm ^? invRegex . _Just of
|
trybackspace cm = case cm ^? invRegex . _Just of
|
||||||
Just (_:_) -> cm & invRegex . _Just %~ init
|
Just (_ : _) ->
|
||||||
|
cm & invRegex . _Just %~ init
|
||||||
& manObject .~ InInventory SortInventory
|
& manObject .~ InInventory SortInventory
|
||||||
Just [] -> cm & invRegex .~ Nothing
|
Just [] -> cm & invRegex .~ Nothing
|
||||||
Nothing -> cm
|
Nothing -> cm
|
||||||
trybackspaceclose cm = case cm ^? closeRegex . _Just of
|
trybackspaceclose cm = case cm ^? closeRegex . _Just of
|
||||||
Just (_:_) -> cm & closeRegex . _Just %~ init
|
Just (_ : _) ->
|
||||||
|
cm & closeRegex . _Just %~ init
|
||||||
& manObject .~ InNearby SortNearby
|
& manObject .~ InNearby SortNearby
|
||||||
Just [] -> cm & closeRegex .~ Nothing
|
Just [] -> cm & closeRegex .~ Nothing
|
||||||
Nothing -> cm
|
Nothing -> cm
|
||||||
@@ -191,16 +219,21 @@ updateBackspaceRegex w = case di ^? subInventory of
|
|||||||
|
|
||||||
updateEnterRegex :: World -> World
|
updateEnterRegex :: World -> World
|
||||||
updateEnterRegex w = case w ^? hud . hudElement . subInventory of
|
updateEnterRegex w = case w ^? hud . hudElement . subInventory of
|
||||||
Just NoSubInventory | invfocus -> w & cWorld . lWorld . creatures . ix 0 . crManipulation %~
|
Just NoSubInventory
|
||||||
( ( invRegex %~ startregex )
|
| invfocus ->
|
||||||
|
w & cWorld . lWorld . creatures . ix 0 . crManipulation
|
||||||
|
%~ ( (invRegex %~ startregex)
|
||||||
. (manObject .~ InInventory SortInventory)
|
. (manObject .~ InInventory SortInventory)
|
||||||
)
|
)
|
||||||
Just NoSubInventory | closefocus -> w & cWorld . lWorld . creatures . ix 0 . crManipulation %~
|
Just NoSubInventory
|
||||||
( ( closeRegex %~ startregex )
|
| closefocus ->
|
||||||
|
w & cWorld . lWorld . creatures . ix 0 . crManipulation
|
||||||
|
%~ ( (closeRegex %~ startregex)
|
||||||
. (manObject .~ InNearby SortNearby)
|
. (manObject .~ InNearby SortNearby)
|
||||||
)
|
)
|
||||||
Just CombineInventory {} -> w & hud . hudElement . subInventory . subInvMap %~
|
Just CombineInventory{} ->
|
||||||
( setShownIntMap
|
w & hud . hudElement . subInventory . subInvMap
|
||||||
|
%~ ( setShownIntMap
|
||||||
. (smSelPos ?~ 0)
|
. (smSelPos ?~ 0)
|
||||||
. (smRegex %~ enterregex)
|
. (smRegex %~ enterregex)
|
||||||
)
|
)
|
||||||
@@ -233,8 +266,8 @@ spaceAction w = case w ^?! hud . hudElement of
|
|||||||
Just (_, Left flit) -> pickUpItem 0 flit w
|
Just (_, Left flit) -> pickUpItem 0 flit w
|
||||||
Just (_, Right but) -> doButtonEvent (_btEvent but) but w
|
Just (_, Right but) -> doButtonEvent (_btEvent but) but w
|
||||||
_ -> w
|
_ -> w
|
||||||
DisplayInventory {_subInventory = DisplayTerminal{}}
|
DisplayInventory{_subInventory = DisplayTerminal{}} ->
|
||||||
-> w & hud . hudElement . subInventory .~ NoSubInventory
|
w & hud . hudElement . subInventory .~ NoSubInventory
|
||||||
_ -> w & hud . hudElement . subInventory .~ NoSubInventory
|
_ -> w & hud . hudElement . subInventory .~ NoSubInventory
|
||||||
where
|
where
|
||||||
--theLoc = doWorldPos (fst (_seenLocations (_cWorld w) IM.! _selLocation (_cWorld w))) w
|
--theLoc = doWorldPos (fst (_seenLocations (_cWorld w) IM.! _selLocation (_cWorld w))) w
|
||||||
@@ -244,6 +277,7 @@ toggleMap :: Universe -> Universe
|
|||||||
toggleMap u = case u ^?! uvWorld . hud . hudElement of
|
toggleMap u = case u ^?! uvWorld . hud . hudElement of
|
||||||
DisplayCarte -> u & uvWorld . hud . hudElement .~ DisplayInventory{_subInventory = NoSubInventory, _diSections = defaultDisplaySections}
|
DisplayCarte -> u & uvWorld . hud . hudElement .~ DisplayInventory{_subInventory = NoSubInventory, _diSections = defaultDisplaySections}
|
||||||
_ -> u & uvWorld . hud . hudElement .~ DisplayCarte
|
_ -> u & uvWorld . hud . hudElement .~ DisplayCarte
|
||||||
|
|
||||||
-- where
|
-- where
|
||||||
-- w = u ^. uvWorld
|
-- w = u ^. uvWorld
|
||||||
-- cfig = u ^. uvConfig
|
-- cfig = u ^. uvConfig
|
||||||
|
|||||||
Reference in New Issue
Block a user