gui module

GUI package.

(See gui/screens for the graphical interfaces.)

gui.button

Module name: button

class game.gui.button.Button(text: str = '', x: int = 0, y: int = 0, width: int = 500, height: int = 50)

Bases: Widget

Class for creating a button.

MAX_HEIGHT = 0
MAX_WIDTH = 0
MIN_HEIGHT = 0
MIN_WIDTH = 0
can_interact() bool

Return whether the widget can be interacted with or not, independent to its visibility.

center(parent_x: int, parent_y: int, parent_width: int, parent_height: int) Self

Center the widget on both axes relative to the specified parent, then return the widget itself.

center_horizontally(parent_x: int, parent_width: int) Self

Center the widget horizontally relative to the specified parent, then return the widget itself.

center_vertically(parent_y: int, parent_height: int) Self

Center the widget vertically relative to the specified parent, then return the widget itself.

center_with_offset(parent_x: int, parent_y: int, parent_width: int, parent_height: int, x: int, y: int) Self

Center the widget with and offset it by x and y relative to the specified parent, then return the widget itself.

draw(window: Window | Surface) None

Draw the widget and its components.

events(e: pygame.event.Event) None

Handle the widget events.

get_background_colour() tuple[int, int, int]

Return the background colour of the button.

get_height() int

Get the height of the widget.

get_state() bool

Return the widget’s visibility and interactivity state.

get_transparency() float

Return the widget’s transparency.

get_width() int

Get the width of the widget.

get_x() int

Return the x position of the widget.

get_y() int

Return the y position of the widget.

is_hovering_over() bool

Return whether the user’s mouse cursor is hovering over the widget or not.

offset(offset_x: int, offset_y: int) Self

Add an offset to the x and y positions of the widget, then return the widget itself.

offset_x(offset_x: int) Self

Add an offset to the x position of the widget, then return the widget itself.

offset_y(offset_y: int) Self

Add an offset to the y position of the widget, then return the widget itself.

resize(window: Window) None

Resize the widget based on the screen dimensions.

set_background_colour(background_colour: tuple[int, int, int]) Self

Set the background colour of the button, then return the button itself.

set_height(height: int) Self

Set the height of the widget, then return the widget itself.

set_interact(state: bool) Self

Set whether the widget is interactable or not, independent to its visibility, then return the widget itself.

set_state(state: bool) Self

Set the widget’s visibility and interactivity state, then return the widget itself.

set_transparency(transparency: float) Self

Set the widget’s transparency, then return the widget itself.

set_width(width: int) Self

Set the width of the widget, then return the widget itself.

set_x(x: int) Self

Set the x position of the widget, then return the widget itself.

set_y(y: int) Self

Set the y position of the widget, then return the widget itself.

update(window: Window) None

Update the widget and its components.

classmethod validate_dimensions(width: int, height: int) None

Test a widget’s dimensions.

gui.checkbox

Module name: checkbox

class game.gui.checkbox.Checkbox(title: str, x: int = 0, y: int = 0, size: int = 20, checked: bool = False)

Bases: Widget

Class for creating a checkbox.

MAX_HEIGHT = 0
MAX_WIDTH = 0
MIN_HEIGHT = 0
MIN_WIDTH = 0
can_interact() bool

Return whether the widget can be interacted with or not, independent to its visibility.

center(parent_x: int, parent_y: int, parent_width: int, parent_height: int) Self

Center the widget on both axes relative to the specified parent, then return the widget itself.

center_horizontally(parent_x: int, parent_width: int) Self

Center the widget horizontally relative to the specified parent, then return the widget itself.

center_vertically(parent_y: int, parent_height: int) Self

Center the widget vertically relative to the specified parent, then return the widget itself.

center_with_offset(parent_x: int, parent_y: int, parent_width: int, parent_height: int, x: int, y: int) Self

Center the widget with and offset it by x and y relative to the specified parent, then return the widget itself.

draw(window: Window | Surface) None

Draw the widget and its components.

events(e: pygame.event.Event) None

Handle the widget events.

get_height() int

Get the height of the widget.

get_state() bool

Return the widget’s visibility and interactivity state.

get_transparency() float

Return the widget’s transparency.

get_width() int

Get the width of the widget.

get_x() int

Return the x position of the widget.

get_y() int

Return the y position of the widget.

is_checked() bool

Return the checked state of the checkbox’s button.

is_hovering_over() bool

Return whether the user’s mouse cursor is hovering over the widget or not.

offset(offset_x: int, offset_y: int) Self

Add an offset to the x and y positions of the widget, then return the widget itself.

offset_x(offset_x: int) Self

Add an offset to the x position of the widget, then return the widget itself.

offset_y(offset_y: int) Self

Add an offset to the y position of the widget, then return the widget itself.

resize(window: Window) None

Resize the widget based on the screen dimensions.

set_checked(state: bool) Self

Set the checked state of the checkbox’s button, then return the checkbox itself.

set_height(height: int) Self

Set the height of the widget, then return the widget itself.

set_interact(state: bool) Self

Set whether the widget is interactable or not, independent to its visibility, then return the widget itself.

set_state(state: bool) Self

Set the widget’s visibility and interactivity state, then return the widget itself.

set_transparency(transparency: float) Self

Set the widget’s transparency, then return the widget itself.

set_width(width: int) Self

Set the width of the widget, then return the widget itself.

set_x(x: int) Self

Set the x position of the widget, then return the widget itself.

set_y(y: int) Self

Set the y position of the widget, then return the widget itself.

update(window: Window) None

Update the widget and its components.

classmethod validate_dimensions(width: int, height: int) None

Test a widget’s dimensions.

gui.horizontal_slider

Module name: horizontal_slider

class game.gui.horizontal_slider.HorizontalSlider(title: str = '', x: int = 0, y: int = 0, width: int = 350)

Bases: Widget

Class for creating a horizontal slider.

MAX_HEIGHT = 0
MAX_WIDTH = 0
MIN_HEIGHT = 0
MIN_WIDTH = 0
button_held(state: bool) Self

Set whether the horizontal slider’s button is held or not, then return the horizontal slider itself.

can_interact() bool

Return whether the widget can be interacted with or not, independent to its visibility.

center(parent_x: int, parent_y: int, parent_width: int, parent_height: int) Self

Center the widget on both axes relative to the specified parent, then return the widget itself.

center_horizontally(parent_x: int, parent_width: int) Self

Center the widget horizontally relative to the specified parent, then return the widget itself.

center_vertically(parent_y: int, parent_height: int) Self

Center the widget vertically relative to the specified parent, then return the widget itself.

center_with_offset(parent_x: int, parent_y: int, parent_width: int, parent_height: int, x: int, y: int) Self

Center the widget with and offset it by x and y relative to the specified parent, then return the widget itself.

draw(window: Window | Surface) None

Draw the widget and its components.

events(e: pygame.event.Event) None

Handle the widget events.

get_bar_width() int

Return the width of the horizontal slider’s bar.

get_height() int

Get the height of the widget.

get_state() bool

Return the widget’s visibility and interactivity state.

