Start simplifying mouse inventory selection
This commit is contained in:
+48
-35
@@ -5,6 +5,7 @@ module Dodge.Inventory (
|
||||
destroyInvItem,
|
||||
updateCloseObjects,
|
||||
changeSwapSel,
|
||||
augInvDirectSelect,
|
||||
scrollAugInvSel,
|
||||
crNumFreeSlots,
|
||||
crInvSize,
|
||||
@@ -14,9 +15,6 @@ module Dodge.Inventory (
|
||||
swapInvItems,
|
||||
) where
|
||||
|
||||
import NewInt
|
||||
import Dodge.Inventory.Location
|
||||
import Dodge.Inventory.RBList
|
||||
import Control.Applicative
|
||||
import Data.Maybe
|
||||
import Dodge.Base
|
||||
@@ -26,19 +24,23 @@ import Dodge.Data.World
|
||||
import Dodge.Euse
|
||||
import Dodge.Inventory.CheckSlots
|
||||
import Dodge.Inventory.CloseObject
|
||||
import Dodge.Inventory.Location
|
||||
import Dodge.Inventory.RBList
|
||||
import Dodge.ItEffect
|
||||
import Dodge.SelectionSections
|
||||
import Geometry
|
||||
import qualified IntMapHelp as IM
|
||||
import LensHelp
|
||||
import ListHelp
|
||||
import NewInt
|
||||
|
||||
--import Padding
|
||||
|
||||
-- TODO check what happens to selection index when dropping non-selected items
|
||||
|
||||
-- should consider never fully destroying items, but assigning a flag saying how
|
||||
-- they were moved from play
|
||||
destroyInvItem ::
|
||||
destroyInvItem ::
|
||||
Int ->
|
||||
-- | Inventory position
|
||||
Int ->
|
||||
@@ -58,31 +60,30 @@ rmInvItem ::
|
||||
Int ->
|
||||
World ->
|
||||
World
|
||||
rmInvItem cid invid w = w
|
||||
& doanyitemeffect
|
||||
& dounequipfunction --the ordering of these is
|
||||
& pointcid . crInv %~ f -- important
|
||||
|
||||
& removeAnySlotEquipment
|
||||
& pointcid . crEquipment . each %~ g
|
||||
& pointcid . crInvEquipped %~ IM.delete invid
|
||||
& pointcid . crInvEquipped %~ IM.mapKeys g
|
||||
|
||||
& removeanyactivation
|
||||
& pointcid . crHotkeys . each %~ g
|
||||
& pointcid . crInvHotkeys %~ IM.delete invid
|
||||
& pointcid . crInvHotkeys %~ IM.mapKeys g
|
||||
|
||||
& updateselection
|
||||
& pointcid %~ updateRootItemID
|
||||
& worldEventFlags . at InventoryChange ?~ ()
|
||||
-- & updateCreatureItemLocations cid
|
||||
rmInvItem cid invid w =
|
||||
w
|
||||
& doanyitemeffect
|
||||
& dounequipfunction --the ordering of these is
|
||||
& pointcid . crInv %~ f -- important
|
||||
& removeAnySlotEquipment
|
||||
& pointcid . crEquipment . each %~ g
|
||||
& pointcid . crInvEquipped %~ IM.delete invid
|
||||
& pointcid . crInvEquipped %~ IM.mapKeys g
|
||||
& removeanyactivation
|
||||
& pointcid . crHotkeys . each %~ g
|
||||
& pointcid . crInvHotkeys %~ IM.delete invid
|
||||
& pointcid . crInvHotkeys %~ IM.mapKeys g
|
||||
& updateselection
|
||||
& pointcid %~ updateRootItemID
|
||||
& worldEventFlags . at InventoryChange ?~ ()
|
||||
where
|
||||
-- & updateCreatureItemLocations cid
|
||||
|
||||
pointcid = cWorld . lWorld . creatures . ix cid
|
||||
|
||||
updateselection
|
||||
| cid == 0 && cr ^? crManipulation . manObject . imSelectedItem == Just invid =
|
||||
scrollAugInvSel (-1) . scrollAugInvSel 1-- . updateInventorySectionItems
|
||||
scrollAugInvSel (-1) . scrollAugInvSel 1 -- . updateInventorySectionItems
|
||||
| otherwise =
|
||||
pointcid . crManipulation . manObject . imSelectedItem %~ g
|
||||
|
||||
@@ -131,12 +132,17 @@ updateCloseObjects w =
|
||||
. filter ((/=) BtNoLabel . _btState)
|
||||
. IM.elems
|
||||
$ w ^. cWorld . lWorld . buttons
|
||||
currentClose = filt $ map Left (IM.elems $ w ^. cWorld . lWorld . floorItems . unNIntMap)
|
||||
++ activeButtons
|
||||
currentClose =
|
||||
filt $
|
||||
map Left (IM.elems $ w ^. cWorld . lWorld . floorItems . unNIntMap)
|
||||
++ activeButtons
|
||||
oldClose = filt $ mapMaybe updatebyid $ w ^. hud . closeObjects
|
||||
oldCloseFiltered = intersectBy closeObjEq oldClose currentClose
|
||||
updatebyid (Left flid) = fmap Left $ w ^? cWorld . lWorld . floorItems . unNIntMap
|
||||
. ix (_unNInt $ _flItID flid)
|
||||
updatebyid (Left flid) =
|
||||
fmap Left $
|
||||
w
|
||||
^? cWorld . lWorld . floorItems . unNIntMap
|
||||
. ix (_unNInt $ _flItID flid)
|
||||
updatebyid (Right btid) = fmap Right $ w ^? cWorld . lWorld . buttons . ix (_btID btid)
|
||||
|
||||
changeSwapSel :: Int -> World -> World
|
||||
@@ -173,17 +179,17 @@ swapInvItems f i w = fromMaybe w $ do
|
||||
ss <- w ^? hud . hudElement . diSections . sssSections . ix 0 . ssItems
|
||||
k <- f i ss
|
||||
let updateselection = case w ^? hud . hudElement . diSections . sssExtra . sssSelPos . _Just of
|
||||
Just (0,j) | j == k -> hud . hudElement . diSections . sssExtra . sssSelPos . _Just . _2 .~ i
|
||||
Just (0,j) | j == i -> hud . hudElement . diSections . sssExtra . sssSelPos . _Just . _2 .~ k
|
||||
Just (0, j) | j == k -> hud . hudElement . diSections . sssExtra . sssSelPos . _Just . _2 .~ i
|
||||
Just (0, j) | j == i -> hud . hudElement . diSections . sssExtra . sssSelPos . _Just . _2 .~ k
|
||||
_ -> id
|
||||
return $
|
||||
w & cWorld . lWorld . creatures . ix 0 %~ updatecreature k
|
||||
& updateselection
|
||||
& worldEventFlags . at InventoryChange ?~ ()
|
||||
& cWorld . lWorld %~ crUpdateItemLocations 0
|
||||
& setInvPosFromSS
|
||||
& cWorld . lWorld %~ crUpdateItemLocations 0 -- the double application is inefficient, but necessary without further changes
|
||||
-- a rethink is maybe in order
|
||||
& cWorld . lWorld %~ crUpdateItemLocations 0
|
||||
& setInvPosFromSS
|
||||
& cWorld . lWorld %~ crUpdateItemLocations 0 -- the double application is inefficient, but necessary without further changes
|
||||
-- a rethink is maybe in order
|
||||
where
|
||||
updatecreature k =
|
||||
(crInv %~ IM.safeSwapKeys i k)
|
||||
@@ -208,6 +214,14 @@ changeSwapWith f w = case w ^? hud . hudElement . diSections . sssExtra . sssSel
|
||||
Just (3, i) -> w & changeSwapClose f i
|
||||
_ -> w
|
||||
|
||||
augInvDirectSelect :: (Int, Int) -> World -> World
|
||||
augInvDirectSelect (i, j) w =
|
||||
w
|
||||
& hud . hudElement . diSections . sssExtra . sssSelPos .~ Just (i, j)
|
||||
& worldEventFlags . at InventoryChange ?~ ()
|
||||
& setInvPosFromSS
|
||||
& cWorld . lWorld %~ crUpdateItemLocations 0
|
||||
|
||||
scrollAugInvSel :: Int -> World -> World
|
||||
scrollAugInvSel yi w
|
||||
| yi == 0 = w
|
||||
@@ -217,7 +231,6 @@ scrollAugInvSel yi w
|
||||
& setInvPosFromSS
|
||||
& cWorld . lWorld %~ crUpdateItemLocations 0
|
||||
|
||||
|
||||
selectedCloseObject :: World -> Maybe (Either FloorItem Button)
|
||||
selectedCloseObject w = do
|
||||
i <-
|
||||
|
||||
Reference in New Issue
Block a user