def __init_file_menu(self): result = [] r = self.btn_file.get_rect() # TODO investigate why r.left offset is different for each button close = CloseProjectButton() close.set_custom_size(DevelopmentScene.BTN_SIZE) close.set_topleft( (int(r.left + DisplaySettings.get_size_by_key()[0] * .001), r.bottom)) close.color = Themes.DEFAULT_THEME.get("menu_background") save = SaveButton() save.set_custom_size(DevelopmentScene.BTN_SIZE) save.set_topleft( (int(r.left + DisplaySettings.get_size_by_key()[0] * .006), close.get_rect().bottom)) save.color = Themes.DEFAULT_THEME.get("menu_background") sae = SaveExitButton() sae.set_custom_size(DevelopmentScene.BTN_SIZE) sae.set_topleft( (int(r.left + DisplaySettings.get_size_by_key()[0] * .002), save.get_rect().bottom)) sae.color = Themes.DEFAULT_THEME.get("menu_background") ex = ExitButton() ex.set_custom_size(DevelopmentScene.BTN_SIZE) ex.set_topleft( (int(r.left + DisplaySettings.get_size_by_key()[0] * .008), sae.get_rect().bottom)) ex.color = Themes.DEFAULT_THEME.get("menu_background") result.extend([close, save, sae, ex]) return result
def __init_run_menu(self): result = list() r = self.btn_run.get_rect() gen = GenerateButton() gen.set_custom_size(DevelopmentScene.BTN_SIZE) gen.set_topleft( (int(r.left + DisplaySettings.get_size_by_key()[0] * .004), r.bottom)) gen.color = Themes.DEFAULT_THEME.get("menu_background") gen_run = GenerateRunButton() gen_run.set_custom_size(DevelopmentScene.BTN_SIZE) gen_run.set_topleft( (int(r.left + DisplaySettings.get_size_by_key()[0] * .002), gen.get_rect().bottom)) gen_run.color = Themes.DEFAULT_THEME.get("menu_background") run = RunButton() run.set_custom_size(DevelopmentScene.BTN_SIZE) run.set_topleft( (int(r.left + DisplaySettings.get_size_by_key()[0] * .009), gen_run.get_rect().bottom)) run.color = Themes.DEFAULT_THEME.get("menu_background") result.extend([gen, gen_run, run]) return result
def update_form(self, coords=None, size=None): if coords is None: self.coords = (int(DisplaySettings.get_size_by_key()[0] * .95 - self.size[0]), int(DisplaySettings.get_size_by_key()[1] * .2)) else: self.coords = coords if size is None: self.size = ( int(DisplaySettings.get_size_by_key()[0] * 0.45), int(DisplaySettings.get_size_by_key()[1] * .75)) else: self.size = size
def set_coordinates(self, pos): x = int(gui_utils.BUTTON_MARGIN * DisplaySettings.get_size_by_key()[0] + self.__width * .5) start = int(DisplaySettings.get_size_by_key()[1] - (DisplaySettings.get_size_by_key()[1] * 0.05 + self.__height * .5)) if pos > 0: y = int(start - (self.__height + int(gui_utils.BUTTON_MARGIN * DisplaySettings.get_size_by_key()[1])) * pos) else: y = start return x, y
def draw_form(self): super().draw_form() if self.visible: font = pg.font.Font(Themes.DEFAULT_THEME.get("banner_font_style"), int(self.size[1] * .07)) txt = font.render(StringUtils.get_string("ID_DISPLAY"), True, Themes.DEFAULT_THEME.get("font")) rect_txt = txt.get_rect() rect_txt.topleft = (int(self.coords[0] * 1.05), int(self.coords[1] * 1.05)) self.display.blit(txt, rect_txt) self.size_select = pg.Rect( (0, int(rect_txt.bottom * 1.2)), (int(self.size[0] * .85), int(self.size[1] * .12))) self.size_select.centerx = self.get_rect().centerx img = Images.get_icon(Images.DROP_DOWN) img[1].midright = (int(self.size_select.right - DisplaySettings.get_size_by_key()[0] * .01), int(self.size_select.center[1])) self.btn_drop_down = img[1] pg.draw.rect(self.display, Themes.DEFAULT_THEME.get("text_area_background"), self.size_select, 0) self.display.blit(img[0], img[1]) font = pg.font.Font(Themes.DEFAULT_THEME.get("text_font_style"), int(self.size_select.height * 0.6)) txt = font.render(self.__size, True, Themes.DEFAULT_THEME.get("text_area_text")) rect_txt = txt.get_rect() rect_txt.center = self.size_select.center self.display.blit(txt, rect_txt) self.draw_drop_down()
def set_custom_size(self, size): self.__height = int(DisplaySettings.get_size_by_key()[1] * size[1]) font = pg.font.Font(Themes.DEFAULT_THEME.get("button_font_style"), int(self.__height * .5)) self.__text = font.render(self.__text_str, True, Themes.DEFAULT_THEME.get("font")) self.__width = int(font.size(self.__text_str)[0] * size[0])
def __init__(self, display): SceneBuilder.__init__(self, display) self.__logger = logger_utils.get_logger(__name__) self.btn_select = SelectButton(0) self.btn_select.color = Themes.DEFAULT_THEME.get("front_screen") self.btn_delete = DeleteButton(0) self.btn_delete.color = Themes.DEFAULT_THEME.get("front_screen") self.btn_back = BackButton(0) self.btn_back.color = Themes.DEFAULT_THEME.get("front_screen") self.file_container = pg.Rect( (int(DisplaySettings.get_size_by_key()[0] * .01), int(DisplaySettings.get_size_by_key()[1] * 0.22)), (int(DisplaySettings.get_size_by_key()[0] * .98), int(DisplaySettings.get_size_by_key()[1] * .66))) self.files = ProjectManager.get_projects() self.__logger.debug(self.files)
def draw_scene(self): # PREPARE DATA font = pg.font.Font(Themes.DEFAULT_THEME.get("banner_font_style"), int(DisplaySettings.get_size_by_key()[1] * .09)) txt = font.render(StringUtils.get_string("ID_CONFIGURATION"), True, Themes.DEFAULT_THEME.get("font")) rect_txt = txt.get_rect() rect_txt.topleft = (int(DisplaySettings.get_size_by_key()[0] * .02), int(DisplaySettings.get_size_by_key()[1] * .05)) # DISPLAY self.display.fill(Themes.DEFAULT_THEME.get("front_screen")) self.display.blit(txt, rect_txt) self.draw_buttons() self.check_button_hover() self.draw_forms() super().draw_scene()
def get_text(self): font = pg.font.Font(Themes.DEFAULT_THEME.get("text_font_style"), int(DisplaySettings.get_size_by_key()[1] * .05)) txt = font.render("{} -- {}".format(self.__state, self.__message), True, Themes.DEFAULT_THEME.get("text_area_text")) rect_txt = txt.get_rect() rect_txt.center = self.__coords return txt, rect_txt
def draw_scene(self): # PREPARE DATA FOR DISPLAY font = pg.font.Font(Themes.DEFAULT_THEME.get("banner_font_style"), int(DisplaySettings.get_size_by_key()[1] * 0.09)) header = font.render(StringUtils.get_string("ID_SAVED_PROJECTS"), True, Themes.DEFAULT_THEME.get("font")) header_rect = header.get_rect() header_rect.topleft = (int(DisplaySettings.get_size_by_key()[0] * .02), int(DisplaySettings.get_size_by_key()[1] * .05)) # PUSH TO DISPLAY self.display.fill(Themes.DEFAULT_THEME.get("front_screen")) self.display.blit(header, header_rect) self.draw_container(header_rect) self.draw_buttons() self.check_button_hover() self.draw_selected_file_boarder() super().draw_scene()
def update_button(self, text, color): self.__text_str = text font = pg.font.Font(Themes.DEFAULT_THEME.get("button_font_style"), int(DisplaySettings.get_size_by_key()[1] * .045)) self.__height = int(font.size(self.__text_str)[1] * 1.1) self.__width = int(font.size(self.__text_str)[0] * 1.1) self.__text = font.render(self.__text_str, True, Themes.DEFAULT_THEME.get("font"))
def __init__(self, display, coords=None, size=None): ABC.__init__(self) self.display = display self.visible = False if size is None: self.size = ( int(DisplaySettings.get_size_by_key()[0] * 0.45), int(DisplaySettings.get_size_by_key()[1] * .75)) else: self.size = size if coords is None: self.coords = (int(DisplaySettings.get_size_by_key()[0] * .95 - self.size[0]), int(DisplaySettings.get_size_by_key()[1] * .2)) else: self.coords = coords self.btn_apply = ApplyButton(0) self.btn_apply.color = Themes.DEFAULT_THEME.get("panel_background") self.btn_apply.set_custom_coordinates( (int((self.coords[0] + self.size[0]) - self.btn_apply.get_rect().width * .53), int((self.coords[1] + self.size[1]) - self.btn_apply.get_rect().height * .6)))
def extract_rect(cls, rect): size = DisplaySettings.get_size_by_key() coord = (BlueprintManager.from_percentage( rect.get("COORDS").get("X"), size[0]), BlueprintManager.from_percentage( rect.get("COORDS").get("Y"), size[1])) size = (BlueprintManager.from_percentage( rect.get("SIZE").get("WIDTH"), size[0]), BlueprintManager.from_percentage( rect.get("SIZE").get("HEIGHT"), size[1])) return coord, size
def __draw_settings_menu(): r = pg.Rect((self.btn_settings.get_rect().left, self.btn_settings.get_rect().bottom), (int(DisplaySettings.get_size_by_key()[0] * .2), int(self.btn_file.get_rect().height * len(self.__settings_menu_content)))) pg.draw.rect(self.display, Themes.DEFAULT_THEME.get("menu_background"), r, 0) for btn in self.__settings_menu_content: pg.draw.rect(self.display, btn.color, btn.get_rect(), 0) self.display.blit(btn.get_text(), btn.get_text_rect())
def __init__(self, text, pos): # TODO set button size according to the text object size font = pg.font.Font(Themes.DEFAULT_THEME.get("button_font_style"), int(DisplaySettings.get_size_by_key()[1] * .045)) self.logger = logger_utils.get_logger(__name__) self.__text_str = text self.__text = font.render(text, True, Themes.DEFAULT_THEME.get("font")) self.__height = int(font.size(self.__text_str)[1] * 1.1) self.__width = int(font.size(self.__text_str)[0] * 1.1) self.color = Themes.DEFAULT_THEME.get( "button") # Default color but overrides in scene drawings self.__x, self.__y = self.set_coordinates(pos)
def __init_edit_menu(self): result = [] r = self.btn_edit.get_rect() add_attr = AddAttrButton() add_attr.set_custom_size(DevelopmentScene.BTN_SIZE) add_attr.set_topleft( (int(r.left + DisplaySettings.get_size_by_key()[0] * .002), r.bottom)) add_attr.color = Themes.DEFAULT_THEME.get("menu_background") add_char = AddCharacterButton() add_char.set_custom_size(DevelopmentScene.BTN_SIZE) add_char.set_topleft( (int(r.left + DisplaySettings.get_size_by_key()[0] * .002), add_attr.get_rect().bottom)) add_char.color = Themes.DEFAULT_THEME.get("menu_background") add_func = AddFunctionButton() add_func.set_custom_size(DevelopmentScene.BTN_SIZE) add_func.set_topleft( (int(r.left + DisplaySettings.get_size_by_key()[0] * .002), add_char.get_rect().bottom)) add_func.color = Themes.DEFAULT_THEME.get("menu_background") add_sprite = AddSpriteButton() add_sprite.set_custom_size(DevelopmentScene.BTN_SIZE) add_sprite.set_topleft( (int(r.left + DisplaySettings.get_size_by_key()[0] * .002), add_func.get_rect().bottom)) add_sprite.color = Themes.DEFAULT_THEME.get("menu_background") clear = ClearConnectionsButton() clear.set_custom_size(DevelopmentScene.BTN_SIZE) clear.set_topleft( (int(r.left + DisplaySettings.get_size_by_key()[0] * .002), add_sprite.get_rect().bottom)) clear.color = Themes.DEFAULT_THEME.get("menu_background") result.extend([add_attr, add_char, add_func, add_sprite, clear]) return result
def draw_buttons(self): self.btn_select.set_custom_coordinates( (int((DisplaySettings.get_size_by_key()[0] - self.btn_select.get_rect().width * .5) * .98), int(self.file_container.bottom + DisplaySettings.get_size_by_key()[1] * 0.015 + self.btn_select.get_rect().height * .5))) self.btn_delete.set_custom_coordinates( (int(self.btn_select.get_rect().left - (DisplaySettings.get_size_by_key()[0] * .005 + self.btn_delete.get_rect().width * .5)), int(self.file_container.bottom + DisplaySettings.get_size_by_key()[1] * 0.015 + self.btn_delete.get_rect().height * .5))) self.btn_back.set_custom_coordinates( (int(self.btn_delete.get_rect().left - (DisplaySettings.get_size_by_key()[0] * .005 + self.btn_back.get_rect().width * .5)), int(self.file_container.bottom + DisplaySettings.get_size_by_key()[1] * 0.015 + self.btn_back.get_rect().height * .5))) pg.draw.rect(self.display, self.btn_select.color, self.btn_select.get_rect(), 0) self.display.blit(self.btn_select.get_text(), self.btn_select.get_text_rect()) pg.draw.rect(self.display, self.btn_delete.color, self.btn_delete.get_rect(), 0) self.display.blit(self.btn_delete.get_text(), self.btn_delete.get_text_rect()) pg.draw.rect(self.display, self.btn_back.color, self.btn_back.get_rect(), 0) self.display.blit(self.btn_back.get_text(), self.btn_back.get_text_rect())
def draw_drop_down(self, font): if self.__is_drop_down_pressed: self.__menu_content.clear() for pos in range(self.__menu_counter, len(GameApi.APIS), 1): if (pos - self.__menu_counter) < 3: rect = pg.Rect( (self.api_select.x, int(self.api_select.y + self.api_select.height * ((pos - self.__menu_counter) + 1))), (int(DisplaySettings.get_size_by_key()[0] * 0.6), int(DisplaySettings.get_size_by_key()[0] * .05))) txt = font.render( GameApi.get_api(pos)[1], True, Themes.DEFAULT_THEME.get("text_area_text")) rect_txt = txt.get_rect() rect_txt.center = rect.center self.__menu_content.append([rect, txt, rect_txt]) for i in range(0, len(self.__menu_content), 1): pg.draw.rect(self.display, Themes.DEFAULT_THEME.get("text_area_background"), self.__menu_content[i][0], 0) self.display.blit(self.__menu_content[i][1], self.__menu_content[i][2])
def __init_btn_coords(self): self.btn_file.set_custom_coordinates( (int(DisplaySettings.get_size_by_key()[0] * gui_utils.BUTTON_MENU_MARGIN + self.btn_file.get_rect().width * .5), int(0 + self.btn_file.get_rect().height * .5))) self.btn_edit.set_custom_coordinates( (int(self.btn_file.get_rect().right + (self.btn_run.get_rect().width * .5 + DisplaySettings.get_size_by_key()[0] * gui_utils.BUTTON_MENU_MARGIN)), int(0 + self.btn_file.get_rect().height * .5))) self.btn_run.set_custom_coordinates( (int(self.btn_edit.get_rect().right + (self.btn_run.get_rect().width * .5 + DisplaySettings.get_size_by_key()[0] * gui_utils.BUTTON_MENU_MARGIN)), int(0 + self.btn_run.get_rect().height * .5))) self.btn_settings.set_custom_coordinates( (int(self.btn_run.get_rect().right + (self.btn_settings.get_rect().width * .5 + DisplaySettings.get_size_by_key()[0] * gui_utils.BUTTON_MENU_MARGIN)), int(0 + self.btn_settings.get_rect().height * .5)))
def draw_buttons(self): # UPDATE BUTTON AFTER THEME/LANGUAGE SET self.btn_theme.update_button( color=Themes.DEFAULT_THEME.get("front_screen")) self.btn_language.update_button( color=Themes.DEFAULT_THEME.get("front_screen")) self.btn_back.update_button( color=Themes.DEFAULT_THEME.get("front_screen")) self.btn_display.update_button( color=Themes.DEFAULT_THEME.get("front_screen")) x = int(DisplaySettings.get_size_by_key()[0] * .02) y = DisplaySettings.get_size_by_key()[1] * .93 pos = 0 self.btn_back.set_custom_coordinates( (int(x + self.btn_back.get_rect().width * .5), int(y - pos * (self.btn_back.get_rect().height + gui_utils.BUTTON_MARGIN * DisplaySettings.get_size_by_key()[1])))) pg.draw.rect(self.display, self.btn_back.color, self.btn_back.get_rect(), 0) self.display.blit(self.btn_back.get_text(), self.btn_back.get_text_rect()) pos += 1 self.btn_theme.set_custom_coordinates( (int(x + self.btn_theme.get_rect().width * .5), int(y - pos * (self.btn_theme.get_rect().height + gui_utils.BUTTON_MARGIN * DisplaySettings.get_size_by_key()[1])))) pg.draw.rect(self.display, self.btn_theme.color, self.btn_theme.get_rect(), 0) self.display.blit(self.btn_theme.get_text(), self.btn_theme.get_text_rect()) pos += 1 self.btn_language.set_custom_coordinates( (int(x + self.btn_language.get_rect().width * .5), int(y - pos * (self.btn_language.get_rect().height + gui_utils.BUTTON_MARGIN * DisplaySettings.get_size_by_key()[1])))) pg.draw.rect(self.display, self.btn_language.color, self.btn_language.get_rect(), 0) self.display.blit(self.btn_language.get_text(), self.btn_language.get_text_rect()) pos += 1 self.btn_display.set_custom_coordinates(( int(x + self.btn_display.get_rect().width * .5), int(y - pos * (self.btn_display.get_rect().height + gui_utils.BUTTON_MARGIN * DisplaySettings.get_size_by_key()[1])))) pg.draw.rect(self.display, self.btn_display.color, self.btn_display.get_rect(), 0) self.display.blit(self.btn_display.get_text(), self.btn_display.get_text_rect())
def parse_blueprints(cls, bps, bp_conns): """Description: Function analyses and creates JSON-format .bp files from blueprint connections. """ ################## # TODO RE-IMPLEMENT METHOD WITH USING BLUEPRINT TO_DICT METHOD ################# data = dict() conns = list() size = DisplaySettings.get_size_by_key() for bp, bp_rect in bps: d = dict() d["BLUEPRINT"] = BlueprintManager.call_parser(bp) d["RECTANGLE"] = { "COORDS": { "X": BlueprintManager.to_percentage(bp_rect[0][0], size[0]), "Y": BlueprintManager.to_percentage(bp_rect[0][1], size[1]) }, "SIZE": { "WIDTH": BlueprintManager.to_percentage(bp_rect[1][0], size[0]), "HEIGHT": BlueprintManager.to_percentage(bp_rect[1][1], size[1]) } } data[bp.name] = json.dumps(d) for i in range(0, len(bp_conns), 1): bp1, bp2 = bp_conns[i] d = dict() d[i] = { "ROOT": { "NAME": bp1.get_blueprint().name, "TYPE": bp1.get_blueprint().get_type() }, "SLAVE": { "NAME": bp2.get_blueprint().name, "TYPE": bp2.get_blueprint().get_type() } } conns.append(d) return data, conns
def __init__(self, display, project): SceneBuilder.__init__(self, display) self.__project = (project.get("PROJECT_NAME"), project.get("PROJECT_API")) pg.display.set_caption("{} - {} {}".format(self.__project[0], self.__project[1], app_utils.CAPTION)) self.__logger = logger_utils.get_logger(__name__) self.__logger.debug("{} --- {}".format(self.__project[0], self.__project[1])) self.btn_file = FileButton() self.btn_file.color = Themes.DEFAULT_THEME.get("background") self.btn_run = RunButton() self.btn_run.color = Themes.DEFAULT_THEME.get("background") self.btn_settings = SettingsButton() self.btn_settings.color = Themes.DEFAULT_THEME.get("background") self.btn_edit = EditButton() self.btn_edit.color = Themes.DEFAULT_THEME.get("background") self.__init_btn_size() self.__file_menu_content = self.__init_file_menu() self.__edit_menu_content = self.__init_edit_menu() self.__settings_menu_content = self.__init_settings_menu() self.__run_menu_content = self.__init_run_menu() self.__btn_file_pressed, self.__btn_edit_pressed, self.__btn_run_pressed, \ self.__btn_settings_pressed = False, False, False, False self.__popup = None self.__cont_panel = ControlPanelForm( self.display, (int(DisplaySettings.get_size_by_key()[0] * .005), int(self.btn_file.get_rect().bottom * 1.005)), (int(DisplaySettings.get_size_by_key()[0] * .265), int(DisplaySettings.get_size_by_key()[1] * .945))) self.__bp_panel = BlueprintControlForm( self.__cont_panel, self.display, self.__project, project.get("GENERATED"), (int(self.__cont_panel.get_rect().right + DisplaySettings.get_size_by_key()[0] * .005), int(self.btn_file.get_rect().bottom * 1.05)), (int(DisplaySettings.get_size_by_key()[0] * .723), int(DisplaySettings.get_size_by_key()[1] * .945))) if project.get("CONNECTIONS") is not None and project.get( "BLUEPRINTS") is not None: self.__bp_panel.load_project(project.get("CONNECTIONS"), project.get("BLUEPRINTS"))
def draw_scene(self): # PREPARE DATA if self.__api == GameApi.DEFAULT_API: self.__api = " --- {} ---".format( StringUtils.get_string("ID_SELECT")) font = pg.font.Font(Themes.DEFAULT_THEME.get("banner_font_style"), int(DisplaySettings.get_size_by_key()[0] * .05)) txt_title = font.render( StringUtils.get_string("ID_TITLE") + ":", True, Themes.DEFAULT_THEME.get("font")) rect_title = txt_title.get_rect() rect_title.topleft = (int(DisplaySettings.get_size_by_key()[0] * .05), int(DisplaySettings.get_size_by_key()[1] * .15)) txt_api = font.render( StringUtils.get_string("ID_GAME_API") + ":", True, Themes.DEFAULT_THEME.get("font")) rect_api = txt_api.get_rect() rect_api.topleft = (int(int(DisplaySettings.get_size_by_key()[0] * .05)), int(rect_title.top + rect_title.height + DisplaySettings.get_size_by_key()[1] * .1)) self.input = pg.Rect( (int(rect_api.right + DisplaySettings.get_size_by_key()[0] * .05), int(rect_title.top)), (int(DisplaySettings.get_size_by_key()[0] * 0.6), int(DisplaySettings.get_size_by_key()[0] * .05))) font = pg.font.Font(Themes.DEFAULT_THEME.get("text_font_style"), int(DisplaySettings.get_size_by_key()[0] * .03)) txt_input = font.render(self.__project_name, True, Themes.DEFAULT_THEME.get("text_area_text")) rect_input = txt_input.get_rect() rect_input.center = self.input.center self.api_select = pg.Rect( (int(rect_api.right + DisplaySettings.get_size_by_key()[0] * .05), int(rect_api.top)), (int(DisplaySettings.get_size_by_key()[0] * 0.6), int(DisplaySettings.get_size_by_key()[0] * .05))) txt_select = font.render(self.__api, True, Themes.DEFAULT_THEME.get("text_area_text")) rect_select = txt_select.get_rect() rect_select.center = self.api_select.center # self.btn_drop_down = self.get_icon(self.api_select) img = Images.get_icon(Images.DROP_DOWN) img[1].midright = (int(self.api_select.right - DisplaySettings.get_size_by_key()[0] * .01), int(self.api_select.center[1])) self.btn_drop_down = img # DISPLAY self.display.fill(Themes.DEFAULT_THEME.get("front_screen")) self.display.blit(txt_title, rect_title) self.display.blit(txt_api, rect_api) pg.draw.rect(self.display, Themes.DEFAULT_THEME.get("text_area_background"), self.input, 0) self.display.blit(txt_input, rect_input) pg.draw.rect(self.display, Themes.DEFAULT_THEME.get("text_area_background"), self.api_select, 0) self.display.blit(self.btn_drop_down[0], self.btn_drop_down[1]) self.display.blit(txt_select, rect_select) self.draw_buttons() self.draw_drop_down(font) self.check_button_hover() if self.__popup is not None: self.__popup.draw(self.display) super().draw_scene()
def __init__(self, state, message): object.__init__(self) self.__state = state self.__message = message self.__coords = (int(DisplaySettings.get_size_by_key()[0] * .5), int(DisplaySettings.get_size_by_key()[1] * .5))