diff --git a/src/Dodge/Data/SelectionList.hs b/src/Dodge/Data/SelectionList.hs index 18f1affcb..5f3fdbb2c 100644 --- a/src/Dodge/Data/SelectionList.hs +++ b/src/Dodge/Data/SelectionList.hs @@ -10,7 +10,6 @@ import Dodge.Data.CardinalPoint data SelectionList = SelectionList { _slPosX :: Float , _slPosY :: Float - , _slOffset :: Int , _slScale :: Float , _slVerticalGap :: Float , _slItems :: [SelectionItem] diff --git a/src/Dodge/Data/Universe.hs b/src/Dodge/Data/Universe.hs index 82cbee83d..b1c667a6d 100644 --- a/src/Dodge/Data/Universe.hs +++ b/src/Dodge/Data/Universe.hs @@ -52,6 +52,7 @@ data ScreenLayer = OptionScreen { _scTitle :: String , _scOptions :: [MenuOption] + , _scOffset :: Int , _scMaybeOption :: Maybe MenuOption , _scOptionFlag :: OptionScreenFlag , _scSelectionList :: SelectionList diff --git a/src/Dodge/Menu/Option.hs b/src/Dodge/Menu/Option.hs index 6ffe0d13b..7c9c01b47 100644 --- a/src/Dodge/Menu/Option.hs +++ b/src/Dodge/Menu/Option.hs @@ -16,6 +16,7 @@ slTitleOptionsEff title ops defstr eff u = OptionScreen { _scTitle = title , _scOptions = ops + , _scOffset = 0 , _scMaybeOption = fmap (Toggle eff . const . MODString) defstr , _scOptionFlag = NormalOptions , _scSelectionList = makeOptionsSelectionList (Just 0) u ops @@ -35,7 +36,6 @@ makeOptionsSelectionList :: Maybe Int -> Universe -> [MenuOption] -> SelectionLi makeOptionsSelectionList mselpos u mos = SelectionList { _slPosX = 50 , _slPosY = 50 - , _slOffset = 0 , _slScale = 2 , _slVerticalGap = 30 , _slItems = optionsToSelections u mos diff --git a/src/Dodge/Render/HUD.hs b/src/Dodge/Render/HUD.hs index 9ad108aee..aa2614c2f 100644 --- a/src/Dodge/Render/HUD.hs +++ b/src/Dodge/Render/HUD.hs @@ -55,7 +55,6 @@ defaultSelectionList = SelectionList , _slScale = 1 , _slPosX = 0 , _slPosY = 0 - , _slOffset = 0 , _slItems = [] , _slShownItems = [] , _slSelPos = Nothing @@ -71,7 +70,6 @@ subInvSelectionList = SelectionList , _slScale = 1 , _slPosX = subInvX , _slPosY = 60 - , _slOffset = 0 , _slItems = [] , _slShownItems = [] , _slSelPos = Nothing diff --git a/src/Dodge/SelectionList.hs b/src/Dodge/SelectionList.hs index ba7deb63a..c2458bef6 100644 --- a/src/Dodge/SelectionList.hs +++ b/src/Dodge/SelectionList.hs @@ -1,11 +1,17 @@ module Dodge.SelectionList where --import Color -import Dodge.Data.SelectionList +import Dodge.Data.Universe import LensHelp +import Data.Maybe -setShownSelectionItems :: SelectionList -> SelectionList -setShownSelectionItems sl = case sl ^? slSizeRestriction of +setShownSelectionItems :: ScreenLayer -> ScreenLayer +setShownSelectionItems sl = fromMaybe sl $ do + offset <- sl ^? scOffset + return $ sl & scSelectionList %~ setShownSelectionItems' offset + +setShownSelectionItems' :: Int -> SelectionList -> SelectionList +setShownSelectionItems' offset sl = case sl ^? slSizeRestriction of Just (SelectionSizeRestriction maxlines _ botit _) | length allitems > maxlines -> sl & slShownItems .~ take (maxlines - 2) (drop offset allitems) -- ++ repeat dummyitem)) @@ -13,5 +19,4 @@ setShownSelectionItems sl = case sl ^? slSizeRestriction of _ -> sl & slShownItems .~ allitems where -- dummyitem = (SelectionItem [] 1 False 0 white 0, DummySelectionItem) - offset = sl ^. slOffset allitems = zipWith (\x y -> (x,ListedSelectionItem y)) (sl ^. slItems) [0..] diff --git a/src/Dodge/TestString.hs b/src/Dodge/TestString.hs index 3b740dc25..9a25457a1 100644 --- a/src/Dodge/TestString.hs +++ b/src/Dodge/TestString.hs @@ -8,7 +8,7 @@ import qualified Data.Map.Strict as M testStringInit :: Universe -> [String] testStringInit u = - [ show $ u ^? uvScreenLayers . _head . scSelectionList . slOffset + [ show $ u ^? uvScreenLayers . _head . scOffset ] ++ [ shortShow $ u ^?! uvWorld . cWorld . lWorld . creatures . ix 0 . crPos ] diff --git a/src/Dodge/Update.hs b/src/Dodge/Update.hs index e7f6a77c3..993d3a461 100644 --- a/src/Dodge/Update.hs +++ b/src/Dodge/Update.hs @@ -103,7 +103,7 @@ mouseClickOptionsList mos sl u = case u ^. uvWorld . input . mouseButtons . at B ScrollSelectionItem -> do maxlines <- sl ^? slSizeRestriction . maxSelectionLines alllines <- sl ^? slLength - Just $ uvScreenLayers . _head . scSelectionList . slOffset %~ + Just $ uvScreenLayers . _head . scOffset %~ (\x -> if x + maxlines - 2 >= alllines then 0 else x + maxlines - 2) SpecialSelectionItem -> Just id _ -> u @@ -155,7 +155,7 @@ optionScreenUpdate mos mop _ sl u = . mouseOverSelectionList sl . menuWheelEvents . over (uvScreenLayers . _head . scSelectionList) (setSelectionListRestriction cfig) - $ over (uvScreenLayers . _head . scSelectionList) setShownSelectionItems + $ over (uvScreenLayers . _head) setShownSelectionItems u where cfig = u ^. uvConfig