Can pick up items by dragging

This commit is contained in:
2024-11-25 14:03:42 +00:00
parent 691ed23eb4
commit 951d1191cc
4 changed files with 30 additions and 23 deletions
+1 -1
View File
@@ -1 +1 @@
All good (593 modules, at 12:39:43) All good (593 modules, at 14:02:41)
+5 -4
View File
@@ -206,10 +206,11 @@ hasLOS p1 p2 =
hasButtonLOS :: Point2 -> Point2 -> World -> Bool hasButtonLOS :: Point2 -> Point2 -> World -> Bool
{-# INLINE hasButtonLOS #-} {-# INLINE hasButtonLOS #-}
hasButtonLOS p1 p2 = hasButtonLOS _ _ = const True
not --hasButtonLOS p1 p2 =
. collidePointTestFilter (not . _wlTouchThrough) p1 p2 -- not
. wlsNearSeg p1 p2 -- . collidePointTestFilter (not . _wlTouchThrough) p1 p2
-- . wlsNearSeg p1 p2
hasLOSIndirect :: Point2 -> Point2 -> World -> Bool hasLOSIndirect :: Point2 -> Point2 -> World -> Bool
{-# INLINE hasLOSIndirect #-} {-# INLINE hasLOSIndirect #-}
+5 -7
View File
@@ -183,8 +183,7 @@ filterSectionsPair ::
String -> String ->
Maybe String -> Maybe String ->
(IM.IntMap (SelectionItem a), IM.IntMap (SelectionItem a)) (IM.IntMap (SelectionItem a), IM.IntMap (SelectionItem a))
filterSectionsPair infocus filtfn itms filtdescription mfilt = filterSectionsPair infocus filtfn itms filtdescription mfilt = (filtsis, itms')
(filtsis, itms')
where where
filtcurs = if infocus then cFilledRect else cWireRect filtcurs = if infocus then cFilledRect else cWireRect
filtsis = fold $ do filtsis = fold $ do
@@ -345,21 +344,19 @@ enterCombineInv :: Configuration -> World -> World
enterCombineInv cfig w = enterCombineInv cfig w =
w & hud . hudElement . subInventory w & hud . hudElement . subInventory
.~ CombineInventory .~ CombineInventory
{ _ciSections = sss { _ciSections = IM.fromDistinctAscList [(-1, filtsection), (0, combsection)]
, _ciSelection = selpos , _ciSelection = selpos
, _ciFilter = Nothing , _ciFilter = Nothing
} }
& hud . hudElement . diInvFilter .~ Nothing & hud . hudElement . diInvFilter .~ Nothing
where where
cm' = IM.fromDistinctAscList . zip [0 ..] $ combineList w cm' = IM.fromDistinctAscList . zip [0 ..] $ combineList w
cm cm | null cm' = IM.singleton 0
| null cm' = IM.singleton 0 $ SelectionInfo ["No possible combinations"] 1 False white 0 $ SelectionInfo ["No possible combinations"] 1 False white 0
| otherwise = cm' | otherwise = cm'
sss = IM.fromDistinctAscList [(-1, filtsection), (0, combsection)]
selpos selpos
| null cm' = Nothing | null cm' = Nothing
| otherwise = Just (0, 0) | otherwise = Just (0, 0)
availablelines = getAvailableListLines secondColumnParams cfig
filtsection = filtsection =
SelectionSection SelectionSection
{ _ssItems = mempty { _ssItems = mempty
@@ -374,6 +371,7 @@ enterCombineInv cfig w =
cm cm
availablelines availablelines
0 0
availablelines = getAvailableListLines secondColumnParams cfig
regexList :: String -> [String] -> Bool regexList :: String -> [String] -> Bool
regexList x = any (List.isInfixOf x) regexList x = any (List.isInfixOf x)
+19 -11
View File
@@ -3,6 +3,7 @@ module Dodge.Update.Input.InGame (
updateMouseInGame, updateMouseInGame,
) where ) where
import Data.Monoid
import NewInt import NewInt
import Control.Applicative import Control.Applicative
import Control.Monad import Control.Monad
@@ -112,22 +113,27 @@ tryDropSelected mpos w = do
xs <- w ^? hud . hudElement . diSelectionExtra xs <- w ^? hud . hudElement . diSelectionExtra
return $ IS.foldr (dropItem cr) w xs return $ IS.foldr (dropItem cr) w xs
tryPickupSelected :: Maybe (Int,Int) -> World -> Maybe World tryPickupSelected :: Int -> Maybe (Int,Int) -> World -> Maybe World
tryPickupSelected mpos w = do tryPickupSelected k mpos w = do
guard $ k == 3
guard $ maybe True (\(i,_) -> i == 0) mpos guard $ maybe True (\(i,_) -> i == 0) mpos
-- cr <- w ^? cWorld . lWorld . creatures . ix 0 cr <- w ^? cWorld . lWorld . creatures . ix 0
-- let nfreeslots = crNumFreeSlots cr let nfreeslots = crNumFreeSlots cr
(3, _) <- w ^? hud . hudElement . diSelection . _Just xs <- w ^? hud . hudElement . diSelectionExtra
-- xs <- w ^? hud . hudElement . diSelectionExtra let itmstopickup = mapMaybe g $ IS.toList xs
-- OverInvDrag 3 x <- w ^? input . mouseContext let slotsneeded = alaf Sum foldMap (_itInvSize . _flIt) $ itmstopickup
return w guard $ nfreeslots >= slotsneeded
-- return $ IS.foldr (dropItem cr) w xs return $ foldl' (flip $ pickUpItem 0) w itmstopickup
where
g i = do
NInt j <- w ^? hud . closeItems . ix i
w ^? cWorld . lWorld . floorItems . unNIntMap . ix j
updateMouseReleaseInGame :: World -> World updateMouseReleaseInGame :: World -> World
updateMouseReleaseInGame w = case w ^. input . mouseContext of updateMouseReleaseInGame w = case w ^. input . mouseContext of
OverInvDrag _ mpos _ _ -> OverInvDrag k mpos _ _ ->
input . mouseContext .~ MouseInGame $ input . mouseContext .~ MouseInGame $
fromMaybe w $ tryDropSelected mpos w <|> tryPickupSelected mpos w fromMaybe w $ tryDropSelected mpos w <|> tryPickupSelected k mpos w
-- OverInvDrag i mpos -> fromMaybe (dropSelected w & input . mouseContext .~ MouseInGame) $ do -- OverInvDrag i mpos -> fromMaybe (dropSelected w & input . mouseContext .~ MouseInGame) $ do
-- j <- mpos -- j <- mpos
-- guard $ fst j == i -- guard $ fst j == i
@@ -243,6 +249,8 @@ shiftInvItems ::
World -> World ->
World World
shiftInvItems k x ab bn xs ss w = fromMaybe w $ do shiftInvItems k x ab bn xs ss w = fromMaybe w $ do
let xk = fst x
guard $ xk == k || xk + 1 == k || xk -1 == k
(maxi,_) <- IS.maxView xs (maxi,_) <- IS.maxView xs
(mini,_) <- IS.minView xs (mini,_) <- IS.minView xs
if x < (k,mini) if x < (k,mini)