get_step_in_pixels() float

Return the number of pixels needed to move the horizontal slider’s button from one value to the next.

get_title() str

Return the title label’s text of the horizontal slider.

get_transparency() float

Return the widget’s transparency.

get_value() int

Return the value of the horizontal slider.

get_value_bounds() tuple[int, int]

Return the value bounds of the horizontal slider (min/max value).

get_value_text() str

Return the value label’s text of the horizontal slider.

get_width() int

Get the width of the widget.

get_x() int

Return the x position of the widget.

get_y() int

Return the y position of the widget.

is_button_held() bool

Return the held state of the horizontal slider’s button.

is_hovering_over() bool

Return whether the user’s mouse cursor is hovering over the widget or not.

is_hovering_over_button() bool

Return whether the user’s mouse cursor is hovering over the horizontal slider’s button or not.

offset(offset_x: int, offset_y: int) Self

Add an offset to the x and y positions of the widget, then return the widget itself.

offset_x(offset_x: int) Self

Add an offset to the x position of the widget, then return the widget itself.

offset_y(offset_y: int) Self

Add an offset to the y position of the widget, then return the widget itself.

resize(window: Window) None

Resize the widget based on the screen dimensions.

set_height(height: int) Self

Set the height of the widget, then return the widget itself.

set_interact(state: bool) Self

Set whether the widget is interactable or not, independent to its visibility, then return the widget itself.

set_state(state: bool) Self

Set the widget’s visibility and interactivity state, then return the widget itself.

set_title(title: str) Self

Set the title’s text of the horizontal slider, then return the horizontal slider itself.

set_transparency(transparency: float) Self

Set the widget’s transparency, then return the widget itself.

set_value(value: int) Self

Set the value of the horizontal slider, then return the horizontal slider itself.

set_value_bounds(min_value: int | None = None, max_value: int | None = None) Self

Set the value bounds of the horizontal slider (min/max value), then return the horizontal slider itself.

set_value_text(text: str) Self

Set the value label’s text of the horizontal slider, then return the horizontal slider itself.

set_width(width: int) Self

Set the width of the widget, then return the widget itself.

set_x(x: int) Self

Set the x position of the widget, then return the widget itself.

set_y(y: int) Self

Set the y position of the widget, then return the widget itself.

update(window: Window) None

Update the widget and its components.

classmethod validate_dimensions(width: int, height: int) None

Test a widget’s dimensions.

gui.hotbar

Module name: hotbar

class game.gui.hotbar.Hotbar(x: int = 0, y: int = 0, slot_count: int = 4)

Bases: Widget

Class for creating a hotbar.

MAX_HEIGHT = 0
MAX_WIDTH = 0
MIN_HEIGHT = 0
MIN_WIDTH = 0
can_interact() bool

Return whether the widget can be interacted with or not, independent to its visibility.

center(parent_x: int, parent_y: int, parent_width: int, parent_height: int) Self

Center the widget on both axes relative to the specified parent, then return the widget itself.

center_horizontally(parent_x: int, parent_width: int) Self

Center the widget horizontally relative to the specified parent, then return the widget itself.

center_vertically(parent_y: int, parent_height: int) Self

Center the widget vertically relative to the specified parent, then return the widget itself.

center_with_offset(parent_x: int, parent_y: int, parent_width: int, parent_height: int, x: int, y: int) Self

Center the widget with and offset it by x and y relative to the specified parent, then return the widget itself.

draw(screen) None

Draw the widget and its components.

events(e: pygame.event.Event) None

Handle the widget events.

get_atlas() pygame.Surface

Return the texture atlas used by the hotbar.

get_height() int

Get the height of the widget.

get_selected_slot() int

Return the selected slot of the hotbar.

get_selected_slot_item() Item

Return the item of the selected hotbar slot.

get_slot(slot_index: int) Slot

Return the slot object of the hotbar at specified index.

get_slots() list[Slot]

Return all hotbar slots.

get_spacing() int

Return the spacing between the hotbar’s slots.

get_state() bool

Return the widget’s visibility and interactivity state.

get_transparency() float

Return the widget’s transparency.

get_width() int

Get the width of the widget.

get_x() int

Return the x position of the widget.

get_y() int

Return the y position of the widget.

init_slots() None

Initialise the hotbar’s slots.

is_hovering_over() bool

Return whether the user’s mouse cursor is hovering over the widget or not.

offset(offset_x: int, offset_y: int) Self

Add an offset to the x and y positions of the widget, then return the widget itself.

offset_x(offset_x: int) Self

Add an offset to the x position of the widget, then return the widget itself.

offset_y(offset_y: int) Self

Add an offset to the y position of the widget, then return the widget itself.

resize(window: Window) None

Resize the widget based on the screen dimensions.

select_slot(slot_index: int) Self

Select a hotbar slot, then return the hotbar itself.

set_atlas(atlas: pygame.Surface) Self

Set the texture atlas that will be used by the hotbar, then return the hotbar itself.

set_height(height: int) Self

Set the height of the widget, then return the widget itself.

set_interact(state: bool) Self

Set whether the widget is interactable or not, independent to its visibility, then return the widget itself.

set_spacing(spacing: int) Self

Set the spacing between the hotbar’s slots, then return the hotbar itself.

set_state(state: bool) Self

Set the widget’s visibility and interactivity state, then return the widget itself.

set_transparency(transparency: float) Self

Set the widget’s transparency, then return the widget itself.

set_width(width: int) Self

Set the width of the widget, then return the widget itself.

set_x(x: int) Self

Set the x position of the widget, then return the widget itself.

set_y(y: int) Self

Set the y position of the widget, then return the widget itself.

unselect_slot(slot_index: int) Self

Unselect a hotbar slot, then return the slot itself.

update(window: Window) None

Update the widget and its components.

classmethod validate_dimensions(width: int, height: int) None

Test a widget’s dimensions.

gui.inputbox

Module name: inputbox

class game.gui.inputbox.InputBox(text: str = '', placeholder_text: str = '', tooltip_text: str = '', x: int = 0, y: int = 0, width: int = 800, height: int = 50)

Bases: Widget

Class for creating an input box.

MAX_HEIGHT = 0
MAX_WIDTH = 0
MIN_HEIGHT = 0
MIN_WIDTH = 0
authorise_only_alnum() Self

Authorise only alphanumerical values (a-zA-Z0-9), then return the input box itself.

authorise_only_alnumdot() Self

Authorise only alphanumerical values (a-zA-Z0-9.), then return the input box itself. This includes the dot (period/full stop) character.

authorise_only_alnumlines() Self

Authorise only alphanumerical values (a-zA-Z0-9-_), then return the input box itself. This includes dashes (hyphens) and underscores.

authorise_only_ascii() Self

Authorise only ASCII characters in the input box, then return the input box itself.

authorise_only_numeric() Self

Authorise only numerical values (0-9) in the input box, then return the input box itself.

can_interact() bool

Return whether the widget can be interacted with or not, independent to its visibility.

center(parent_x: int, parent_y: int, parent_width: int, parent_height: int) Self

