Introduce idea of world event flags
This commit is contained in:
+47
-33
@@ -22,22 +22,22 @@ module Dodge.Inventory (
|
||||
setInvPosFromSS,
|
||||
) where
|
||||
|
||||
import Dodge.DisplayInventory
|
||||
import Dodge.SelectionSections
|
||||
import Control.Applicative
|
||||
import Dodge.Data.SelectionList
|
||||
import Color
|
||||
import Control.Applicative
|
||||
import qualified Data.Map.Strict as M
|
||||
import Data.Maybe
|
||||
import Dodge.Base
|
||||
import Dodge.Data.Config
|
||||
import Dodge.Data.SelectionList
|
||||
import Dodge.Data.World
|
||||
import Dodge.DisplayInventory
|
||||
import Dodge.Euse
|
||||
import Dodge.Inventory.CheckSlots
|
||||
import Dodge.Inventory.CloseObject
|
||||
import Dodge.Inventory.Color
|
||||
import Dodge.ItEffect
|
||||
import Dodge.Reloading
|
||||
import Dodge.SelectionSections
|
||||
import Geometry
|
||||
import qualified IntMapHelp as IM
|
||||
import LensHelp
|
||||
@@ -45,6 +45,7 @@ import ListHelp
|
||||
import Padding
|
||||
|
||||
-- TODO check what happens to selection index when dropping non-selected items
|
||||
|
||||
-- | after this the item at the inventory position will no longer exist
|
||||
rmInvItem ::
|
||||
-- | Creature id
|
||||
@@ -55,6 +56,7 @@ rmInvItem ::
|
||||
World
|
||||
rmInvItem cid invid w = case w ^? getcid . crInv . ix invid . itUse . useAmount of
|
||||
Just x | x > 1 -> w & pointcid . crInv . ix invid . itUse . useAmount -~ 1
|
||||
& worldEventFlags . at InventoryChange ?~ ()
|
||||
_ ->
|
||||
w
|
||||
& pointcid %~ crCancelReloading
|
||||
@@ -66,16 +68,16 @@ rmInvItem cid invid w = case w ^? getcid . crInv . ix invid . itUse . useAmount
|
||||
& pointcid . crInvEquipped %~ IM.delete invid
|
||||
& pointcid . crInvEquipped %~ IM.mapKeys g
|
||||
& updateselection
|
||||
& worldEventFlags . at InventoryChange ?~ ()
|
||||
where
|
||||
|
||||
getcid = cWorld . lWorld . creatures . ix cid
|
||||
pointcid = cWorld . lWorld . creatures . ix cid
|
||||
|
||||
updateselection
|
||||
| cid == 0 && cr ^? crManipulation . manObject . inInventory . ispItem == Just invid
|
||||
= scrollAugInvSel (-1) . scrollAugInvSel 1 . updateInventorySectionItems
|
||||
| otherwise
|
||||
= pointcid . crManipulation . manObject . inInventory . ispItem %~ g
|
||||
| cid == 0 && cr ^? crManipulation . manObject . inInventory . ispItem == Just invid =
|
||||
scrollAugInvSel (-1) . scrollAugInvSel 1 . updateInventorySectionItems
|
||||
| otherwise =
|
||||
pointcid . crManipulation . manObject . inInventory . ispItem %~ g
|
||||
|
||||
cr = w ^?! cWorld . lWorld . creatures . ix cid
|
||||
itm = _crInv cr IM.! invid
|
||||
@@ -111,13 +113,14 @@ rmSelectedInvItem cid w = case w ^? cWorld . lWorld . creatures . ix cid . crMan
|
||||
Nothing -> w
|
||||
|
||||
selNumPos :: ManipulatedObject -> World -> Maybe Int
|
||||
selNumPos mo w = w ^? hud . hudElement . diSections >>=
|
||||
case mo of
|
||||
InInventory SortInventory -> selSecSelPos (-1) 0
|
||||
InInventory (SelItem i _) -> selSecSelPos 0 i
|
||||
SelNothing -> selSecSelPos 1 0
|
||||
InNearby SortNearby -> selSecSelPos 2 0
|
||||
InNearby (SelCloseObject i) -> selSecSelPos 3 i
|
||||
selNumPos mo w =
|
||||
w ^? hud . hudElement . diSections
|
||||
>>= case mo of
|
||||
InInventory SortInventory -> selSecSelPos (-1) 0
|
||||
InInventory (SelItem i _) -> selSecSelPos 0 i
|
||||
SelNothing -> selSecSelPos 1 0
|
||||
InNearby SortNearby -> selSecSelPos 2 0
|
||||
InNearby (SelCloseObject i) -> selSecSelPos 3 i
|
||||
|
||||
-- there are still more ListDisplayParams to integrate here
|
||||
selNumTextEndPos :: Configuration -> ListDisplayParams -> SelectionSections a -> Int -> Int -> Maybe Point2
|
||||
@@ -130,8 +133,13 @@ selNumTextEndPos cfig ldp sss i j = do
|
||||
hh = halfHeight cfig
|
||||
hw = halfWidth cfig
|
||||
|
||||
selNumEndMidHeight :: Configuration -> ListDisplayParams -> SelectionSections a -> Int
|
||||
-> Int -> Maybe Point2
|
||||
selNumEndMidHeight ::
|
||||
Configuration ->
|
||||
ListDisplayParams ->
|
||||
SelectionSections a ->
|
||||
Int ->
|
||||
Int ->
|
||||
Maybe Point2
|
||||
selNumEndMidHeight cfig ldp sss i j = do
|
||||
ipos <- selSecSelPos i j sss
|
||||
size <- selSecSelSize i j sss
|
||||
@@ -165,12 +173,12 @@ updateCloseObjects w =
|
||||
& updatecursorposifnecessary
|
||||
where
|
||||
newcloseobjects = unionBy closeObjEq oldCloseFiltered currentClose
|
||||
updatecursorposifnecessary
|
||||
= case w ^? cWorld . lWorld . creatures . ix 0 . crManipulation . manObject. inNearby . ispCloseObject of
|
||||
Just i
|
||||
updatecursorposifnecessary =
|
||||
case w ^? cWorld . lWorld . creatures . ix 0 . crManipulation . manObject . inNearby . ispCloseObject of
|
||||
Just i
|
||||
| i >= length newcloseobjects -> scrollAugInvSel 1
|
||||
| isNothing (w ^? hud . hudElement . diSections . sssSections . ix 3 . ssItems . ix i)
|
||||
-> scrollAugInvSel (-1)
|
||||
| isNothing (w ^? hud . hudElement . diSections . sssSections . ix 3 . ssItems . ix i) ->
|
||||
scrollAugInvSel (-1)
|
||||
_ -> id
|
||||
filt = filter $ \obj -> dist ypos (closeObjPos obj) < 40 && hasButtonLOS ypos (closeObjPos obj) w
|
||||
ypos = _crPos $ you w
|
||||
@@ -321,17 +329,21 @@ closeObjScrollDir x
|
||||
|
||||
changeSwapInvSel :: Int -> World -> World
|
||||
changeSwapInvSel k w = case you w ^? crManipulation . manObject of
|
||||
Just (InInventory (SelItem i _)) -> w & cWorld . lWorld . creatures . ix 0 %~ updatecreature i
|
||||
Just (InNearby (SelCloseObject i)) -> w
|
||||
& cWorld . lWorld . creatures . ix 0 . crManipulation . manObject . inNearby . ispCloseObject
|
||||
Just (InInventory (SelItem i _)) ->
|
||||
w & cWorld . lWorld . creatures . ix 0 %~ updatecreature i
|
||||
& worldEventFlags . at InventoryChange ?~ ()
|
||||
Just (InNearby (SelCloseObject i)) ->
|
||||
w
|
||||
& cWorld . lWorld . creatures . ix 0 . crManipulation . manObject . inNearby . ispCloseObject
|
||||
.~ ((i - k) `mod` numCO)
|
||||
& hud . closeObjects %~ swapIndices i ((i - k) `mod` numCO)
|
||||
& worldEventFlags . at InventoryChange ?~ ()
|
||||
_ -> w
|
||||
where
|
||||
updatecreature i =
|
||||
(crInv %~ IM.safeSwapKeys (i `mod` n) (swapi i))
|
||||
. (crLeftInvSel . lisMPos . _Just %~ updateLeftInvSel i)
|
||||
. (crManipulation . manObject . inInventory . ispItem %~ (`mod` n) . subtract k)
|
||||
. (crManipulation . manObject . inInventory . ispItem %~ (`mod` n) . subtract k)
|
||||
. (crInvEquipped %~ IM.safeSwapKeys i (swapi i))
|
||||
. swapSite i (swapi i)
|
||||
. swapSite (swapi i) i
|
||||
@@ -352,15 +364,17 @@ scrollAugInvSel yi w
|
||||
| yi == 0 = w
|
||||
| otherwise =
|
||||
w & hud . hudElement . diSections %~ scrollSelectionSections yi
|
||||
& worldEventFlags . at InventoryChange ?~ ()
|
||||
& setInvPosFromSS
|
||||
|
||||
setInvPosFromSS :: World -> World
|
||||
setInvPosFromSS w = w
|
||||
& cWorld . lWorld . creatures . ix 0 . crManipulation . manObject .~ thesel
|
||||
setInvPosFromSS w =
|
||||
w
|
||||
& cWorld . lWorld . creatures . ix 0 . crManipulation . manObject .~ thesel
|
||||
where
|
||||
thesel = fromMaybe SelNothing $ do
|
||||
sss <- w ^? hud . hudElement . diSections
|
||||
(i,j) <- sss ^? sssExtra . sssSelPos . _Just
|
||||
(i, j) <- sss ^? sssExtra . sssSelPos . _Just
|
||||
case i of
|
||||
(-1) -> Just $ InInventory SortInventory
|
||||
0 -> Just $ InInventory (SelItem j NoInvSelAction)
|
||||
@@ -368,10 +382,10 @@ setInvPosFromSS w = w
|
||||
2 -> Just $ InNearby SortNearby
|
||||
3 -> Just $ InNearby $ SelCloseObject j
|
||||
_ -> error "selection out of bounds"
|
||||
|
||||
|
||||
selectedCloseObject :: World -> Maybe (Either FloorItem Button)
|
||||
selectedCloseObject w = do
|
||||
i <- you w ^? crManipulation . manObject . inNearby . ispCloseObject
|
||||
<|> fmap fst (IM.lookupMin =<< w ^? hud . hudElement . diSections . sssSections . ix 3 . ssItems)
|
||||
i <-
|
||||
you w ^? crManipulation . manObject . inNearby . ispCloseObject
|
||||
<|> fmap fst (IM.lookupMin =<< w ^? hud . hudElement . diSections . sssSections . ix 3 . ssItems)
|
||||
w ^? hud . closeObjects . ix i
|
||||
|
||||
Reference in New Issue
Block a user