Allow terminals to block input
This commit is contained in:
+2
-1
@@ -939,7 +939,8 @@ data Block = Block
|
|||||||
, _blMaterial :: BlockMaterial
|
, _blMaterial :: BlockMaterial
|
||||||
}
|
}
|
||||||
data BlockMaterial = WoodBlock | DirtBlock | StoneBlock | GlassBlock | MetalBlock
|
data BlockMaterial = WoodBlock | DirtBlock | StoneBlock | GlassBlock | MetalBlock
|
||||||
data TerminalStatus = Connected | Disconnected
|
data TerminalStatus = TerminalOff | TerminalBusy | TerminalReady
|
||||||
|
deriving (Eq,Ord,Show)
|
||||||
data TerminalInput = TerminalInput
|
data TerminalInput = TerminalInput
|
||||||
{ _tiText :: T.Text
|
{ _tiText :: T.Text
|
||||||
, _tiFocus :: Bool
|
, _tiFocus :: Bool
|
||||||
|
|||||||
@@ -257,7 +257,7 @@ defaultTerminal = Terminal
|
|||||||
, _tmScrollCommands = []
|
, _tmScrollCommands = []
|
||||||
, _tmWriteCommands = []
|
, _tmWriteCommands = []
|
||||||
, _tmDeathEffect = const id
|
, _tmDeathEffect = const id
|
||||||
, _tmStatus = Disconnected
|
, _tmStatus = TerminalOff
|
||||||
, _tmCommandHistory = []
|
, _tmCommandHistory = []
|
||||||
, _tmToggles = M.empty
|
, _tmToggles = M.empty
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -45,7 +45,7 @@ import SDL
|
|||||||
|
|
||||||
handleEvent :: Event -> Universe -> IO (Maybe Universe)
|
handleEvent :: Event -> Universe -> IO (Maybe Universe)
|
||||||
handleEvent e = case eventPayload e of
|
handleEvent e = case eventPayload e of
|
||||||
TextInputEvent tev -> handleTextInput (textInputEventText tev)
|
TextInputEvent tev -> return . Just . handleTextInput (textInputEventText tev)
|
||||||
KeyboardEvent kev -> handleKeyboardEvent kev
|
KeyboardEvent kev -> handleKeyboardEvent kev
|
||||||
MouseMotionEvent mmev -> return . handleMouseMotionEvent mmev
|
MouseMotionEvent mmev -> return . handleMouseMotionEvent mmev
|
||||||
MouseButtonEvent mbev -> return . Just . over uvWorld (handleMouseButtonEvent mbev)
|
MouseButtonEvent mbev -> return . Just . over uvWorld (handleMouseButtonEvent mbev)
|
||||||
@@ -144,7 +144,7 @@ wheelEvent y w = case _hudElement $ _hud w of
|
|||||||
DisplayInventory (CombineInventory _) -> w
|
DisplayInventory (CombineInventory _) -> w
|
||||||
& hud . hudElement . subInventory . combineInvSel . _Just %~ ((`mod` numcombs) . subtract yi)
|
& hud . hudElement . subInventory . combineInvSel . _Just %~ ((`mod` numcombs) . subtract yi)
|
||||||
DisplayInventory (DisplayTerminal tmid)
|
DisplayInventory (DisplayTerminal tmid)
|
||||||
| rbDown && inTermFocus w -> w
|
| rbDown && inTermFocus w -> guardDisconnectedID tmid w $ w
|
||||||
& terminals . ix tmid %~ updatetermsubsel
|
& terminals . ix tmid %~ updatetermsubsel
|
||||||
| inTermFocus w -> w
|
| inTermFocus w -> w
|
||||||
& terminals . ix tmid %~ updatetermsel
|
& terminals . ix tmid %~ updatetermsel
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
module Dodge.Event.Keyboard
|
module Dodge.Event.Keyboard
|
||||||
( handleKeyboardEvent
|
( handleKeyboardEvent
|
||||||
, handleTextInput
|
, handleTextInput
|
||||||
|
, guardDisconnectedID
|
||||||
) where
|
) where
|
||||||
import Dodge.Terminal
|
import Dodge.Terminal
|
||||||
import Dodge.InputFocus
|
import Dodge.InputFocus
|
||||||
@@ -30,20 +31,26 @@ import qualified Data.Text as T
|
|||||||
-- dealt with using key presses (handlePressedKey)
|
-- dealt with using key presses (handlePressedKey)
|
||||||
-- also, note that this currently "doubles" the inputs to both terminals if both
|
-- also, note that this currently "doubles" the inputs to both terminals if both
|
||||||
-- are open
|
-- are open
|
||||||
handleTextInput :: T.Text -> Universe -> IO (Maybe Universe)
|
handleTextInput :: T.Text -> Universe -> Universe
|
||||||
handleTextInput text u = return . Just $ u
|
handleTextInput text u = u
|
||||||
& menuLayers . ix 0 . scInput %~ updateText
|
& menuLayers . ix 0 . scInput %~ updateText
|
||||||
& updateTerminalText
|
& updateTerminalText
|
||||||
where
|
where
|
||||||
updateTerminalText = case u ^? uvWorld . hud . hudElement . subInventory of
|
updateTerminalText = case u ^? uvWorld . hud . hudElement . subInventory of
|
||||||
Just (DisplayTerminal tmid) | hasfocus tmid
|
Just (DisplayTerminal tmid) | hasfocus tmid
|
||||||
-> uvWorld . terminals . ix tmid . tmInput . tiText %~ updateText
|
-> uvWorld %~ \w -> guardDisconnectedID tmid w (w & terminals . ix tmid . tmInput . tiText %~ updateText)
|
||||||
_ -> id
|
_ -> id
|
||||||
hasfocus tmid = fromMaybe False $ u ^? uvWorld . terminals . ix tmid . tmInput . tiFocus
|
hasfocus tmid = fromMaybe False $ u ^? uvWorld . terminals . ix tmid . tmInput . tiFocus
|
||||||
updateText s = case T.unpack text of
|
updateText s = case T.unpack text of
|
||||||
";" -> s
|
";" -> s
|
||||||
_ -> s `T.append` T.toUpper text
|
_ -> s `T.append` T.toUpper text
|
||||||
|
|
||||||
|
guardDisconnectedID :: Int -> World -> World -> World
|
||||||
|
guardDisconnectedID tmid w w' = case w ^? terminals . ix tmid . tmStatus of
|
||||||
|
Just TerminalReady -> w'
|
||||||
|
_ -> 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.
|
||||||
On press, adds the scancode, and perhaps applies a direct effect:
|
On press, adds the scancode, and perhaps applies a direct effect:
|
||||||
|
|||||||
@@ -7,5 +7,7 @@ import Data.Maybe
|
|||||||
inTermFocus :: World -> Bool
|
inTermFocus :: World -> Bool
|
||||||
inTermFocus w = fromMaybe False $ do
|
inTermFocus w = fromMaybe False $ do
|
||||||
tmid <- w ^? hud . hudElement . subInventory . termID
|
tmid <- w ^? hud . hudElement . subInventory . termID
|
||||||
w ^? terminals . ix tmid . tmInput . tiFocus
|
hasfocus <- w ^? terminals . ix tmid . tmInput . tiFocus
|
||||||
|
connectionstatus <- w ^? terminals . ix tmid . tmStatus
|
||||||
|
return $ hasfocus && connectionstatus == TerminalReady
|
||||||
|
|
||||||
|
|||||||
@@ -120,10 +120,11 @@ accessTerminal mtmid w = case mtmid of
|
|||||||
& terminals . ix tmid %~ tryToBoot
|
& terminals . ix tmid %~ tryToBoot
|
||||||
where
|
where
|
||||||
tryToBoot tm = case _tmStatus tm of
|
tryToBoot tm = case _tmStatus tm of
|
||||||
Connected -> tm
|
TerminalReady -> tm
|
||||||
Disconnected -> tm
|
TerminalBusy -> tm
|
||||||
& tmFutureLines ++.~ _tmProgram tm tm w
|
TerminalOff -> tm
|
||||||
& tmStatus .~ Connected
|
& tmFutureLines .~ _tmProgram tm tm w
|
||||||
|
& tmStatus .~ TerminalBusy
|
||||||
|
|
||||||
simpleTermMessage :: [String] -> Terminal
|
simpleTermMessage :: [String] -> Terminal
|
||||||
simpleTermMessage strs = defaultTerminal & tmFutureLines .~ map makeTermLine strs
|
simpleTermMessage strs = defaultTerminal & tmFutureLines .~ map makeTermLine strs
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import Dodge.Data
|
|||||||
import Dodge.Combine
|
import Dodge.Combine
|
||||||
import Dodge.Clock
|
import Dodge.Clock
|
||||||
import Dodge.Base
|
import Dodge.Base
|
||||||
|
--import Dodge.InputFocus
|
||||||
--import Dodge.Combine.Combinations
|
--import Dodge.Combine.Combinations
|
||||||
import Dodge.Inventory
|
import Dodge.Inventory
|
||||||
import Dodge.Inventory.ItemSpace
|
import Dodge.Inventory.ItemSpace
|
||||||
@@ -144,10 +145,12 @@ displayTerminal tid cfig w = fromMaybe mempty $ do
|
|||||||
$ _tmDisplayedLines tm
|
$ _tmDisplayedLines tm
|
||||||
]
|
]
|
||||||
where
|
where
|
||||||
displayTermInput tp = case _tmInput tp of
|
displayTermInput tm = case _tmInput tm of
|
||||||
TerminalInput s inputstatus _
|
TerminalInput s hasfoc _ -> (++ [(displayInputText tm s++displayBlinkCursor hasfoc,white)])
|
||||||
-> (++ [('>':T.unpack s++displayBlinkCursor inputstatus,white)])
|
displayInputText tm s
|
||||||
displayBlinkCursor inputstatus | inputstatus = clockCycle 10 (V.fromList ["_",""]) w
|
| _tmStatus tm == TerminalReady = '>':T.unpack s
|
||||||
|
| otherwise = ""
|
||||||
|
displayBlinkCursor hasfoc | hasfoc = clockCycle 10 (V.fromList ["_",""]) w
|
||||||
| otherwise = []
|
| otherwise = []
|
||||||
|
|
||||||
drawRBOptions :: Configuration -> World -> RightButtonOptions -> Picture
|
drawRBOptions :: Configuration -> World -> RightButtonOptions -> Picture
|
||||||
|
|||||||
+18
-11
@@ -25,7 +25,7 @@ quitCommand = TerminalCommand
|
|||||||
}
|
}
|
||||||
disconnectTerminal :: Terminal -> World -> World
|
disconnectTerminal :: Terminal -> World -> World
|
||||||
disconnectTerminal tm w = w
|
disconnectTerminal tm w = w
|
||||||
& terminals . ix (_tmID tm) . tmStatus .~ Disconnected
|
& terminals . ix (_tmID tm) . tmStatus .~ TerminalOff
|
||||||
& exitTerminalSubInv
|
& exitTerminalSubInv
|
||||||
& terminals . ix (_tmID tm) . tmFutureLines .~
|
& terminals . ix (_tmID tm) . tmFutureLines .~
|
||||||
[ TerminalLineTerminalEffect 0 (tmDisplayedLines .~ [])
|
[ TerminalLineTerminalEffect 0 (tmDisplayedLines .~ [])
|
||||||
@@ -185,15 +185,21 @@ singleCommand followingLines command aliases htext eff = TerminalCommand
|
|||||||
,_tcEffect = \_ _ -> NoArguments $ TerminalLineEffect 0 (const eff) : map makeTermLine followingLines
|
,_tcEffect = \_ _ -> NoArguments $ TerminalLineEffect 0 (const eff) : map makeTermLine followingLines
|
||||||
}
|
}
|
||||||
|
|
||||||
|
guardDisconnected :: Terminal -> World -> World -> World
|
||||||
|
guardDisconnected tm w w' = case _tmStatus tm of
|
||||||
|
TerminalOff -> w
|
||||||
|
TerminalBusy -> w
|
||||||
|
TerminalReady -> w'
|
||||||
|
|
||||||
doTerminalEffectLB :: Terminal -> World -> World
|
doTerminalEffectLB :: Terminal -> World -> World
|
||||||
doTerminalEffectLB tm w = fromMaybe w $ do
|
doTerminalEffectLB tm w = guardDisconnected tm w $ fromMaybe w $ do
|
||||||
s <- fmap T.unpack $ w ^? terminals . ix (_tmID tm) . tmInput . tiText
|
s <- fmap T.unpack $ w ^? terminals . ix (_tmID tm) . tmInput . tiText
|
||||||
if null (words s)
|
if null (words s)
|
||||||
then Just $ defocusTerminalInput w
|
then Just $ defocusTerminalInput w
|
||||||
else return $ terminalReturnEffect tm w
|
else return $ terminalReturnEffect tm w
|
||||||
|
|
||||||
terminalReturnEffect :: Terminal -> World -> World
|
terminalReturnEffect :: Terminal -> World -> World
|
||||||
terminalReturnEffect tm w = fromMaybe w $ do
|
terminalReturnEffect tm w = guardDisconnected tm w $ fromMaybe w $ do
|
||||||
s <- fmap T.unpack $ w ^? terminals . ix (_tmID tm) . tmInput . tiText
|
s <- fmap T.unpack $ w ^? terminals . ix (_tmID tm) . tmInput . tiText
|
||||||
return $ runTerminalString s tm $ w
|
return $ runTerminalString s tm $ w
|
||||||
& terminals . ix (_tmID tm) . tmFutureLines .~ [makeTermLine ('>':s)]
|
& terminals . ix (_tmID tm) . tmFutureLines .~ [makeTermLine ('>':s)]
|
||||||
@@ -241,9 +247,7 @@ basicTerminal = defaultTerminal
|
|||||||
,_tmInput = defaultTerminalInput
|
,_tmInput = defaultTerminalInput
|
||||||
,_tmScrollCommands = [quitCommand]
|
,_tmScrollCommands = [quitCommand]
|
||||||
,_tmWriteCommands = [helpCommand,commandsCommand]
|
,_tmWriteCommands = [helpCommand,commandsCommand]
|
||||||
,_tmProgram = \_ _ -> termSoundLine computerBeepingS
|
,_tmProgram = \_ _ -> connectionBlurb1
|
||||||
: TerminalLineTerminalEffect 0 (tmStatus .~ Connected)
|
|
||||||
: map makeTermLine connectionBlurb
|
|
||||||
, _tmDeathEffect = doDeathTriggers
|
, _tmDeathEffect = doDeathTriggers
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -255,8 +259,11 @@ doDeathTriggers tm w = w
|
|||||||
doDeathToggle :: TerminalToggle -> IM.IntMap (World -> Bool) -> IM.IntMap (World -> Bool)
|
doDeathToggle :: TerminalToggle -> IM.IntMap (World -> Bool) -> IM.IntMap (World -> Bool)
|
||||||
doDeathToggle (TerminalToggle trid f) = ix trid %~ f
|
doDeathToggle (TerminalToggle trid f) = ix trid %~ f
|
||||||
|
|
||||||
connectionBlurb :: [String]
|
connectionBlurb1 :: [TerminalLine]
|
||||||
connectionBlurb =
|
connectionBlurb1 =
|
||||||
["CONNECTING ..."
|
[termSoundLine computerBeepingS
|
||||||
,"COMPLETE"
|
,TerminalLineDisplay 0 (const ("CONNECTING ...",white))
|
||||||
]
|
,TerminalLineDisplay 10 (const ("...",white))
|
||||||
|
,TerminalLineDisplay 10 (const ("CONNECTED",white))
|
||||||
|
,TerminalLineTerminalEffect 0 (tmStatus .~ TerminalReady)]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user