Center the widget on both axes relative to the specified parent, then return the widget itself.

center_horizontally(parent_x: int, parent_width: int) Self

Center the widget horizontally relative to the specified parent, then return the widget itself.

center_vertically(parent_y: int, parent_height: int) Self

Center the widget vertically relative to the specified parent, then return the widget itself.

center_with_offset(parent_x: int, parent_y: int, parent_width: int, parent_height: int, x: int, y: int) Self

Center the widget with and offset it by x and y relative to the specified parent, then return the widget itself.

clean_text(text: str) str

Clean the text of any unauthorised characters.

draw(window: Window | Surface) None

Draw the widget and its components.

events(e: pygame.event.Event) None

Handle the widget events.

get_background_colour() tuple[int, int, int]

Return the background colour of the input box.

get_border_colour() tuple[int, int, int]

Return the border colour of the input box.

get_cursor_colour() tuple[int, int, int]

Return the cursor colour of the input box.

get_height() int

Get the height of the widget.

get_max_text_length() int

Return the input box’s max text length.

get_placeholder_text() str

Return the placeholder label text.

get_read_only() bool

Return the input box’s read-only state.

get_state() bool

Return the widget’s visibility and interactivity state.

get_text() str

Return the label text of the input box.

get_transparency() float

Return the widget’s transparency.

get_width() int

Get the width of the widget.

get_x() int

Return the x position of the widget.

get_y() int

Return the y position of the widget.

is_hovering_over() bool

Return whether the user’s mouse cursor is hovering over the widget or not.

is_selected() bool

Return whether the input box is selected or not.

offset(offset_x: int, offset_y: int) Self

Add an offset to the x and y positions of the widget, then return the widget itself.

offset_x(offset_x: int) Self

Add an offset to the x position of the widget, then return the widget itself.

offset_y(offset_y: int) Self

Add an offset to the y position of the widget, then return the widget itself.

resize(window: Window) None

Resize the widget based on the screen dimensions.

scroll_text() None

Internal method for calculating how and when to scroll text when going beyond the input box. I am aware of how awful it is. Why? because O(n). What does that mean? the larger the text, the slower it gets! Very bad! Might not be that noticeable for small strings, but still… TODO: Make it better, fool.

set_background_colour(background_colour: tuple[int, int, int]) Self

Set the background colour of the input box, then return the input box itself.

set_border_colour(border_colour: tuple[int, int, int]) Self

Set the border colour of the input box, then return the input box itself.

set_cursor_colour(cursor_colour: tuple[int, int, int]) Self

Set the cursor colour of the input box, then return the input box itself.

set_height(height: int) Self

Set the height of the widget, then return the widget itself.

set_interact(state: bool) Self

Set whether the widget is interactable or not, independent to its visibility, then return the widget itself.

set_max_text_length(max_text_length: int) Self

Set the input box’s max text length, then return the input box itself.

set_placeholder_text(placeholder_text: str) Self

Set the placeholder label text of the input box, then return the input box itself.

set_placeholder_text_colour(placeholder_text_colour: tuple[int, int, int]) Self

Set the placeholder text colour, then return the input box itself.

set_read_only(state: bool) Self

Set the input box’s read-only state, then return the input box itself.

set_selected(state) Self

Set the selected state of the input box, then return the input box itself.

set_state(state: bool) Self

Set the widget’s visibility and interactivity state, then return the widget itself.

set_text(text: str) Self

Set the label text of the input box, then return the input box itself.

set_text_colour(text_colour: tuple[int, int, int]) Self

Set the text colour, then return the input box itself.

set_tooltip_text(tooltip_text: str) Self

Set the input box’s tooltip text, then return the input box itself.

set_transparency(transparency: float) Self

Set the widget’s transparency, then return the widget itself.

set_width(width: int) Self

Set the width of the widget, then return the widget itself.

set_x(x: int) Self

Set the x position of the widget, then return the widget itself.

set_y(y: int) Self

Set the y position of the widget, then return the widget itself.

update(window: Window) None

Update the widget and its components.

classmethod validate_dimensions(width: int, height: int) None

Test a widget’s dimensions.

gui.label

Module name: label

class game.gui.label.Label(text: str = '', x: int = 0, y: int = 0)

Bases: Widget

Class for creating a label.

DEFAULT_FONT = '/home/docs/checkouts/readthedocs.org/user_builds/tile-game/checkouts/latest/game/assets/font.ttf'
DEFAULT_FONT_SIZE_LARGE = 13
DEFAULT_FONT_SIZE_NORMAL = 11
DEFAULT_FONT_SIZE_SMALL = 8
MAX_HEIGHT = 0
MAX_WIDTH = 0
MIN_HEIGHT = 0
MIN_WIDTH = 0
can_interact() bool

Return whether the widget can be interacted with or not, independent to its visibility.

center(parent_x: int, parent_y: int, parent_width: int, parent_height: int) Self

Center the widget on both axes relative to the specified parent, then return the widget itself.

center_horizontally(parent_x: int, parent_width: int) Self

Center the widget horizontally relative to the specified parent, then return the widget itself.

center_vertically(parent_y: int, parent_height: int) Self

Center the widget vertically relative to the specified parent, then return the widget itself.

center_with_offset(parent_x: int, parent_y: int, parent_width: int, parent_height: int, x: int, y: int) Self

Center the widget with and offset it by x and y relative to the specified parent, then return the widget itself.

draw(window: Window | Surface) None

Draw the widget and its components.

events(e: pygame.event.Event) None

Handle the widget events.

get_colour() tuple[int, int, int]

Return the label’s text colour.

get_font_size() int

Return the font size of the label.

get_font_sizes() tuple[int, int, int]

Return the small, medium and large sizes of the label’s text.

get_height() int

Get the height of the widget.

get_shadow_colour() tuple[int, int, int]

Return the label’s text shadow colour.

get_shadow_x_offset() int

Return the x offset of the label’s shadow.

get_shadow_y_offset() int

Return the y offset of the label’s shadow.

get_state() bool

Return the widget’s visibility and interactivity state.

get_text() str

Return the label’s text.

get_total_height() int

Return the total height of the label.

get_transparency() float

Return the widget’s transparency.

get_width() int

Get the width of the widget.

get_x() int

Return the x position of the widget.

get_y() int

Return the y position of the widget.

has_antialiasing() bool

Returns True if the label has antialiasing enabled.

is_hovering_over() bool

Return whether the user’s mouse cursor is hovering over the widget or not.

offset(offset_x: int, offset_y: int) Self

Add an offset to the x and y positions of the widget, then return the widget itself.

offset_x(offset_x: int) Self

Add an offset to the x position of the widget, then return the widget itself.

offset_y(offset_y: int) Self

Add an offset to the y position of the widget, then return the widget itself.

resize(window: Window) None

Resize the widget based on the screen dimensions.

set_antialiasing(state: bool) Self

Set the antialiasing state of the label, then return the label itself.

set_auto_font_size(width: int, height: int, max_width: int, max_height: int) Self

