Work on mouse selection in menus
This commit is contained in:
+24
-2
@@ -6,6 +6,8 @@ Description : Simulation update
|
||||
-}
|
||||
module Dodge.Update (updateUniverse) where
|
||||
|
||||
import Dodge.Menu.Option
|
||||
import Dodge.Data.SelectionList
|
||||
import Dodge.InputFocus
|
||||
import Dodge.Event.Menu
|
||||
import Color
|
||||
@@ -89,10 +91,29 @@ gotoTerminal w = case _uvScreenLayers w of
|
||||
(InputScreen{} : _) -> w
|
||||
_ -> w & uvScreenLayers .:~ InputScreen T.empty "Enter command"
|
||||
|
||||
optionScreenUpdates :: Universe -> Universe
|
||||
optionScreenUpdates u = case u ^? uvScreenLayers . _head of
|
||||
Just (OptionScreen {_scOptions = mos, _scSelPos = mselpos}) -> mouseOverSelectionList
|
||||
(makeOptionsSelectionList mselpos u mos) u
|
||||
_ -> u
|
||||
|
||||
mouseOverSelectionList :: SelectionList -> Universe -> Universe
|
||||
mouseOverSelectionList sl u
|
||||
| x > xl && x < xr = u & uvScreenLayers . _head . scSelPos .~ Just (ceiling $ y' / 50)
|
||||
| otherwise = u
|
||||
where
|
||||
y' = hh - (75 + y + _slPosY sl)
|
||||
xl = _slPosX sl - hw
|
||||
xr = xl + _slScale sl * 15 * 9
|
||||
V2 x y = u ^. uvWorld . input . mousePos
|
||||
cfig = u ^. uvConfig
|
||||
hh = halfHeight cfig
|
||||
hw = halfWidth cfig
|
||||
|
||||
updateUseInput :: Universe -> Universe
|
||||
updateUseInput u = case u ^? uvScreenLayers . _head of
|
||||
Just (InputScreen thetext _) -> doInputScreenInput thetext u
|
||||
Just OptionScreen{_scOptions = mos, _scDefaultEff = defeff} -> menuWheelEvents $
|
||||
Just OptionScreen{_scOptions = mos, _scDefaultEff = defeff} -> optionScreenUpdates . menuWheelEvents $
|
||||
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
|
||||
@@ -233,8 +254,9 @@ functionalUpdate w =
|
||||
$ over uvWorld updatePastWorlds w
|
||||
|
||||
menuWheelEvents :: Universe -> Universe
|
||||
menuWheelEvents u = u & uvScreenLayers . _head . scSelPos . _Just -~ y
|
||||
menuWheelEvents u = u & uvScreenLayers . _head . scSelPos . _Just %~ (\y' -> (y' - y) `mod` ymax)
|
||||
where
|
||||
ymax = maybe 0 length (u ^? uvScreenLayers . _head . scOptions)
|
||||
y = u ^. uvWorld . input . scrollAmount
|
||||
|
||||
updateWheelEvents :: World -> World
|
||||
|
||||
Reference in New Issue
Block a user