diff --git a/src/Dodge/Data/SelectionList.hs b/src/Dodge/Data/SelectionList.hs index 06a8aba87..18f1affcb 100644 --- a/src/Dodge/Data/SelectionList.hs +++ b/src/Dodge/Data/SelectionList.hs @@ -24,9 +24,7 @@ data SelectionList = SelectionList } data SelectionItemIndex = ListedSelectionItem Int - | DummySelectionItem - | ScrollUpSelectionItem - | ScrollDownSelectionItem + | ScrollSelectionItem | SpecialSelectionItem data SpecialSelectionItem = NoSpecialSelectionItem diff --git a/src/Dodge/Menu/Option.hs b/src/Dodge/Menu/Option.hs index c789dbd8b..6ffe0d13b 100644 --- a/src/Dodge/Menu/Option.hs +++ b/src/Dodge/Menu/Option.hs @@ -21,6 +21,14 @@ slTitleOptionsEff title ops defstr eff u = , _scSelectionList = makeOptionsSelectionList (Just 0) u ops } +refreshOptionsSelectionList :: Universe -> Universe +refreshOptionsSelectionList u = u & uvScreenLayers . ix 0 %~ f + where + f sl = case sl of + OptionScreen {_scOptions = mops} -> sl & scSelectionList . slItems .~ optionsToSelections u mops + _ -> sl + + --makeOptionsSelectionList :: Maybe Int -> Universe -> [MenuOption] -> Maybe String -> SelectionList --makeOptionsSelectionList mselpos u mos defstr = SelectionList makeOptionsSelectionList :: Maybe Int -> Universe -> [MenuOption] -> SelectionList diff --git a/src/Dodge/SelectionList.hs b/src/Dodge/SelectionList.hs index 32ecc6779..ba7deb63a 100644 --- a/src/Dodge/SelectionList.hs +++ b/src/Dodge/SelectionList.hs @@ -7,11 +7,9 @@ import LensHelp setShownSelectionItems :: SelectionList -> SelectionList setShownSelectionItems sl = case sl ^? slSizeRestriction of Just (SelectionSizeRestriction maxlines _ botit _) - | length allitems <= maxlines -> sl & slShownItems .~ allitems --- | offset > length allitems + 3 - maxlines -> sl - | otherwise -> + | length allitems > maxlines -> sl & slShownItems .~ take (maxlines - 2) (drop offset allitems) -- ++ repeat dummyitem)) - ++ [(botit,ScrollDownSelectionItem)] + ++ [(botit,ScrollSelectionItem)] _ -> sl & slShownItems .~ allitems where -- dummyitem = (SelectionItem [] 1 False 0 white 0, DummySelectionItem) diff --git a/src/Dodge/Update.hs b/src/Dodge/Update.hs index 6d11062c9..e7f6a77c3 100644 --- a/src/Dodge/Update.hs +++ b/src/Dodge/Update.hs @@ -7,6 +7,7 @@ Description : Simulation update module Dodge.Update (updateUniverse) where --import Dodge.Menu.Option +import Dodge.Menu.Option import Dodge.SelectionList import Dodge.Data.SelectionList import Dodge.InputFocus @@ -98,14 +99,12 @@ mouseClickOptionsList mos sl u = case u ^. uvWorld . input . mouseButtons . at B i <- sl ^. slSelPos si <- sl ^? slShownItems . ix i . _2 return $ maybe u ($ u) $ case si of - ListedSelectionItem j -> mos ^? ix j . moEff - ScrollUpSelectionItem -> Just $ uvScreenLayers . _head . scSelectionList . slOffset %~ (max 0 . subtract 5) - ScrollDownSelectionItem -> do + ListedSelectionItem j -> fmap (refreshOptionsSelectionList .) (mos ^? ix j . moEff) + ScrollSelectionItem -> do maxlines <- sl ^? slSizeRestriction . maxSelectionLines alllines <- sl ^? slLength Just $ uvScreenLayers . _head . scSelectionList . slOffset %~ (\x -> if x + maxlines - 2 >= alllines then 0 else x + maxlines - 2) - DummySelectionItem -> Just id SpecialSelectionItem -> Just id _ -> u