Rethink selection lists as intmaps
This commit is contained in:
@@ -5,6 +5,7 @@ module Dodge.Update.Input (
|
||||
doSubInvRegexInput,
|
||||
) where
|
||||
|
||||
import SelectionIntMap
|
||||
import qualified Data.Map.Strict as M
|
||||
import Data.Char
|
||||
import Dodge.Base.You
|
||||
@@ -45,8 +46,12 @@ backspaceInputted u = case u ^. uvWorld . input . pressedKeys . at ScancodeBacks
|
||||
doSubInvRegexInput :: Universe -> Universe
|
||||
doSubInvRegexInput u
|
||||
| any ( (== Just InitialPress) . (`M.lookup` pkeys)) [ScancodeReturn,ScancodeEscape,ScancodeSlash]
|
||||
= u & uvWorld . hud . hudElement . subInventory . subInvRegexInput .~ False
|
||||
| otherwise = u & doTextInputOver (uvWorld . hud . hudElement . subInventory . subInvRegex)
|
||||
= u & uvWorld . hud . hudElement . subInventory . subInvMap . smRegexInput .~ False
|
||||
| ScancodeBackspace `M.member` pkeys
|
||||
&& u ^? uvWorld . hud . hudElement . subInventory . subInvMap . smRegex == Just ""
|
||||
= u & uvWorld . hud . hudElement . subInventory . subInvMap . smRegexInput .~ False
|
||||
| otherwise = u & doTextInputOver (uvWorld . hud . hudElement . subInventory . subInvMap . smRegex)
|
||||
& uvWorld . hud . hudElement . subInventory . subInvMap %~ setShownIntMap
|
||||
where
|
||||
pkeys = u ^. uvWorld . input . pressedKeys
|
||||
|
||||
@@ -89,7 +94,7 @@ updateKeyInGame uv sc InitialPress = case sc of
|
||||
ScancodeC -> over uvWorld toggleCombineInv uv
|
||||
-- the following should be put in a more sensible place
|
||||
--ScancodeSlash -> set (uvWorld . hud . hudElement . subInventory . subInvRegexInput) True uv
|
||||
ScancodeSlash -> set (uvWorld . hud . hudElement . subInventory . subInvRegexInput) True uv
|
||||
ScancodeSlash -> set (uvWorld . hud . hudElement . subInventory . subInvMap . smRegexInput) True uv
|
||||
-- in fact the whole logic should probably be rethought, oh well
|
||||
_ -> uv
|
||||
updateKeyInGame uv sc LongPress = case sc of
|
||||
|
||||
@@ -2,10 +2,11 @@ module Dodge.Update.Scroll (
|
||||
updateWheelEvent,
|
||||
) where
|
||||
|
||||
import SelectionIntMap
|
||||
import Dodge.SelectionList
|
||||
import qualified Data.Map.Strict as M
|
||||
import Data.Maybe
|
||||
import Dodge.Base
|
||||
import Dodge.Combine
|
||||
import Dodge.Data.Universe
|
||||
import Dodge.HeldScroll
|
||||
import Dodge.InputFocus
|
||||
@@ -49,11 +50,11 @@ updateWheelEvent yi w = case w ^. hud . hudElement of
|
||||
invKeyDown = ScancodeCapsLock `M.member` _pressedKeys (_input w)
|
||||
|
||||
moveCombineSel :: Int -> World -> World
|
||||
moveCombineSel yi w = moveSubSel yi (length $ combineItemListYou w) w
|
||||
moveCombineSel yi = hud . hudElement . subInventory . subInvMap %~ moveSelectionMapSelection yi
|
||||
|
||||
moveSubSel :: Int -> Int -> World -> World
|
||||
moveSubSel yi maxyi =
|
||||
hud . hudElement . subInventory . subInvSel . _Just
|
||||
hud . hudElement . subInventory . subInvMSel . _Just
|
||||
%~ ((`mod` maxyi) . subtract yi)
|
||||
|
||||
guardDisconnectedID :: Int -> World -> World -> World
|
||||
|
||||
@@ -3,6 +3,7 @@ module Dodge.Update.UsingInput (
|
||||
updateUsingInput,
|
||||
) where
|
||||
|
||||
import Dodge.Data.SelectionList
|
||||
import Control.Lens
|
||||
import qualified Data.Map.Strict as M
|
||||
import Dodge.Base.You
|
||||
@@ -30,11 +31,12 @@ pressedMBEffects subinv pkeys w = case subinv of
|
||||
| ButtonLeft `M.member` pkeys && w ^?! input . hammers . ix SubInvHam /= HammerUp ->
|
||||
w & input . hammers . ix SubInvHam .~ HammerDown
|
||||
| otherwise -> pressedMBEffectsNoInventory pkeys w
|
||||
CombineInventory mi _ False
|
||||
CombineInventory SelectionIntMap {_smSelPos = mi, _smRegexInput = False}
|
||||
| pkeys ^? ix ButtonLeft == Just False ->
|
||||
maybeexitcombine (maybe id doCombine mi w) & input . hammers . ix SubInvHam .~ HammerDown
|
||||
CombineInventory _ _ True | pkeys ^? ix ButtonLeft == Just False
|
||||
-> w & hud . hudElement . subInventory . subInvRegexInput .~ False
|
||||
CombineInventory SelectionIntMap {_smRegexInput = True}
|
||||
| pkeys ^? ix ButtonLeft == Just False
|
||||
-> w & hud . hudElement . subInventory . subInvMap . smRegexInput .~ False
|
||||
DisplayTerminal tmid
|
||||
| pkeys ^? ix ButtonLeft == Just False && inTermFocus w ->
|
||||
doTerminalEffectLB (w ^?! cWorld . lWorld . terminals . ix tmid) w
|
||||
|
||||
Reference in New Issue
Block a user