display.button documentation - wladekpal/The-Lazy-Snek GitHub Wiki
display.button.Button
Button is an abstract class representing buttons displayed on level window and used to control level simulation.
Properties
simulation
-gameply.simulation.Simulation
type object that is simulation controlled by button.texture
- square-sizedpygame.image
type object that is a texture of button displayed on screen.displayed_texture
-pygame.image
type object that block uses to display itself.displayed_side_length
- side length ofdisplayed_texture
. Note:displayed_texture
anddisplayed_side_length
are used to cache informations about last time that button was displayed on screen.displayed_texture
is a scaled version of button'stexture
property. If new display request demands same side length as the last one (which is most often the case), block's texture won't be scaled again, thus self_draw() method will execute much faster.
Button(simulation, texture)
Class constructor. Sets simulation
and texture
properties to values given in constructor, corresponding to their names.
action_when_clicked():
Abstract method. Implemented should interract with simulation in a way predefined by button role when the button is clicked.
process_mouse_click(mouse_position)
Checks if mouse_position
belongs to button's display area. If so, button's action_when_clicked()
method is called.
self_draw(frame, positionm side_length)
Draws texture representing button into frame, with the top-left corner placed at position and scales the texture side to side_length.
frame
- pygame.Surface
type object
position
- two integer tuple representing position of displayed block's top-left corner on frame
side_length
- side length of displayed square-shaped texture
replace_texture(texture)
Replaces current button's texture with given one.
texture
- new button texture
gameplay.button.RestartButton
Button responsible for restarting level simulation when clicked. Inherits from gameplay.button.Button
.
action_when_clicked(
Restarts level simulation.
gameplay.button.CancelButton
Button responsible for cancelling level simulation when clicked. Inherits from gameplay.button.Button
.
action_when_clicked()
Cancels level simulation.
gameplay.button.PlayButton
Button responsible for playing, pausing or resuming level simulation when clicked. Has two additional properties: primary_texture
and secondary_texture
, which are used to switch button texture depending on actual button onclick behaviour (play icon for playing or resuming simulation, pause button when pausing simulation which is currently running). Inherits from gameplay.button.Button
.
Additional properties:
- primary_texture -
pygame.image
type object displayed when button click runs or resums simulation. - secondary_texture -
pygame.image
type object displayed when button click pauses currently running simulation.
PlayButton(simulation, texture, secondary_texture)
Sets primary_texture
value to texture
and secondary_texture
value to secondary_texture
. Other properties are set same as in gameplay.button.Button constructor.
self_draw(frame, position, side_length).
Checks current simulation state and switches texture
to correspond to current button role. After that, executes same method of gameplay.button.Button
class.
gameplay.button.StepByStepButton
Button responsible for making one step in simulation. Has two additional properties: primary_texture
and secondary_texture
, which are used to switch button texture depending on actual game state. Inherits from gameplay.button.Button
.
Additional properties:
- primary_texture -
pygame.image
type object displayed when game state isPAUSED
. - secondary_texture -
pygame.image
type object displayed when game state isRUNNING
orINACTIVE
.
StepByStepButton(simulation, texture, secondary_texture)
Sets primary_texture
value to texture
and secondary_texture
value to secondary_texture
. Other properties are set same as in gameplay.button.Button constructor.
self_draw(frame, position, side_length).
Checks current simulation state and switches texture
to correspond to current button role. After that, executes same method of gameplay.button.Button
class.