Partially working change to selected items
This commit is contained in:
+111
-93
@@ -3,7 +3,7 @@
|
||||
module Dodge.Inventory (
|
||||
checkInvSlotsYou,
|
||||
rmSelectedInvItem,
|
||||
invSelPos,
|
||||
--invSelPos,
|
||||
invSelSize,
|
||||
selNumPos,
|
||||
selNumTextPos,
|
||||
@@ -59,7 +59,8 @@ rmInvItem cid invid w = case w ^? getcid . crInv . ix invid . itUse . useAmount
|
||||
w
|
||||
& pointcid . crInv %~ f
|
||||
& pointcid %~ crCancelReloading
|
||||
& pointcid . crInvSel . iselPos %~ g
|
||||
-- & pointcid . crInvSel . iselPos %~ g THIS NEEDS CHECKING
|
||||
& pointcid . crInvSel . isel . ispItem %~ g
|
||||
& pointcid . crLeftInvSel . lisMPos %~ g'
|
||||
& removeAnySlotEquipment
|
||||
& dounequipfunction
|
||||
@@ -97,7 +98,9 @@ rmInvItem cid invid w = case w ^? getcid . crInv . ix invid . itUse . useAmount
|
||||
| otherwise = Just x
|
||||
|
||||
rmSelectedInvItem :: Int -> World -> World
|
||||
rmSelectedInvItem cid w = rmInvItem cid (crSel (w ^?! cWorld . lWorld . creatures . ix cid)) w
|
||||
rmSelectedInvItem cid w = case w ^? cWorld . lWorld . creatures . ix cid . crInvSel . isel . ispItem of
|
||||
Just i -> rmInvItem cid i w
|
||||
Nothing -> w
|
||||
|
||||
augmentedInvSizes :: World -> IM.IntMap Int
|
||||
augmentedInvSizes = trimapAugmentInv itSlotsTaken 1 closeObjectSize
|
||||
@@ -146,8 +149,8 @@ selNumMidHeight cfig w i = V2 (150 - hw) (hh + bump - (20 * fromIntegral ipos +
|
||||
selNumCol :: Int -> World -> Color
|
||||
selNumCol i w = fromMaybe white $ trimapAugmentInv _itInvColor invDimColor closeObjectCol w IM.!? i
|
||||
|
||||
invSelPos :: World -> Int
|
||||
invSelPos w = sum . fst $ IM.split (yourInvSel w) (augmentedInvSizes w)
|
||||
--invSelPos :: World -> Int
|
||||
--invSelPos w = sum . fst $ IM.split (yourInvSel w) (augmentedInvSizes w)
|
||||
|
||||
updateTerminal :: World -> World
|
||||
updateTerminal = checkTermDist
|
||||
@@ -164,12 +167,14 @@ checkTermDist w = case w ^? hud . hudElement . subInventory . termID of
|
||||
updateCloseObjects :: World -> World
|
||||
updateCloseObjects w =
|
||||
w
|
||||
& hud . closeObjects .~ unionBy closeObjEq oldCloseFiltered currentClose
|
||||
& cWorld . lWorld . creatures . ix 0 . crInvSel . iselPos %~ updateinvsel
|
||||
& hud . closeObjects .~ newcloseobjects
|
||||
& updatecursorposifnecessary
|
||||
where
|
||||
updateinvsel curinvsel
|
||||
| length (augmentedInvSizes w) <= curinvsel = max 0 $ length (augmentedInvSizes w) - 1
|
||||
| otherwise = curinvsel
|
||||
newcloseobjects = unionBy closeObjEq oldCloseFiltered currentClose
|
||||
updatecursorposifnecessary
|
||||
= case w ^? cWorld . lWorld . creatures . ix 0 . crInvSel . isel . ispCloseObject of
|
||||
Just i | i >= length newcloseobjects -> changeAugInvSel 1
|
||||
_ -> id
|
||||
filt = filter $ \obj -> dist ypos (closeObjPos obj) < 40 && hasButtonLOS ypos (closeObjPos obj) w
|
||||
ypos = _crPos $ you w
|
||||
activeButtons =
|
||||
@@ -188,7 +193,8 @@ updateRBList w
|
||||
| w ^? rbOptions . opItemID == mcurrentitemid =
|
||||
w & setEquipAllocation & setEquipActivation
|
||||
| otherwise = fromMaybe (w & rbOptions .~ NoRightButtonOptions) $ do
|
||||
esite <- cr ^? crInv . ix curinvid . itUse . equipEffect . eeSite
|
||||
i <- cr ^? crInvSel . isel . ispItem
|
||||
esite <- cr ^? crInv . ix i . itUse . equipEffect . eeSite
|
||||
itid <- mcurrentitemid
|
||||
return $
|
||||
w
|
||||
@@ -203,13 +209,16 @@ updateRBList w
|
||||
& setEquipAllocation
|
||||
& setEquipActivation
|
||||
where
|
||||
mcurrentitemid = cr ^? crInv . ix curinvid . itID
|
||||
curinvid = crSel cr
|
||||
mcurrentitemid = do
|
||||
i <- cr ^? crInvSel . isel . ispItem
|
||||
cr ^? crInv . ix i . itID
|
||||
--curinvid = crSel cr
|
||||
cr = you w
|
||||
|
||||
chooseEquipmentPosition :: Creature -> [EquipPosition] -> Int
|
||||
chooseEquipmentPosition cr eps = fromMaybe (chooseFreeSite cr eps) $ do
|
||||
ep <- cr ^? crInvEquipped . ix (crSel cr)
|
||||
i <- cr ^? crInvSel . isel . ispItem
|
||||
ep <- cr ^? crInvEquipped . ix i
|
||||
elemIndex ep eps
|
||||
|
||||
chooseFreeSite :: Creature -> [EquipPosition] -> Int
|
||||
@@ -218,42 +227,44 @@ chooseFreeSite cr = fromMaybe 0 . findIndex hasnoequipment
|
||||
hasnoequipment ep = isNothing $ cr ^? crEquipment . ix ep
|
||||
|
||||
setEquipAllocation :: World -> World
|
||||
setEquipAllocation w = case _rbOptions w of
|
||||
EquipOptions{_opEquip = es, _opSel = i} ->
|
||||
case you w ^? crInvEquipped . ix (crSel (you w)) of
|
||||
Just epos
|
||||
| es !! i == epos ->
|
||||
setEquipAllocation w = fromMaybe w $ do
|
||||
curpos <- you w ^? crInvSel . isel . ispItem
|
||||
return $ case _rbOptions w of
|
||||
EquipOptions{_opEquip = es, _opSel = i} ->
|
||||
case you w ^? crInvEquipped . ix curpos of
|
||||
Just epos
|
||||
| es !! i == epos ->
|
||||
w & rbOptions . opAllocateEquipment
|
||||
.~ RemoveEquipment
|
||||
{ _allocOldPos = epos
|
||||
}
|
||||
Just epos
|
||||
| isJust (you w ^? crEquipment . ix (es !! i)) ->
|
||||
w & rbOptions . opAllocateEquipment
|
||||
.~ SwapEquipment
|
||||
{ _allocOldPos = epos
|
||||
, _allocNewPos = es !! i
|
||||
, _allocSwapID = _crEquipment (you w) M.! (es !! i)
|
||||
}
|
||||
Just epos ->
|
||||
w & rbOptions . opAllocateEquipment
|
||||
.~ RemoveEquipment
|
||||
{ _allocOldPos = epos
|
||||
}
|
||||
Just epos
|
||||
| isJust (you w ^? crEquipment . ix (es !! i)) ->
|
||||
w & rbOptions . opAllocateEquipment
|
||||
.~ SwapEquipment
|
||||
.~ MoveEquipment
|
||||
{ _allocOldPos = epos
|
||||
, _allocNewPos = es !! i
|
||||
, _allocSwapID = _crEquipment (you w) M.! (es !! i)
|
||||
}
|
||||
Just epos ->
|
||||
w & rbOptions . opAllocateEquipment
|
||||
.~ MoveEquipment
|
||||
{ _allocOldPos = epos
|
||||
, _allocNewPos = es !! i
|
||||
}
|
||||
Nothing
|
||||
| isJust (you w ^? crEquipment . ix (es !! i)) ->
|
||||
Nothing
|
||||
| isJust (you w ^? crEquipment . ix (es !! i)) ->
|
||||
w & rbOptions . opAllocateEquipment
|
||||
.~ ReplaceEquipment
|
||||
{ _allocNewPos = es !! i
|
||||
, _allocRemoveID = _crEquipment (you w) M.! (es !! i)
|
||||
}
|
||||
Nothing ->
|
||||
w & rbOptions . opAllocateEquipment
|
||||
.~ ReplaceEquipment
|
||||
.~ PutOnEquipment
|
||||
{ _allocNewPos = es !! i
|
||||
, _allocRemoveID = _crEquipment (you w) M.! (es !! i)
|
||||
}
|
||||
Nothing ->
|
||||
w & rbOptions . opAllocateEquipment
|
||||
.~ PutOnEquipment
|
||||
{ _allocNewPos = es !! i
|
||||
}
|
||||
_ -> w
|
||||
_ -> w
|
||||
|
||||
setEquipActivation :: World -> World
|
||||
setEquipActivation w = case w ^? rbOptions . opAllocateEquipment of
|
||||
@@ -261,7 +272,7 @@ setEquipActivation w = case w ^? rbOptions . opAllocateEquipment of
|
||||
Just RemoveEquipment{} ->
|
||||
case you w ^. crLeftInvSel . lisMPos of
|
||||
Just i
|
||||
| i == invsel ->
|
||||
| Just i == minvsel ->
|
||||
w & rbOptions . opActivateEquipment
|
||||
.~ DeactivateEquipment
|
||||
{ _deactivateEquipment = i
|
||||
@@ -269,12 +280,12 @@ setEquipActivation w = case w ^? rbOptions . opAllocateEquipment of
|
||||
_ -> w & rbOptions . opActivateEquipment .~ NoChangeActivateEquipment
|
||||
Just rbos ->
|
||||
case you w ^. crLeftInvSel . lisMPos of
|
||||
Just i | i == invsel -> w & rbOptions . opActivateEquipment .~ NoChangeActivateEquipment
|
||||
Just i | Just i == minvsel -> w & rbOptions . opActivateEquipment .~ NoChangeActivateEquipment
|
||||
Just i
|
||||
| invselcanactivate ->
|
||||
w & rbOptions . opActivateEquipment
|
||||
.~ ActivateDeactivateEquipment
|
||||
{ _activateEquipment = invsel
|
||||
{ _activateEquipment = fromJust minvsel
|
||||
, _deactivateEquipment = i
|
||||
}
|
||||
Just i
|
||||
@@ -285,13 +296,17 @@ setEquipActivation w = case w ^? rbOptions . opAllocateEquipment of
|
||||
| invselcanactivate ->
|
||||
w & rbOptions . opActivateEquipment
|
||||
.~ ActivateEquipment
|
||||
{ _activateEquipment = invsel
|
||||
{ _activateEquipment = fromJust minvsel
|
||||
}
|
||||
Nothing -> w & rbOptions . opActivateEquipment .~ NoChangeActivateEquipment
|
||||
Nothing -> w & rbOptions . opActivateEquipment .~ NoChangeActivateEquipment
|
||||
where
|
||||
invsel = crSel (you w)
|
||||
invselcanactivate = isJust (you w ^? crInv . ix invsel . itUse . leftUse)
|
||||
--invsel = crSel (you w)
|
||||
minvsel = cr ^? crInvSel . isel . ispItem
|
||||
cr = you w
|
||||
invselcanactivate = isJust $ do
|
||||
i <- minvsel
|
||||
return $ cr ^? crInv . ix i . itUse . leftUse
|
||||
|
||||
equipSiteToPositions :: EquipSite -> [EquipPosition]
|
||||
equipSiteToPositions es = case es of
|
||||
@@ -310,14 +325,10 @@ closeObjScrollDir x
|
||||
changeInvSel :: Int -> World -> World
|
||||
changeInvSel i w
|
||||
| i == 0 || n == 0 = w
|
||||
| yourInvSel w < n =
|
||||
w
|
||||
& pointcrInvSel . iselPos %~ (`mod` n) . subtract i
|
||||
& pointcrInvSel . iselAction .~ NoInvSelAction
|
||||
| otherwise =
|
||||
w
|
||||
& pointcrInvSel . iselPos %~ ((+ n) . (`mod` numCO) . subtract (i + n))
|
||||
& pointcrInvSel . iselAction .~ NoInvSelAction
|
||||
| otherwise = w
|
||||
& pointcrInvSel . isel . ispItem %~ (`mod` n) . subtract i
|
||||
& pointcrInvSel . isel . iselAction .~ NoInvSelAction
|
||||
& pointcrInvSel . isel . ispCloseObject %~ (`mod` numCO) . subtract i
|
||||
where
|
||||
-- arguably this should jump the invpos into the inventory proper
|
||||
pointcrInvSel = cWorld . lWorld . creatures . ix 0 . crInvSel
|
||||
@@ -325,47 +336,58 @@ changeInvSel i w
|
||||
numCO = length $ w ^. hud . closeObjects
|
||||
|
||||
changeSwapInvSel :: Int -> World -> World
|
||||
changeSwapInvSel k w
|
||||
| k == 0 = w
|
||||
| yourInvSel w < n =
|
||||
w
|
||||
& cWorld . lWorld . creatures . ix 0 %~ updatecreature
|
||||
| yourInvSel w > n =
|
||||
w
|
||||
& cWorld . lWorld . creatures . ix 0 . crInvSel . iselPos .~ ico'
|
||||
& hud . closeObjects %~ swapIndices (i - (n + 1)) (ico' - (n + 1))
|
||||
| otherwise = w
|
||||
changeSwapInvSel k w = case you w ^? crInvSel . isel of
|
||||
Just (SelItem i _) -> w & cWorld . lWorld . creatures . ix 0 %~ updatecreature i
|
||||
Just (SelCloseObject i) -> w
|
||||
& cWorld . lWorld . creatures . ix 0 . crInvSel . isel . ispCloseObject
|
||||
.~ ((i - k) `mod` numCO)
|
||||
& hud . closeObjects %~ swapIndices i ((i - k) `mod` numCO)
|
||||
_ -> w
|
||||
where
|
||||
updatecreature =
|
||||
(crInv %~ IM.safeSwapKeys (i `mod` n) swapi)
|
||||
. (crLeftInvSel . lisMPos . _Just %~ updateLeftInvSel)
|
||||
. (crInvSel . iselPos %~ (`mod` n) . subtract k)
|
||||
. (crInvEquipped %~ IM.safeSwapKeys i swapi)
|
||||
. swapSite i swapi
|
||||
. swapSite swapi i
|
||||
updatecreature i =
|
||||
(crInv %~ IM.safeSwapKeys (i `mod` n) (swapi i))
|
||||
. (crLeftInvSel . lisMPos . _Just %~ updateLeftInvSel i)
|
||||
. (crInvSel . isel . ispItem %~ (`mod` n) . subtract k)
|
||||
. (crInvEquipped %~ IM.safeSwapKeys i (swapi i))
|
||||
. swapSite i (swapi i)
|
||||
. swapSite (swapi i) i
|
||||
swapSite a b = case cr ^? crInvEquipped . ix a of
|
||||
Just epos -> crEquipment . ix epos .~ b
|
||||
Nothing -> id
|
||||
cr = you w
|
||||
swapi = (i - k) `mod` n
|
||||
updateLeftInvSel li
|
||||
| i == li = swapi
|
||||
| swapi == li = i
|
||||
swapi i = (i - k) `mod` n
|
||||
updateLeftInvSel i li
|
||||
| i == li = swapi i
|
||||
| swapi i == li = i
|
||||
| otherwise = li
|
||||
i = crSel cr
|
||||
ico' = ((i - (k + n + 1)) `mod` numCO) + n + 1
|
||||
n = length $ _crInv cr
|
||||
numCO = length $ w ^. hud . closeObjects
|
||||
|
||||
changeAugInvSel :: Int -> World -> World
|
||||
changeAugInvSel i w
|
||||
| i == 0 = w
|
||||
changeAugInvSel yi w
|
||||
| yi == 0 = w
|
||||
| otherwise =
|
||||
w
|
||||
& cWorld . lWorld . creatures . ix 0 . crInvSel . iselPos %~ (`mod` n) . subtract i
|
||||
& cWorld . lWorld . creatures . ix 0 . crInvSel . iselAction .~ NoInvSelAction
|
||||
w & cWorld . lWorld . creatures . ix 0 . crInvSel . isel %~ f
|
||||
where
|
||||
n = length (yourInv w) + length (w ^. hud . closeObjects) + 1
|
||||
f = fromAugSelPos w . (`mod` (ninv + nclose + 1)) . subtract yi . toAugSelPos w
|
||||
ninv = length (yourInv w)
|
||||
nclose = length (w ^. hud . closeObjects)
|
||||
|
||||
toAugSelPos :: World -> ManipulatedObject -> Int
|
||||
toAugSelPos w mo = case mo of
|
||||
SelItem i _ -> i
|
||||
SelNothing -> ninv
|
||||
SelCloseObject i -> ninv + i + 1
|
||||
where
|
||||
ninv = length (yourInv w)
|
||||
|
||||
fromAugSelPos :: World -> Int -> ManipulatedObject
|
||||
fromAugSelPos w i
|
||||
| i > ninv = SelCloseObject (i - ninv - 1)
|
||||
| i == ninv = SelNothing
|
||||
| otherwise = SelItem i NoInvSelAction
|
||||
where
|
||||
ninv = length (yourInv w)
|
||||
|
||||
bestCloseObjectIndex :: World -> Maybe Int
|
||||
bestCloseObjectIndex w = findIndex f $ w ^. hud . closeObjects
|
||||
@@ -375,13 +397,9 @@ bestCloseObjectIndex w = findIndex f $ w ^. hud . closeObjects
|
||||
ycr = you w
|
||||
|
||||
selectedCloseObject :: World -> Maybe (Int, Either FloorItem Button)
|
||||
selectedCloseObject w
|
||||
| invsel >= (length inv + 1) = selectNthCloseObject w (invsel - (length inv + 1))
|
||||
| otherwise = selectNthCloseObject w =<< bestCloseObjectIndex w
|
||||
where
|
||||
invsel = crSel cr
|
||||
cr = you w
|
||||
inv = _crInv cr
|
||||
selectedCloseObject w = case you w ^? crInvSel . isel . ispCloseObject of
|
||||
Just i -> selectNthCloseObject w i
|
||||
Nothing -> selectNthCloseObject w =<< bestCloseObjectIndex w
|
||||
|
||||
selectNthCloseObject :: World -> Int -> Maybe (Int, Either FloorItem Button)
|
||||
selectNthCloseObject w n = (length (yourInv w) + n + 1,) <$> (_closeObjects (_hud w) !? n)
|
||||
|
||||
Reference in New Issue
Block a user