module Dodge.InputFocus ( inTextInputFocus, ) where import Control.Monad import Data.Maybe import Dodge.Data.World import LensHelp inTextInputFocus :: World -> Bool inTextInputFocus = isJust . inputFocusI inputFocusI :: World -> Maybe ((String -> Identity String) -> World -> Identity World) inputFocusI = textInputFocus textInputFocus :: Applicative f => World -> Maybe ((String -> f String) -> World -> f World) textInputFocus w = case w ^? hud . hudElement . subInventory of Just NoSubInventory{} -> case he ^? diSelection . _Just . _1 of Just (-1) -> Just $ hud . hudElement . diInvFilter . _Just Just 2 -> Just $ hud . hudElement . diCloseFilter . _Just _ -> Nothing Just CombineInventory{} -> case he ^? subInventory . ciSelection . _Just . _1 of Just (-1) -> Just $ hud . hudElement . subInventory . ciFilter . _Just _ -> Nothing Just DisplayTerminal{_termID = tmid} -> do connectionstatus <- w ^? cWorld . lWorld . terminals . ix tmid . tmStatus guard $ connectionstatus == TerminalReady return $ cWorld . lWorld . terminals . ix tmid . tmInput . tiText _ -> Nothing where he = w ^. hud . hudElement