Separate selection list items from display parameters
This commit is contained in:
+32
-37
@@ -11,49 +11,27 @@ import Dodge.Data.Universe
|
||||
import qualified Data.Set as Set
|
||||
import LensHelp
|
||||
|
||||
slTitleOptionsEff :: String -> [MenuOption] -> Maybe String -> (Universe -> Universe) -> Universe -> ScreenLayer
|
||||
slTitleOptionsEff title ops defstr eff u =
|
||||
initializeOptionMenu :: String -> [MenuOption] -> Maybe String -> (Universe -> Universe) -> Universe -> ScreenLayer
|
||||
initializeOptionMenu 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
|
||||
, _scSelectionList = makeOptionsSelectionList 10 (Just 0) u ops
|
||||
, _scAvailableLines = 10
|
||||
, _scShownItems = []
|
||||
, _scListDisplayParams = ListDisplayParams
|
||||
{ _ldpPosX = 50
|
||||
, _ldpPosY = 50
|
||||
, _ldpScale = 2
|
||||
, _ldpVerticalGap = 30
|
||||
, _ldpWidth = FixedSelectionWidth 15
|
||||
, _ldpSizeRestriction = SelectionSizeRestriction overflowit
|
||||
, _ldpCursorType = BorderCursor (Set.fromList [North,South,West])
|
||||
}
|
||||
}
|
||||
|
||||
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] -> SelectionList
|
||||
makeOptionsSelectionList mselpos u mos = SelectionList
|
||||
{ _slPosX = 50
|
||||
, _slPosY = 50
|
||||
, _slScale = 2
|
||||
, _slVerticalGap = 30
|
||||
, _slItems = optionsToSelections u mos
|
||||
, _slShownItems = []
|
||||
, _slSelPos = mselpos
|
||||
, _slCursorType = BorderCursor (Set.fromList [North,South,West])
|
||||
, _slWidth = FixedSelectionWidth 15
|
||||
, _slLength = length $ optionsToSelections u mos
|
||||
, _slSizeRestriction = SelectionSizeRestriction overflowit
|
||||
-- , _slSpecialItem = fromMaybe NoSpecialSelectionItem $ do
|
||||
-- str <- defstr
|
||||
-- return $ BottomSelectionItem SelectionItem
|
||||
-- { _siPictures = [color white $ text str]
|
||||
-- , _siHeight = 1
|
||||
-- , _siIsSelectable = True
|
||||
-- , _siWidth = length str
|
||||
-- , _siColor = white
|
||||
-- , _siOffX = 0
|
||||
-- }
|
||||
}
|
||||
where
|
||||
overflowit = SelectionItem
|
||||
{ _siPictures = [text "MORE OPTIONS"]
|
||||
@@ -64,9 +42,26 @@ makeOptionsSelectionList mselpos u mos = SelectionList
|
||||
, _siOffX = 0
|
||||
}
|
||||
|
||||
optionsToSelections :: Universe -> [MenuOption] -> [SelectionItem]
|
||||
optionsToSelections u ops = map colStrToSelItem colstrs
|
||||
refreshOptionsSelectionList :: Universe -> Universe
|
||||
refreshOptionsSelectionList u = u & uvScreenLayers . ix 0 %~ f
|
||||
where
|
||||
f sl = case sl of
|
||||
OptionScreen {_scOptions = mops
|
||||
, _scAvailableLines = maxlines}
|
||||
-> sl & scSelectionList . slItems .~ optionsToSelections maxlines u mops
|
||||
_ -> sl
|
||||
|
||||
makeOptionsSelectionList :: Int -> Maybe Int -> Universe -> [MenuOption] -> SelectionList
|
||||
makeOptionsSelectionList maxlines mselpos u mos = SelectionList
|
||||
{ _slItems = optionsToSelections maxlines u mos
|
||||
, _slSelPos = mselpos
|
||||
, _slLength = length $ optionsToSelections maxlines u mos
|
||||
}
|
||||
|
||||
optionsToSelections :: Int -> Universe -> [MenuOption] -> [SelectionItem]
|
||||
optionsToSelections maxlines u allops = map colStrToSelItem colstrs
|
||||
where
|
||||
ops = take maxlines allops
|
||||
maxOptionLength = 3 + maximum (0 : map (optionValueOffset u) ops)
|
||||
colstrs = map (menuOptionToString u maxOptionLength) ops
|
||||
|
||||
|
||||
Reference in New Issue
Block a user