From b615d6ce575427f834a6af75e1ecaca3492e1d3a Mon Sep 17 00:00:00 2001 From: justin Date: Sun, 19 Feb 2023 12:23:27 +0000 Subject: [PATCH] Continue shuffle --- src/Dodge/Update/Input.hs | 41 +++++++++++++++++++++++++++++++--- src/Dodge/Update/UsingInput.hs | 30 +------------------------ 2 files changed, 39 insertions(+), 32 deletions(-) diff --git a/src/Dodge/Update/Input.hs b/src/Dodge/Update/Input.hs index b5b0452d8..04b977b48 100644 --- a/src/Dodge/Update/Input.hs +++ b/src/Dodge/Update/Input.hs @@ -2,6 +2,8 @@ module Dodge.Update.Input ( updateUseInput, ) where +import Dodge.Data.Combine +import Geometry import Dodge.SelectionList import Dodge.Base.Window import Dodge.Menu.Option @@ -43,16 +45,28 @@ updateUseInputOnScreen sl = case sl of updateUseInputInGame :: HUDElement -> Universe -> Universe updateUseInputInGame h u = case h of - DisplayCarte -> u + DisplayCarte -> over uvWorld updatePressedButtonsCarte u DisplayInventory si _ -> case si of - DisplayTerminal tmid | inTermFocus (_uvWorld u) -> updateKeysInTerminal tmid u - CombineInventory _ _ _ + DisplayTerminal tmid + | lbinitialpress && inTermFocus w -> + over uvWorld (doTerminalEffectLB (w ^?! cWorld . lWorld . terminals . ix tmid)) u + | inTermFocus (_uvWorld u) -> updateKeysInTerminal tmid u + | lbinitialpress -> + u & uvWorld . cWorld . lWorld . terminals . ix tmid . tmInput . tiFocus %~ const True + CombineInventory _ _ sss | inSubInvRegex (u ^. uvWorld) -> doSubInvRegexInput u + | lbinitialpress -> tryCombine sss u -- maybeexitcombine (maybe id doCombine mi w) _ | inInvRegex (u ^. uvWorld) -> doRegexInput (-1) invRegex invRegex u _ | inCloseRegex (u ^. uvWorld) -> doRegexInput 2 closeRegex closeRegex u _ -> M.foldlWithKey' updateKeyInGame u pkeys where + w = u ^. uvWorld pkeys = u ^. uvWorld . input . pressedKeys + pmb = u ^. uvWorld . input . mouseButtons + lbinitialpress = pmb ^? ix ButtonLeft == Just False + +tryCombine :: SelectionSections CombinableItem -> Universe -> Universe +tryCombine sss w = w doTextInputOver :: ASetter' Universe String -> Universe -> Universe doTextInputOver p u = @@ -374,3 +388,24 @@ setSelectionListRestriction :: Configuration -> ScreenLayer -> ScreenLayer setSelectionListRestriction cfig screen = fromMaybe screen $ do ldps <- screen ^? scListDisplayParams return $ screen & scAvailableLines %~ const (getAvailableListLines ldps cfig) + +updatePressedButtonsCarte w = updatePressedButtonsCarte' (_mouseButtons (_input w)) w + +updatePressedButtonsCarte' :: M.Map MouseButton Bool -> World -> World +updatePressedButtonsCarte' pkeys w + | isDown ButtonRight = + w + & input . clickMousePos .~ _mousePos (_input w) + & hud . carteCenter %~ (-.- trans) + | isDown ButtonLeft = + w + & input . clickMousePos .~ _mousePos (_input w) + & hud . carteRot -~ rot + & hud . carteZoom *~ czoom + | otherwise = w + where + isDown but = but `M.member` pkeys + rot = angleBetween (_mousePos (_input w)) (_clickMousePos (_input w)) + czoom = magV (_mousePos (_input w)) / magV (_clickMousePos (_input w)) + trans = rotateV (w ^. hud . carteRot) + $ 1 / (w ^. hud . carteZoom) *.* (_mousePos (_input w) -.- _clickMousePos (_input w)) diff --git a/src/Dodge/Update/UsingInput.hs b/src/Dodge/Update/UsingInput.hs index 9ca809467..fa762b21a 100644 --- a/src/Dodge/Update/UsingInput.hs +++ b/src/Dodge/Update/UsingInput.hs @@ -22,19 +22,11 @@ updateUsingInput :: World -> World updateUsingInput w = case w ^. hud . hudElement of DisplayInventory {_subInventory = subinv} -> pressedMBEffects subinv (_mouseButtons (_input w)) w - DisplayCarte -> - updatePressedButtonsCarte (_mouseButtons (_input w)) w + DisplayCarte -> w pressedMBEffects :: SubInventory -> M.Map MouseButton Bool -> World -> World pressedMBEffects subinv pkeys w = case subinv of NoSubInventory -> pressedMBEffectsNoInventory pkeys w - CombineInventory _ _ sss - | lbinitialpress -> tryCombine sss w -- maybeexitcombine (maybe id doCombine mi w) - DisplayTerminal tmid - | lbinitialpress && inTermFocus w -> - doTerminalEffectLB (w ^?! cWorld . lWorld . terminals . ix tmid) w - | lbinitialpress -> - w & cWorld . lWorld . terminals . ix tmid . tmInput . tiFocus %~ const True _ -> w where lbinitialpress = pkeys ^? ix ButtonLeft == Just False @@ -44,8 +36,6 @@ pressedMBEffects subinv pkeys w = case subinv of -- (hud . hudElement . subInventory . subInvMap . smItems .~ combineList w') w' -- | otherwise = w' & hud . hudElement . subInventory .~ NoSubInventory -tryCombine :: SelectionSections CombinableItem -> World -> World -tryCombine sss w = w pressedMBEffectsNoInventory :: M.Map MouseButton Bool -> World -> World pressedMBEffectsNoInventory pkeys w @@ -70,21 +60,3 @@ doCombine i w = undefined -- Nothing -> w -- Just (CombinableItem is it _) -> createAndSelectItem it $ foldr (rmInvItem 0) w (sort is) -updatePressedButtonsCarte :: M.Map MouseButton Bool -> World -> World -updatePressedButtonsCarte pkeys w - | isDown ButtonRight = - w - & input . clickMousePos .~ _mousePos (_input w) - & hud . carteCenter %~ (-.- trans) - | isDown ButtonLeft = - w - & input . clickMousePos .~ _mousePos (_input w) - & hud . carteRot -~ rot - & hud . carteZoom *~ czoom - | otherwise = w - where - isDown but = but `M.member` pkeys - rot = angleBetween (_mousePos (_input w)) (_clickMousePos (_input w)) - czoom = magV (_mousePos (_input w)) / magV (_clickMousePos (_input w)) - trans = rotateV (w ^. hud . carteRot) - $ 1 / (w ^. hud . carteZoom) *.* (_mousePos (_input w) -.- _clickMousePos (_input w))