From 65b1352ef2e463393d0504c32b73bdcf7c99491a Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Sat, 30 Nov 2019 22:43:17 -0500 Subject: 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. --- src/Xanthous/Game/Draw.hs | 44 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) (limited to 'src/Xanthous/Game/Draw.hs') 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) -- cgit 1.4.1