Separate selection list items from display parameters

This commit is contained in:
2022-12-23 12:22:57 +00:00
parent 6ac4e5d669
commit b072dc9e9a
10 changed files with 141 additions and 132 deletions
+22 -20
View File
@@ -98,7 +98,7 @@ mouseClickOptionsList mos screen u = fromMaybe u $ do
Just $ case u ^. uvWorld . input . mouseButtons . at ButtonLeft of
Just False -> fromMaybe u $ do
i <- sl ^. slSelPos
si <- sl ^? slShownItems . ix i . _2
si <- screen ^? scShownItems . ix i . _2
return $ maybe u ($ u) $ case si of
ListedSelectionItem j -> fmap (refreshOptionsSelectionList .) (mos ^? ix j . moEff)
ScrollSelectionItem -> do
@@ -109,18 +109,18 @@ mouseClickOptionsList mos screen u = fromMaybe u $ do
SpecialSelectionItem -> Just id
_ -> u
mouseOverSelectionList :: SelectionList -> Universe -> Universe
mouseOverSelectionList sl u
mouseOverSelectionList :: ListDisplayParams -> SelectionList -> Universe -> Universe
mouseOverSelectionList ldps sl u
| x > xl && x < xr && ylower == yupper && mmoving
&& ylower >= 0 && ylower < ymax = u & uvScreenLayers . _head . scSelectionList . slSelPos ?~ yupper
| otherwise = u
where
ymax = maybe 0 length $ u ^? uvScreenLayers . _head . scSelectionList . slShownItems
ymax = maybe 0 length $ u ^? uvScreenLayers . _head . scSelectionList . slItems
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
ylower = ceiling $ (hh - (75 + y + _ldpPosY ldps)) / 50
yupper = floor $ (hh - (15 + y + _ldpPosY ldps)) / 50
xl = _ldpPosX ldps - hw
xr = xl + _ldpScale ldps * 15 * 9
V2 x y = u ^. uvWorld . input . mousePos
cfig = u ^. uvConfig
hh = halfHeight cfig
@@ -129,22 +129,23 @@ mouseOverSelectionList sl u
setSelectionListRestriction' :: Configuration -> ScreenLayer -> ScreenLayer
setSelectionListRestriction' cfig screen = fromMaybe screen $ do
sl <- screen ^? scSelectionList
return $ screen & scAvailableLines %~ const (setSelectionListRestriction cfig sl)
ldps <- screen ^? scListDisplayParams
return $ screen & scAvailableLines %~ const (setSelectionListRestriction ldps cfig sl)
setSelectionListRestriction :: Configuration -> SelectionList -> Int
setSelectionListRestriction cfig sl = nlines
setSelectionListRestriction :: ListDisplayParams -> Configuration -> SelectionList -> Int
setSelectionListRestriction ldps cfig sl = nlines
where
nlines = floor ((dToBot - vgap) / itmHeight)
vgap = sl ^. slVerticalGap
itmHeight = 10 * sl ^. slScale + vgap
dToBot = cfig ^. windowY - (sl ^. slPosY + dFromScreenBot)
vgap = ldps ^. ldpVerticalGap
itmHeight = 10 * ldps ^. ldpScale + vgap
dToBot = cfig ^. windowY - (ldps ^. ldpPosY + dFromScreenBot)
dFromScreenBot = 5 -- fromMaybe 0 $ sl ^? slSizeRestriction . ssrType . ssrFromScreenBottom
updateUseInput :: Universe -> Universe
updateUseInput u = case u ^? uvScreenLayers . _head of
Just (InputScreen thetext _) -> doInputScreenInput thetext u
Just screen@OptionScreen{_scOptions = mos, _scMaybeOption = mop, _scOptionFlag = flag, _scSelectionList = sellist}
-> optionScreenUpdate screen mos mop flag sellist u
Just screen@OptionScreen{_scOptions = mos, _scMaybeOption = mop, _scOptionFlag = flag, _scSelectionList = sellist, _scListDisplayParams = ldps}
-> optionScreenUpdate screen mos mop flag ldps sellist u
-- Just ColumnsScreen{} -> u & uvScreenLayers %~ tail
_ -> case u ^? uvWorld . cWorld . lWorld . hud . hudElement . subInventory of
Just (DisplayTerminal tmid) | inTermFocus (_uvWorld u) -> updateKeysInTerminal tmid u
@@ -153,15 +154,16 @@ updateUseInput u = case u ^? uvScreenLayers . _head of
pkeys = u ^. uvWorld . input . pressedKeys
optionScreenUpdate :: ScreenLayer -> [MenuOption] -> Maybe MenuOption -> OptionScreenFlag
-> ListDisplayParams
-> SelectionList
-> Universe -> Universe
optionScreenUpdate screen mos mop _ sl u =
optionScreenUpdate screen mos mop _ ldps sl u =
optionScreenDefEff mop
. mouseClickOptionsList mos screen
. mouseOverSelectionList sl
. mouseOverSelectionList ldps sl
. menuWheelEvents
. over (uvScreenLayers . _head) (setSelectionListRestriction' cfig)
$ over (uvScreenLayers . _head) (setShownSelectionItems cfig)
$ over (uvScreenLayers . _head) setShownSelectionItems
u
where
cfig = u ^. uvConfig
@@ -306,7 +308,7 @@ functionalUpdate w =
menuWheelEvents :: Universe -> Universe
menuWheelEvents u = u & uvScreenLayers . _head . scSelectionList . slSelPos . _Just %~ (\y' -> (y' - y) `mod` ymax)
where
ymax = max 1 $ maybe 1 length (u ^? uvScreenLayers . _head . scSelectionList . slShownItems)
ymax = max 1 $ maybe 1 length (u ^? uvScreenLayers . _head . scSelectionList . slItems)
y = u ^. uvWorld . input . scrollAmount
updateWheelEvents :: World -> World