Set the automatic font size of the label, then return the label itself.

set_colour(colour: tuple[int, int, int]) Self

Set the label’s text colour, then return the label itself.

set_font_size(font_size: int) Self

Set the font size of the label, then return the label itself.

set_font_sizes(font_sizes: tuple[int, int, int]) Self

Set the small, medium and large sizes of the label’s text, then return the label itself.

set_height(height: int) Self

Set the height of the widget, then return the widget itself.

set_interact(state: bool) Self

Set whether the widget is interactable or not, independent to its visibility, then return the widget itself.

set_shadow_colour(shadow_colour) Self

Set the label’s text shadow colour, then return the label itself.

set_shadow_x_offset(offset) Self

Set the x offset of the label’s shadow, then return the label itself.

set_shadow_y_offset(offset) Self

Set the y offset of the label’s shadow, then return the label itself.

set_state(state: bool) Self

Set the widget’s visibility and interactivity state, then return the widget itself.

set_text(text: str) Self

Set the label’s text, then return the label itself.

set_transparency(transparency: float) Self

Set the widget’s transparency, then return the widget itself.

set_width(width: int) Self

Set the width of the widget, then return the widget itself.

set_x(x: int) Self

Set the x position of the widget, then return the widget itself.

set_y(y: int) Self

Set the y position of the widget, then return the widget itself.

update(window: Window) None

Update the widget and its components.

classmethod validate_dimensions(width: int, height: int) None

Test a widget’s dimensions.

gui.nametag

Module name: nametag

class game.gui.nametag.NameTag(text: str = '', x: int = 0, y: int = 0)

Bases: Widget

Class for creating a nametag.

MAX_HEIGHT = 0
MAX_WIDTH = 0
MIN_HEIGHT = 0
MIN_WIDTH = 0
can_interact() bool

Return whether the widget can be interacted with or not, independent to its visibility.

center(parent_x: int, parent_y: int, parent_width: int, parent_height: int) Self

Center the widget on both axes relative to the specified parent, then return the widget itself.

center_horizontally(parent_x: int, parent_width: int) Self

Center the widget horizontally relative to the specified parent, then return the widget itself.

center_vertically(parent_y: int, parent_height: int) Self

Center the widget vertically relative to the specified parent, then return the widget itself.

center_with_offset(parent_x: int, parent_y: int, parent_width: int, parent_height: int, x: int, y: int) Self

Center the widget with and offset it by x and y relative to the specified parent, then return the widget itself.

draw(window: Window | Surface) None

Draw the widget and its components.

events(e: pygame.event.Event) None

Handle the widget events.

get_background_colour() tuple[int, int, int]

Return the background colour of the nametag.

get_height() int

Get the height of the widget.

get_state() bool

Return the widget’s visibility and interactivity state.

get_transparency() float

Return the widget’s transparency.

get_width() int

Get the width of the widget.

get_x() int

Return the x position of the widget.

get_y() int

Return the y position of the widget.

is_hovering_over() bool

Return whether the user’s mouse cursor is hovering over the widget or not.

offset(offset_x: int, offset_y: int) Self

Add an offset to the x and y positions of the widget, then return the widget itself.

offset_x(offset_x: int) Self

Add an offset to the x position of the widget, then return the widget itself.

offset_y(offset_y: int) Self

Add an offset to the y position of the widget, then return the widget itself.

resize(window: Window) None

Resize the widget based on the screen dimensions.

set_background_colour(background_colour: tuple[int, int, int]) Self

Set the background colour of the nametag, then return the nametag itself.

set_height(height: int) Self

Set the height of the widget, then return the widget itself.

set_interact(state: bool) Self

Set whether the widget is interactable or not, independent to its visibility, then return the widget itself.

set_state(state: bool) Self

Set the widget’s visibility and interactivity state, then return the widget itself.

set_transparency(transparency: float) Self

Set the widget’s transparency, then return the widget itself.

set_width(width: int) Self

Set the width of the widget, then return the widget itself.

set_x(x: int) Self

Set the x position of the widget, then return the widget itself.

set_y(y: int) Self

Set the y position of the widget, then return the widget itself.

update(window: Window) None

Update the widget and its components.

classmethod validate_dimensions(width: int, height: int) None

Test a widget’s dimensions.

gui.ordering_container

Module name: ordering_container

class game.gui.ordering_container.OrderingContainer

Bases: Widget

Class for creating an ordering container. This is used for containing widgets that require ordering, like for tabbing between widgets. This isn’t a visible GUI component.

MAX_HEIGHT = 0
MAX_WIDTH = 0
MIN_HEIGHT = 0
MIN_WIDTH = 0
can_interact() bool

Return whether the widget can be interacted with or not, independent to its visibility.

center(parent_x: int, parent_y: int, parent_width: int, parent_height: int) Self

Center the widget on both axes relative to the specified parent, then return the widget itself.

center_horizontally(parent_x: int, parent_width: int) Self

Center the widget horizontally relative to the specified parent, then return the widget itself.

center_vertically(parent_y: int, parent_height: int) Self

Center the widget vertically relative to the specified parent, then return the widget itself.

center_with_offset(parent_x: int, parent_y: int, parent_width: int, parent_height: int, x: int, y: int) Self

Center the widget with and offset it by x and y relative to the specified parent, then return the widget itself.

draw(window: Window | Surface) None

Draw the widget and its components.

events(e: pygame.event.Event) None

Handle the widget events.

get_height() int

Get the height of the widget.

get_state() bool

Return the widget’s visibility and interactivity state.

get_transparency() float

Return the widget’s transparency.

get_widgets() list[any]

Return the ordering container’s widgets array.

get_width() int

Get the width of the widget.

get_x() int

Return the x position of the widget.

get_y() int

Return the y position of the widget.

is_hovering_over() bool

Return whether the user’s mouse cursor is hovering over the widget or not.

offset(offset_x: int, offset_y: int) Self

Add an offset to the x and y positions of the widget, then return the widget itself.

offset_x(offset_x: int) Self

Add an offset to the x position of the widget, then return the widget itself.

offset_y(offset_y: int) Self

Add an offset to the y position of the widget, then return the widget itself.

resize(window: Window) None

Resize the widget based on the screen dimensions.

set_height(height: int) Self

Set the height of the widget, then return the widget itself.

set_interact(state: bool) Self

Set whether the widget is interactable or not, independent to its visibility, then return the widget itself.

set_state(state: bool) Self

Set the widget’s visibility and interactivity state, then return the widget itself.

set_transparency(transparency: float) Self

Set the widget’s transparency, then return the widget itself.

set_widgets(widgets: list[any]) Self

Set the ordering container’s widgets array, then return the ordering container itself

set_width(width: int) Self

Set the width of the widget, then return the widget itself.

set_x(x: int) Self

Set the x position of the widget, then return the widget itself.

set_y(y: int) Self

Set the y position of the widget, then return the widget itself.

update(window: Window) None

Update the widget and its components.

classmethod validate_dimensions(width: int, height: int) None

Test a widget’s dimensions.

gui.progress_bar

