Simplify buttons
This commit is contained in:
@@ -1,55 +1,63 @@
|
||||
module Dodge.LevelGen.Switch
|
||||
( makeSwitch
|
||||
, makeButton
|
||||
, makeSwitchSPic
|
||||
, drawSwitchWire
|
||||
) where
|
||||
module Dodge.LevelGen.Switch (
|
||||
makeSwitch,
|
||||
makeButton,
|
||||
makeSwitchSPic,
|
||||
drawSwitchWire,
|
||||
) where
|
||||
|
||||
import Dodge.Data.Button
|
||||
import Dodge.Data.WorldEffect
|
||||
import Dodge.Default
|
||||
import Dodge.SoundLogic
|
||||
import Picture
|
||||
import ShapePicture
|
||||
import Shape
|
||||
import Geometry
|
||||
import Picture
|
||||
import Shape
|
||||
import ShapePicture
|
||||
import Control.Lens
|
||||
|
||||
makeButton
|
||||
:: Color
|
||||
-> WdWd -- ^ Effect when pressed
|
||||
-> Button
|
||||
makeButton col eff = defaultButton
|
||||
{ _btEvent = ButtonPress BtInactive ButtonDoNothing click1S eff col
|
||||
, _btState = BtOff
|
||||
}
|
||||
makeButton ::
|
||||
Color ->
|
||||
-- | Effect when pressed
|
||||
WdWd ->
|
||||
Button
|
||||
makeButton col eff =
|
||||
defaultButton
|
||||
{ -- { _btEvent = ButtonPress BtInactive ButtonDoNothing click1S eff col
|
||||
_btEvent = ButtonPress False eff col
|
||||
-- , _btState = BtOff
|
||||
}
|
||||
|
||||
-- TODO remove duplication
|
||||
drawSwitchWire :: Color -> Color -> Button -> SPic
|
||||
drawSwitchWire col1 col2 bt
|
||||
| _btState bt == BtOff = flick $ pi/4
|
||||
| otherwise = flick (negate (pi/4))
|
||||
| bt ^? btEvent . btOn == Just False = flick $ pi / 4
|
||||
| otherwise = flick (negate (pi / 4))
|
||||
where
|
||||
flick a = noPic ( mconcat
|
||||
[ colorSH col1 . translateSHz 10 . upperBox Small Typical 10 $ rectNSWE (-2) (-5) (-10) 10
|
||||
, colorSH col2 . translateSH (V3 0 (-2) 15) . rotateSH a . upperBox Small Typical 2
|
||||
$ rectNSWE 10 0 (-2) 2
|
||||
]
|
||||
)
|
||||
flick a =
|
||||
noPic
|
||||
( mconcat
|
||||
[ colorSH col1 . translateSHz 10 . upperBox Small Typical 10 $ rectNSWE (-2) (-5) (-10) 10
|
||||
, colorSH col2 . translateSH (V3 0 (-2) 15) . rotateSH a . upperBox Small Typical 2 $
|
||||
rectNSWE 10 0 (-2) 2
|
||||
]
|
||||
)
|
||||
|
||||
makeSwitchSPic
|
||||
:: Color
|
||||
-> Color
|
||||
-> WdWd -- ^ Switch on effect
|
||||
-> WdWd -- ^ Switch off effect
|
||||
-> Button
|
||||
makeSwitchSPic c1 c2 effOn effOff = defaultButton
|
||||
{ _btEvent = ButtonSimpleSwith effOn effOff c1 c2
|
||||
, _btState = BtOff
|
||||
}
|
||||
|
||||
makeSwitch
|
||||
:: Color
|
||||
-> Color
|
||||
-> WdWd -- ^ Switch on effect
|
||||
-> WdWd -- ^ Switch off effect
|
||||
-> Button
|
||||
makeSwitchSPic ::
|
||||
Color ->
|
||||
Color ->
|
||||
-- | Switch on effect
|
||||
WdWd ->
|
||||
-- | Switch off effect
|
||||
WdWd ->
|
||||
Button
|
||||
makeSwitchSPic c1 c2 effOn effOff =
|
||||
defaultButton & btEvent .~ ButtonSwitch effOn effOff c1 c2 False
|
||||
|
||||
makeSwitch ::
|
||||
Color ->
|
||||
Color ->
|
||||
-- | Switch on effect
|
||||
WdWd ->
|
||||
-- | Switch off effect
|
||||
WdWd ->
|
||||
Button
|
||||
makeSwitch col1 col2 = makeSwitchSPic col1 col2
|
||||
|
||||
Reference in New Issue
Block a user