Refactor control list display

This commit is contained in:
2021-09-13 01:39:53 +01:00
parent d11d19c9e8
commit b27c174d93
6 changed files with 79 additions and 52 deletions
+34 -4
View File
@@ -11,6 +11,7 @@ import Dodge.Data
import Dodge.Base.Window
import Picture
import Dodge.Menu
import Padding
menuScreen
:: World
@@ -23,6 +24,7 @@ menuScreen w screen = case screen of
(InputScreen s) -> drawOptions w ('>':s) []
(TerminalScreen t xs ) -> displayStringList w $ map snd $ filter (( > t) . fst) xs
(DisplayScreen sd ) -> sd w
(ColumnsScreen title pairs) -> drawTwoColumnsScreen w title pairs
displayStringList :: World -> [String] -> Picture
displayStringList w ss = pictures
@@ -33,6 +35,26 @@ displayStringList w ss = pictures
hw = halfWidth w
ys = [0,22..]
f y s = translate (10-hw) y . scale 0.15 0.15 $ text s
drawTwoColumnsScreen
:: World
-> String
-> [(String,String)]
-> Picture
drawTwoColumnsScreen w title lps = pictures
[darkenBackground w
,drawTitle w title
,drawTwoColumns w lps
]
drawTwoColumns :: World -> [(String,String)] -> Picture
drawTwoColumns w lps = pictures $ zipWith f [hh-100,hh-130..] lps
where
f y (s1,s2) = translate (50-hw) y $ sc $ rightPad ln '.' s1 ++ s2
sc = scale 0.15 0.15 . color white . text
hh = halfHeight w
hw = halfWidth w
ln = maximum (map (length . fst) lps) + 3
drawOptions
:: World
@@ -40,8 +62,8 @@ drawOptions
-> [MenuOption] -- ^ Options
-> Picture
drawOptions w title ops = pictures $
[darkenBackground
,theTitle]
[darkenBackground w
,drawTitle w title]
++
zipWith (\ s vpos -> placeString (-hw + 50) vpos 0.2 s) (map (menuOptionToString w) ops') [hh-100,hh-150 ..]
where
@@ -49,8 +71,16 @@ drawOptions w title ops = pictures $
notInvisible InvisibleToggle {} = False
notInvisible _ = True
placeString x y sc t = translate x y $ scale sc sc $ color white $ text t
darkenBackground = color (withAlpha 0.5 black) $ polygon $ screenBox w
theTitle = placeString (-hw + 30) (hh - 50) 0.4 title
hh = halfHeight w
hw = halfWidth w
darkenBackground :: World -> Picture
darkenBackground = color (withAlpha 0.5 black) . polygon . screenBox
drawTitle :: World -> String -> Picture
drawTitle w = placeString (-hw + 30) (hh - 50) 0.4
where
placeString x y sc t = translate x y $ scale sc sc $ color white $ text t
hh = halfHeight w
hw = halfWidth w