Simplify button drawing

This commit is contained in:
2025-06-25 15:40:12 +01:00
parent bf0bc22720
commit 6e9d4918a1
9 changed files with 40 additions and 46 deletions
+1 -1
View File
File diff suppressed because one or more lines are too long
+7 -5
View File
@@ -5,12 +5,14 @@ import Dodge.Data.Button
import Geometry import Geometry
import Shape import Shape
import ShapePicture import ShapePicture
import Control.Lens
drawButton :: ButtonDraw -> Button -> SPic drawButton :: Button -> SPic
drawButton bd = case bd of drawButton bt = case bt ^. btEvent of
DefaultDrawButton col -> defaultDrawButton col ButtonPress {_bpColor = col} -> defaultDrawButton col bt
DefaultDrawSwitch col1 col2 -> drawSwitch col1 col2 ButtonSimpleSwith {_bssColor1 = col1, _bssColor2 = col2} -> drawSwitch col1 col2 bt
DrawNoButton -> const mempty ButtonAccessTerminal -> mempty
ButtonDoNothing -> mempty
drawSwitch :: Color -> Color -> Button -> SPic drawSwitch :: Color -> Color -> Button -> SPic
drawSwitch col1 col2 bt drawSwitch col1 col2 bt
+2 -2
View File
@@ -9,13 +9,13 @@ import Dodge.WorldEffect
doButtonEvent :: ButtonEvent -> Button -> World -> World doButtonEvent :: ButtonEvent -> Button -> World -> World
doButtonEvent be = case be of doButtonEvent be = case be of
ButtonDoNothing -> const id ButtonDoNothing -> const id
ButtonPress newstate newevent thesound f -> \b -> ButtonPress newstate newevent thesound f c -> \b ->
doWdWd f doWdWd f
. set (cWorld . lWorld . buttons . ix (_btID b) . btState) newstate . set (cWorld . lWorld . buttons . ix (_btID b) . btState) newstate
. set (cWorld . lWorld . buttons . ix (_btID b) . btEvent) newevent . set (cWorld . lWorld . buttons . ix (_btID b) . btEvent) newevent
. soundStart (LeverSound 0) (_btPos b) thesound Nothing . soundStart (LeverSound 0) (_btPos b) thesound Nothing
--ButtonSwitch onstate onevent onsound oneff offstate offevent offsound offeff -> undefined --ButtonSwitch onstate onevent onsound oneff offstate offevent offsound offeff -> undefined
ButtonSimpleSwith oneff offeff -> flipSwitch oneff offeff ButtonSimpleSwith oneff offeff _ _ -> flipSwitch oneff offeff
ButtonAccessTerminal -> accessTerminal . _btTermMID ButtonAccessTerminal -> accessTerminal . _btTermMID
flipSwitch :: WdWd -> WdWd -> Button -> World -> World flipSwitch :: WdWd -> WdWd -> Button -> World -> World
+13 -19
View File
@@ -13,11 +13,11 @@ import Dodge.Data.WorldEffect
import Geometry.Data import Geometry.Data
import Sound.Data import Sound.Data
data ButtonDraw --data ButtonDraw
= DefaultDrawButton Color -- = DefaultDrawButton Color
| DefaultDrawSwitch Color Color -- | DefaultDrawSwitch Color Color
| DrawNoButton -- | DrawNoButton
--deriving (Eq, Ord, Show, Read) --Generic, Flat) -- --deriving (Eq, Ord, Show, Read) --Generic, Flat)
data ButtonEvent data ButtonEvent
= ButtonDoNothing = ButtonDoNothing
@@ -26,28 +26,22 @@ data ButtonEvent
, _bpEvent :: ButtonEvent , _bpEvent :: ButtonEvent
, _bpSound :: SoundID , _bpSound :: SoundID
, _bpEff :: WdWd , _bpEff :: WdWd
, _bpColor :: Color
} }
| -- | ButtonSwitch | ButtonSimpleSwith
-- {_bonState :: ButtonState
-- ,_bonEvent :: ButtonEvent
-- ,_bonSound :: SoundID
-- ,_bonEff :: WorldEffect
-- ,_boffState :: ButtonState
-- ,_boffEvent :: ButtonEvent
-- ,_boffSound :: SoundID
-- ,_boffEff :: WorldEffect
-- }
ButtonSimpleSwith
{ _bonEff :: WdWd { _bonEff :: WdWd
, _boffEff :: WdWd , _boffEff :: WdWd
, _bssColor1 :: Color
, _bssColor2 :: Color
} }
| ButtonAccessTerminal | ButtonAccessTerminal
--deriving (Eq, Show, Read) --, Generic) --deriving (Eq, Show, Read) --, Generic)
--h--deriving (Eq, Show, Read) --Generic, Flat) --h--deriving (Eq, Show, Read) --Generic, Flat)
data Button = Button data Button = Button
{ _btPict :: ButtonDraw --Button -> SPic {
, _btPos :: Point2 -- _btPict :: ButtonDraw --Button -> SPic
_btPos :: Point2
, _btRot :: Float , _btRot :: Float
, _btEvent :: ButtonEvent --Button -> World -> World , _btEvent :: ButtonEvent --Button -> World -> World
, _btID :: Int , _btID :: Int
@@ -65,7 +59,7 @@ data ButtonState = BtOn | BtOff | BtInactive
makeLenses ''Button makeLenses ''Button
makeLenses ''ButtonEvent makeLenses ''ButtonEvent
deriveJSON defaultOptions ''ButtonDraw --deriveJSON defaultOptions ''ButtonDraw
deriveJSON defaultOptions ''ButtonState deriveJSON defaultOptions ''ButtonState
deriveJSON defaultOptions ''ButtonEvent deriveJSON defaultOptions ''ButtonEvent
deriveJSON defaultOptions ''Button deriveJSON defaultOptions ''Button
+2 -2
View File
@@ -49,10 +49,10 @@ defaultMachine =
defaultButton :: Button defaultButton :: Button
defaultButton = defaultButton =
Button Button
{ _btPict = DefaultDrawButton (dark red) { _btPos = V2 0 0
, _btPos = V2 0 0
, _btRot = 0 , _btRot = 0
, _btEvent = ButtonPress BtInactive ButtonDoNothing click1S NoWorldEffect , _btEvent = ButtonPress BtInactive ButtonDoNothing click1S NoWorldEffect
(dark red)
, _btID = 0 , _btID = 0
, _btState = BtOff , _btState = BtOff
, _btTermMID = Nothing , _btTermMID = Nothing
+6 -7
View File
@@ -18,8 +18,7 @@ makeButton
-> WdWd -- ^ Effect when pressed -> WdWd -- ^ Effect when pressed
-> Button -> Button
makeButton col eff = defaultButton makeButton col eff = defaultButton
{ _btPict = DefaultDrawButton col { _btEvent = ButtonPress BtInactive ButtonDoNothing click1S eff col
, _btEvent = ButtonPress BtInactive ButtonDoNothing click1S eff
, _btState = BtOff , _btState = BtOff
} }
@@ -37,13 +36,13 @@ drawSwitchWire col1 col2 bt
) )
makeSwitchSPic makeSwitchSPic
:: ButtonDraw :: Color
-> Color
-> WdWd -- ^ Switch on effect -> WdWd -- ^ Switch on effect
-> WdWd -- ^ Switch off effect -> WdWd -- ^ Switch off effect
-> Button -> Button
makeSwitchSPic dswitch effOn effOff = defaultButton makeSwitchSPic c1 c2 effOn effOff = defaultButton
{ _btPict = dswitch { _btEvent = ButtonSimpleSwith effOn effOff c1 c2
, _btEvent = ButtonSimpleSwith effOn effOff
, _btState = BtOff , _btState = BtOff
} }
@@ -53,4 +52,4 @@ makeSwitch
-> WdWd -- ^ Switch on effect -> WdWd -- ^ Switch on effect
-> WdWd -- ^ Switch off effect -> WdWd -- ^ Switch off effect
-> Button -> Button
makeSwitch col1 col2 = makeSwitchSPic (DefaultDrawSwitch col1 col2) makeSwitch col1 col2 = makeSwitchSPic col1 col2
+6 -6
View File
@@ -11,15 +11,15 @@ import Dodge.Placement.Instance.LightSource
import Dodge.PlacementSpot import Dodge.PlacementSpot
import Geometry import Geometry
triggerSwitchSPic :: ButtonDraw -> PlacementSpot -> Placement triggerSwitchSPic :: Color -> Color -> PlacementSpot -> Placement
triggerSwitchSPic sdraw ps = psPtCont ps (PutTrigger False) $ triggerSwitchSPic c1 c2 ps = psPtCont ps (PutTrigger False) $
\tp -> \tp ->
Just $ Just $
pContID pContID
ps ps
( PutButton ( PutButton
( makeSwitchSPic ( makeSwitchSPic
sdraw c1 c2
(SetTrigger True $ trigid tp) (SetTrigger True $ trigid tp)
(SetTrigger False $ trigid tp) (SetTrigger False $ trigid tp)
) )
@@ -28,15 +28,15 @@ triggerSwitchSPic sdraw ps = psPtCont ps (PutTrigger False) $
where where
trigid tp = fromJust $ _plMID tp trigid tp = fromJust $ _plMID tp
triggerSwitchSPicLight :: ButtonDraw -> PlacementSpot -> Placement triggerSwitchSPicLight :: Color -> Color -> PlacementSpot -> Placement
triggerSwitchSPicLight sdraw ps = psPtCont ps (PutTrigger False) $ triggerSwitchSPicLight c1 c2 ps = psPtCont ps (PutTrigger False) $
\tp -> Just $ \tp -> Just $
pContID atFstLnkOut (PutLS thels) $ pContID atFstLnkOut (PutLS thels) $
\lsid -> \lsid ->
Just $ Just $
pContID pContID
ps ps
(PutButton (makeSwitchSPic sdraw (oneff lsid $ trigid tp) (offeff lsid $ trigid tp))) (PutButton (makeSwitchSPic c1 c2 (oneff lsid $ trigid tp) (offeff lsid $ trigid tp)))
(const Nothing) (const Nothing)
where where
thels = lsColPosRad (V3 0.5 0 0) (V3 0 0 78) 75 thels = lsColPosRad (V3 0.5 0 0) (V3 0 0 78) 75
+1 -2
View File
@@ -51,8 +51,7 @@ putMessageTerminal col =
termButton :: Button termButton :: Button
termButton = termButton =
Button Button
{ _btPict = DrawNoButton { _btPos = 0
, _btPos = 0
, _btRot = 0 , _btRot = 0
, _btEvent = ButtonAccessTerminal , _btEvent = ButtonAccessTerminal
, _btID = 0 , _btID = 0
+1 -1
View File
@@ -106,7 +106,7 @@ floorItemSPic flit =
btSPic :: Button -> SPic btSPic :: Button -> SPic
btSPic bt = btSPic bt =
uncurryV translateSPxy (_btPos bt) $ uncurryV translateSPxy (_btPos bt) $
rotateSP (_btRot bt) (drawButton (_btPict bt) bt) rotateSP (_btRot bt) (drawButton bt)
mcSPic :: LWorld -> Machine -> SPic mcSPic :: LWorld -> Machine -> SPic
mcSPic lw mc = mcSPic lw mc =