Module name: progress_bar

class game.gui.progress_bar.ProgressBar(title: str = '', x: int = 0, y: int = 0, width: int = 800, height: int = 30, value: int = 0, min_value: int = 0, max_value: int = 100)

Bases: Widget

Class for creating a progress bar

MAX_HEIGHT = 0
MAX_WIDTH = 0
MIN_HEIGHT = 0
MIN_WIDTH = 0
can_interact() bool

Return whether the widget can be interacted with or not, independent to its visibility.

center(parent_x: int, parent_y: int, parent_width: int, parent_height: int) Self

Center the widget on both axes relative to the specified parent, then return the widget itself.

center_horizontally(parent_x: int, parent_width: int) Self

Center the widget horizontally relative to the specified parent, then return the widget itself.

center_vertically(parent_y: int, parent_height: int) Self

Center the widget vertically relative to the specified parent, then return the widget itself.

center_with_offset(parent_x: int, parent_y: int, parent_width: int, parent_height: int, x: int, y: int) Self

Center the widget with and offset it by x and y relative to the specified parent, then return the widget itself.

draw(window: Window | Surface) None

Draw the widget and its components.

events(e: pygame.event.Event) None

Handle the widget events.

get_filled_end_colour() tuple[int, int, int]

Return the filled end colour of the progress bar.

get_filled_start_colour() tuple[int, int, int]

Return the filled start colour of the progress bar.

get_height() int

Get the height of the widget.

get_state() bool

Return the widget’s visibility and interactivity state.

get_title() str

Return the title text of the progress bar.

get_transparency() float

Return the widget’s transparency.

get_unfilled_colour() tuple[int, int, int]

Return the unfilled colour of the progress bar.

get_value() int

Return the value of the progress bar.

get_value_bounds() tuple[int, int]

Return the value bounds of the progress bar (min/max values).

get_width() int

Get the width of the widget.

get_x() int

Return the x position of the widget.

get_y() int

Return the y position of the widget.

is_hovering_over() bool

Return whether the user’s mouse cursor is hovering over the widget or not.

offset(offset_x: int, offset_y: int) Self

Add an offset to the x and y positions of the widget, then return the widget itself.

offset_x(offset_x: int) Self

Add an offset to the x position of the widget, then return the widget itself.

offset_y(offset_y: int) Self

Add an offset to the y position of the widget, then return the widget itself.

resize(window: Window) None

Resize the widget based on the screen dimensions.

set_filled_end_colour(filled_end_colour: tuple[int, int, int]) Self

Set the filled end colour of the progress bar, then return the progress bar itself.

set_filled_start_colour(filled_start_colour: tuple[int, int, int]) Self

Set the filled start colour of the progress bar, then return the progress bar itself.

set_height(height: int) Self

Set the height of the widget, then return the widget itself.

set_interact(state: bool) Self

Set whether the widget is interactable or not, independent to its visibility, then return the widget itself.

set_state(state: bool) Self

Set the widget’s visibility and interactivity state, then return the widget itself.

set_title(title: str) Self

Set the title text of the progress bar, then return the progress bar itself.

set_transparency(transparency: float) Self

Set the widget’s transparency, then return the widget itself.

set_unfilled_colour(unfilled_colour: tuple[int, int, int]) Self

Set the unfilled colour of the progress bar, then return the progress bar itself.

set_value(value: int) Self

Set the value of the progress bar, then return the progress bar itself.

set_value_bounds(min_value: int | None = None, max_value: int | None = None) Self

Set the value bounds of the progress bar (min/max values), then return the progress bar itself.

set_width(width: int) Self

Set the width of the widget, then return the widget itself.

set_x(x: int) Self

Set the x position of the widget, then return the widget itself.

set_y(y: int) Self

Set the y position of the widget, then return the widget itself.

update(window: Window) None

Update the widget and its components.

classmethod validate_dimensions(width: int, height: int) None

Test a widget’s dimensions.

gui.screen_manager

Module name: screen_manager

This module manages all the GUIs, their visibility and their behaviour.

class game.gui.screen_manager.Screens(game)

Bases: object

Class for creating a collection of screens.

events(e: pygame.event.Event) None

Handle the events of the different screens.

perform_translation() None

Translate all UIs to selected locale.

task_create_server() None

Screen task for creating a server.

task_join_server() None

Screen task for joining a server.

update() None

Update the screens.

update_ui() None

Update the screen UIs.

gui.screens

Screens package.

It holds all the different graphical user interfaces (or screens if you prefer something shorter but longer than the acronym ‘GUI’ (pronounced /ˈɡuː.i/ by the way)).

gui.screens.crash_screen

Module name: crash_screen

class game.gui.screens.crash_screen.CrashScreen(game: Game)

Bases: Screen

Class for creating the crash screen.

draw() None

Draw the screen and its components.

events(e: pygame.event.Event) None

Handle the screen events.

get_state() bool

Return the screen’s visibility and interactivity state.

initialise_surface(alpha: int = 136) pygame.Surface

Initialise the screen’s surface.

set_state(state: bool) None

Set the screen’s visibility and interactivity state, then return the screen itself

translate() None

Update the text of all text-related components to their translated equivalents.

update_ui() None

Update the screen and its components.

gui.screens.credits_screen

Module name: credits_screen

class game.gui.screens.credits_screen.CreditsScreen(game: Game)

Bases: Screen

Class for creating the credits screen.

draw() None

Draw the screen and its components.

events(e: pygame.event.Event) None

Handle the screen events.

get_state() bool

Return the screen’s visibility and interactivity state.

initialise_surface(alpha: int = 136) pygame.Surface

Initialise the screen’s surface.

set_state(state: bool) None

Set the screen’s visibility and interactivity state, then return the screen itself

translate() None

Update the text of all text-related components to their translated equivalents.

update_ui() None

Update the screen and its components.

gui.screens.fx_screen

Module name: fx_screen

class game.gui.screens.fx_screen.FxScreen(game: Game)

Bases: Screen

Class for creating an effect layer screen.

draw() None

Draw the screen and its components.

static draw_falling_snow_layer(screen: pygame.Surface)

Draw falling snow layer to screen.

events(e: pygame.event.Event) None

Handle the screen events.

get_state() bool

Return the screen’s visibility and interactivity state.

initialise_surface(alpha: int = 136) pygame.Surface

Initialise the screen’s surface.

set_state(state: bool) Self

Set the screen’s visibility and interactivity state, then return the screen itself

translate() None

Update the text of all text-related components to their translated equivalents.

update_ui() None

Update the screen and its components.

gui.screens.gameover_screen

Module name: gameover_screen

class game.gui.screens.gameover_screen.GameoverScreen(game: Game)

Bases: Screen

Class for creating the game-over screen.

draw() None

Draw the screen and its components.

events(e: pygame.event.Event) None

Handle the screen events.

get_state() bool

Return the screen’s visibility and interactivity state.

initialise_surface(alpha: int = 136) pygame.Surface

Initialise the screen’s surface.

set_state(state: bool) None

Set the screen’s visibility and interactivity state, then return the screen itself

