pymasep.interface ================= .. py:module:: pymasep.interface Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/pymasep/interface/cut_scene_interface_state/index /autoapi/pymasep/interface/environment_interface/index /autoapi/pymasep/interface/interface/index /autoapi/pymasep/interface/interface_controller/index /autoapi/pymasep/interface/interface_state/index /autoapi/pymasep/interface/ui_board/index /autoapi/pymasep/interface/ui_choice/index /autoapi/pymasep/interface/ui_dialog_box/index /autoapi/pymasep/interface/ui_dice_selection/index /autoapi/pymasep/interface/ui_init_object_window/index /autoapi/pymasep/interface/ui_input/index /autoapi/pymasep/interface/ui_merchant/index /autoapi/pymasep/interface/ui_simple_input/index /autoapi/pymasep/interface/ui_talk/index /autoapi/pymasep/interface/user_event/index Attributes ---------- .. autoapisummary:: pymasep.interface.SQUARE_SELECTED_EVENT pymasep.interface.SQUARE_VALIDATION_EVENT pymasep.interface.INIT_WINDOW_VALIDATION_EVENT Classes ------- .. autoapisummary:: pymasep.interface.Interface pymasep.interface.EnvironmentInterface pymasep.interface.InterfaceController pymasep.interface.InterfaceState pymasep.interface.UIBoard pymasep.interface.UIBoardSquare pymasep.interface.UIInitObjectWindow pymasep.interface.UIInput pymasep.interface.UIDiceSelection pymasep.interface.UIMerchant pymasep.interface.UIDialogBox pymasep.interface.UITalk Package Contents ---------------- .. py:class:: Interface(app, received_q_id, cfg, game_class_=None, interface_role=None, remote_engine_host = None, remote_engine_port = None, search_remote = False) Bases: :py:obj:`pymasep.application.sub_app.SubApp` Sub application that displays an environment and interact with user :param app: main application :param received_q_id: id of the queue used by the sub app to receive messages. :param cfg: Configuration of the interface. :param game_class_: Class of the game. :param interface_role: Role of the interface. See @ConnectedSubAppInfo. :param remote_engine_host: Host of the remote engine. May be None if interface is in the same process of engine. :param remote_engine_port: Port of the remote engine. May be None if interface is in the same process of engine. :param search_remote: True if the interface has to search the server on LAN. Default False :raise ConnectionError: If the interface does not find a server on the LAN. .. py:attribute:: screen :value: None screen to display on .. py:attribute:: virtual_screen :value: None virtual screen to render on .. py:attribute:: virtual_screen_size :value: (100, 100) size of the virtual screen to render on .. py:attribute:: font :value: None font of the system .. py:attribute:: fontSize :value: 14 size of the system font .. py:attribute:: end :value: False interface loop end .. py:attribute:: root_path root path of the application .. py:attribute:: ui_manager :value: None pygame_gui manager instance .. py:attribute:: ui_theme_file :value: None pygame_gui theme file .. py:attribute:: resources displaying resource .. py:attribute:: skip_observation may some observations skipped? .. py:attribute:: system_color :value: (255, 255, 0) system color for displaying information .. py:attribute:: interface_role role of the interface. see @ConnectedSubAppInfo .. py:attribute:: environment environment interface .. py:attribute:: game .. py:attribute:: controller_interface_class_ :value: None class of the controller used by the interface .. py:attribute:: controller :value: None controller used by the interface .. py:attribute:: last_step_choose_action :value: None last step the interface have chosen action .. py:attribute:: console :value: None console UI .. py:attribute:: interface_dbg_info_index :value: 0 DEBUG information .. py:attribute:: debug_info_labels :value: [] DEBUG labels .. py:attribute:: fps :value: [] DEBUG FPS information .. py:attribute:: engine_id :value: None connected engine id .. py:attribute:: remote_engine_host host of the engine .. py:attribute:: remote_engine_port port of the engine .. py:method:: load_resources() Load the graphical resources .. py:method:: init_graphics() Init the graphical elements .. py:method:: add_debug_label() Adding a new graphical debug labels. A text can be set later to add debug info, displayed on the top of all. :return: The index of the new added label .. py:method:: init_game() Initialize game : Connect to engine, define the game and register self as a new interface .. py:method:: receive_observation() Wait for an OBSERVATION message (or END_GAME) from the engine and update the interface environment .. py:method:: handle_event() Handle interface events .. py:method:: choose_action() Let the agent choose action if conditions are respected: - The interface is a ROLE_ACTOR - The interface has received a new observation since the agent's last action. .. py:method:: send_action() Send the action chosen by the interface. Only if the interface is a ROLE_ACTOR .. py:method:: update() update the current app state .. py:method:: display_text(text, position) quick display of a text with system font. :param text: text to display :param position: position of the text .. py:method:: render(time_delta) Render the environment current state and other information on screen .. py:method:: run() Main interface loop .. py:class:: EnvironmentInterface(id_env = None, cfg = None) Bases: :py:obj:`pymasep.common.environment.Environment` Represents the environment of the game (Interface part). This object keeps all dynamic value of the game. This environment chooses the action of the agent controlled by the interface. :param id_env: the id of the environment. If None, a new uuid will be set :parm cfg: the configuration of the environment .. py:attribute:: controlled_agent :value: None the agent controlled by the interface .. py:method:: choose_action() tell the agent controlled by interface to choose their action .. py:method:: update_current_next(observation_xml, additional_info) update the current state of the interface from the observation :param observation_xml: observation as XML :param additional_info: additional information .. py:class:: InterfaceController(environment) Bases: :py:obj:`pymasep.common.Controller` Abstract controller to control an agent in the environment :param environment: environment for the controller .. py:method:: select_action(event) Selection action according to the interface event :param event: The event (List here all events handled by) :return: True if the event has been processed .. py:class:: InterfaceState(sub_application, container_dim=(100, 100)) Bases: :py:obj:`pymasep.application.sub_app_state.SubAppState` This class implements the concept (pretty much) of Game State for the interface :param sub_application: the sub application where the state is defined :param container_dim: pygame_ui general container dimension (in pixel) .. py:attribute:: ui_container :value: None pygame_gui container that include all pygame_gui elements for the state .. py:attribute:: container_dim dimension of the pygame_gui container .. py:method:: init() Initialisation of the state .. py:method:: clean() The state is destroyed. Clean all elements of the state (including ui_container) .. py:method:: pause() Pause the state. Change the ui_container display .. py:method:: handle_event(event) :abstractmethod: Handle events in the state :param event: The event to handle .. py:method:: update() The update phase of the state. For interface, it corresponds to choose action, send action and receive observation. .. py:method:: render(time_delta) The render part : how to display the state .. py:method:: on_receive_observation() Callback when the interface receives an observation .. py:class:: UIBoard(relative_rect, manager, container, sub_application, image_surface, game_data, game_class_, origin_coord_map, square_size, player_name) Bases: :py:obj:`pygame_gui.core.UIContainer` Board with square where token can be put. For information, layer of elements: background : 90 agents tokens: 100 selected square: 150 :param relative_rect: position and dimensions of the board (pixels) :param manager: Manager (from pygame_gui) :param container: Container of the board (form pygame_gui) :param sub_application: sub application instance (the interface) :param image_surface: the image surface to display the board :param game_data: the data map (see @GridTools) :param game_class_: the class of the game :param origin_coord_map: pixel coordinate of the origin of the (0, 0) map position :param square_size: size of a square of the boad :param player_name: name of the player handle by the board .. py:attribute:: RUN_MODE :value: 'Run' Mode of the board : Rune .. py:attribute:: SELECT_SQUARE_MODE :value: 'SelectSquare' Mode of the board : Select a square .. py:attribute:: SELECT_PIECE_MODE :value: 'SelectPiece' Mode of the board : Select a piece on the board .. py:attribute:: background_image bacground image of the board .. py:attribute:: game_data data of the board .. py:attribute:: game_class_ .. py:attribute:: sub_application interface pointer .. py:attribute:: origin_coord_map pixel origin of the (0, 0) map position .. py:attribute:: square_size square size of the element in pixel .. py:attribute:: player_name name of the player handle by the board .. py:attribute:: agents_tokens agent UITokens .. py:attribute:: objects_tokens object UITokens .. py:attribute:: spotlight_squares squares that are spotlight .. py:attribute:: hovered_board_pos :value: None position of the board that is hovered .. py:attribute:: modes possible mode of the board .. py:attribute:: current_mode :value: None current mode of the board .. py:attribute:: board_debug_info_idx idx of the board debug info .. py:attribute:: last_step_updated :value: None the last step when the board has been updated .. py:method:: add_spotlight_square_state(board_pos, state) Set a spotlight square at a desired state :param board_pos: Position on the board :param state: state to set see @UIBoardElement .. py:method:: remove_spotlight_square_state(board_pos, state) Remove a spotlighted square which is at a desired state :param board_pos: Position on the board :param state: state which will be removed .. py:method:: map_pos_to_surface_pos(map_pos) Convert a map position to the surface position (pixel) :param map_pos: Position on the map (tuple) :return: surface position (tuple of pixel) .. py:method:: surface_pos_to_map_pos(surface_pos) convert the surface position to a map position :param surface_pos: the surface position (pixel) :return: the map position (tuple) .. py:method:: get_spotlight_squares_from_state(state) get all the squares on the baard that are on a certain state :param state: state to find :return: List of squares .. py:method:: update_with_observation(time_delta) Part of the update directly depending on the observation and that must be called only once per observation :param time_delta: Time passed since the last call .. py:method:: update(time_delta) Update the element of the board according to the observation :param time_delta: Time passed since the last call .. py:method:: process_event(event) Process an event on the board. :param event: The event to process :return: True the event has been processed .. py:method:: set_mode(mode) Set the mode of the board. :param mode: Mode of the board. .. py:class:: UIBoardSquare(manager, board, square_size, board_pos) Bases: :py:obj:`UIBoardElement` Square of the board :param manager: Manager (from pygame_gui) :param board: Board where this element is put :param board_pos: Position where this element put (board coordinates) :param square_size: square size (in pixel) .. py:attribute:: surface .. py:data:: SQUARE_SELECTED_EVENT Board event : A square has been selected .. py:data:: SQUARE_VALIDATION_EVENT Board event : A list of squares has been validate .. py:data:: INIT_WINDOW_VALIDATION_EVENT Init windows event : all inputs have been validated .. py:class:: UIInitObjectWindow(rect, ui_manager, sub_application, object_to_init_name) Bases: :py:obj:`pygame_gui.elements.UIWindow` Windows used by the user to initialize one object or agent (Characteristics in state "init") :param rect: Position and size of the window :param ui_manager: Manager (from pygame_gui) :param sub_application: the sub application (interface) that will handle the window :param object_to_init_name: name of the Object or Agent to init .. py:method:: _get_initializer_for_charac(charac) Get the initializer from the charac, or from it's ObjectState or from its Object. :param charac: Characteristic :return: the initializer for the charac .. py:method:: _get_object_to_init() .. py:attribute:: sub_application interface application .. py:attribute:: object_to_init_name name of the agent to init .. py:attribute:: entries ui entries to initialize the characteristics .. py:attribute:: font_info font information to calcutate sizes .. py:attribute:: margin margin of the window .. py:attribute:: active_player_label name of the player to initialize the characteristics .. py:attribute:: center_x .. py:attribute:: pos_y .. py:attribute:: object_to_init .. py:attribute:: charac_to_init .. py:attribute:: containers_to_init .. py:attribute:: button_rect .. py:attribute:: button_validation button to validate the initialization .. py:method:: process_event(event) Process the events of the windows. UI_BUTTON_PRESSED is handling on this method. :param event: Event to process :return: True if the event has been processed .. py:method:: update(time_delta) Update the element of the window according to the value of the shared Characteristics. :param time_delta: Time passed since the last call .. py:class:: UIInput(relative_rect, manager, container, label_text, waited_type, error_resource) Bases: :py:obj:`pygame_gui.core.UIContainer` General and abstract input with label and a value to write or select :param relative_rect: position and size of the input :param manager: Manager (from pygame_gui) :param container: Container of the UIInput (form pygame_gui) :param label_text: Text of the label :param waited_type: Expected type of the value :param error_resource: Image displayed when an error occurs .. py:attribute:: font_info .. py:attribute:: waited_type expected type of the input value .. py:attribute:: validated :value: True is the input valid .. py:attribute:: error_pos position and size of the error icon .. py:attribute:: label_pos position of the label .. py:attribute:: _ .. py:attribute:: error_image error image displayed when an error occurs .. py:attribute:: error ui image for error .. py:method:: set_text(text) :abstractmethod: Set the text of the input. To implement on subclasses. :param text: Text of the input .. py:method:: get_text() :abstractmethod: Set the text of the input. To implement on subclasses. :return: Text of the input .. py:method:: update(time_delta) Update on validating value input :param time_delta: Time passed since the last call .. py:method:: validate() Validate if the value of the UIInput respects some constraints :return: True if the value is valid .. py:class:: UIDiceSelection(relative_rect, manager, container, label_text, dices, error_resource) Bases: :py:obj:`pymasep.interface.ui_simple_input.UISimpleInput` UI Input that used dices results for value :param relative_rect: Position and size of the choice :param manager: Manager (from pygame_gui) :param container: Container of the UIDiceSelection (form pygame_gui) :param label_text: Text of the label :param error_resource: Image displayed when an error occurs .. py:attribute:: dices dices to launch. See dices.py .. py:attribute:: dice_pos position of the dice button .. py:attribute:: dice_button button to launch the dices .. py:method:: set_text(text) set the result of the dices as string :param text: result of the dice .. py:method:: get_text() return the result of the dices as string :return: result of the dices .. py:method:: process_event(event) Process event to launch dices if the user presses the button. :param event: Event that could be a UI_BUTTON_PRESSED :return: True if the event has been processed .. py:method:: validate() Validate if the value of the UIInput respects some constraints. In this case, the value of the dice must be between min and max value of the dice expression. :return: True if the value is valid .. py:class:: UIMerchant(relative_rect, manager, container, item_list, sub_application, object_to_init_name) Bases: :py:obj:`pygame_gui.elements.UIPanel` Interface for selecting objects to buy or to take from a container :param relative_rect: Position and size of the window :param manager: Manager (from pygame_gui) :param container: Container of the UIMerchant (form pygame_gui) :param sub_application: the sub application (interface) that will handle the panel :param object_to_init_name: name of the Object or Agent to init .. py:attribute:: sub_application interface application .. py:attribute:: object_to_init_name name of the agent to initialize container .. py:attribute:: selected_item_to_add :value: [] items to add to the container .. py:attribute:: selected_item_to_remove :value: [] items to remove from the container .. py:attribute:: item_list list of possible items .. py:attribute:: label_pos cost label position .. py:attribute:: costs cost UI label .. py:attribute:: list_objects_rect list of possible items rectangle .. py:attribute:: list_objects UI element of possible items .. py:attribute:: list_objects_chosen_rect chosen objects rectangle .. py:attribute:: list_objects_chosen UI element of chosen items .. py:attribute:: add_button UI button to add items .. py:attribute:: del_button UI button to remove items .. py:method:: process_event(event) process event to launch dices if user press the button. :param event: event that could be a UI_BUTTON_PRESSED :return: True if the event has been processed .. py:method:: update(time_delta) Update the UI element :param time_delta: time delta since last call .. py:class:: UIDialogBox(rect, ui_manager, choice) Bases: :py:obj:`pygame_gui.elements.UIWindow` Dialogue box to choose what to say :param rect: Rect of the dialog box. :param ui_manager: UIManagerInterface :param choice: List of tuples containing the link target (id the of dialog) and the displayed text .. py:attribute:: choice possible choices of talk .. py:attribute:: tb_choice :value: [] ui text box elements .. py:attribute:: next_y_pos :value: 10 .. py:method:: process_event(event) Process the event UI_TEXT_BOX_LINK_CLICKED and post an TALK_EVENT :param event: The event to process. .. py:class:: UITalk(relative_rect, manager, container, html_text, speaker_name = None) Bases: :py:obj:`pygame_gui.elements.UIAutoResizingContainer` Dialog Box to display talks :param relative_rect: position and dimensions of the dialog box (pixels) :param manager: Manager (from pygame_gui) :param container: Container of the board (form pygame_gui) :param html_text: HTML text of the dialog box. :param speaker_name: Name of the speaker. If None, this part of the component is not displayed. .. py:attribute:: bubble_width :value: 20 size of the bubble area .. py:attribute:: speaker_label_height :value: 0 height of the speaker label .. py:attribute:: html_text text to display on the dialog box .. py:attribute:: speaker_name_label :value: None speaker's name ' .. py:attribute:: talk_label ui label for displaying the text .. py:attribute:: bubble_talk image of the bubble .. py:attribute:: _img