Remove explicit scancode from menu items

This commit is contained in:
2022-11-04 08:42:30 +00:00
parent 6e7cd14f49
commit c263012b61
11 changed files with 81 additions and 85 deletions
+20 -5
View File
@@ -66,6 +66,7 @@ import SDL
import Sound.Data
import StrictHelp
import qualified Data.Text as T
import ListHelp
updateUniverse :: Universe -> Universe
updateUniverse u =
@@ -93,16 +94,29 @@ gotoTerminal w = case _uvScreenLayers w of
optionScreenUpdates :: Universe -> Universe
optionScreenUpdates u = case u ^? uvScreenLayers . _head of
Just (OptionScreen {_scOptions = mos, _scSelPos = mselpos}) -> mouseOverSelectionList
Just (OptionScreen {_scOptions = mos, _scSelPos = mselpos}) ->
mouseClickSelectionList mos mselpos
$ mouseOverSelectionList
(makeOptionsSelectionList mselpos u mos) u
_ -> u
mouseClickSelectionList :: [MenuOption] -> Maybe Int -> Universe -> Universe
mouseClickSelectionList mos mi u = case u ^. uvWorld . input . mouseButtons . at ButtonLeft of
Just False -> fromMaybe u $ do
i <- mi
mo <- mos !? i
return $ _moEff mo u
_ -> u
mouseOverSelectionList :: SelectionList -> Universe -> Universe
mouseOverSelectionList sl u
| x > xl && x < xr = u & uvScreenLayers . _head . scSelPos .~ Just (ceiling $ y' / 50)
| x > xl && x < xr && ylower == yupper && mmoving
&& ylower >= 0 && ylower < _slLength sl = u & uvScreenLayers . _head . scSelPos ?~ yupper
| otherwise = u
where
y' = hh - (75 + y + _slPosY sl)
mmoving = u ^. uvWorld . input . mouseMoving
ylower = ceiling $ (hh - (75 + y + _slPosY sl)) / 50
yupper = floor $ (hh - (15 + y + _slPosY sl)) / 50
xl = _slPosX sl - hw
xr = xl + _slScale sl * 15 * 9
V2 x y = u ^. uvWorld . input . mousePos
@@ -113,8 +127,8 @@ mouseOverSelectionList sl u
updateUseInput :: Universe -> Universe
updateUseInput u = case u ^? uvScreenLayers . _head of
Just (InputScreen thetext _) -> doInputScreenInput thetext u
Just OptionScreen{_scOptions = mos, _scDefaultEff = defeff} -> optionScreenUpdates . menuWheelEvents $
foldl' (\u' scode -> optionListToEffects defeff scode mos u') u (M.keys $ M.filter (== InitialPress) pkeys)
Just OptionScreen{_scOptions = mos, _scDefaultEff = defeff} -> optionScreenUpdates . menuWheelEvents $ u
-- foldl' (\u' scode -> optionListToEffects defeff scode mos u') u (M.keys $ M.filter (== InitialPress) pkeys)
Just ColumnsScreen{} -> u & uvScreenLayers %~ tail
_ -> case u ^? uvWorld . cWorld . lWorld . hud . hudElement . subInventory of
Just (DisplayTerminal tmid) | inTermFocus (_uvWorld u) -> updateKeysInTerminal tmid u-- M.foldlWithKey' (updateKeyInTerminal tmid) u pkeys
@@ -126,6 +140,7 @@ updateUniverseLast :: Universe -> Universe
updateUniverseLast =
over uvWorld (input . mouseButtons . each .~ True) -- to determine if the mouse button is held
. over uvWorld (input . pressedKeys . each %~ f)
. over uvWorld (input . mouseMoving .~ False)
where
f LongPress = LongPress
f _ = ShortPress