translate() None

Update the text of all text-related components to their translated equivalents.

update_ui() None

Update the screen and its components.

gui.screens.loading_screen

Module name: loading_screen

class game.gui.screens.loading_screen.LoadingScreen(game: Game)

Bases: Screen

Class for creating the loading screen.

draw() None

Draw the screen and its components.

events(e: pygame.event.Event) None

Handle the screen events.

get_state() bool

Return the screen’s visibility and interactivity state.

initialise_surface(alpha: int = 136) pygame.Surface

Initialise the screen’s surface.

set_state(state: bool) None

Set the screen’s visibility and interactivity state, then return the screen itself

translate() None

Update the text of all text-related components to their translated equivalents.

update_ui() None

Update the screen and its components.

gui.screens.main_hud

Module name: main_hud

class game.gui.screens.main_hud.MainHud(game: Game)

Bases: Screen

Class for creating the main (player) HUD.

draw() None

Draw the screen and its components.

events(e: pygame.event.Event) None

Handle the screen events.

get_state() bool

Return the screen’s visibility and interactivity state.

initialise_surface(alpha: int = 136) pygame.Surface

Initialise the screen’s surface.

set_state(state: bool) None

Set the screen’s visibility and interactivity state, then return the screen itself

translate() None

Update the text of all text-related components to their translated equivalents.

update_ui() None

Update the screen and its components.

gui.screens.mainmenu_screen

Module name: mainmenu_screen

class game.gui.screens.mainmenu_screen.MainMenuScreen(game: Game)

Bases: Screen

Class for creating the main menu screen.

draw() None

Draw the screen and its components.

events(e: pygame.event.Event) None

Handle the screen events.

get_state() bool

Return the screen’s visibility and interactivity state.

initialise_surface(alpha: int = 136) pygame.Surface

Initialise the screen’s surface.

set_state(state: bool) None

Set the screen’s visibility and interactivity state, then return the screen itself

translate() None

Update the text of all text-related components to their translated equivalents.

update_ui() None

Update the screen and its components.

gui.screens.map_screen

Module name: map_screen

class game.gui.screens.map_screen.MapScreen(game: Game)

Bases: Screen

Class for creating the map screen.

draw() None

Draw the screen and its components.

events(e: pygame.event.Event) None

Handle the screen events.

get_state() bool

Return the screen’s visibility and interactivity state.

initialise_map() None

Initialise the screen’s map component.

initialise_surface(alpha: int = 136) pygame.Surface

Initialise the screen’s surface.

reset_map() None

Reset the map attributes.

set_state(state: bool) None

Set the screen’s visibility and interactivity state, then return the screen itself

translate() None

Update the text of all text-related components to their translated equivalents.

update_ui() None

Update the screen and its components.

gui.screens.options_screen

Module name: options_screen

class game.gui.screens.options_screen.OptionsScreen(game: Game)

Bases: Screen

Class for creating the options screen.

draw() None

Draw the screen and its components.

events(e: pygame.event.Event) None

Handle the screen events.

get_state() bool

Return the screen’s visibility and interactivity state.

initialise_surface(alpha: int = 136) pygame.Surface

Initialise the screen’s surface.

set_state(state: bool) None

Set the screen’s visibility and interactivity state, then return the screen itself

translate() None

Update the text of all text-related components to their translated equivalents.

update_ui() None

Update the screen and its components.

gui.screens.pause_screen

Module name: pause_screen

class game.gui.screens.pause_screen.PauseScreen(game: Game)

Bases: Screen

Class for creating the pause screen.

draw() None

Draw the screen and its components.

events(e: pygame.event.Event) None

Handle the screen events.

get_state() bool

Return the screen’s visibility and interactivity state.

initialise_surface(alpha: int = 136) pygame.Surface

Initialise the screen’s surface.

set_state(state: bool) None

Set the screen’s visibility and interactivity state, then return the screen itself

translate() None

Update the text of all text-related components to their translated equivalents.

update_ui() None

Update the screen and its components.

gui.screens.playerlist_screen

Module name: playerlist_screen

class game.gui.screens.playerlist_screen.PlayerListScreen(game: Game)

Bases: Screen

Class for creating the player list screen.

draw() None

Draw the screen and its components.

events(e: pygame.event.Event) None

Handle the screen events.

get_state() bool

Return the screen’s visibility and interactivity state.

initialise_surface(alpha: int = 136) pygame.Surface

Initialise the screen’s surface.

set_state(state: bool) None

Set the screen’s visibility and interactivity state, then return the screen itself

translate() None

Update the text of all text-related components to their translated equivalents.

update_ui() None

Update the screen and its components.

gui.screens.screen

Module name: screen

This module defines the base class for all graphical user interfaces.

class game.gui.screens.screen.Screen(game: Game)

Bases: object

Class for creating a screen.

draw() None

Draw the screen and its components.

events(e: pygame.event.Event) None

Handle the screen events.

get_state() bool

Return the screen’s visibility and interactivity state.

initialise_surface(alpha: int = 136) pygame.Surface

Initialise the screen’s surface.

set_state(state: bool) Self

Set the screen’s visibility and interactivity state, then return the screen itself

translate() None

Update the text of all text-related components to their translated equivalents.

update_ui() None

Update the screen and its components.

gui.screens.serverconnect_screen

Module name: serverconnect_screen

class game.gui.screens.serverconnect_screen.ServerConnectScreen(game: Game)

Bases: Screen

Class for creating the server connection screen.

draw() None

Draw the screen and its components.

events(e: pygame.event.Event) None

Handle the screen events.

get_state() bool

Return the screen’s visibility and interactivity state.

initialise_surface(alpha: int = 136) pygame.Surface

Initialise the screen’s surface.

reset_info_label() None

Reset the information label back to its default state, then update the screen UI.

set_state(state: bool) None

Set the screen’s visibility and interactivity state, then return the screen itself

translate() None

Update the text of all text-related components to their translated equivalents.

update_info_label(code: int) None

Update info label’s text and colour based on received connection code, then update the screen UI.

update_ui() None

Update the screen and its components.

gui.screens.servercreate_screen

Module name: servercreate_screen

class game.gui.screens.servercreate_screen.ServerCreateScreen(game: Game)

Bases: Screen

Class for creating the server create screen.

draw() None

Draw the screen and its components.

events(e: pygame.event.Event) None

Handle the screen events.

get_state() bool

Return the screen’s visibility and interactivity state.

initialise_surface(alpha: int = 136) pygame.Surface

Initialise the screen’s surface.

initialise_themes() None

Initialise the world theme select box.

set_state(state: bool) None

Set the screen’s visibility and interactivity state, then return the screen itself

translate() None

Update the text of all text-related components to their translated equivalents.

update_ui() None

Update the screen and its components.

gui.screens.serverjoin_screen

Module name: serverjoin_screen

class game.gui.screens.serverjoin_screen.ServerJoinScreen(game: Game)

Bases: Screen

Class for creating the server join screen.

draw() None

Draw the screen and its components.

events(e: pygame.event.Event) None

