Work towards unifying all in game input
This commit is contained in:
@@ -19,7 +19,7 @@ import qualified SDL
|
|||||||
-- | The AI equivalent for your control.
|
-- | The AI equivalent for your control.
|
||||||
yourControl :: Creature -> World -> World
|
yourControl :: Creature -> World -> World
|
||||||
yourControl cr w
|
yourControl cr w
|
||||||
| inputFocus w = w
|
| inInputFocus w = w
|
||||||
| not intopinv = w & cWorld . lWorld . creatures . ix (_crID cr)
|
| not intopinv = w & cWorld . lWorld . creatures . ix (_crID cr)
|
||||||
%~ wasdWithAiming w (_mvSpeed $ _crMvType cr)
|
%~ wasdWithAiming w (_mvSpeed $ _crMvType cr)
|
||||||
| otherwise =
|
| otherwise =
|
||||||
|
|||||||
@@ -43,6 +43,11 @@ data SelectionSections a = SelectionSections
|
|||||||
, _sssSelPos :: Maybe (Int,Int)
|
, _sssSelPos :: Maybe (Int,Int)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
--data SSSExtra :: SSSExtra
|
||||||
|
-- { _sssSelPos :: Maybe (Int,Int)
|
||||||
|
-- , _sssFilters :: IntMap (Maybe String
|
||||||
|
-- }
|
||||||
|
|
||||||
data SectionCursor = SectionCursor
|
data SectionCursor = SectionCursor
|
||||||
{ _scurPos :: Int
|
{ _scurPos :: Int
|
||||||
, _scurSize :: Int
|
, _scurSize :: Int
|
||||||
|
|||||||
+110
-22
@@ -1,13 +1,19 @@
|
|||||||
module Dodge.InputFocus
|
module Dodge.InputFocus (
|
||||||
( inTermFocus
|
inTermFocus,
|
||||||
, inInvRegex
|
inInvRegex,
|
||||||
, inCloseRegex
|
inCloseRegex,
|
||||||
, inSubInvRegex
|
inSubInvRegex,
|
||||||
, inputFocus
|
inputFocus,
|
||||||
) where
|
inInputFocus,
|
||||||
|
regexScope,
|
||||||
|
regexFocus,
|
||||||
|
-- , inputFocus'
|
||||||
|
) where
|
||||||
|
|
||||||
import Dodge.Data.SelectionList
|
import Control.Monad
|
||||||
|
import Data.IntMap.Strict (IntMap)
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
|
import Dodge.Data.SelectionList
|
||||||
import Dodge.Data.World
|
import Dodge.Data.World
|
||||||
import LensHelp
|
import LensHelp
|
||||||
|
|
||||||
@@ -18,23 +24,105 @@ inTermFocus w = fromMaybe False $ do
|
|||||||
connectionstatus <- w ^? cWorld . lWorld . terminals . ix tmid . tmStatus
|
connectionstatus <- w ^? cWorld . lWorld . terminals . ix tmid . tmStatus
|
||||||
return $ hasfocus && connectionstatus == TerminalReady
|
return $ hasfocus && connectionstatus == TerminalReady
|
||||||
|
|
||||||
inInvRegex :: World -> Bool
|
regexScope ::
|
||||||
|
(Applicative f1, Applicative f2, Num c) =>
|
||||||
|
World ->
|
||||||
|
Maybe
|
||||||
|
( ( IntMap (Maybe String) ->
|
||||||
|
f1 (IntMap (Maybe String))
|
||||||
|
) ->
|
||||||
|
HUDElement ->
|
||||||
|
f1 HUDElement
|
||||||
|
, (Maybe (Int, Int) -> f2 (Maybe (Int, Int))) ->
|
||||||
|
HUDElement ->
|
||||||
|
f2 HUDElement
|
||||||
|
, c
|
||||||
|
)
|
||||||
|
regexScope w = case w ^? hud . hudElement . subInventory of
|
||||||
|
Just NoSubInventory -> case he ^? diSections . fssSections . sssSelPos . _Just of
|
||||||
|
Just (-1, _) -> di (-1)
|
||||||
|
Just (0, _) -> di (-1)
|
||||||
|
Just (2, _) -> di 2
|
||||||
|
Just (3, _) -> di 2
|
||||||
|
_ -> Nothing
|
||||||
|
Just CombineInventory{} ->
|
||||||
|
Just (subInventory . ciSections . fssFilters, subInventory . ciSections . fssSections . sssSelPos, (-1))
|
||||||
|
_ -> Nothing
|
||||||
|
where
|
||||||
|
di x = Just (diSections . fssFilters, diSections . fssSections . sssSelPos, x)
|
||||||
|
he = w ^. hud . hudElement
|
||||||
|
|
||||||
|
regexFocus ::
|
||||||
|
(Applicative f1, Applicative f2, Num c) =>
|
||||||
|
World ->
|
||||||
|
Maybe
|
||||||
|
( ( IntMap (Maybe String) ->
|
||||||
|
f1 (IntMap (Maybe String))
|
||||||
|
) ->
|
||||||
|
HUDElement ->
|
||||||
|
f1 HUDElement
|
||||||
|
, (Maybe (Int, Int) -> f2 (Maybe (Int, Int))) ->
|
||||||
|
HUDElement ->
|
||||||
|
f2 HUDElement
|
||||||
|
, c
|
||||||
|
)
|
||||||
|
regexFocus w = case w ^? hud . hudElement . subInventory of
|
||||||
|
Just NoSubInventory -> case he ^? diSections . fssSections . sssSelPos . _Just of
|
||||||
|
Just (-1, _) -> di (-1)
|
||||||
|
Just (2, _) -> di 2
|
||||||
|
_ -> Nothing
|
||||||
|
Just CombineInventory{} ->
|
||||||
|
Just (subInventory . ciSections . fssFilters, subInventory . ciSections . fssSections . sssSelPos, (-1))
|
||||||
|
_ -> Nothing
|
||||||
|
where
|
||||||
|
di x = Just (diSections . fssFilters, diSections . fssSections . sssSelPos, x)
|
||||||
|
he = w ^. hud . hudElement
|
||||||
|
|
||||||
|
inInputFocus :: World -> Bool
|
||||||
|
inInputFocus = isJust . inputFocusI
|
||||||
|
|
||||||
|
inputFocusI :: World -> Maybe ((String -> Identity String) -> World -> Identity World)
|
||||||
|
inputFocusI = inputFocus
|
||||||
|
|
||||||
|
inputFocus ::
|
||||||
|
Applicative f =>
|
||||||
|
World ->
|
||||||
|
Maybe ((String -> f String) -> World -> f World)
|
||||||
|
inputFocus w = case w ^? hud . hudElement . subInventory of
|
||||||
|
Just NoSubInventory -> case he ^? diSections . fssSections . sssSelPos . _Just of
|
||||||
|
Just (-1, _) -> di (-1)
|
||||||
|
Just (2, _) -> di 2
|
||||||
|
_ -> Nothing
|
||||||
|
Just CombineInventory{} -> case he ^? subInventory . ciSections . fssSections . sssSelPos . _Just of
|
||||||
|
Just (-1, _) -> Just $ hud . hudElement . subInventory . ciSections . fssFilters . ix (-1) . _Just
|
||||||
|
_ -> Nothing
|
||||||
|
Just DisplayTerminal{_termID = tmid} -> do
|
||||||
|
hasfocus <- w ^? cWorld . lWorld . terminals . ix tmid . tmInput . tiFocus
|
||||||
|
connectionstatus <- w ^? cWorld . lWorld . terminals . ix tmid . tmStatus
|
||||||
|
guard $ hasfocus && connectionstatus == TerminalReady
|
||||||
|
return $ cWorld . lWorld . terminals . ix tmid . tmInput . tiText
|
||||||
|
_ -> Nothing
|
||||||
|
where
|
||||||
|
di x = Just $ hud . hudElement . diSections . fssFilters . ix x . _Just
|
||||||
|
he = w ^. hud . hudElement
|
||||||
|
|
||||||
|
inInvRegex :: World -> Bool
|
||||||
inInvRegex w = fromMaybe False $ do
|
inInvRegex w = fromMaybe False $ do
|
||||||
sss <- w ^? hud . hudElement . diSections . fssSections
|
sss <- w ^? hud . hudElement . diSections . fssSections
|
||||||
i <- sss ^? sssSelPos . _Just . _1
|
i <- sss ^? sssSelPos . _Just . _1
|
||||||
return $ i == (-1)
|
return $ i == (-1)
|
||||||
|
|
||||||
inCloseRegex :: World -> Bool
|
inCloseRegex :: World -> Bool
|
||||||
inCloseRegex w = fromMaybe False $ do
|
inCloseRegex w = fromMaybe False $ do
|
||||||
sss <- w ^? hud . hudElement . diSections . fssSections
|
sss <- w ^? hud . hudElement . diSections . fssSections
|
||||||
i <- sss ^? sssSelPos . _Just . _1
|
i <- sss ^? sssSelPos . _Just . _1
|
||||||
return $ i == 2
|
return $ i == 2
|
||||||
|
|
||||||
inSubInvRegex :: World -> Bool
|
inSubInvRegex :: World -> Bool
|
||||||
inSubInvRegex w = fromMaybe False $ do
|
inSubInvRegex w = fromMaybe False $ do
|
||||||
sss <- w ^? hud . hudElement . subInventory . ciSections . fssSections
|
sss <- w ^? hud . hudElement . subInventory . ciSections . fssSections
|
||||||
i <- sss ^? sssSelPos . _Just . _1
|
i <- sss ^? sssSelPos . _Just . _1
|
||||||
return $ i == (-1)
|
return $ i == (-1)
|
||||||
|
|
||||||
inputFocus :: World -> Bool
|
--inputFocus :: World -> Bool
|
||||||
inputFocus w = inTermFocus w || inSubInvRegex w || inInvRegex w || inCloseRegex w
|
--inputFocus w = inTermFocus w || inSubInvRegex w || inInvRegex w || inCloseRegex w
|
||||||
|
|||||||
@@ -194,7 +194,7 @@ rotateCamera cfig w
|
|||||||
| keydown SDL.ScancodeE = over cWorld (rotateCameraBy (-0.025)) w
|
| keydown SDL.ScancodeE = over cWorld (rotateCameraBy (-0.025)) w
|
||||||
| otherwise = ifConfigWallRotate cfig w
|
| otherwise = ifConfigWallRotate cfig w
|
||||||
where
|
where
|
||||||
keydown scode = scode `M.member` _pressedKeys (_input w) && not (inputFocus w)
|
keydown scode = scode `M.member` _pressedKeys (_input w) && not (inInputFocus w)
|
||||||
|
|
||||||
zoomFromItem ::
|
zoomFromItem ::
|
||||||
ItZoom ->
|
ItZoom ->
|
||||||
|
|||||||
+10
-13
@@ -59,6 +59,9 @@ updateUseInputInGame h u = case h of
|
|||||||
CombineInventory {_ciSections = FilterableSections {_fssSections = sss}}
|
CombineInventory {_ciSections = FilterableSections {_fssSections = sss}}
|
||||||
| inSubInvRegex (u ^. uvWorld) -> u & uvWorld . hud . hudElement . subInventory . ciSections %~ doRegexInput u (-1)
|
| inSubInvRegex (u ^. uvWorld) -> u & uvWorld . hud . hudElement . subInventory . ciSections %~ doRegexInput u (-1)
|
||||||
| lbinitialpress -> maybeExitCombine $ over uvWorld (tryCombine sss) u
|
| lbinitialpress -> maybeExitCombine $ over uvWorld (tryCombine sss) u
|
||||||
|
-- _ -> case regexFocus w of
|
||||||
|
-- Nothing -> M.foldlWithKey' updateKeyInGame u pkeys
|
||||||
|
-- Just (filtpoint,selpoint,i) -> u & uvWorld . p %~ doRegexInput
|
||||||
_ | inInvRegex (u ^. uvWorld) -> u & uvWorld . hud . hudElement . diSections %~ doRegexInput u (-1)
|
_ | inInvRegex (u ^. uvWorld) -> u & uvWorld . hud . hudElement . diSections %~ doRegexInput u (-1)
|
||||||
_ | inCloseRegex (u ^. uvWorld) -> u & uvWorld . hud . hudElement . diSections %~ doRegexInput u 2
|
_ | inCloseRegex (u ^. uvWorld) -> u & uvWorld . hud . hudElement . diSections %~ doRegexInput u 2
|
||||||
_ -> M.foldlWithKey' updateKeyInGame u pkeys
|
_ -> M.foldlWithKey' updateKeyInGame u pkeys
|
||||||
@@ -82,13 +85,6 @@ maybeExitCombine u
|
|||||||
|
|
||||||
doTextInputOver :: ASetter' Universe String -> Universe -> Universe
|
doTextInputOver :: ASetter' Universe String -> Universe -> Universe
|
||||||
doTextInputOver p u = doTextInputOver' u p u
|
doTextInputOver p u = doTextInputOver' u p u
|
||||||
-- u & 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' :: Universe -> ASetter' a String -> a -> a
|
||||||
doTextInputOver' u p x =
|
doTextInputOver' u p x =
|
||||||
@@ -219,21 +215,22 @@ updateEnterRegex w = case w ^? hud . hudElement . subInventory of
|
|||||||
| secfocus (-1) 0 ->
|
| secfocus (-1) 0 ->
|
||||||
w & cWorld . lWorld . creatures . ix 0 . crManipulation . manObject
|
w & cWorld . lWorld . creatures . ix 0 . crManipulation . manObject
|
||||||
.~ InInventory SortInventory
|
.~ InInventory SortInventory
|
||||||
& hud . hudElement . diSections . fssFilters . ix (-1) %~ enterregex
|
& hud . hudElement . diSections %~ enterregex (-1)
|
||||||
Just NoSubInventory
|
Just NoSubInventory
|
||||||
| secfocus 2 3 ->
|
| secfocus 2 3 ->
|
||||||
w & cWorld . lWorld . creatures . ix 0 . crManipulation . manObject .~ InNearby SortNearby
|
w & cWorld . lWorld . creatures . ix 0 . crManipulation . manObject .~ InNearby SortNearby
|
||||||
& hud . hudElement . diSections . fssFilters . ix 2 %~ enterregex
|
& hud . hudElement . diSections %~ enterregex 2
|
||||||
Just CombineInventory{} -> w & hud . hudElement . subInventory . ciSections . fssFilters . ix (-1)
|
Just CombineInventory{} -> w & hud . hudElement . subInventory . ciSections %~ enterregex (-1)
|
||||||
%~ enterregex
|
|
||||||
_ -> w
|
_ -> w
|
||||||
where
|
where
|
||||||
di = w ^. hud . hudElement
|
di = w ^. hud . hudElement
|
||||||
secfocus a b = fromMaybe False $ do
|
secfocus a b = fromMaybe False $ do
|
||||||
i <- di ^? diSections . fssSections . sssSelPos . _Just . _1
|
i <- di ^? diSections . fssSections . sssSelPos . _Just . _1
|
||||||
return $ i == a || i == b
|
return $ i == a || i == b
|
||||||
enterregex Nothing = Just ""
|
enterregex x fss = fss & fssFilters . ix x %~ f
|
||||||
enterregex x = x
|
& fssSections . sssSelPos ?~ (x,0)
|
||||||
|
f Nothing = Just ""
|
||||||
|
f x = x
|
||||||
|
|
||||||
--overSection :: (SelectionSection a -> SelectionSection a) -> SelectionSections a -> SelectionSections a
|
--overSection :: (SelectionSection a -> SelectionSection a) -> SelectionSections a -> SelectionSections a
|
||||||
--overSection f sss = fromMaybe sss $ do
|
--overSection f sss = fromMaybe sss $ do
|
||||||
|
|||||||
Reference in New Issue
Block a user