Permalink
Browse files

message ops (implement #11 (comment))

  • Loading branch information...
1 parent 7f49100 commit a6e2b8033168c4f992203148a81a26f14bdc0b84 @Mikolaj Mikolaj committed Aug 16, 2011
Showing with 18 additions and 17 deletions.
  1. +11 −11 src/Action.hs
  2. +2 −2 src/Actions.hs
  3. +3 −2 src/EffectAction.hs
  4. +2 −2 src/ItemAction.hs
View
@@ -85,17 +85,17 @@ display = displayGeneric ColorFull id
overlay :: String -> Action Bool
overlay txt = Action (\ s e p k a st ms -> displayLevel ColorFull s p st ms (Just txt) >>= k st ms)
--- | Set the current message.
-messageWipeAndSet :: Message -> Action ()
-messageWipeAndSet nm = Action (\ s e p k a st ms -> k st nm ())
+-- | Wipe out and set a new value for the current message.
+messageReset :: Message -> Action ()
+messageReset nm = Action (\ s e p k a st ms -> k st nm ())
-- | Add to the current message.
messageAdd :: Message -> Action ()
messageAdd nm = Action (\ s e p k a st ms -> k st (addMsg ms nm) ())
-- | Clear the current message.
-resetMessage :: Action Message
-resetMessage = Action (\ s e p k a st ms -> k st "" ms)
+messageClear :: Action ()
+messageClear = Action (\ s e p k a st ms -> k st "" ())
-- | Get the current message.
currentMessage :: Action Message
@@ -147,7 +147,7 @@ debug x = return () -- liftIO $ hPutStrLn stderr x
-- | Print the given message, then abort.
abortWith :: Message -> Action a
abortWith msg = do
- messageWipeAndSet msg
+ messageReset msg
display
abort
@@ -169,12 +169,12 @@ messageMoreConfirm dm msg = do
-- | Print message, await confirmation, ignore confirmation.
messageMore :: Message -> Action ()
-messageMore msg = resetMessage >> messageMoreConfirm ColorFull msg >> return ()
+messageMore msg = messageClear >> messageMoreConfirm ColorFull msg >> return ()
-- | Print a yes/no question and return the player's answer.
messageYesNo :: Message -> Action Bool
messageYesNo msg = do
- messageWipeAndSet (msg ++ yesno)
+ messageReset (msg ++ yesno)
displayGeneric ColorBW id -- turn player's attention to the choice
session getYesNo
@@ -188,12 +188,12 @@ messageOverlayConfirm msg txt = messageOverlaysConfirm msg [txt]
messageOverlaysConfirm :: Message -> [String] -> Action Bool
messageOverlaysConfirm msg [] =
do
- resetMessage
+ messageClear
display
return True
messageOverlaysConfirm msg (x:xs) =
do
- messageWipeAndSet msg
+ messageReset msg
b <- overlay (x ++ more)
if b
then do
@@ -205,7 +205,7 @@ messageOverlaysConfirm msg (x:xs) =
else stop
where
stop = do
- resetMessage
+ messageClear
display
return False
View
@@ -230,7 +230,7 @@ remember =
openclose :: Bool -> Action ()
openclose o =
do
- messageWipeAndSet "direction?"
+ messageReset "direction?"
display
e <- session nextCommand
pl <- gets splayer
@@ -369,7 +369,7 @@ fleeDungeon =
items = L.concatMap mitems (levelHeroList state)
if total == 0
then do
- go <- resetMessage >> messageMoreConfirm ColorFull "Coward!"
+ go <- messageClear >> messageMoreConfirm ColorFull "Coward!"
when go $
messageMore "Next time try to grab some loot before escape!"
end
View
@@ -308,7 +308,7 @@ displayItems msg sorted is = do
L.map (\ i -> letterLabel (iletter i) ++ objectItem state i ++ " ")
((if sorted then sortBy (cmpLetter' `on` iletter) else id) is)
let ovl = inv ++ more
- messageWipeAndSet msg
+ messageReset msg
overlay ovl
stopRunning :: Action ()
@@ -319,7 +319,8 @@ history :: Action ()
history =
do
(_, sx) <- gets (lsize . slevel)
- msg <- resetMessage
+ msg <- currentMessage
+ messageClear
config <- gets sconfig
let historyMax = Config.get config "ui" "historyMax"
-- TODO: not ideal, continuations of sentences are atop beginnings.
View
@@ -290,11 +290,11 @@ getItem prompt p ptext is0 isn = do
interact = do
when (L.null is0 && L.null tis) $
abortWith "Not carrying anything."
- messageWipeAndSet (prompt ++ " " ++ choice)
+ messageReset (prompt ++ " " ++ choice)
display
session nextCommand >>= perform
perform command = do
- resetMessage
+ messageClear
case command of
K.Char '?' -> do
-- filter for supposedly suitable objects

0 comments on commit a6e2b80

Please sign in to comment.