Handle the screen events.

get_state() bool

Return the screen’s visibility and interactivity state.

initialise_surface(alpha: int = 136) pygame.Surface

Initialise the screen’s surface.

set_state(state: bool) None

Set the screen’s visibility and interactivity state, then return the screen itself

translate() None

Update the text of all text-related components to their translated equivalents.

update_ui() None

Update the screen and its components.

gui.screens.servermenu_screen

Module name: servermenu_screen

class game.gui.screens.servermenu_screen.ServerMenuScreen(game: Game)

Bases: Screen

Class for creating the server menu screen.

draw() None

Draw the screen and its components.

events(e: pygame.event.Event) None

Handle the screen events.

get_state() bool

Return the screen’s visibility and interactivity state.

initialise_surface(alpha: int = 136) pygame.Surface

Initialise the screen’s surface.

set_state(state: bool) None

Set the screen’s visibility and interactivity state, then return the screen itself

translate() None

Update the text of all text-related components to their translated equivalents.

update_ui() None

Update the screen and its components.

gui.selectbox

Module name: select_list

class game.gui.selectbox.SelectBox(x: int = 0, y: int = 0, width: int = 800, height: int = 50, tooltip_text: str = '')

Bases: Widget

Class for creating a select box.

ARROW_X_OFFSET = 10
MAX_ARROW_WIDTH = 15
MAX_HEIGHT = 0
MAX_VALUE_HEIGHT = 50
MAX_VISIBLE_VALUES = 3
MAX_WIDTH = 0
MIN_ARROW_WIDTH = 4
MIN_HEIGHT = 0
MIN_VALUE_HEIGHT = 10
MIN_WIDTH = 0
can_interact() bool

Return whether the widget can be interacted with or not, independent to its visibility.

center(parent_x: int, parent_y: int, parent_width: int, parent_height: int) Self

Center the widget on both axes relative to the specified parent, then return the widget itself.

center_horizontally(parent_x: int, parent_width: int) Self

Center the widget horizontally relative to the specified parent, then return the widget itself.

center_vertically(parent_y: int, parent_height: int) Self

Center the widget vertically relative to the specified parent, then return the widget itself.

center_with_offset(parent_x: int, parent_y: int, parent_width: int, parent_height: int, x: int, y: int) Self

Center the widget with and offset it by x and y relative to the specified parent, then return the widget itself.

draw(window: Window | Surface) None

Draw the select box and its components.

draw_value_list(window: Window) None

Draw the select box’s value list and its components. This is used independently to the draw method, to handle the rendering priority independent to the actual select box rendering priority.

events(e: pygame.event.Event) None

Handle the select box events.

get_current_index() int

Return the select box’s current index.

get_height() int

Get the height of the widget.

get_selected() str

Return the select box’s current value by its current index.

get_state() bool

Return the widget’s visibility and interactivity state.

get_transparency() float

Return the widget’s transparency.

get_values() list[str]

Return the select box’s values.

get_width() int

Get the width of the widget.

get_x() int

Return the x position of the widget.

get_y() int

Return the y position of the widget.

has_selected_a_value() bool

Return whether the user has selected a value in the value list or not.

is_hovering_over() bool

Return whether the user’s mouse cursor is hovering over the widget or not.

is_hovering_over_display_box()

Return whether the user’s mouse cursor is hovering over the select box’s display box.

is_hovering_over_value(index: int)

Return whether the user’s mouse cursor is hovering over the provided select box value by index.

is_hovering_over_value_list()

Return whether the user’s mouse cursor is hovering over the select box’s value list.

is_open() bool

Return True if the select box is open (and values are visible).

offset(offset_x: int, offset_y: int) Self

Add an offset to the x and y positions of the widget, then return the widget itself.

offset_x(offset_x: int) Self

Add an offset to the x position of the widget, then return the widget itself.

offset_y(offset_y: int) Self

Add an offset to the y position of the widget, then return the widget itself.

resize(window: Window) None

Resize the widget based on the screen dimensions.

set_current_index(index: int) Self

Set the select box’s current index, then return the select box itself.

set_height(height: int) Self

Set the height of the widget, then return the widget itself.

set_interact(state: bool) Self

Set whether the widget is interactable or not, independent to its visibility, then return the widget itself.

set_open(state: bool) Self

Set the open state of the select box (visibility of the select box’s value list), then return the select box itself.

set_state(state: bool) Self

Set the widget’s visibility and interactivity state, then return the widget itself.

set_tooltip_text(tooltip_text: str) Self

Set the display box’s tooltip text, then return the select box itself.

set_transparency(transparency: float) Self

Set the widget’s transparency, then return the widget itself.

set_values(values: list[str]) Self

Set the select box’s values, then return the select box itself.

set_width(width: int) Self

Set the width of the widget, then return the widget itself.

set_x(x: int) Self

Set the x position of the widget, then return the widget itself.

set_y(y: int) Self

Set the y position of the widget, then return the widget itself.

update(window: Window) None

Update the widget and its components.

classmethod validate_dimensions(width: int, height: int) None

Test a widget’s dimensions.

gui.slot

Module name: slot

class game.gui.slot.Slot(x: int = 0, y: int = 0, size: int = 64)

Bases: Widget

Class for creating a slot.

MAX_HEIGHT = 0
MAX_WIDTH = 0
MIN_HEIGHT = 0
MIN_WIDTH = 0
can_interact() bool

Return whether the widget can be interacted with or not, independent to its visibility.

center(parent_x: int, parent_y: int, parent_width: int, parent_height: int) Self

Center the widget on both axes relative to the specified parent, then return the widget itself.

center_horizontally(parent_x: int, parent_width: int) Self

Center the widget horizontally relative to the specified parent, then return the widget itself.

center_vertically(parent_y: int, parent_height: int) Self

Center the widget vertically relative to the specified parent, then return the widget itself.

center_with_offset(parent_x: int, parent_y: int, parent_width: int, parent_height: int, x: int, y: int) Self

Center the widget with and offset it by x and y relative to the specified parent, then return the widget itself.

clear_item_asset() Self

Clear the item asset of the slot, then return the slot itself.

draw(window: pygame.Surface) None

Draw the widget and its components.

events(e: pygame.event.Event) None

Handle the widget events.

get_height() int

Get the height of the widget.

get_inner_colour() tuple[int, int, int]

Return the inner colour of the slot.

get_inner_width() int

Return the inner width of the slot.

get_item() Item

Return the item of the slot.

get_item_asset() pygame.Surface

Return the item asset of the slot.

get_outline_colour() tuple[int, int, int]

Return the outline colour of the slot.

get_outline_width() int

Return the outline width of the slot.

get_state() bool

Return the widget’s visibility and interactivity state.

get_transparency() float

Return the widget’s transparency.

get_width() int

Get the width of the widget.

get_x() int

Return the x position of the widget.

get_y() int

Return the y position of the widget.

is_hovering_over() bool

Return whether the user’s mouse cursor is hovering over the widget or not.

is_selected() bool

Return whether the slot is selected or not.

