Decouple selection section inventory position
This commit is contained in:
@@ -38,24 +38,26 @@ updateUseInputInGame u = case u ^. uvWorld . hud . hudElement of
|
||||
| inTermFocus (_uvWorld u) -> updateKeysInTerminal tmid u
|
||||
| lbinitialpress ->
|
||||
u & uvWorld . cWorld . lWorld . terminals . ix tmid . tmInput . tiFocus %~ const True
|
||||
CombineInventory{_ciSections = sss}
|
||||
CombineInventory{_ciSections = sss, _ciSelection = msel}
|
||||
| inSubInvRegex (u ^. uvWorld) ->
|
||||
u
|
||||
& uvWorld . hud . hudElement . subInventory . ciSections
|
||||
%~ doRegexInput (u ^. uvWorld . input) (-1)
|
||||
& uvWorld . hud . hudElement . subInventory
|
||||
%~ docombineregexinput
|
||||
& uvWorld . worldEventFlags . at CombineInventoryChange ?~ ()
|
||||
| lbinitialpress ->
|
||||
(uvWorld . worldEventFlags . at InventoryChange ?~ ()) . maybeExitCombine $
|
||||
over uvWorld (tryCombine sss) u
|
||||
over uvWorld (tryCombine sss msel) u
|
||||
& uvWorld . worldEventFlags . at CombineInventoryChange ?~ ()
|
||||
_
|
||||
| inInvRegex (u ^. uvWorld) ->
|
||||
u & uvWorld . hud . hudElement . diSections %~ doRegexInput (u ^. uvWorld . input) (-1)
|
||||
u & uvWorld . hud . hudElement %~ dodisplayregexinput (-1)
|
||||
-- . diSections %~ doRegexInput (u ^. uvWorld . input) (-1)
|
||||
& uvWorld . worldEventFlags . at InventoryChange ?~ ()
|
||||
& uvWorld %~ setInvPosFromSS
|
||||
_
|
||||
| inCloseRegex (u ^. uvWorld) ->
|
||||
u & uvWorld . hud . hudElement . diSections %~ doRegexInput (u ^. uvWorld . input) 2
|
||||
--u & uvWorld . hud . hudElement . diSections %~ doRegexInput (u ^. uvWorld . input) 2
|
||||
u & uvWorld . hud . hudElement %~ dodisplayregexinput 2
|
||||
& uvWorld . worldEventFlags . at InventoryChange ?~ ()
|
||||
& uvWorld %~ setInvPosFromSS
|
||||
_ -> M.foldlWithKey' updateKeyInGame u pkeys
|
||||
@@ -63,6 +65,18 @@ updateUseInputInGame u = case u ^. uvWorld . hud . hudElement of
|
||||
w = u ^. uvWorld
|
||||
pkeys = u ^. uvWorld . input . pressedKeys
|
||||
lbinitialpress = u ^? uvWorld . input . mouseButtons . ix ButtonLeft == Just 0
|
||||
docombineregexinput ci = fromMaybe ci $ do
|
||||
sss <- ci ^? ciSections
|
||||
msel <- ci ^? ciSelection
|
||||
let (sss',msel') = doRegexInput (u ^. uvWorld . input) (-1) sss msel
|
||||
return $ ci & ciSections .~ sss'
|
||||
& ciSelection .~ msel'
|
||||
dodisplayregexinput x di = fromMaybe di $ do
|
||||
sss <- di ^? diSections
|
||||
msel <- di ^? diSelection
|
||||
let (sss',msel') = doRegexInput (u ^. uvWorld . input) x sss msel
|
||||
return $ di & diSections .~ sss'
|
||||
& diSelection .~ msel'
|
||||
|
||||
updatePressedButtonsCarte :: World -> World
|
||||
updatePressedButtonsCarte w = updatePressedButtonsCarte' (_mouseButtons (_input w)) w
|
||||
@@ -132,17 +146,18 @@ updateLongPressInGame uv sc = case sc of
|
||||
ScancodeSpace -> over uvWorld spaceAction uv
|
||||
_ -> uv
|
||||
|
||||
doRegexInput :: Input -> Int -> SelectionSections a -> SelectionSections a
|
||||
doRegexInput inp i sss
|
||||
doRegexInput :: Input -> Int -> SelectionSections a -> Maybe (Int,Int)
|
||||
-> (SelectionSections a, Maybe (Int,Int))
|
||||
doRegexInput inp i sss msel
|
||||
| backspacetonothing || escapekey = endregex i 0
|
||||
| endkeys || endmouse = endregex (i + 1) (j -1)
|
||||
| otherwise = sss & doTextInputOver inp (sssExtra . sssFilters . ix i . _Just)
|
||||
| otherwise = (sss & doTextInputOver inp (sssExtra . sssFilters . ix i . _Just)
|
||||
, msel)
|
||||
where
|
||||
endregex a b =
|
||||
sss
|
||||
& sssExtra . sssFilters . ix i .~ Nothing
|
||||
(sss & sssExtra . sssFilters . ix i .~ Nothing
|
||||
& sssSections . ix i . ssItems .~ mempty
|
||||
& ssSetCursor (ssLookupDown a b)
|
||||
, msel & ssSetCursor (ssLookupDown a b) sss)
|
||||
j = fromMaybe 0 $ do
|
||||
itms <- sss ^? sssSections . ix (i + 1) . ssItems
|
||||
fst <$> IM.lookupMin itms
|
||||
@@ -161,53 +176,59 @@ updateBackspaceRegex :: World -> World
|
||||
updateBackspaceRegex w = case di ^? subInventory of
|
||||
Just NoSubInventory{}
|
||||
| secfocus (-1) 0 ->
|
||||
w & hud . hudElement . diSections %~ trybackspace (-1)
|
||||
w & hud . hudElement %~ trybackspace (-1)
|
||||
& worldEventFlags . at InventoryChange ?~ ()
|
||||
Just NoSubInventory{}
|
||||
| secfocus 2 3 ->
|
||||
w & hud . hudElement . diSections %~ trybackspace 2
|
||||
w & hud . hudElement %~ trybackspace 2
|
||||
& worldEventFlags . at InventoryChange ?~ ()
|
||||
Just CombineInventory{} ->
|
||||
w & hud . hudElement . subInventory . ciSections %~ trybackspace (-1)
|
||||
w & hud . hudElement . subInventory %~ trybackspace' (-1)
|
||||
& worldEventFlags . at InventoryChange ?~ ()
|
||||
_ -> w
|
||||
where
|
||||
secfocus a b = fromMaybe False $ do
|
||||
i <- di ^? diSections . sssExtra . sssSelPos . _Just . _1
|
||||
i <- di ^? diSelection . _Just . _1
|
||||
return $ i == a || i == b
|
||||
trybackspace x sss = fromMaybe sss $ do
|
||||
-- i <- fss ^? fssSections . sssSelPos . _Just . _1
|
||||
-- guard (i == x || i == x+1)
|
||||
trybackspace x he = fromMaybe he $ do
|
||||
sss <- he ^? diSections
|
||||
str <- sss ^? sssExtra . sssFilters . ix x . _Just
|
||||
return $ case str of
|
||||
(_ : _) ->
|
||||
sss & sssExtra . sssFilters . ix x . _Just %~ init
|
||||
& sssExtra . sssSelPos ?~ (x, 0)
|
||||
[] -> sss & sssExtra . sssFilters . ix x .~ Nothing
|
||||
he & diSections . sssExtra . sssFilters . ix x . _Just %~ init
|
||||
& diSelection ?~ (x, 0)
|
||||
[] -> he & diSections . sssExtra . sssFilters . ix x .~ Nothing
|
||||
trybackspace' x ci = fromMaybe ci $ do
|
||||
sss <- ci ^? ciSections
|
||||
str <- sss ^? sssExtra . sssFilters . ix x . _Just
|
||||
return $ case str of
|
||||
(_ : _) ->
|
||||
ci & ciSections . sssExtra . sssFilters . ix x . _Just %~ init
|
||||
& ciSelection ?~ (x, 0)
|
||||
[] -> ci & ciSections . sssExtra . sssFilters . ix x .~ Nothing
|
||||
di = w ^. hud . hudElement
|
||||
|
||||
updateEnterRegex :: World -> World
|
||||
updateEnterRegex w = case w ^? hud . hudElement . subInventory of
|
||||
Just NoSubInventory{}
|
||||
| secfocus (-1) 0 ->
|
||||
w & hud . hudElement . diSections . sssExtra . sssSelPos ?~ (-1, 0)
|
||||
w & hud . hudElement . diSelection ?~ (-1, 0)
|
||||
& hud . hudElement . diSections %~ enterregex (-1)
|
||||
Just NoSubInventory{}
|
||||
| secfocus 2 3 ->
|
||||
w & hud . hudElement . diSections . sssExtra . sssSelPos ?~ (2, 0)
|
||||
w & hud . hudElement . diSelection ?~ (2, 0)
|
||||
& hud . hudElement . diSections %~ enterregex 2
|
||||
Just CombineInventory{} ->
|
||||
w & hud . hudElement . subInventory . ciSections %~ enterregex (-1)
|
||||
& hud . hudElement . subInventory . ciSections . sssExtra . sssSelPos ?~ (-1, 0)
|
||||
& hud . hudElement . subInventory . ciSelection ?~ (-1, 0)
|
||||
_ -> w
|
||||
where
|
||||
di = w ^. hud . hudElement
|
||||
secfocus a b = fromMaybe False $ do
|
||||
i <- di ^? diSections . sssExtra . sssSelPos . _Just . _1
|
||||
i <- di ^? diSelection . _Just . _1
|
||||
return $ i == a || i == b
|
||||
enterregex x sss =
|
||||
sss & sssExtra . sssFilters . ix x %~ f
|
||||
& sssExtra . sssSelPos ?~ (x, 0)
|
||||
f Nothing = Just ""
|
||||
f x = x
|
||||
|
||||
@@ -242,6 +263,7 @@ toggleMap u = case u ^. uvWorld . hud . hudElement of
|
||||
.~ DisplayInventory
|
||||
{ _subInventory = NoSubInventory NoMouseSel Nothing
|
||||
, _diSections = defaultInvSections
|
||||
, _diSelection = Nothing
|
||||
}
|
||||
_ -> u & uvWorld . hud . hudElement .~ DisplayCarte
|
||||
|
||||
@@ -254,9 +276,9 @@ toggleTweakInv w = case w ^? hud . hudElement . subInventory of
|
||||
|
||||
-- mi = 0 <$ (yourSelectedItem w >>= (^? itTweaks . tweakParams . ix 0))
|
||||
|
||||
tryCombine :: SelectionSections CombinableItem -> World -> World
|
||||
tryCombine sss w = fromMaybe w $ do
|
||||
(i, j) <- sss ^? sssExtra . sssSelPos . _Just
|
||||
tryCombine :: SelectionSections CombinableItem -> Maybe (Int,Int) -> World -> World
|
||||
tryCombine sss msel w = fromMaybe w $ do
|
||||
(i, j) <- msel
|
||||
CombinableItem is it _ <- sss ^? sssSections . ix i . ssItems . ix j . siPayload
|
||||
return $
|
||||
snd (createItemYou it (foldr (destroyInvItem 0) w (sort is)))
|
||||
|
||||
Reference in New Issue
Block a user