Highlight dropped items, work towards fixing pickup selection change
This commit is contained in:
@@ -38,7 +38,7 @@ data HUD = HUD
|
|||||||
}
|
}
|
||||||
|
|
||||||
data Selection = Sel {_slSec :: Int, _slInt :: Int}
|
data Selection = Sel {_slSec :: Int, _slInt :: Int}
|
||||||
deriving (Eq)
|
deriving (Eq,Show)
|
||||||
|
|
||||||
makeLenses ''HUD
|
makeLenses ''HUD
|
||||||
makeLenses ''Selection
|
makeLenses ''Selection
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ data ItemLocation
|
|||||||
, _ilEquipSite :: Maybe EquipSite
|
, _ilEquipSite :: Maybe EquipSite
|
||||||
}
|
}
|
||||||
| OnTurret {_ilTuID :: Int}
|
| OnTurret {_ilTuID :: Int}
|
||||||
| OnFloor -- {_ilFlID :: NewInt FloorInt}
|
| OnFloor {_ilCloseSel :: Bool} -- {_ilFlID :: NewInt FloorInt}
|
||||||
| InVoid
|
| InVoid
|
||||||
deriving (Eq, Show, Ord, Read) --Generic, Flat)
|
deriving (Eq, Show, Ord, Read) --Generic, Flat)
|
||||||
|
|
||||||
|
|||||||
@@ -15,8 +15,9 @@ copyItemToFloor :: Point2 -> Item -> World -> World
|
|||||||
copyItemToFloor p it w =
|
copyItemToFloor p it w =
|
||||||
w'
|
w'
|
||||||
& cWorld . lWorld . floorItems . at (it ^. itID . unNInt) ?~ FlIt q r
|
& cWorld . lWorld . floorItems . at (it ^. itID . unNInt) ?~ FlIt q r
|
||||||
& cWorld . lWorld . items . at (it ^. itID . unNInt) ?~ (it & itLocation .~ OnFloor)
|
& cWorld . lWorld . items . at (it ^. itID . unNInt) ?~ (it & itLocation .~ OnFloor False)
|
||||||
& hud . closeItems .:~ _itID it -- puts item at top of close items
|
& hud . closeItems .:~ _itID it -- puts item at top of close items
|
||||||
|
& cWorld . highlightItems . at (it ^. itID . unNInt) ?~ 20
|
||||||
where
|
where
|
||||||
(q, w') = findWallFreeDropPoint (_dimRad $ itDim it) p w
|
(q, w') = findWallFreeDropPoint (_dimRad $ itDim it) p w
|
||||||
r = fst . randomR (- pi, pi) $ _randGen w
|
r = fst . randomR (- pi, pi) $ _randGen w
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ destroyItem itid w = case w ^? cWorld . lWorld . items . ix itid . itLocation of
|
|||||||
Nothing -> error $ "Tried to destroy item that does not exist; item id: " ++ show itid
|
Nothing -> error $ "Tried to destroy item that does not exist; item id: " ++ show itid
|
||||||
Just InInv{_ilCrID = cid, _ilInvID = invid} -> destroyInvItem cid invid w
|
Just InInv{_ilCrID = cid, _ilInvID = invid} -> destroyInvItem cid invid w
|
||||||
Just OnTurret{} -> error "need to write code for destroying items on turrets"
|
Just OnTurret{} -> error "need to write code for destroying items on turrets"
|
||||||
Just OnFloor ->
|
Just OnFloor{} ->
|
||||||
w
|
w
|
||||||
& cWorld . lWorld . items . at itid .~ Nothing
|
& cWorld . lWorld . items . at itid .~ Nothing
|
||||||
& cWorld . lWorld . floorItems . at itid .~ Nothing
|
& cWorld . lWorld . floorItems . at itid .~ Nothing
|
||||||
|
|||||||
+18
-20
@@ -22,12 +22,12 @@ import qualified IntMapHelp as IM
|
|||||||
import NewInt
|
import NewInt
|
||||||
|
|
||||||
-- this assumes that this item is currently on the floor
|
-- this assumes that this item is currently on the floor
|
||||||
tryPutItemInInv :: Maybe Int -> Int -> Int -> World -> Maybe (NewInt InvInt, World)
|
tryPutItemInInv :: Maybe Int -> Int -> World -> Maybe (NewInt InvInt, World)
|
||||||
tryPutItemInInv mcipos cid itid w = do
|
tryPutItemInInv mcipos itid w = do
|
||||||
itm <- w ^? cWorld . lWorld . items . ix itid
|
itm <- w ^? cWorld . lWorld . items . ix itid
|
||||||
invid <- checkInvSlotsYou itm w
|
invid <- checkInvSlotsYou itm w
|
||||||
let itloc = InInv
|
let itloc = InInv
|
||||||
{ _ilCrID = cid
|
{ _ilCrID = 0
|
||||||
, _ilInvID = invid
|
, _ilInvID = invid
|
||||||
, _ilIsRoot = False
|
, _ilIsRoot = False
|
||||||
, _ilIsSelected = False
|
, _ilIsSelected = False
|
||||||
@@ -36,17 +36,18 @@ tryPutItemInInv mcipos cid itid w = do
|
|||||||
}
|
}
|
||||||
return $ (invid,) $
|
return $ (invid,) $
|
||||||
w
|
w
|
||||||
& crUpdateItemLocations
|
|
||||||
& setInvPosFromSS
|
|
||||||
& crUpdateItemLocations
|
& crUpdateItemLocations
|
||||||
-- not sure about the order of these...
|
-- not sure about the order of these...
|
||||||
& cWorld . lWorld . creatures . ix cid . crInv . at invid ?~ itid
|
& cWorld . lWorld . creatures . ix 0 . crInv . at invid ?~ itid
|
||||||
& cWorld . lWorld . items . ix itid . itLocation .~ itloc
|
& cWorld . lWorld . items . ix itid . itLocation .~ itloc
|
||||||
& cWorld . lWorld . floorItems . at itid .~ Nothing
|
& cWorld . lWorld . floorItems . at itid .~ Nothing
|
||||||
& updateselectionextra invid
|
& updateselectionextra invid
|
||||||
& updatecloseitemset
|
& updatecloseitemset
|
||||||
& maybeselect invid
|
& maybeselect invid
|
||||||
& cWorld . highlightItems . at itid ?~ 20
|
& cWorld . highlightItems . at itid ?~ 20
|
||||||
|
& setInvPosFromSS
|
||||||
|
& crUpdateItemLocations
|
||||||
|
& setInvPosFromSS
|
||||||
where
|
where
|
||||||
maybeselect invid = fromMaybe id $ do
|
maybeselect invid = fromMaybe id $ do
|
||||||
i <- mcipos
|
i <- mcipos
|
||||||
@@ -56,39 +57,36 @@ tryPutItemInInv mcipos cid itid w = do
|
|||||||
updatecloseitemset = fromMaybe id $ do
|
updatecloseitemset = fromMaybe id $ do
|
||||||
i <- mcipos
|
i <- mcipos
|
||||||
return $ hud . diSections . ix 3 . ssSet %~ IS.deleteShift i
|
return $ hud . diSections . ix 3 . ssSet %~ IS.deleteShift i
|
||||||
updateselectionextra i
|
updateselectionextra i = (hud . diSections . ix 0 . ssSet %~ IS.map (f i))
|
||||||
| cid == 0 = (hud . diSections . ix 0 . ssSet %~ IS.map (f i))
|
|
||||||
. (hud . diSelection . _Just . slInt %~ f i)
|
. (hud . diSelection . _Just . slInt %~ f i)
|
||||||
| otherwise = id
|
|
||||||
f j i | i >= _unNInt j = i + 1
|
f j i | i >= _unNInt j = i + 1
|
||||||
| otherwise = i
|
| otherwise = i
|
||||||
|
|
||||||
-- not sure why we have the cid here, this will probably only work for cid == 0
|
tryPutItemInInvAt :: Maybe Int -> Int -> Int -> World -> Maybe World
|
||||||
tryPutItemInInvAt :: Maybe Int -> Int -> Int -> Int -> World -> Maybe World
|
tryPutItemInInvAt mcipos i itid w = do
|
||||||
tryPutItemInInvAt mcipos i cid itid w = do
|
(j, w') <- tryPutItemInInv mcipos itid w
|
||||||
(j, w') <- tryPutItemInInv mcipos cid itid w
|
|
||||||
guard (i <= _unNInt j)
|
guard (i <= _unNInt j)
|
||||||
return $ foldr f w' [i + 1 .. _unNInt j]
|
return $ foldr f w' [i + 1 .. _unNInt j]
|
||||||
where
|
where
|
||||||
f j = swapInvItems (\_ _ -> Just (j -1)) j
|
f j = swapInvItems (\_ _ -> Just (j -1)) j
|
||||||
|
|
||||||
createItemYou :: Item -> World -> World
|
createItemYou :: Item -> World -> World
|
||||||
createItemYou itm w = maybe w' snd $ tryPutItemInInv Nothing 0 itid w'
|
createItemYou itm w = maybe w' snd $ tryPutItemInInv Nothing itid w'
|
||||||
where
|
where
|
||||||
itid = IM.newKey $ w ^. cWorld . lWorld . items
|
itid = IM.newKey $ w ^. cWorld . lWorld . items
|
||||||
pos = w ^?! cWorld . lWorld . creatures . ix 0 . crPos . _xy
|
pos = w ^?! cWorld . lWorld . creatures . ix 0 . crPos . _xy
|
||||||
w' = copyItemToFloor pos (itm & itID .~ NInt itid) w
|
w' = copyItemToFloor pos (itm & itID .~ NInt itid) w
|
||||||
|
|
||||||
-- the duplication is annoying...
|
-- the duplication is annoying...
|
||||||
pickUpItem :: Int -> (Int,Int) -> World -> World
|
pickUpItem :: (Int,Int) -> World -> World
|
||||||
pickUpItem cid (i,itid) w = fromMaybe w $ do
|
pickUpItem (i,itid) w = fromMaybe w $ do
|
||||||
p <- w ^? cWorld . lWorld . floorItems . ix itid . flItPos
|
p <- w ^? cWorld . lWorld . floorItems . ix itid . flItPos
|
||||||
soundStart (CrSound cid) p pickUpS Nothing . snd <$> tryPutItemInInv (Just i) cid itid w
|
soundStart (CrSound 0) p pickUpS Nothing . snd <$> tryPutItemInInv (Just i) itid w
|
||||||
|
|
||||||
pickUpItemAt :: Int -> Int -> (Int,Int) -> World -> World
|
pickUpItemAt :: Int -> (Int,Int) -> World -> World
|
||||||
pickUpItemAt invid cid (i,itid) w = fromMaybe w $ do
|
pickUpItemAt invid (i,itid) w = fromMaybe w $ do
|
||||||
p <- w ^? cWorld . lWorld . floorItems . ix itid . flItPos
|
p <- w ^? cWorld . lWorld . floorItems . ix itid . flItPos
|
||||||
soundStart (CrSound cid) p pickUpS Nothing <$> tryPutItemInInvAt (Just i) invid cid itid w
|
soundStart (CrSound 0) p pickUpS Nothing <$> tryPutItemInInvAt (Just i) invid itid w
|
||||||
& _Just . hud . diSections . ix 0 . ssSet %~ IS.map f
|
& _Just . hud . diSections . ix 0 . ssSet %~ IS.map f
|
||||||
where
|
where
|
||||||
f j | j >= invid = j +1
|
f j | j >= invid = j +1
|
||||||
|
|||||||
@@ -231,8 +231,12 @@ closeItemToSelectionItem w i = do
|
|||||||
, _siColor = col
|
, _siColor = col
|
||||||
, _siOffX = 0
|
, _siOffX = 0
|
||||||
, _siPayload = Nothing
|
, _siPayload = Nothing
|
||||||
, _siDisplayMod = DropShadowSI
|
, _siDisplayMod = dmod
|
||||||
}
|
}
|
||||||
|
where
|
||||||
|
dmod = maybe DropShadowSI (const HighlightSI)
|
||||||
|
$ w ^? cWorld . highlightItems . ix i
|
||||||
|
|
||||||
|
|
||||||
closeButtonToSelectionItem :: World -> Int -> Maybe (SelectionItem ())
|
closeButtonToSelectionItem :: World -> Int -> Maybe (SelectionItem ())
|
||||||
closeButtonToSelectionItem w i = do
|
closeButtonToSelectionItem w i = do
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ placeSpotID rid ps pt w = case pt of
|
|||||||
in ( i
|
in ( i
|
||||||
, w
|
, w
|
||||||
& gwWorld . cWorld . lWorld . floorItems . at i ?~ FlIt p rot
|
& gwWorld . cWorld . lWorld . floorItems . at i ?~ FlIt p rot
|
||||||
& gwWorld . cWorld . lWorld . items . at i ?~ (itm & itID .~ NInt i & itLocation .~ OnFloor)
|
& gwWorld . cWorld . lWorld . items . at i ?~ (itm & itID .~ NInt i & itLocation .~ OnFloor False)
|
||||||
)
|
)
|
||||||
PutCrit cr -> plNewUpID (gwWorld . cWorld . lWorld . creatures) crID (mvCr p rot cr) w
|
PutCrit cr -> plNewUpID (gwWorld . cWorld . lWorld . creatures) crID (mvCr p rot cr) w
|
||||||
PutForeground fs ->
|
PutForeground fs ->
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ interactWithCloseObj :: Either (NewInt ItmInt) Button -> World -> World
|
|||||||
interactWithCloseObj e w = worldEventFlags . at InventoryChange ?~ () $ case e of
|
interactWithCloseObj e w = worldEventFlags . at InventoryChange ?~ () $ case e of
|
||||||
(Left flit) -> fromMaybe w $ do
|
(Left flit) -> fromMaybe w $ do
|
||||||
i <- w ^? hud . diSelection . _Just . slInt
|
i <- w ^? hud . diSelection . _Just . slInt
|
||||||
return $ pickUpItem 0 (i,_unNInt flit) w
|
return $ pickUpItem (i,_unNInt flit) w
|
||||||
(Right but) -> doButtonEvent (but ^. btEvent) but w
|
(Right but) -> doButtonEvent (but ^. btEvent) but w
|
||||||
|
|
||||||
getSelectedCloseObj :: World -> Maybe (Either (NewInt ItmInt) Button)
|
getSelectedCloseObj :: World -> Maybe (Either (NewInt ItmInt) Button)
|
||||||
|
|||||||
@@ -58,10 +58,10 @@ crs :: Universe -> [Creature]
|
|||||||
crs u = u ^.. uvWorld . cWorld . lWorld . creatures . each
|
crs u = u ^.. uvWorld . cWorld . lWorld . creatures . each
|
||||||
|
|
||||||
testStringInit :: Universe -> [String]
|
testStringInit :: Universe -> [String]
|
||||||
testStringInit u = [u ^. uvWorld . input . mouseContext . to show]
|
testStringInit u = [u ^. uvWorld . input . mouseContext . to show
|
||||||
|
, u ^. uvWorld . hud . diSelection . to show
|
||||||
|
] <> u ^.. uvWorld . hud . diSections . each . ssSet . to show
|
||||||
-- u ^. uvWorld . hud . manObject . to prettyShort
|
-- u ^. uvWorld . hud . manObject . to prettyShort
|
||||||
-- <>
|
|
||||||
-- u ^.. uvWorld . hud . diSections . each . ssSet . to show
|
|
||||||
--testStringInit u = u ^. uvWorld . cWorld . lWorld . creatures . ix 5 . crActionPlan . to prettyShort
|
--testStringInit u = u ^. uvWorld . cWorld . lWorld . creatures . ix 5 . crActionPlan . to prettyShort
|
||||||
--[show . getSum $ foldMap (Sum . crslime) (crs u)]
|
--[show . getSum $ foldMap (Sum . crslime) (crs u)]
|
||||||
-- u ^.. tocrs . each . crType . slimeSplitTimer . to show
|
-- u ^.. tocrs . each . crType . slimeSplitTimer . to show
|
||||||
|
|||||||
+2
-1
@@ -426,7 +426,8 @@ updateMouseContext cfig u = case u ^? uvScreenLayers . ix 0 of
|
|||||||
|
|
||||||
updateMouseContextGame :: Config -> Universe -> MouseContext -> MouseContext
|
updateMouseContextGame :: Config -> Universe -> MouseContext -> MouseContext
|
||||||
updateMouseContextGame cfig u = \case
|
updateMouseContextGame cfig u = \case
|
||||||
OverInvDrag i -> OverInvDrag i -- (inverseSelNumPos cfig invDP mpos disss ^? _Just . nonInf)
|
--OverInvDrag i -> OverInvDrag i -- (inverseSelNumPos cfig invDP mpos disss ^? _Just . nonInf)
|
||||||
|
x@OverInvDrag{} -> x
|
||||||
x@OverInvDragSelect{} -> x
|
x@OverInvDragSelect{} -> x
|
||||||
MouseGameRotate x
|
MouseGameRotate x
|
||||||
| ButtonRight `M.member` (w ^. input . mouseButtons) -> MouseGameRotate x
|
| ButtonRight `M.member` (w ^. input . mouseButtons) -> MouseGameRotate x
|
||||||
|
|||||||
@@ -194,11 +194,11 @@ tryPickupSelected k mpos w = do
|
|||||||
ispickup = map (_unNInt . _itID) itmstopickup
|
ispickup = map (_unNInt . _itID) itmstopickup
|
||||||
guard $ nfreeslots >= slotsneeded
|
guard $ nfreeslots >= slotsneeded
|
||||||
return $ case mpos of
|
return $ case mpos of
|
||||||
Just (0, j) -> foldr (pickUpItemAt j 0) w (zip is ispickup) & newdisel j joff
|
Just (0, j) -> foldr (pickUpItemAt j) w (zip is ispickup) & newdisel j joff
|
||||||
_ -> foldl' (flip $ pickUpItem 0) w (zip is ispickup) & newdisel (length (cr ^. crInv)) joff
|
_ -> foldl' (flip $ pickUpItem) w (zip is ispickup) & newdisel (length (cr ^. crInv)) joff
|
||||||
|
-- _ -> foldr (pickUpItem 0) w (zip is ispickup) & newdisel (length (cr ^. crInv)) joff
|
||||||
where
|
where
|
||||||
newdisel j joff =
|
newdisel j joff = hud . diSelection ?~ Sel 0 (j + joff)
|
||||||
(hud . diSelection ?~ Sel 0 (j + joff))
|
|
||||||
g i = do
|
g i = do
|
||||||
NInt j <- w ^? hud . closeItems . ix i
|
NInt j <- w ^? hud . closeItems . ix i
|
||||||
w ^? cWorld . lWorld . items . ix j
|
w ^? cWorld . lWorld . items . ix j
|
||||||
|
|||||||
Reference in New Issue
Block a user