about summary refs log tree commit diff
path: root/src/Xanthous/Game/Draw.hs
diff options
context:
space:
mode:
authorGriffin Smith <root@gws.fyi>2019-12-01T03·43-0500
committerGriffin Smith <root@gws.fyi>2019-12-01T03·43-0500
commit65b1352ef2e463393d0504c32b73bdcf7c99491a (patch)
tree9bbd627db18babdeff099d7a248103e2148a93f8 /src/Xanthous/Game/Draw.hs
parent71b628c604556bc2d829f12980db99c9a526ec84 (diff)
Add a very basic inventory panel
Add a very basic inventory panel to the game opened by pressing `i`,
which displays the contents of the player's inventory in a basic list.
Diffstat (limited to 'src/Xanthous/Game/Draw.hs')
-rw-r--r--src/Xanthous/Game/Draw.hs44
1 files changed, 34 insertions, 10 deletions
diff --git a/src/Xanthous/Game/Draw.hs b/src/Xanthous/Game/Draw.hs
index ab0e31f8a04a..7947c6efe917 100644
--- a/src/Xanthous/Game/Draw.hs
+++ b/src/Xanthous/Game/Draw.hs
@@ -27,7 +27,7 @@ import           Xanthous.Game
                  , debugState, allRevealed
                  )
 import           Xanthous.Game.Prompt
-import           Xanthous.Resource (Name)
+import           Xanthous.Resource (Name, Panel(..))
 import qualified Xanthous.Resource as Resource
 import           Xanthous.Orphans ()
 --------------------------------------------------------------------------------
@@ -41,23 +41,23 @@ cursorPosition game
   = showCursor Resource.Character (game ^. characterPosition . loc)
 
 drawMessages :: MessageHistory -> Widget Name
-drawMessages = txt . (<> " ") . unwords . oextract
+drawMessages = txtWrap . (<> " ") . unwords . oextract
 
 drawPromptState :: GamePromptState m -> Widget Name
 drawPromptState NoPrompt = emptyWidget
 drawPromptState (WaitingPrompt msg (Prompt _ pt ps pri _)) =
   case (pt, ps, pri) of
     (SStringPrompt, StringPromptState edit, _) ->
-      txt msg <+> renderEditor (txt . fold) True edit
-    (SDirectionPrompt, DirectionPromptState, _) -> txt msg
-    (SContinue, _, _) -> txt msg
+      txtWrap msg <+> renderEditor (txtWrap . fold) True edit
+    (SDirectionPrompt, DirectionPromptState, _) -> txtWrap msg
+    (SContinue, _, _) -> txtWrap msg
     (SMenu, _, menuItems) ->
-      txt msg
+      txtWrap msg
       <=> foldl' (<=>) emptyWidget (map drawMenuItem $ itoList menuItems)
-    _ -> txt msg
+    _ -> txtWrap msg
   where
     drawMenuItem (chr, MenuOption m _) =
-      str ("[" <> pure chr <> "] ") <+> txt m
+      str ("[" <> pure chr <> "] ") <+> txtWrap m
 
 drawEntities
   :: (Position -> Bool)
@@ -95,11 +95,32 @@ drawMap game
     -- character can't see them
     (game ^. entities)
 
+bullet :: Char
+bullet = '•'
+
+drawPanel :: GameState -> Panel -> Widget Name
+drawPanel game panel
+  = border
+  . hLimit 35
+  . viewport (Resource.Panel panel) Vertical
+  $ case panel of
+      InventoryPanel ->
+        let items = game ^. character . inventory
+        in if null items
+           then txtWrap "Your inventory is empty right now."
+           else
+             txtWrap "You are currently carrying the following items:"
+             <=> txt " "
+             <=> foldl' (<=>) emptyWidget
+                 (map
+                  (txtWrap . ((bullet <| " ") <>) . description)
+                  items)
+
 drawCharacterInfo :: Character -> Widget Name
 drawCharacterInfo ch = txt " " <+> charName <+> charHitpoints
   where
     charName | Just n <- ch ^. characterName
-             = txt n <+> txt " "
+             = txt $ n <> " "
              | otherwise
              = emptyWidget
     charHitpoints
@@ -114,5 +135,8 @@ drawGame game
        NoPrompt -> drawMessages (game ^. messageHistory)
        _ -> emptyWidget
   <=> drawPromptState (game ^. promptState)
-  <=> border (drawMap game)
+  <=>
+  (maybe emptyWidget (drawPanel game) (game ^. activePanel)
+  <+> border (drawMap game)
+  )
   <=> drawCharacterInfo (game ^. character)