offset(offset_x: int, offset_y: int) Self

Add an offset to the x and y positions of the widget, then return the widget itself.

offset_x(offset_x: int) Self

Add an offset to the x position of the widget, then return the widget itself.

offset_y(offset_y: int) Self

Add an offset to the y position of the widget, then return the widget itself.

resize(window: Window) None

Resize the widget based on the screen dimensions.

select() Self

Select the slot, then return the slot itself.

set_height(height: int) Self

Set the height of the widget, then return the widget itself.

set_inner_colour(inner_colour: tuple[int, int, int]) Self

Set the inner colour of the slot, then return the slot itself.

set_inner_width(inner_width: int) Self

Set the inner width of the slot, then return the slot itself.

set_interact(state: bool) Self

Set whether the widget is interactable or not, independent to its visibility, then return the widget itself.

set_item(item: Item) Self

Set the item of the slot, then return the slot itself.

set_outline_colour(outline_colour: tuple[int, int, int]) Self

Set the outline colour of the slot, then return the slot itself.

set_outline_width(outline_width: int) Self

Return the outline width of the slot.

set_state(state: bool) Self

Set the widget’s visibility and interactivity state, then return the widget itself.

set_transparency(transparency: float) Self

Set the widget’s transparency, then return the widget itself.

set_width(width: int) Self

Set the width of the widget, then return the widget itself.

set_x(x: int) Self

Set the x position of the widget, then return the widget itself.

set_y(y: int) Self

Set the y position of the widget, then return the widget itself.

unselect() Self

Unselect the slot, then return the slot itself.

update(window: Window) None

Update the widget and its components.

classmethod validate_dimensions(width: int, height: int) None

Test a widget’s dimensions.

gui.tooltip

Module name: tooltip

class game.gui.tooltip.Tooltip(x: int = 0, y: int = 0, text: str = '')

Bases: Widget

Class for creating a tooltip.

MAX_HEIGHT = 0
MAX_WIDTH = 0
MIN_HEIGHT = 0
MIN_WIDTH = 0
can_interact() bool

Return whether the widget can be interacted with or not, independent to its visibility.

center(parent_x: int, parent_y: int, parent_width: int, parent_height: int) Self

Center the widget on both axes relative to the specified parent, then return the widget itself.

center_horizontally(parent_x: int, parent_width: int) Self

Center the widget horizontally relative to the specified parent, then return the widget itself.

center_vertically(parent_y: int, parent_height: int) Self

Center the widget vertically relative to the specified parent, then return the widget itself.

center_with_offset(parent_x: int, parent_y: int, parent_width: int, parent_height: int, x: int, y: int) Self

Center the widget with and offset it by x and y relative to the specified parent, then return the widget itself.

draw(window: Window | Surface) None

Draw the widget and its components.

events(e: pygame.event.Event) None

Handle the widget events.

get_height() int

Get the height of the widget.

get_state() bool

Return the widget’s visibility and interactivity state.

get_text() str

Return the tooltip text.

get_transparency() float

Return the widget’s transparency.

get_width() int

Get the width of the widget.

get_x() int

Return the x position of the widget.

get_y() int

Return the y position of the widget.

initialise_surface() pygame.Surface

Initialise the tooltip’s surface.

is_hovering_over() bool

Return whether the user’s mouse cursor is hovering over the widget or not.

offset(offset_x: int, offset_y: int) Self

Add an offset to the x and y positions of the widget, then return the widget itself.

offset_x(offset_x: int) Self

Add an offset to the x position of the widget, then return the widget itself.

offset_y(offset_y: int) Self

Add an offset to the y position of the widget, then return the widget itself.

resize(window: Window) None

Resize the widget based on the screen dimensions.

set_height(height: int) Self

Set the height of the widget, then return the widget itself.

set_interact(state: bool) Self

Set whether the widget is interactable or not, independent to its visibility, then return the widget itself.

set_state(state: bool) Self

Set the widget’s visibility and interactivity state, then return the widget itself.

set_text(text: str) Self

Set the tooltip text, then return the tooltip itself.

set_transparency(transparency: float) Self

Set the widget’s transparency, then return the widget itself.

set_width(width: int) Self

Set the width of the widget, then return the widget itself.

set_x(x: int) Self

Set the x position of the widget, then return the widget itself.

set_y(y: int) Self

Set the y position of the widget, then return the widget itself.

update(window: Window) None

Update the widget and its components.

classmethod validate_dimensions(width: int, height: int) None

Test a widget’s dimensions.

gui.widget

Module name: widget

This module defines the base class for all GUI widgets.

class game.gui.widget.Widget(x: int, y: int, width: int = 0, height: int = 0)

Bases: object

Class for creating a widget.

MAX_HEIGHT = 0
MAX_WIDTH = 0
MIN_HEIGHT = 0
MIN_WIDTH = 0
can_interact() bool

Return whether the widget can be interacted with or not, independent to its visibility.

center(parent_x: int, parent_y: int, parent_width: int, parent_height: int) Self

Center the widget on both axes relative to the specified parent, then return the widget itself.

center_horizontally(parent_x: int, parent_width: int) Self

Center the widget horizontally relative to the specified parent, then return the widget itself.

center_vertically(parent_y: int, parent_height: int) Self

Center the widget vertically relative to the specified parent, then return the widget itself.

center_with_offset(parent_x: int, parent_y: int, parent_width: int, parent_height: int, x: int, y: int) Self

Center the widget with and offset it by x and y relative to the specified parent, then return the widget itself.

draw(window: Window | Surface) None

Draw the widget and its components.

events(e: pygame.event.Event) None

Handle the widget events.

get_height() int

Get the height of the widget.

get_state() bool

Return the widget’s visibility and interactivity state.

get_transparency() float

Return the widget’s transparency.

get_width() int

Get the width of the widget.

get_x() int

Return the x position of the widget.

get_y() int

Return the y position of the widget.

is_hovering_over() bool

Return whether the user’s mouse cursor is hovering over the widget or not.

offset(offset_x: int, offset_y: int) Self

Add an offset to the x and y positions of the widget, then return the widget itself.

offset_x(offset_x: int) Self

Add an offset to the x position of the widget, then return the widget itself.

offset_y(offset_y: int) Self

Add an offset to the y position of the widget, then return the widget itself.

resize(window: Window) None

Resize the widget based on the screen dimensions.

set_height(height: int) Self

Set the height of the widget, then return the widget itself.

set_interact(state: bool) Self

Set whether the widget is interactable or not, independent to its visibility, then return the widget itself.

set_state(state: bool) Self

Set the widget’s visibility and interactivity state, then return the widget itself.

set_transparency(transparency: float) Self

Set the widget’s transparency, then return the widget itself.

set_width(width: int) Self

Set the width of the widget, then return the widget itself.

set_x(x: int) Self

Set the x position of the widget, then return the widget itself.

set_y(y: int) Self

Set the y position of the widget, then return the widget itself.

update(window: Window) None

Update the widget and its components.

classmethod validate_dimensions(width: int, height: int) None

Test a widget’s dimensions.