def __init__(self, size, cell_size, redraw, external_e): self.unit = None ## self.cell = None probleme self.e_img = thorpy.Image.make(pygame.Surface(cell_size)) ## self.e_img = thorpy.Image.make(pygame.Surface((1,1))) self.blank_img = pygame.Surface(cell_size) self.e_name = guip.get_title("Unit infos (no unit)") # ## self.e_group = thorpy.make_group([self.e_img, self.e_name]) ghost = thorpy.Ghost([self.e_img, self.e_name]) ghost.finish() self.e_img.set_center_pos(ghost.get_fus_center()) self.e_name.set_center_pos(self.e_img.get_fus_center()) ghost.fit_children() self.e_group = ghost # self.elements = [self.e_group] self.e = thorpy.Box.make(self.elements) self.e.set_size((size[0], None)) for e in self.e.get_elements(): e.recenter() ## #emap : to be displayed when a cell is clicked self.em_title = guip.get_title("Unit informations") ## self.em_coord = guip.get_text("") ## self.em_altitude = guip.get_text("") self.em_name = guip.get_small_text("") self.em_rename = guip.get_small_button("Rename", self.rename_current_unit) self.em_name_rename = thorpy.make_group([self.em_name, self.em_rename]) #### self.em_name_rename = thorpy.Clickable.make(elements=[self.em_name, self.em_rename]) #### thorpy.store(self.em_name_rename) self.em_name_rename.fit_children() self.em_unit_img_img = thorpy.Image.make(pygame.Surface(cell_size)) self.em_unit_img = thorpy.Clickable.make( elements=[self.em_unit_img_img]) self.em_unit_img.fit_children() self.em_unit_name = guip.get_text("") self.em_unit = thorpy.make_group([self.em_unit_img, self.em_unit_name]) self.em_elements = [ self.em_title, thorpy.Line.make(100), self.em_unit, self.em_name_rename ] self.em = thorpy.Box.make(self.em_elements) self.em.set_main_color((200, 200, 200, 150)) self.launched = False self.redraw = redraw self.external_e = external_e reac = thorpy.Reaction(thorpy.THORPY_EVENT, self.set_unlaunched, {"id": thorpy.constants.EVENT_UNLAUNCH}) external_e.add_reaction(reac) self.last_cell_clicked = None self.e_img.visible = False
def get_journal(game): journal_title = thorpy.make_text("Journal", font_size=thorpy.style.FONT_SIZE + 3, font_color=TCOLOR) line = thorpy.Line.make(100, "h") elements = [] #entries for name, day, coord, h, t, text in game.journal.entries: e_name = thorpy.make_text(name, font_color=(0, 0, 255)) infos = thorpy.make_text(" ".join([ "| Day", str(day), ", coord=", coord, ", alt=", str(round(h)), ", temp=", str(round(t)) ]), font_color=(50, 50, 150)) ## e_title = thorpy.Element.make(elements=[e_name,infos]) ## thorpy.store(e_title, mode="h") e_title = thorpy.make_group([e_name, infos]) e_title.fit_children() elements.append(e_title) elements.append(thorpy.make_text(" " + thorpy.pack_text(400, text))) subbox = thorpy.Element.make(elements=elements, size=(500, 300)) thorpy.store(subbox, elements, x=3, y=0, align="left", gap=3) # def add_entry(): add_journal_entry(game) thorpy.functions.quit_menu_func() ok = thorpy.make_button("Ok", func=thorpy.functions.quit_menu_func) add = thorpy.make_button("Add entry", func=add_entry) ok_add = thorpy.make_group([ok, add]) # box = thorpy.Element.make(elements=[journal_title, subbox, ok_add]) box.set_main_color((200, 200, 200, 100)) thorpy.store(box) box.fit_children() box.set_size((None, int(1.3 * subbox.get_fus_rect().h))) # subbox.set_prison() subbox.refresh_lift() ## box.add_reaction(thorpy.ConstantReaction(pygame.KEYDOWN, ## thorpy.functions.quit_menu_func, ## {"key":pygame.K_SPACE})) box.center() m = thorpy.Menu([box]) m.play()
def __init__(self, text, length, limvals, initial_value, reblit=None, type_=float, order="ins"): import thorpy self.text = thorpy.make_button(text, self.focus) self.slider = thorpy.SliderX.make(length, limvals, "", type_, initial_value) self.ins = thorpy.Inserter.make("", value=str(initial_value)) if order == "ins": els = [self.text, self.ins, self.slider] else: els = [self.text, self.slider, self.ins] self.e = thorpy.make_group(els) reac_slide = thorpy.Reaction( reacts_to=thorpy.constants.THORPY_EVENT, reac_func=self.at_slide, event_args={"id": thorpy.constants.EVENT_SLIDE}) reac_ins = thorpy.Reaction( reacts_to=thorpy.constants.THORPY_EVENT, reac_func=self.at_insert, event_args={"id": thorpy.constants.EVENT_INSERT}) self.e.add_reactions([reac_slide, reac_ins]) self.e._manager = self self.ins._manager = self self.slider._manager = self self.e.get_value = self.slider.get_value self.reblit = reblit if not self.reblit: self.reblit = self.e.unblit_and_reblit
def __init__(self, player_name, min_val, max_val, trials): #init some parameters of the game ... self.player_name = player_name self.min_val = min_val #the minimum value to guess self.max_val = max_val #the maximum value to guess self.init_trials = trials #keep the original trials amount in memory self.trials = trials #remaining number of trials #the number to guess: self.number = random.randint(self.min_val, self.max_val) self.guess = None #the current player guess self.e_quit = thorpy.make_button("Quit", func=thorpy.functions.quit_menu_func) self.e_restart = thorpy.make_button("Restart", func=self.restart) #a ghost for storing quit and restart: self.e_group_menu = thorpy.make_group([self.e_quit, self.e_restart]) #a counter displaying the trials and some hint/infos about the game self.e_counter = thorpy.make_text(text=self.get_trials_text(), font_color=(0, 0, 255)) #the inserter element in which player can insert his guess self.e_insert = thorpy.Inserter(name="Try:") self.e_background = thorpy.Background( color=(200, 200, 255), elements=[self.e_counter, self.e_insert, self.e_group_menu]) thorpy.store(self.e_background, gap=20) #reaction called each time the player has inserted something reaction_insert = thorpy.ConstantReaction( reacts_to=thorpy.constants.THORPY_EVENT, reac_func=self.reac_insert_func, event_args={ "id": thorpy.constants.EVENT_INSERT, "el": self.e_insert }) self.e_background.add_reaction(reaction_insert)
def get_object(img, oktext, funcok, name, skills, star): eimage = thorpy.Image.make(img) eok = thorpy.make_button(oktext, func=funcok) ename = thorpy.make_text(name) ## sk1 = thorpy.make_text(s1) # star_full = thorpy.change_color_on_img(star, (255, 0, 255), (255, 201, 14), (255, 255, 255)) star_empty = thorpy.change_color_on_img(star, (255, 0, 255), (255, 255, 255), (255, 255, 255)) w, h = star.get_size() stars = thorpy.Element.make(size=(5 * w, 2 * h * len(skills))) skill_elements = [] for skillname in skills: value = skills[skillname] sname = thorpy.make_text(skillname + ": ") nfill = int(value * 5) nempty = 5 - nfill elements = [sname] for i in range(nfill): elements.append(thorpy.Image.make(star_full)) for i in range(nempty): elements.append(thorpy.Image.make(star_empty)) skill_elements.append(thorpy.make_group(elements)) eskill = thorpy.Box.make(skill_elements) # e = thorpy.Element.make(elements=[eimage, ename, eskill, eok]) thorpy.store(e, mode="h") e.fit_children() return e
def make_instruction(text): splits = text.split(":") title, corpus = splits[0], "".join(splits[1:]) corpus = thorpy.pack_text(int(0.6*parameters.S), corpus) etitle = thorpy.make_text(title, font_color=(255,0,0)) ecorpus = thorpy.Element.make(corpus) return thorpy.make_group([etitle, ecorpus])
def launch_blocking_choices(text, choices, parent=None, title_fontsize=None, title_fontcolor=None, func=None): """choices are tuple (text,func)""" if title_fontsize is None: title_fontsize = thorpy.style.FONT_SIZE if title_fontcolor is None: title_fontcolor = thorpy.style.FONT_COLOR elements = [thorpy.make_button(t, f) for t, f in choices] ghost = thorpy.make_group(elements) e_text = thorpy.make_text(text, title_fontsize, title_fontcolor) box = thorpy.Box.make([e_text, ghost]) box.center() from thorpy.miscgui.reaction import ConstantReaction for e in elements: reac = ConstantReaction(thorpy.constants.THORPY_EVENT, thorpy.functions.quit_menu_func, { "id": thorpy.constants.EVENT_UNPRESS, "el": e }) box.add_reaction(reac) from thorpy.menus.tickedmenu import TickedMenu m = TickedMenu(box) m.play() box.unblit() if parent: parent.partial_blit(None, box.get_fus_rect()) box.update() if func: func()
def __init__(self, me, size, cell_size, redraw, external_e): self.me = me self.wline = int(0.75*size[0]) self.e_coordalt = thorpy.make_text("(?,?)", font_size=10, font_color=(200,200,200)) self.e_mat_img = thorpy.Image.make(pygame.Surface(cell_size)) self.e_mat_name = guip.get_text("") self.e_obj_name = guip.get_text("") self.e_mat_obj = thorpy.make_group([self.e_mat_name, self.e_obj_name], "v") ## self.e_mat = thorpy.make_group([self.e_mat_img, self.e_mat_obj]) self.e_mat = thorpy.Box(elements=[self.e_mat_img, self.e_mat_obj]) ## self.e_mat.fit_children(axis=(False, True)) self.elements = [self.e_mat, self.e_coordalt] self.e = thorpy.Box.make(self.elements) self.e.set_main_color((20,20,20)) self.e.set_size((size[0],int(0.8*self.e.get_fus_size()[1])), margins=(2,2)) for e in self.e.get_elements(): e.recenter() self.cell = None #emap : to be displayed when a cell is clicked self.em_title = guip.get_title("Cell informations") self.em_coord = guip.get_text("") self.em_altitude = guip.get_text("") self.em_name = guip.get_small_text("") self.em_rename = guip.get_small_button("Rename", self.rename_current_cell) self.em_name_rename = thorpy.make_group([self.em_name, self.em_rename]) ## self.em_name_rename = thorpy.Clickable.make(elements=[self.em_name, self.em_rename]) ## thorpy.store(self.em_name_rename) self.em_name_rename.fit_children() self.em_mat_img_img = thorpy.Image.make(pygame.Surface(cell_size)) self.em_mat_img = thorpy.Clickable.make(elements=[self.em_mat_img_img]) self.em_mat_img.fit_children() self.em_mat_name = guip.get_text("") self.em_obj_name = guip.get_text("") self.em_mat_obj = thorpy.make_group([self.em_mat_name, self.em_obj_name], "v") self.em_mat = thorpy.make_group([self.em_mat_img, self.em_mat_obj]) ## self.em_elements = [self.em_title, thorpy.Line.make(self.wline), self.em_mat, self.em_coord, self.em_altitude, self.em_name_rename] self.em_elements = [self.em_title, thorpy.Line.make(self.wline), self.em_mat, self.em_coord, self.em_name_rename] self.em = thorpy.Box.make(self.em_elements) self.em.set_main_color((200,200,200,150)) self.launched = False self.redraw = redraw self.external_e = external_e reac = thorpy.Reaction(thorpy.THORPY_EVENT, self.set_unlaunched, {"id":thorpy.constants.EVENT_UNLAUNCH}) external_e.add_reaction(reac) self.last_cell_clicked = None
def displayLauncher(): # Declare Variables index = None #int game = None #String application = None #Application(thorpy) buttons = [None, None, None] #Clickable(thorpy) Array scoreboardButton = None #Clickable(thorpy) quitButton = None #Clickable(thorpy) buttonGroup = None #Group(thorpy) menu = None #Menu(thorpy) background = None #Background(thorpy) painter = None #Painters(thorpy) title = None #Text(thorpy) # Create GUI and set theme application = thorpy.Application(size=(1280, 800), caption="Mini-Arcade") thorpy.theme.set_theme("human") # Create title title = thorpy.make_text("Mini-Arcade\n", 35, (0, 0, 0)) # Create buttons painter = thorpy.painters.roundrect.RoundRect(size=(150, 75), color=(102, 204, 255), radius=0.3) for index, game in enumerate(Launcher.gameTitle): buttons[index] = Launcher.createButton(game, index, painter) scoreboardButton = thorpy.Clickable("Scoreboard") scoreboardButton.user_func = Launcher.launchScoreboard scoreboardButton.set_painter(painter) scoreboardButton.finish() scoreboardButton.set_font_size(23) scoreboardButton.set_font_color_hover((255, 255, 255)) quitButton = thorpy.Clickable("Exit") quitButton.user_func = thorpy.functions.quit_menu_func quitButton.set_painter(painter) quitButton.finish() quitButton.set_font_size(23) quitButton.set_font_color_hover((255, 255, 255)) # Format the buttons buttonGroup = thorpy.make_group(buttons) # Set background background = thorpy.Background( color=(255, 255, 255), elements=[title, buttonGroup, scoreboardButton, quitButton]) thorpy.store(background) # Create menu and display menu = thorpy.Menu(background) menu.play() # Exiting application.quit()
def get_help_text(*texts, start="normal"): if start == "normal": state = 0 else: state = 1 get_text = {0: guip.get_info_text, 1: guip.get_highlight_text} els = [] for text in texts: els.append(get_text[state](text)) state = 1 if state == 0 else 0 return thorpy.make_group(els)
def launch_blocking_choices_str(text, choices, parent=None, title_fontsize=None, title_fontcolor=None, func=None, store="v"): """choices are tuple (text,func)""" if title_fontsize is None: title_fontsize = thorpy.style.FONT_SIZE if title_fontcolor is None: title_fontcolor = thorpy.style.FONT_COLOR class Choice: value = None def choice_func(value): Choice.value = value elements = [] for name in choices: e = thorpy.make_button(name, choice_func, {"value": name}) elements.append(e) ghost = thorpy.make_group(elements, mode=store) e_text = thorpy.make_text(text, title_fontsize, title_fontcolor) box = thorpy.Box.make([e_text, thorpy.Line(100, "h"), ghost]) box.center() from thorpy.miscgui.reaction import ConstantReaction for e in elements: reac = ConstantReaction(thorpy.constants.THORPY_EVENT, thorpy.functions.quit_menu_func, { "id": thorpy.constants.EVENT_UNPRESS, "el": e }) box.add_reaction(reac) def click_outside(e): if not box.get_fus_rect().collidepoint(e.pos): thorpy.functions.quit_menu_func() reac = thorpy.Reaction(pygame.MOUSEBUTTONDOWN, click_outside) box.add_reaction(reac) from thorpy.menus.tickedmenu import TickedMenu m = TickedMenu(box) m.play() box.unblit() if parent: parent.partial_blit(None, box.get_fus_rect()) box.update() if func: func() return Choice.value
def launch_nonblocking_choices(text, choices, parent=None, title_fontsize=None, title_fontcolor=None, func=None): """choices are tuple (text,func)""" from thorpy.miscgui.launchers.launcher import post_done if title_fontsize is None: title_fontsize = thorpy.style.FONT_SIZE if title_fontcolor is None: title_fontcolor = thorpy.style.FONT_COLOR elements = [thorpy.make_button(t, f) for t, f in choices] ghost = thorpy.make_group(elements) e_text = thorpy.make_text(text, title_fontsize, title_fontcolor) box = thorpy.Box.make([e_text, ghost]) box.center() from thorpy.miscgui.reaction import ConstantReaction for e in elements: reac = ConstantReaction(thorpy.constants.THORPY_EVENT, post_done, { "id": thorpy.constants.EVENT_UNPRESS, "el": e }, {"el": box}) box.add_reaction(reac) thorpy.launch_nonblocking(box)
def add_players(self): gameStartNewButton = thorpy.make_button("Start Game", func=self.start_game) goBackButton = thorpy.make_button("Go Back", func=self.start_menu) buttonsGroup = thorpy.make_group([gameStartNewButton, goBackButton]) self.replace_elements([self.player1Edit, self.player2Edit, buttonsGroup])
def drawBoard(): # Declare variables application = None #Application(thorpy) title = None #Text(thorpy) content = None #Text(thorpy) buttons = [None, None, None] #Clickable/Element(thorpy) Array quitButton = None #Clickable(thorpy) painter1 = None #Painters(thorpy) painter2 = None #Painters(thorpy) buttonGroup = None #Group(thorpy) menu = None #Menu(thorpy) background = None #Background(thorpy) contentString = None #String # Create GUI and set theme application = thorpy.Application(size=(1280, 800), caption="Mini-Arcade") thorpy.theme.set_theme("human") # Create title title = thorpy.make_text("Scoreboard\n", 35, (0, 0, 0)) # Create buttons painter1 = thorpy.painters.roundrect.RoundRect(size=(100, 50), color=(102, 204, 255), radius=0.3) painter2 = thorpy.painters.roundrect.RoundRect(size=(100, 50), color=(57, 197, 187), radius=0.3) for index, game in enumerate(Scoreboard.gameTitle): buttons[index] = Scoreboard.createButton(game, index, painter1, painter2) quitButton = thorpy.Clickable("Return") quitButton.user_func = Scoreboard.exitScoreboard quitButton.set_painter(painter1) quitButton.finish() quitButton.set_font_size(17) quitButton.set_font_color_hover((255, 255, 255)) # Create texts contentString = "" for index, score in enumerate( Scoreboard.scores[Scoreboard.displayGame]): contentString = contentString + str(index + 1) + ": " + str(score) + "\n" contentString += "\n\n" content = thorpy.make_text(contentString, 20, (0, 0, 0)) # Format the buttons and texts buttonGroup = thorpy.make_group(buttons) # Set background background = thorpy.Background( color=(255, 255, 255), elements=[title, buttonGroup, content, quitButton]) thorpy.store(background) # Create menu and display menu = thorpy.Menu(background) menu.play() # Exiting application.quit()
def build_gui_elements(self): #worst function ever e_hmap = thorpy.Image.make(self.cam.img_hmap) e_hmap.stick_to("screen", "right", "right", False) e_hmap.add_reaction( thorpy.Reaction(pygame.MOUSEMOTION, self.func_reac_mousemotion)) e_hmap.add_reaction( thorpy.Reaction(pygame.MOUSEBUTTONDOWN, self.func_reac_click)) e_hmap.add_reaction( thorpy.Reaction(pygame.MOUSEBUTTONUP, self.func_reac_unclick)) self.e_hmap = e_hmap e_title_hmap = guip.get_title("Map") box_hmap = thorpy.Box.make([e_hmap]) box_hmap.fit_children((self.box_hmap_margin, ) * 2) thorpy.makeup.add_basic_help(box_hmap, "Click to move camera on miniature map") self.topbox = thorpy.make_group([e_title_hmap, box_hmap], "v") self.box_hmap = box_hmap ######################################################################## self.cam.set_gui_elements(e_hmap, box_hmap) ######################################################################## if len(self.zoom_cell_sizes) > 1: self.e_zoom = thorpy.SliderX.make(self.menu_width // 4, (0, 100), "Zoom (%)", int, initial_value=100) def func_reac_zoom(e): levels = len(self.zoom_cell_sizes) - 1 level = int(levels * self.e_zoom.get_value() / self.e_zoom.limvals[1]) self.set_zoom(levels - level, False) ######################################################################## self.cell_info = gui.CellInfo( self.menu_rect.inflate((-10, 0)).size, self.cell_rect.size, self.draw_no_update, e_hmap) self.unit_info = gui.UnitInfo( self.menu_rect.inflate((-10, 0)).size, self.cell_rect.size, self.draw_no_update, e_hmap) ## self.misc_info = gui.MiscInfo(self.menu_rect.inflate((-10,0)).size) self.menu_button = thorpy.make_menu_button() ######################################################################## elements = [ self.topbox, ## self.misc_info.e, self.cell_info.e, self.unit_info.e, self.menu_button ] if len(self.zoom_cell_sizes) > 1: elements.insert(0, self.e_zoom) self.e_box = thorpy.Element.make(elements=elements, size=self.menu_rect.size) thorpy.store(self.e_box) self.e_box.stick_to("screen", "right", "right") ######################################################################## if len(self.zoom_cell_sizes) > 1: reac_zoom = thorpy.Reaction( reacts_to=thorpy.constants.THORPY_EVENT, reac_func=func_reac_zoom, event_args={ "id": thorpy.constants.EVENT_SLIDE, "el": self.e_zoom }, reac_name="zoom slide") self.e_box.add_reaction(reac_zoom) ######################################################################## thorpy.add_keydown_reaction(self.e_box, pygame.K_KP_PLUS, self.increment_zoom, params={"value": -1}, reac_name="k plus") thorpy.add_keydown_reaction(self.e_box, pygame.K_KP_MINUS, self.increment_zoom, params={"value": 1}, reac_name="k minus") wheel_reac1 = thorpy.ConstantReaction(pygame.MOUSEBUTTONDOWN, self.increment_zoom, {"button": 4}, {"value": 1}) wheel_reac2 = thorpy.ConstantReaction(pygame.MOUSEBUTTONDOWN, self.increment_zoom, {"button": 5}, {"value": -1}) self.e_box.add_reactions([wheel_reac1, wheel_reac2]) ######################################################################## velocity = 0.2 thorpy.add_keydown_reaction(self.e_box, pygame.K_LEFT, self.move_cam_and_refresh, params={"delta": (-velocity, 0)}, reac_name="k left") thorpy.add_keydown_reaction(self.e_box, pygame.K_RIGHT, self.move_cam_and_refresh, params={"delta": (velocity, 0)}, reac_name="k right") thorpy.add_keydown_reaction(self.e_box, pygame.K_UP, self.move_cam_and_refresh, params={"delta": (0, -velocity)}, reac_name="k up") thorpy.add_keydown_reaction(self.e_box, pygame.K_DOWN, self.move_cam_and_refresh, params={"delta": (0, velocity)}, reac_name="k down") ######################################################################## self.help_box = gui.HelpBox([ ("Move camera", [("To move the map, drag it with", "<LMB>", "or hold", "<LEFT SHIFT>", "while moving mouse."), ("The minimap on the upper right can be clicked or hold with", "<LMB>", "in order to move the camera."), ("The", "<KEYBOARD ARROWS>", "can also be used to scroll the map view.")]), ("Zoom", [("Use the", "zoom slider", "or", "<NUMPAD +/- >", "to change zoom level."), ("You can also alternate zoom levels by pressing", "<RMB>", ".")]), ("Miscellaneous", [("Press", "<g>", "to toggle grid lines display.")]) ]) thorpy.add_keydown_reaction(self.e_box, pygame.K_g, self.toggle_show_grid_lines, reac_name="toggle grid")
def __init__(self, me, size, cell_size, redraw, external_e): self.me = me self.wline = int(0.75*size[0]) self.unit = None ## self.cell = None probleme self.e_img = thorpy.Image.make(pygame.Surface(cell_size)) ## self.e_img = thorpy.Image.make(pygame.Surface((1,1))) self.blank_img = pygame.Surface(cell_size) self.e_name = guip.get_text("") self.e_race = guip.get_text("") self.e_name_and_race = thorpy.Box([self.e_name, self.e_race]) self.e_name_and_race.fit_children() ghost = thorpy.Ghost([self.e_img, self.e_name_and_race]) ghost.finish() self.e_img.set_center_pos(ghost.get_fus_center()) self.e_name.set_center_pos(self.e_img.get_fus_center()) ghost.fit_children() self.e_group = ghost # self.elements = [self.e_group] self.e = thorpy.Box.make(self.elements) self.e.set_main_color((20,20,20)) self.e.set_size((size[0],None)) for e in self.e.get_elements(): e.recenter() ## #emap : to be displayed when a cell is clicked self.em_title = guip.get_title("Unit informations") ## self.em_coord = guip.get_text("") ## self.em_altitude = guip.get_text("") ## self.em_name = guip.get_small_text("") self.em_rename = guip.get_small_button("Rename", self.rename_current_unit) ## self.em_rename.scale_to_title() ## self.em_name_rename = thorpy.make_group([self.em_name, self.em_rename]) #### self.em_name_rename = thorpy.Clickable.make(elements=[self.em_name, self.em_rename]) #### thorpy.store(self.em_name_rename) ## self.em_name_rename.fit_children() self.em_unit_img_img = thorpy.Image.make(pygame.Surface(cell_size)) self.em_unit_img = thorpy.Clickable.make(elements=[self.em_unit_img_img]) self.em_unit_img.fit_children() self.em_unit_name = guip.get_text("") self.em_unit_race = guip.get_text("") self.em_nameNrace = thorpy.make_group([self.em_unit_name, self.em_unit_race], "v") self.em_unit = thorpy.make_group([self.em_unit_img, self.em_nameNrace]) self.em_elements = [self.em_title, thorpy.Line.make(self.wline), self.em_unit, self.em_rename]#self.em_name_rename] # self.em_mat_img_img = thorpy.Image.make(pygame.Surface(cell_size)) self.em_mat_img = thorpy.Clickable.make(elements=[self.em_mat_img_img]) self.em_mat_img.fit_children() def show_terrain_infos(): cell = self.unit.cell self.me.cell_info.last_cell_clicked = cell pos = self.me.cam.get_rect_at_coord(cell.coord).center self.me.cell_info.launch_em(cell, pos, self.me.cam.map_rect) ## self.em_button_cell = guip.get_button("Terrain infos", show_terrain_infos) self.em_mat_img.user_func = show_terrain_infos self.em_elements += [thorpy.Line.make(self.wline), self.em_mat_img] self.em = thorpy.Box.make(self.em_elements) self.em.set_main_color((200,200,200,150)) self.launched = False self.redraw = redraw self.external_e = external_e reac = thorpy.Reaction(thorpy.THORPY_EVENT, self.set_unlaunched, {"id":thorpy.constants.EVENT_UNLAUNCH}) external_e.add_reaction(reac) self.last_cell_clicked = None self.e_img.visible = False
def show_players_infos(self): w = self.game.me.screen.get_width() // 2 objs = ["village", "windmill", "tower"] unit_types = set([u.str_type for u in self.game.units]) boxes = [] o_e = [] for pn in [0, 1]: p = self.game.players[pn] title = thorpy.make_text(p.name, 15, p.color_rgb) line = thorpy.Line(w, "h") p = self.game.players[pn] els = [] for typ in objs: for o in self.game.get_objects_of_team(p.team, typ): ## img = self.game.me.extract_img(o.cell) if typ == "village": img = self.game.village.imgs_z_t[0][0] elif typ == "windmill": img = self.game.windmill.imgs_z_t[0][0] elif typ == "tower": img = p.race.tower.imgs_z_t[0][0] els.append(thorpy.Image(img)) o_e.append((els[-1], o)) thorpy.grid_store(10, pygame.Rect(0, 0, 100, 100), els) g_buildings = thorpy.make_group(els, mode=None) # els = [] for typ in unit_types: for u in self.game.units: if u.str_type == typ and u.race.team == p.team: img = u.imgs_z_t[0][u.get_current_frame()] els.append(thorpy.Image(img)) o_e.append((els[-1], u)) thorpy.grid_store(10, pygame.Rect(0, 0, 100, 100), els) g_units = thorpy.make_group(els, mode=None) # money_img = thorpy.Image(self.e_gold_img.get_image()) money_txt = thorpy.make_text(str(p.money)) income = self.game.compute_player_income(p) income_txt = thorpy.make_text(" (income: " + str(income) + ")") g_money = thorpy.make_group([money_img, money_txt, income_txt]) g = thorpy.Element( elements=[title, line, g_units, g_buildings, g_money]) thorpy.store(g) g.fit_children() boxes.append(g) e = thorpy.Box(boxes) e.center() def refresh(): for element, obj in o_e: img = obj.imgs_z_t[0][obj.get_current_frame()] ## fire = self.game.get_object("fire", obj.cell.coord) ## if fire: ## img_fire = fire.imgs_z_t[0][fire.get_current_frame()] ## r = img_fire.get_rect() ## w,h = img.get_size() ## r.center = w//2, h//2 ## r.bottom = h ## img.blit(img_fire, r) element.set_image(img) self.game.me.func_reac_time() self.game.t += 1 e.blit() pygame.display.flip() thorpy.add_time_reaction(e, refresh) def click(): if not e.get_fus_rect().collidepoint(pygame.mouse.get_pos()): thorpy.functions.quit_menu_func() thorpy.add_click_reaction(e, click) m = thorpy.Menu(e, fps=self.game.me.fps) m.play()
def get_cannibalism(game): title = thorpy.make_text("Cannibalism", font_size=thorpy.style.FONT_SIZE + 3, font_color=TCOLOR) descr = thorpy.make_text("Who should be eaten by the others?") class Choice: choice = None def choice1(): if thorpy.launch_binary_choice("Are you sure?"): Choice.choice = "a" thorpy.functions.quit_menu_func() else: box.unblit_and_reblit() def choice2(): Choice.choice = "c" thorpy.functions.quit_menu_func() def choice3(): Choice.choice = "h" thorpy.functions.quit_menu_func() ## a = thorpy.make_button() ## choices = [a, c, h, ("cancel",None)] a = thorpy.pack_text(150, "You won't be able to know your position anymore.") c = thorpy.pack_text(150, "Sailing will become very difficult. ") h = thorpy.pack_text( 150, "Your chances of sucess while hunting will be very low.") choices = [(a, choice1), (c, choice2), (h, choice3), ("cancel", None)] ## thorpy.launch_blocking_choices("Blocking choices box!\n", choices, ## parent=game.element) #for auto unblit ## launcher = thorpy.launch_choices("LOL", choices) ## launcher.launch() ea = thorpy.make_button("Astronomer", choice1) ea.set_main_color((0, 0, 255)) at = thorpy.make_text(a, font_size=thorpy.style.FONT_SIZE - 2) ab = thorpy.make_group([ea, at], "v") # ec = thorpy.make_button("Captain", choice2) ec.set_main_color((255, 0, 0)) ct = thorpy.make_text(c, font_size=thorpy.style.FONT_SIZE - 2) cb = thorpy.make_group([ec, ct], "v") # eh = thorpy.make_button("Hunter", choice3) eh.set_main_color((0, 255, 0)) ht = thorpy.make_text(h, font_size=thorpy.style.FONT_SIZE - 2) hb = thorpy.make_group([eh, ht], "v") # cancel = thorpy.make_button("Cancel") cancel.set_as_menu_exiter() # bar1, bar2 = thorpy.Line.make(100, "h"), thorpy.Line.make(100, "h") # crew = [] if game.a.life > 0: crew.append(ab) if game.h.life > 0: crew.append(hb) if game.c.life > 0: crew.append(cb) elements = [title, descr, bar1] + crew + [bar2, cancel] ## box = thorpy.Element.make(elements=elements) ## thorpy.store(box,mode="h") box = thorpy.Box.make(elements) box.center() m = thorpy.Menu([box]) m.play() return Choice.choice