Allow for ingame terminal input
This commit is contained in:
@@ -14,7 +14,9 @@ import qualified Data.Set as S
|
|||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
{- | The AI equivalent for your control. -}
|
{- | The AI equivalent for your control. -}
|
||||||
yourControl :: Creature -> World -> World
|
yourControl :: Creature -> World -> World
|
||||||
yourControl cr w = w
|
yourControl cr w = case w ^? hud . hudElement . subInventory . termParams . termInput . _Just of
|
||||||
|
Just _ -> w
|
||||||
|
_ -> w
|
||||||
& creatures . ix (_crID cr) %~
|
& creatures . ix (_crID cr) %~
|
||||||
(wasdWithAiming w (_mvSpeed $ _crMvType cr) . mouseActionsCr (_mouseButtons w))
|
(wasdWithAiming w (_mvSpeed $ _crMvType cr) . mouseActionsCr (_mouseButtons w))
|
||||||
& updateUsingInput
|
& updateUsingInput
|
||||||
|
|||||||
+1
-1
@@ -388,7 +388,7 @@ data TerminalParams = NoTerminalParams | TerminalParams
|
|||||||
, _termTitle :: String
|
, _termTitle :: String
|
||||||
, _termSel :: Maybe Int
|
, _termSel :: Maybe Int
|
||||||
, _termOptions :: [(String, World -> World)]
|
, _termOptions :: [(String, World -> World)]
|
||||||
, _termInput :: Maybe (String, String -> World -> World)
|
, _termInput :: Maybe (T.Text, String -> World -> World)
|
||||||
}
|
}
|
||||||
data TerminalLine
|
data TerminalLine
|
||||||
= TerminalLineDisplay
|
= TerminalLineDisplay
|
||||||
|
|||||||
+27
-11
@@ -22,18 +22,15 @@ import SDL
|
|||||||
--import Data.Text (unpack)
|
--import Data.Text (unpack)
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
|
|
||||||
|
-- annoyingly, the text input event doesn't register backspace, so this has to be
|
||||||
|
-- dealt with elsewhere
|
||||||
handleTextInput :: T.Text -> Universe -> IO (Maybe Universe)
|
handleTextInput :: T.Text -> Universe -> IO (Maybe Universe)
|
||||||
handleTextInput text = return . Just . -- case mState of
|
handleTextInput text = return . Just . (menuLayers . ix 0 . scInput %~ updateText)
|
||||||
-- InputScreen {} ->
|
. (uvWorld . hud . hudElement . subInventory . termParams . termInput . _Just . _1 %~ updateText)
|
||||||
(menuLayers . ix 0 . scInput %~ updateText)
|
|
||||||
-- _ -> id
|
|
||||||
where
|
where
|
||||||
updateText s = case T.unpack text of
|
updateText s = case T.unpack text of
|
||||||
"\b" -> undefined
|
";" -> s
|
||||||
_ -> s `T.append` text
|
_ -> s `T.append` T.toUpper text
|
||||||
|
|
||||||
-- | null (_menuLayers w) = return $ Just w
|
|
||||||
-- | otherwise = handleTextInMenu (head $ _menuLayers w) text w
|
|
||||||
|
|
||||||
{- | Handles keyboard press and release.
|
{- | Handles keyboard press and release.
|
||||||
On release, remove scancode from the 'Set' of pressed keys.
|
On release, remove scancode from the 'Set' of pressed keys.
|
||||||
@@ -54,12 +51,14 @@ handlePressedKey _ scode w = case scode of
|
|||||||
ScancodeF5 -> return . Just $ doQuicksave w
|
ScancodeF5 -> return . Just $ doQuicksave w
|
||||||
ScancodeF9 -> return . Just $ loadSaveSlot QuicksaveSlot w
|
ScancodeF9 -> return . Just $ loadSaveSlot QuicksaveSlot w
|
||||||
ScancodeSemicolon -> return . Just $ gotoTerminal w
|
ScancodeSemicolon -> return . Just $ gotoTerminal w
|
||||||
_ | null (_menuLayers w) -> return $ uvWorld (handlePressedKeyInGame scode) w
|
_ | null (_menuLayers w) -> case w ^? uvWorld . hud . hudElement . subInventory . termParams . termInput . _Just of
|
||||||
|
Just {} -> return $ uvWorld (handlePressedKeyTerminal scode) w
|
||||||
|
_ -> return $ uvWorld (handlePressedKeyInGame scode) w
|
||||||
_ -> handlePressedKeyInMenu (head $ _menuLayers w) scode w
|
_ -> handlePressedKeyInMenu (head $ _menuLayers w) scode w
|
||||||
|
|
||||||
handlePressedKeyInGame :: Scancode -> World -> Maybe World
|
handlePressedKeyInGame :: Scancode -> World -> Maybe World
|
||||||
handlePressedKeyInGame scode w = case scode of
|
handlePressedKeyInGame scode w = case scode of
|
||||||
ScancodeEscape -> Nothing
|
ScancodeEscape -> Just $ pauseGame $ escapeMap w
|
||||||
ScancodeSpace -> Just $ spaceAction w
|
ScancodeSpace -> Just $ spaceAction w
|
||||||
ScancodeP -> Just $ pauseGame $ escapeMap w
|
ScancodeP -> Just $ pauseGame $ escapeMap w
|
||||||
ScancodeF -> Just $ youDropItem w
|
ScancodeF -> Just $ youDropItem w
|
||||||
@@ -71,6 +70,23 @@ handlePressedKeyInGame scode w = case scode of
|
|||||||
ScancodeI -> Just $ w & hud . hudElement %~ toggleInspectInv
|
ScancodeI -> Just $ w & hud . hudElement %~ toggleInspectInv
|
||||||
_ -> Just w
|
_ -> Just w
|
||||||
|
|
||||||
|
|
||||||
|
handlePressedKeyTerminal :: Scancode -> World -> Maybe World
|
||||||
|
handlePressedKeyTerminal scode w = case scode of
|
||||||
|
ScancodeEscape -> Just $ w & hud . hudElement . subInventory .~ NoSubInventory
|
||||||
|
ScancodeReturn -> Just $ w & doTerminalEffect
|
||||||
|
ScancodeBackspace -> Just $ w
|
||||||
|
& hud . hudElement . subInventory . termParams . termInput . _Just . _1 %~ doBackspace
|
||||||
|
_ -> Just w
|
||||||
|
where
|
||||||
|
doBackspace t = case T.unsnoc t of
|
||||||
|
Nothing -> t
|
||||||
|
Just (t',_) -> t'
|
||||||
|
doTerminalEffect w' = fromMaybe w' $ do
|
||||||
|
f <- w' ^? hud . hudElement . subInventory . termParams . termInput . _Just . _2
|
||||||
|
s <- w' ^? hud . hudElement . subInventory . termParams . termInput . _Just . _1
|
||||||
|
return $ f (T.unpack s) w'
|
||||||
|
|
||||||
toggleTweakInv :: HUDElement -> HUDElement
|
toggleTweakInv :: HUDElement -> HUDElement
|
||||||
toggleTweakInv he = case he of
|
toggleTweakInv he = case he of
|
||||||
DisplayInventory TweakInventory -> DisplayInventory NoSubInventory
|
DisplayInventory TweakInventory -> DisplayInventory NoSubInventory
|
||||||
|
|||||||
+6
-17
@@ -1,6 +1,5 @@
|
|||||||
module Dodge.Event.Menu
|
module Dodge.Event.Menu
|
||||||
( handlePressedKeyInMenu
|
( handlePressedKeyInMenu
|
||||||
-- , handleTextInMenu
|
|
||||||
) where
|
) where
|
||||||
import Dodge.Data
|
import Dodge.Data
|
||||||
import Dodge.Debug.Terminal
|
import Dodge.Debug.Terminal
|
||||||
@@ -9,21 +8,11 @@ import Dodge.Menu.PushPop
|
|||||||
|
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
--import Control.Monad
|
--import Control.Monad
|
||||||
--import Control.Lens
|
import Control.Lens
|
||||||
import SDL
|
import SDL
|
||||||
--import qualified Debug.Trace
|
--import qualified Debug.Trace
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
|
|
||||||
--handleTextInMenu :: ScreenLayer -> T.Text -> Universe -> IO (Maybe Universe)
|
|
||||||
--handleTextInMenu mState text = return . Just . -- case mState of
|
|
||||||
---- InputScreen {} ->
|
|
||||||
-- (menuLayers . ix 0 . scInput %~ updateText)
|
|
||||||
---- _ -> id
|
|
||||||
-- where
|
|
||||||
-- updateText s = case T.unpack text of
|
|
||||||
-- "\b" -> undefined
|
|
||||||
-- _ -> s `T.append` text
|
|
||||||
|
|
||||||
handlePressedKeyInMenu :: ScreenLayer -> Scancode -> Universe -> IO (Maybe Universe)
|
handlePressedKeyInMenu :: ScreenLayer -> Scancode -> Universe -> IO (Maybe Universe)
|
||||||
handlePressedKeyInMenu mState scode = case mState of
|
handlePressedKeyInMenu mState scode = case mState of
|
||||||
OptionScreen { _scOptions = mos, _scDefaultEff = defeff}
|
OptionScreen { _scOptions = mos, _scDefaultEff = defeff}
|
||||||
@@ -35,13 +24,13 @@ handlePressedKeyInMenu mState scode = case mState of
|
|||||||
ScancodeEscape -> popScreen
|
ScancodeEscape -> popScreen
|
||||||
ScancodeReturn -> popScreen . applyTerminalString (T.unpack s)
|
ScancodeReturn -> popScreen . applyTerminalString (T.unpack s)
|
||||||
ScancodeTab -> autoCompleteTerminal (T.unpack s) help
|
ScancodeTab -> autoCompleteTerminal (T.unpack s) help
|
||||||
-- ScancodeBackspace -> return . Just . (menuLayers . ix 0 . scInput %~ doBackspace)
|
ScancodeBackspace -> return . Just . (menuLayers . ix 0 . scInput %~ doBackspace)
|
||||||
-- text input handled by handleText
|
-- text input handled by handleTextInput
|
||||||
_ -> return . Just
|
_ -> return . Just
|
||||||
where
|
where
|
||||||
-- doBackspace [_] = ['>']
|
doBackspace t = case T.unsnoc t of
|
||||||
-- doBackspace (x:xs) = init (x:xs)
|
Nothing -> t
|
||||||
-- doBackspace _ = ['>']
|
Just (t',_) -> t'
|
||||||
|
|
||||||
optionListToEffects
|
optionListToEffects
|
||||||
:: (Universe -> IO (Maybe Universe))
|
:: (Universe -> IO (Maybe Universe))
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ import LensHelp
|
|||||||
import qualified Data.Map.Strict as M
|
import qualified Data.Map.Strict as M
|
||||||
--import qualified Data.Set as S
|
--import qualified Data.Set as S
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
|
import qualified Data.Text as T
|
||||||
--import SDL
|
--import SDL
|
||||||
--import Data.List
|
--import Data.List
|
||||||
--import System.Random
|
--import System.Random
|
||||||
@@ -170,7 +171,7 @@ updateTerminalLine w = case w ^? hud . hudElement . subInventory . termParams .
|
|||||||
& hud . hudElement . subInventory . termParams . termSel ?~ 0
|
& hud . hudElement . subInventory . termParams . termSel ?~ 0
|
||||||
Just (TerminalLineInput _ func) -> w
|
Just (TerminalLineInput _ func) -> w
|
||||||
& hud . hudElement . subInventory . termParams . termFutureLines %~ tail
|
& hud . hudElement . subInventory . termParams . termFutureLines %~ tail
|
||||||
& hud . hudElement . subInventory . termParams . termInput ?~ ("",func)
|
& hud . hudElement . subInventory . termParams . termInput ?~ (T.empty,func)
|
||||||
|
|
||||||
-- this looks ugly...
|
-- this looks ugly...
|
||||||
updateCloseObjects :: World -> World
|
updateCloseObjects :: World -> World
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import qualified Data.Set as S
|
|||||||
--import qualified Data.IntSet as IS
|
--import qualified Data.IntSet as IS
|
||||||
import Control.Lens
|
import Control.Lens
|
||||||
import SDL (MouseButton (..))
|
import SDL (MouseButton (..))
|
||||||
|
import qualified Data.Text as T
|
||||||
--import Data.List
|
--import Data.List
|
||||||
--import Data.Bifunctor
|
--import Data.Bifunctor
|
||||||
|
|
||||||
@@ -123,7 +124,7 @@ subInventoryDisplay subinv cfig w = case subinv of
|
|||||||
where
|
where
|
||||||
displayTermInput tp = case _termInput tp of
|
displayTermInput tp = case _termInput tp of
|
||||||
Nothing -> id
|
Nothing -> id
|
||||||
Just (s,_) -> (++ [('>':s++clockCycle 10 (V.fromList ["_",""]) w,white)])
|
Just (s,_) -> (++ [('>':T.unpack s++clockCycle 10 (V.fromList ["_",""]) w,white)])
|
||||||
closeobjectcursor = case selectedCloseObject w of
|
closeobjectcursor = case selectedCloseObject w of
|
||||||
Nothing -> mempty
|
Nothing -> mempty
|
||||||
Just (i,co) -> listCursorNS clObjFloatIn 0 cfig (selNumPos i w) (closeObjectCol co) topInvW (invSelSize i w)
|
Just (i,co) -> listCursorNS clObjFloatIn 0 cfig (selNumPos i w) (closeObjectCol co) topInvW (invSelSize i w)
|
||||||
|
|||||||
Reference in New Issue
Block a user