Readd space action on buttons

This commit is contained in:
2024-11-24 23:34:03 +00:00
parent 7d2a4bf439
commit 9e0f0536e2
9 changed files with 125 additions and 148 deletions
+1 -1
View File
@@ -51,7 +51,7 @@ data HUD = HUD
, _carteZoom :: Float
, _carteRot :: Float
, _closeItems :: [NewInt FloorInt]
, _closeInterfaces :: [Int]
, _closeButtons :: [Int]
}
makeLenses ''HUD
+1 -1
View File
@@ -157,7 +157,7 @@ defaultHUD =
, _carteZoom = 0.5
, _carteRot = 0
, _closeItems = mempty
, _closeInterfaces = mempty
, _closeButtons = mempty
}
defaultDisplayInventory :: HUDElement
+1 -1
View File
@@ -156,7 +156,7 @@ updateDisplaySections w cfig =
interfaces = (5,btitems)
btitems =
IM.fromDistinctAscList . zip [0 ..] $
mapMaybe (closeButtonToSelectionItem w) (w ^. hud . closeInterfaces)
mapMaybe (closeButtonToSelectionItem w) (w ^. hud . closeButtons)
makehead str i = (i,IM.singleton 0 $ SelectionInfo [str] 1 False white 0)
statushead = (-4,IM.singleton 0 $ SelectionInfo ["STATUS"] 1 False white 0)
statusdisplay = (-3,IM.singleton 0 $ SelectionInfo ["HEALTH: "++show (_crHP cr)] 1 False white 0)
+8 -38
View File
@@ -9,16 +9,13 @@ module Dodge.Inventory (
scrollAugInvSel,
crNumFreeSlots,
crInvSize,
selectedCloseItem,
setInvPosFromSS,
module Dodge.Inventory.RBList,
swapInvItems,
scrollAugNextInSection,
-- isFilteringInv,
swapItemWith,
) where
import Control.Applicative
import Control.Monad
import Data.Function
import qualified Data.IntSet as IS
@@ -123,7 +120,7 @@ updateCloseObjects :: World -> World
updateCloseObjects w =
w
& hud . closeItems %~ f
& hud . closeInterfaces %~ g
& hud . closeButtons %~ g
where
g oldbts = intersect oldbts cbts `union` cbts
f olditems = intersect olditems citems `union` citems
@@ -156,33 +153,6 @@ changeSwapSel yi w
where
f g i m = fst <$> g i m
--changeSwapClose ::
-- (Int -> IM.IntMap (SelectionItem ()) -> Maybe Int) ->
-- Int ->
-- World ->
-- World
--changeSwapClose f i w = fromMaybe w $ do
-- ss <- w ^? hud . hudElement . diSections . ix 3 . ssItems
-- k <- f i ss
-- let doswap j
-- | j == i = k
-- | j == k = i
-- | otherwise = j
-- return $
-- w
-- & swapAnyExtraSelection i k
-- & cWorld . lWorld . creatures . ix 0 . crManipulation . manObject . ispCloseItem
-- %~ doswap
-- & hud . closeItems %~ swapIndices i k
-- & hud . hudElement . diSelection . _Just . _2 %~ doswap
-- & worldEventFlags . at InventoryChange ?~ ()
--changeSwapClose' ::
-- (Int -> IM.IntMap (SelectionItem ()) -> Maybe Int) ->
-- Int ->
-- World ->
-- World
changeSwapOther ::
((Int -> Identity Int) -> ManipulatedObject -> Identity ManipulatedObject) ->
Int ->
@@ -334,10 +304,10 @@ scrollAugNextInSection w =
sss <- he ^? diSections
return $ he & diSelection %~ nextInSectionSS sss
selectedCloseItem :: World -> Maybe FloorItem
selectedCloseItem w = do
i <-
you w ^? crManipulation . manObject . ispCloseItem
<|> fmap fst (IM.lookupMin =<< w ^? hud . hudElement . diSections . ix 3 . ssItems)
flitid <- w ^? hud . closeItems . ix i . unNInt
w ^? cWorld . lWorld . floorItems . unNIntMap . ix flitid
--selectedCloseItem :: World -> Maybe FloorItem
--selectedCloseItem w = do
-- i <-
-- you w ^? crManipulation . manObject . ispCloseItem
-- <|> fmap fst (IM.lookupMin =<< w ^? hud . hudElement . diSections . ix 3 . ssItems)
-- flitid <- w ^? hud . closeItems . ix i . unNInt
-- w ^? cWorld . lWorld . floorItems . unNIntMap . ix flitid
+23 -26
View File
@@ -2,12 +2,10 @@
module Dodge.Inventory.SelectionList (
invSelectionItem,
invSelectionItem',
closeItemToSelectionItem,
closeButtonToSelectionItem,
) where
import NewInt
import Dodge.Data.ComposedItem
import Dodge.Data.SelectionList
import Dodge.Data.World
@@ -16,12 +14,10 @@ import Dodge.Item.Display
import Dodge.Item.Grammar
import Dodge.Item.InventoryColor
import LensHelp
import NewInt
import Padding
import Picture.Base
invSelectionItem' :: Creature -> Int -> ComposedItem -> SelectionItem ()
invSelectionItem' = invSelectionItem 0
invSelectionItem :: Int -> Creature -> Int -> ComposedItem -> SelectionItem ()
invSelectionItem indent cr i ci =
SelectionItem
@@ -57,30 +53,31 @@ closeItemToSelectionItem :: World -> NewInt FloorInt -> Maybe (SelectionItem ())
closeItemToSelectionItem w (NInt i) = do
e <- w ^? cWorld . lWorld . floorItems . unNIntMap . ix i
let (pics, col) = closeItemToTextPictures e
return SelectionItem
{ _siPictures = pics
, _siHeight = length pics
, _siIsSelectable = True
, _siColor = col
, _siOffX = 0
, _siPayload = ()
}
return
SelectionItem
{ _siPictures = pics
, _siHeight = length pics
, _siIsSelectable = True
, _siColor = col
, _siOffX = 0
, _siPayload = ()
}
closeButtonToSelectionItem :: World -> Int -> Maybe (SelectionItem ())
closeButtonToSelectionItem w i = do
bt <- w ^? cWorld . lWorld . buttons . ix i
return SelectionItem
{ _siPictures = [_btText bt]
, _siHeight = 1
, _siIsSelectable = True
, _siColor = yellow
, _siOffX = 0
, _siPayload = ()
}
return
SelectionItem
{ _siPictures = [_btText bt]
, _siHeight = 1
, _siIsSelectable = True
, _siColor = yellow
, _siOffX = 0
, _siPayload = ()
}
closeItemToTextPictures :: FloorItem -> ([String], Color)
closeItemToTextPictures flit =
let it = _flIt flit
in (basicItemDisplay it, itemInvColor . pciToCI $ basePCI it)
closeItemToTextPictures flit =
(basicItemDisplay it, itemInvColor . pciToCI $ basePCI it)
where
it = _flIt flit
+1 -1
View File
@@ -224,7 +224,7 @@ yourAugmentedItem f x g w = case you w ^? crManipulation . manObject of
return . g $ Left flit
-- g . Left $ w ^?! hud . closeItems . ix i
Just (SelCloseButton i) -> fromMaybe x $ do
j <- w ^? hud . closeInterfaces . ix i
j <- w ^? hud . closeButtons . ix i
flit <- w ^? cWorld . lWorld . buttons . ix j
return . g $ Right flit
_ -> x
+36 -26
View File
@@ -3,6 +3,7 @@ module Dodge.Update.Input.InGame (
updateMouseInGame,
) where
import NewInt
import Control.Applicative
import Control.Monad
import Data.Foldable
@@ -47,35 +48,28 @@ updateUseInputInGame u = updateFunctionKeys $ case u ^. uvWorld . hud . hudEleme
& uvWorld . worldEventFlags . at CombineInventoryChange ?~ ()
_
| inInvRegex (u ^. uvWorld) ->
u & uvWorld . hud . hudElement %~ dodisplayregexinput (-1)
u & uvWorld . hud . hudElement
%~ dodisplayregexinput diInvFilter diInvFilter (-1)
& uvWorld . worldEventFlags . at InventoryChange ?~ ()
& uvWorld %~ setInvPosFromSS
_
| inCloseRegex (u ^. uvWorld) ->
u & uvWorld . hud . hudElement %~ dodisplayregexinput' 2
u & uvWorld . hud . hudElement
%~ dodisplayregexinput diCloseFilter diCloseFilter 2
& uvWorld . worldEventFlags . at InventoryChange ?~ ()
& uvWorld %~ setInvPosFromSS
_ -> M.foldlWithKey' updateKeyInGame u pkeys
where
pkeys = u ^. uvWorld . input . pressedKeys
dodisplayregexinput x di = fromMaybe di $ do
dodisplayregexinput filterprism filterlens x di = fromMaybe di $ do
sss <- di ^? diSections
msel <- di ^? diSelection
filts <- di ^? diInvFilter
filts <- di ^? filterprism
let (sss', msel', filts') = doRegexInput (u ^. uvWorld . input) x sss msel filts
return $
di & diSections .~ sss'
& diSelection .~ msel'
& diInvFilter .~ filts'
dodisplayregexinput' x di = fromMaybe di $ do
sss <- di ^? diSections
msel <- di ^? diSelection
filts <- di ^? diCloseFilter
let (sss', msel', filts') = doRegexInput (u ^. uvWorld . input) x sss msel filts
return $
di & diSections .~ sss'
& diSelection .~ msel'
& diCloseFilter .~ filts'
& filterlens .~ filts'
docombineregexinput sss msel ci = fromMaybe ci $ do
filts <- ci ^? ciFilter
let (sss', msel', filts') = doRegexInput (u ^. uvWorld . input) (-1) sss msel filts
@@ -453,27 +447,43 @@ pauseGame u = u & uvScreenLayers .~ [pauseMenu u]
spaceAction :: World -> World
spaceAction w = case w ^. hud . hudElement of
DisplayCarte -> w & hud . carteCenter .~ theLoc
DisplayInventory{_subInventory = NoSubInventory{}} -> case Left <$> selectedCloseItem w of
Just (Left flit) ->
pickUpItem 0 flit w
DisplayInventory{_subInventory = NoSubInventory{}} -> fromMaybe w $ do
cobj <- selCloseObj w
return $ case cobj of -- case Left <$> selectedCloseItem w of
(Left flit) -> pickUpItem 0 flit w
& worldEventFlags . at InventoryChange ?~ ()
Just (Right but) ->
doButtonEvent (_btEvent but) but w
(Right but) -> doButtonEvent (_btEvent but) but w
& worldEventFlags . at InventoryChange ?~ ()
_ -> w
DisplayInventory{_subInventory = DisplayTerminal{}} ->
w & hud . hudElement . subInventory
.~ NoSubInventory --MouseInvNothing
DisplayInventory{_subInventory = DisplayTerminal{}} -> w
& hud . hudElement . subInventory .~ NoSubInventory
& worldEventFlags . at InventoryChange ?~ ()
_ ->
w & hud . hudElement . subInventory
.~ NoSubInventory --MouseInvNothing
_ -> w & hud . hudElement . subInventory .~ NoSubInventory
where
theLoc =
doWorldPos
(w ^?! cWorld . lWorld . seenLocations . ix (w ^. cWorld . lWorld . selLocation) . _1)
w
selCloseObj :: World -> Maybe (Either FloorItem Button)
selCloseObj w = selobj <|> firstcitem <|> firstcbut
where
selobj = do
(i,j) <- w ^? hud . hudElement . diSelection . _Just
case i of
3 -> do
NInt k <- w ^? hud . closeItems . ix j
fmap Left $ w ^? cWorld . lWorld . floorItems . unNIntMap . ix k
5 -> do
k <- w ^? hud . closeButtons . ix j
fmap Right $ w ^? cWorld . lWorld . buttons . ix k
_ -> Nothing
firstcitem = do
NInt k <- w ^? hud . closeItems . ix 0
fmap Left $ w ^? cWorld . lWorld . floorItems . unNIntMap . ix k
firstcbut = do
k <- w ^? hud . closeButtons . ix 0
fmap Right $ w ^? cWorld . lWorld . buttons . ix k
toggleMap :: Universe -> Universe
toggleMap u = case u ^. uvWorld . hud . hudElement of
DisplayCarte ->