Permalink
Browse files

improve item UI a bit

  • Loading branch information...
1 parent 337d9c4 commit cd77a31b34007e73f96e4d8f1255f072b4692d8a @Mikolaj Mikolaj committed Mar 28, 2011
Showing with 30 additions and 27 deletions.
  1. +19 −24 src/Actions.hs
  2. +11 −3 src/Grammar.hs
View
@@ -35,6 +35,7 @@ import qualified Save
import Terrain
import qualified Effect
import EffectAction
+import Keys hiding (Up, Down)
-- All the rest of the Action stuff.
@@ -513,6 +514,20 @@ inventory =
session getConfirm
abortWith ""
+-- | Let the player choose any item with a given group name.
+-- Note that this does not guarantee an item from the group to be chosen,
+-- as the player can override the choice.
+getGroupItem :: String -> -- name of the group
+ String -> -- prompt
+ [Item] -> -- all objects in question
+ String -> -- how to refer to the collection of objects,
+ -- e.g., "in your inventory"
+ Action (Maybe Item)
+getGroupItem groupName prompt is packName =
+ let choice i = ItemKind.jname (ItemKind.getIK (ikind i)) == groupName
+ header = capitalize $ suffixS groupName
+ in getItem prompt choice header is packName
+
drinkPotion :: Action ()
drinkPotion =
do
@@ -523,7 +538,7 @@ drinkPotion =
if L.null items
then abortWith "You are not carrying anything."
else do
- i <- getPotion "What to drink?" items "inventory"
+ i <- getGroupItem "potion" "What to drink?" items "in your inventory"
case i of
Just i'@(Item { ikind = ik })
| ItemKind.jname (ItemKind.getIK ik) == "potion" ->
@@ -548,7 +563,7 @@ readScroll =
if L.null items
then abortWith "You are not carrying anything."
else do
- i <- getScroll "What to read?" items "inventory"
+ i <- getGroupItem "scroll" "What to read?" items "in your inventory"
case i of
Just i'@(Item { ikind = ik })
| ItemKind.jname (ItemKind.getIK ik) == "scroll" ->
@@ -639,27 +654,6 @@ removeFromLoc i loc =
adj = M.adjust (\ (t, rt) -> (remove t, rt)) loc
remove t = t { titems = removeItemByKind i (titems t) }
--- | Let the player choose any potion.
--- Note that this does not guarantee a potion to be chosen,
--- as the player can override the choice.
-getPotion :: String -> -- prompt
- [Item] -> -- all objects in question
- String -> -- how to refer to the collection of objects,
- -- e.g., "in your inventory"
- Action (Maybe Item)
-getPotion prompt is isn =
- let choice i = ItemKind.jname (ItemKind.getIK (ikind i)) == "potion"
- in getItem prompt choice "Potions" is isn
-
-getScroll :: String -> -- prompt
- [Item] -> -- all objects in question
- String -> -- how to refer to the collection of objects,
- -- e.g., "in your inventory"
- Action (Maybe Item)
-getScroll prompt is isn =
- let choice i = ItemKind.jname (ItemKind.getIK (ikind i)) == "scroll"
- in getItem prompt choice "Scrolls" is isn
-
actorPickupItem :: Actor -> Action ()
actorPickupItem actor =
do
@@ -721,7 +715,7 @@ getItem :: String -> -- prompt message
getItem prompt p ptext is0 isn =
let is = L.filter p is0
choice | L.null is = "[*]"
- | otherwise = "[" ++ letterRange (concatMap (maybeToList . iletter) is) ++ " or ?*]"
+ | otherwise = "[" ++ letterRange (concatMap (maybeToList . iletter) is) ++ " or ?* or " ++ showKey Keys.Return ++ "]"
r = do
message (prompt ++ " " ++ choice)
display
@@ -738,6 +732,7 @@ getItem prompt p ptext is0 isn =
if b then session (getOptionalConfirm (const r) h')
else r
K.Char l -> return (find (\ i -> maybe False (== l) (iletter i)) is0)
+ K.Return -> return (case is of [] -> Nothing ; i : _ -> Just i)
_ -> return Nothing
h
in r
View
@@ -13,16 +13,24 @@ import ItemState
import ItemKind
import Effect
+
+suffixS :: String -> String
+suffixS word = word ++ "s"
+
+capitalize :: String -> String
+capitalize [] = []
+capitalize (c : cs) = toUpper c : cs
+
-- | How to refer to a movable in object position of a sentence.
objectMovable :: MovableKind -> String
objectMovable mk = nname mk
-- | How to refer to a movable in subject position of a sentence.
subjectMovable :: MovableKind -> String
-subjectMovable x = let (s:r) = objectMovable x in toUpper s : r
+subjectMovable x = capitalize $ objectMovable x
verbMovable :: MovableKind -> String -> String
-verbMovable mk v = if nname mk == "you" then v else v ++ "s"
+verbMovable mk v = if nname mk == "you" then v else suffixS v
-- | Sentences such like "The dog barks".
subjectMovableVerb :: MovableKind -> String -> String
@@ -55,7 +63,7 @@ makeObject 1 adj obj = let b = adj obj
in case b of
(c:_) | c `elem` "aeio" -> "an " ++ b
_ -> "a " ++ b
-makeObject n adj obj = show n ++ " " ++ adj (obj ++ "s")
+makeObject n adj obj = show n ++ " " ++ adj (suffixS obj)
objectItem :: State -> Item -> String
objectItem state o =

0 comments on commit cd77a31

Please sign in to comment.