def __init__(self, gameState, screen): self.gameState = gameState self.font = pygame.font.SysFont("monospace", 15) self.screen = screen pokemon_button = thorpy.make_button("Pokemons", func=change_state_loop, params={"gui": self}) quit_button = thorpy.make_button("Quit", func=change_state_loop, params={"gui": self}) self.boxMap = thorpy.Box.make(elements=[pokemon_button, quit_button]) self.menuMap = thorpy.Menu(self.boxMap) for element in self.menuMap.get_population(): element.surface = screen self.boxMap.set_topleft((0, 502)) attack_button = thorpy.make_button("Attack", func=self.attack_enemy) escape_button = thorpy.make_button("Escape", func=self.flee) self.boxBattle = thorpy.Box.make( elements=[attack_button, escape_button]) self.menuBattle = thorpy.Menu(self.boxBattle) for element in self.menuBattle.get_population(): element.surface = screen self.boxBattle.set_topleft((0, 502)) pass
def __init__(self, parent, screen, background, font): super().__init__(parent, screen, background, font) self.rows = 15 self.columns = 15 self.mine_count = (self.rows * self.columns) / 10 self.gameboard = Minefield(self, screen, background, font, self.rows, self.columns, self.mine_count) self.title = thorpy.make_text('Minesweeper', font_size=20, font_color=(0, 0, 150)) self.start_button = thorpy.make_button( 'New Game', func=MainMenu.activate_gameboard, params={'self': self}) self.options_button = thorpy.make_button( 'Options', func=MainMenu.activate_options, params={'self': self}) self.quit_button = thorpy.make_button('Quit', func=MainMenu.quit, params={'self': self}) self.box = thorpy.Box(elements=[ self.title, self.start_button, self.options_button, self.quit_button ], size=(screen.get_width(), screen.get_height())) thorpy.store(self.box) self.menu = thorpy.Menu(self.box) for element in self.menu.get_population(): element.surface = self.screen
def __init__(self, screen, scene_manager): super(State, self).__init__() self.scene_manager = scene_manager self.screen = screen self.screen_rect = self.screen.get_rect() # font settings self.font_size = 18 self.font_name = pygame.font.match_font('arial') self.font = pygame.font.Font(self.font_name, self.font_size) # define colors self.WHITE = (255, 255, 255) self.BLACK = (0, 0, 0) self.RED = (255, 0, 0) self.GREEN = (0, 255, 0) self.BLUE = (0, 0, 255) self.YELLOW = (255, 255, 0) self.BAR_LENGTH = 100 self.BAR_HEIGHT = 10 # menu self.quit_btn = thorpy.make_button("Quit", func=thorpy.functions.quit_func) self.ng_btn = thorpy.make_button("New game", func = self.scene_manager.go_to, params = {'scene':'game', 'state':'init'}) self.res_btn = thorpy.make_button("Resume", func = self.scene_manager.go_to, params = { 'scene':'game', 'state':'resume'}) self.box = thorpy.Box.make(elements=[self.quit_btn, self.ng_btn, self.res_btn]) self.menu = thorpy.Menu(self.box) for element in self.menu.get_population(): element.surface = self.screen self.box.set_topleft((200, 200))
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 init_ui(screen): slider = thorpy.SliderX(100, (5, 15), "Simulation speed") slider.user_func = slider_reaction button_stop = thorpy.make_button("Quit", func=stop_execution) button_pause = thorpy.make_button("Pause", func=pause_execution) button_play = thorpy.make_button("Play", func=start_execution) timer = thorpy.OneLineText("Seconds passed") button_load = thorpy.make_button(text="Load a file", func=open_file) box = thorpy.Box(elements=[ slider, button_pause, button_stop, button_play, button_load, timer ]) reaction1 = thorpy.Reaction( reacts_to=thorpy.constants.THORPY_EVENT, reac_func=slider_reaction, event_args={"id": thorpy.constants.EVENT_SLIDE}, params={}, reac_name="slider reaction") box.add_reaction(reaction1) menu = thorpy.Menu(box) for element in menu.get_population(): element.surface = screen box.set_topleft((0, 0)) box.blit() box.update() return menu, box, timer
def launch_ingame_options(): thorpy.set_theme("classic") def func(): parameters.scene.refresh_display() box.blit() pygame.display.flip() e, varset = get_display_options() e2 = thorpy.make_button("Show help", scenario.launch_help, {"func": func}) def leave(): if thorpy.launch_binary_choice("Are you sure?"): parameters.scene.abandon = True thorpy.functions.quit_menu_func() func() q = thorpy.make_button("Abandon", leave) box = thorpy.make_ok_box( [thorpy.make_text("Pause"), thorpy.Line.make(100, "h"), e, e2, q]) box.e_ok.user_func = thorpy.functions.quit_menu_func box.e_ok.user_params = {} ## boxletter.set_main_color((200,200,200,50)) box.set_main_color((200, 200, 255, 200)) box.center() scenario.launch(box) parameters.scene.cam.set_aa(varset.get_value("aa")) parameters.VISIBILITY = varset.get_value("visibility") thorpy.set_theme(parameters.THEME)
def create_gui(self): #Create buttons and place them in a box play_button = thorpy.make_button("Play", func=self.restart_game) play_button.set_size((200,50)) quit_button = thorpy.make_button("Quit", func=self.quit_game) box = thorpy.Box([play_button, quit_button]) self.elements.append(box) self.difficulty_button = thorpy.make_button("Difficulty: " + self.difficulty, func=self.select_dificulty) self.elements.append(self.difficulty_button)
def make_buttons(self): save_button = thorpy.make_button("Save", func=self.network.send, params={"data": ["save"]}) quit_button = thorpy.make_button("Quit", func=pg.quit) buttons = [save_button, quit_button] [button.set_font_size(20) for button in buttons] [button.scale_to_title() for button in buttons] return buttons
def __init__(self, game): self.game = game self.game.gui = self self.e_chars = {c: None for c in self.game.chars()} # import scenario def l_func_after(): ## self.game.element.blit() self.game.cam.show(self.game.screen) self.game.blit_things() self.e_pause.blit() pygame.display.flip() def launch_stats(): scenario.launch(self.get_stats(), l_func_after) def save_game(): game.autosave() thorpy.launch_blocking_alert("Game saved") l_func_after() self.e_controls = thorpy.make_button("See instructions", scenario.launch, { "e": game, "func": l_func_after }) # self.e_save = thorpy.make_button("Save game", save_game) self.e_stats = thorpy.make_button("Statistics", launch_stats) self.e_options = thorpy.make_button("Options", launch_options) # self.e_pause = thorpy.make_ok_cancel_box( [self.e_controls, self.e_save, self.e_stats, self.e_options], "Continue game", "Quit game") # self.pause_launcher = thorpy.get_launcher(self.e_pause, launching=game.element) self.e_options.user_params = {"game": game, "epause": self.e_pause} reac_esc = thorpy.ConstantReaction(pygame.KEYDOWN, self.pause_launcher.launch, {"key": pygame.K_ESCAPE}) self.game.element.add_reaction(reac_esc) self.e_pause.set_main_color((200, 200, 255, 100)) def quit_game(): thorpy.launch_blocking_choices( "This will quit the game. Make sure you saved the game.", [("Ok", thorpy.functions.quit_func), ("Cancel", None)]) l_func_after() self.e_pause.e_cancel.user_func = quit_game self.e_pause.e_cancel.user_params = {}
def drawSplash(): # readFile() # Declaration of the application in which the menu is going to live. application = thorpy.Application(size=(500, 500), caption='ThorPy stupid Example') # Setting the graphical theme. By default, it is 'classic' (windows98-like). thorpy.theme.set_theme('human') # Declaration of some elements... global board useless1 = thorpy.make_button("This button is useless.\nAnd you can't click it.") text = "This button also is useless.\nBut you can click it anyway." useless2 = thorpy.Clickable.make(text) draggable = thorpy.Draggable.make("Drag me!") box1 = thorpy.make_ok_box([useless1, useless2, draggable]) options1 = thorpy.make_button("Some useless things...") thorpy.set_launcher(options1, box1) inserter = thorpy.Inserter.make(name="Tip text: ", value="This is a default text.", size=(150, 20)) file_browser = thorpy.Browser.make(path="C:/Users/", text="Please have a look.") browser_launcher = thorpy.BrowserLauncher.make(browser=file_browser, const_text="Choose a file: ", var_text="") color_setter = thorpy.ColorSetter.make() color_launcher = thorpy.ColorSetterLauncher.make(color_setter, "Launch color setter") options2 = thorpy.make_button("Useful things") box2 = thorpy.make_ok_box([inserter, color_launcher, browser_launcher]) thorpy.set_launcher(options2, box2) quit_button = thorpy.make_button("Quit") quit_button.set_as_exiter() central_box = thorpy.Box.make([options1, options2, quit_button]) central_box.set_main_color((200, 200, 200, 120)) central_box.center() # Declaration of a background element - include your own path! background = thorpy.Background.make(image=thorpy.style.EXAMPLE_IMG, elements=[central_box]) menu = thorpy.Menu(elements=background, fps=45) menu.play()
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 fill_buttons_list(self): thorpy.set_theme("round") for text, button_function in self.b_info.items(): button_to_add = thorpy.make_button(text, button_function) button_to_add.set_font_size(20) button_to_add.scale_to_title() self.buttons.append(button_to_add)
def get_infoalert_text(text): e = thorpy.make_button(text) e.set_font_size(HFS) e.set_font_color(HFC) e.set_main_color((200,200,200,100)) e.scale_to_title() return e
def __init__(self, **args): """ crea los campos de inserción, el botón y el menú que los agrupa """ self._inserters = OrderedDict() self._boton = None self._valores = OrderedDict() self._superficie = None self._menu = thorpy.Menu() self._caja = None self._activado = False if 'entradas' in args: for entrada in args['entradas']: self._inserters[entrada] = thorpy.Inserter(entrada + ": ") self._valores[entrada] = None self._boton = thorpy.make_button('Aceptar', func=self.leer) elementos = [v for v in self._inserters.values()] elementos.append(self._boton) self._caja = thorpy.Box(elements=elementos) self._boton.set_topleft((50, 50)) #self._caja.add_elements([self._boton]) self._caja.blit() self._caja.update() self._menu.add_to_population(self._caja) if 'func' in args: # no aplica para este programa, porque llama a la función de lanzar pass
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 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, 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 first_render(self, location): self.elements = [] self.elements.append(thorpy.make_text("Smelter")) self.smelt_items = [thorpy.Clickable.make("None") for x in range(self.max_inv_size)] self.button = thorpy.make_button("Smelt", func=self.smelt) self.smelt_item_box = thorpy.Box.make(elements=self.smelt_items) self.elements.append(self.smelt_item_box) self.elements.append(self.button) self.smelted_item = thorpy.Clickable.make("None") self.smelted_item_box = thorpy.Box.make(elements=[self.smelted_item]) self.elements.append(self.smelted_item_box) self.box = thorpy.Box.make(elements=self.elements) self.drag = thorpy.Draggable.make(elements=[self.box]) reaction = thorpy.Reaction(reacts_to=thorpy.constants.THORPY_EVENT, reac_func=self._pop_smelter, params={"item": self.smelted_item}, event_args={"id":thorpy.constants.EVENT_PRESS}) for item in self.elements: item.center(axis=(True, False), element=self.box) self.drag.add_reaction(reaction) self.drag.set_topleft(location) self.sub_menu = thorpy.Menu(self.drag) thorpy.functions.set_current_menu(self.sub_menu) self.sub_menu.blit_and_update()
def first_render(self, location): self.elements = [] self.elements.append(thorpy.make_text("Inventory")) self.item_clickables = [thorpy.Clickable.make("None") for x in range(self.max_inv_size)] self.item_box = thorpy.Box.make(elements=self.item_clickables) self.elements.append(self.item_box) self.button = thorpy.make_button("Inv", func=self._print_all) self.elements.append(self.button) self.inv_box = thorpy.Box.make(elements=self.elements) self.inv_drag = thorpy.Draggable.make(elements=[self.inv_box]) for item in self.item_clickables: item.center(axis=(True, False), element=self.inv_box) # this reaction allows us to click the item we want to smelt # and transfer it into the smelter reaction = thorpy.Reaction(reacts_to=thorpy.constants.THORPY_EVENT, reac_func=self._add_to_smelter, params={"item": item}, event_args={"id":thorpy.constants.EVENT_PRESS}) self.inv_drag.add_reaction(reaction) self.inv_drag.set_topleft(location) self.inv_menu = thorpy.Menu(self.inv_drag) thorpy.functions.set_current_menu(self.inv_menu) self.inv_menu.blit_and_update()
def create_gui(self): if self.game.score == self.personal_high_score: best_score_text = thorpy.make_text("New Personal Best: " + str(self.personal_high_score)) best_score_text.set_font_size(20) gold = (150,150,50) best_score_text.set_font_color(gold) else: best_score_text = thorpy.make_text("Personal Best: " + str(self.personal_high_score)) score = thorpy.make_text("Score: " + str(self.game.score)) score.set_font_size(18) snake_length = thorpy.make_text("Length: " + str(len(self.game.game_snake.q))) snake_length.set_font_size(18) #self.score_header = thorpy.MultilineText(text="Loading scores from server...") self.score_header = thorpy.make_text(text="Loading...") self.input = thorpy.Inserter(name="Enter Your Name:", value=self.game.player_name) self.input.enter() submit_button = thorpy.make_button("Submit", func=self.submit_player_name) self.elements.append(best_score_text) self.elements.append(score) self.elements.append(snake_length) self.elements.append(self.input) self.elements.append(submit_button) if self.input_error: error_message = thorpy.make_text("The name cannot contain a , or spaces or a |.") self.elements.append(error_message)
def main(): pygame.init() # Iniciamos pygame. infoObject = pygame.display.Info() icon = pygame.image.load('images/ant.png') preferredSize = int(infoObject.current_h * 0.88) # Obtenemos la altura de la pantalla. application = thorpy.Application((preferredSize, preferredSize), "Langton's Ant", "pygame") # Verifica si el tamaño ingresado es válido y si lo es, inicia la simulación. def start(): if tamaño.get_value().isdigit() and iteraciones.get_value().isdigit(): tam = int(tamaño.get_value()) it = int(iteraciones.get_value()) if tam > 0 and it > 0: if tam > int(0.65 * (preferredSize // 2)): thorpy.launch_blocking_alert( title="¡Tamaño no soportado!", text= "El tamaño actual generaría una grilla con celdas de tamaño cero.", parent=background) tamaño.set_value("") else: simulation.simulate(tam, it, preferredSize) else: thorpy.launch_blocking_alert(title="¡Tamaño no soportado!", text="El tamaño no es válido.", parent=background) else: thorpy.launch_blocking_alert( title="¡Valores incorrectos!", text="Los valores introducidos no son válidos.", parent=background) tamaño.set_value("") iteraciones.set_value("") iteraciones = thorpy.Inserter(name="Iteraciones: ", value="1") # Campo de número de iteraciones. tamaño = thorpy.Inserter(name="Tamaño: ", value="10") # Campo de tamaño. boton = thorpy.make_button("Aceptar", start) # Botón aceptar. title_element = thorpy.make_text("Configurar simulación", 22, (255, 255, 255)) central_box = thorpy.Box(elements=[iteraciones, tamaño, boton]) # Contenedor central. central_box.fit_children(margins=(30, 30)) central_box.center() # center on screen central_box.set_main_color((220, 220, 220, 180)) background = thorpy.Background((0, 0, 0), elements=[title_element, central_box]) thorpy.store(background) menu = thorpy.Menu(background) menu.play() # Lanzamos el menú. application.quit()
def main(): pygame.init() screen = display.set_mode((WIDTH, HEIGHT), 0, 32) # declaration of algorithms for ThorPy buttons runKnn = thorpy.make_button("kNN", func=lambda: run_classification("KNN")) runLda = thorpy.make_button("LDA", func=lambda: run_classification("LDA")) runNB = thorpy.make_button("NB", func=lambda: run_classification("NB")) runTree = thorpy.make_button("Decision Tree", func=lambda: run_classification("TREE")) runForest = thorpy.make_button("Random Forest", func=lambda: run_classification("RF")) runSvc = thorpy.make_button("SVM", func=lambda: run_classification("SVM")) runGB = thorpy.make_button("Gradient Boosting", func=lambda: run_classification("GB")) runPerc = thorpy.make_button("Perceptron", func=lambda: run_classification("PERC")) runReset = thorpy.make_button("RESET", func=reset) # create a box of buttons box = thorpy.Box.make(elements=[ runKnn, runLda, runNB, runTree, runForest, runSvc, runGB, runPerc, runReset ]) menu = thorpy.Menu(box) box.set_topleft((600, 5)) box.blit() box.update() display.set_caption("Classification algorithms tester byPK") while True: clock.tick(40) for event in pygame.event.get(): menu.react(event) #read an event if event.type == QUIT: pygame.quit() sys.exit() if pygame.mouse.get_pressed()[0]: pos = pygame.mouse.get_pos() if pos[0] < 600: if color == RED: red_points.append(pos) if color == GREEN: green_points.append(pos) if pos[0] > 600 and pos[1] > 450: #click on switch area switch_color() refresh(screen) display.update()
def __init__(self, size): self.componentes = [0, 0, 0] self.insertion_i = thorpy.Inserter("i:") self.insertion_j = thorpy.Inserter("j:") self.insertion_k = thorpy.Inserter("k:") self.boton = thorpy.make_button("Ok", func=self.leer_todo) self.projectionViewer = None self.vector = None self.titulo = None
def process_key_pressed(self): pp = pygame.key.get_pressed() if pp[pygame.K_LEFT]: self.laser_rect.centerx = self.hero.pos.x move_hero_left() elif pp[pygame.K_RIGHT]: self.laser_rect.centerx = self.hero.pos.x move_hero_right() elif pp[pygame.K_UP]: move_hero_up() elif pp[pygame.K_DOWN]: move_hero_down() # if pp[pygame.K_SPACE]: if self.i%MOD_BULLET == 0: self.hero.shoot((0,-BULLET_SPEED)) elif pp[pygame.K_r]: if self.i - self.last_rocket > p.MOD_ROCKET: self.hero.shoot_rocket((0,-ROCKET_SPEED)) self.last_rocket = self.i elif pp[pygame.K_LSHIFT]: self.hero.shoot_laser() elif pp[pygame.K_RETURN]: self.hero.shoot_nuke() elif pp[pygame.K_p]: print("pause") self.e_pause.blit() pygame.display.flip() thorpy.get_application().pause() elif pp[pygame.K_ESCAPE]: e_quit = thorpy.make_button("Quit", thorpy.functions.quit_func) e_continue = thorpy.make_button("Continue", thorpy.functions.quit_menu_func) e_options, vs = menus.get_options() def redraw(): box.unblit_and_reblit() e_commands = thorpy.make_button("Instructions", menus.launch_commands, {"after":redraw}) box = thorpy.Box.make(elements=[e_commands, e_options, e_quit, e_continue]) box.center() menus.launch(box) p.SOUND = vs.get_value("sound") p.NSMOKE = vs.get_value("smokes") p.DEBRIS = vs.get_value("debris")
def create_load_menu(self): self.background_image() thorpy.set_theme("round") games = self.network.send(["get_games_to_load"]) self.load_buttons = [ thorpy.make_button(str(game), func=self.load_game, params={ "which_game": i, "games": games }) for i, game in enumerate(games) ] self.load_buttons.append( thorpy.make_button("Quit", func=self.quit_submenu)) [button.set_font_size(20) for button in self.load_buttons] [button.scale_to_title() for button in self.load_buttons] self.load_box = thorpy.Box(self.load_buttons) load_submenu = thorpy.Menu(self.load_box) return load_submenu
def __init__(self, screen) -> None: self.game_id = None self.screen = screen self.startNewButton = thorpy.make_button("Start Game", func=self.add_players) self.joinButton = thorpy.make_button("Join Game", func=self.join_game) self.player1Edit = thorpy.Inserter.make("Player 1 name: ") self.player2Edit = thorpy.Inserter.make("Player 2 name: ") self.box = thorpy.Box.make(elements=[self.startNewButton, self.joinButton], size=(300, 300)) thorpy.store(self.box) self.box.set_center((screen_middle_h, screen_middle_v)) self.menu = thorpy.Menu(self.box) for el in self.menu.get_population(): el.surface = self.screen self.box.blit() self.box.update()
def mainmenu(): W, H = thorpy.functions.get_screen_size() title = graphics.get_title() ## box = thorpy.make_textbox("Credits", text, hline=100) ## box.set_main_color((200,200,200,100)) ## thorpy.launch_blocking(box) e_start = thorpy.make_button("Start game", thorpy.functions.quit_menu_func) e_options, vs = get_options() e_credits = thorpy.make_button("Credits", launch_credits) e_quit = thorpy.make_button("Quit", thorpy.functions.quit_func) space_img = image = thorpy.load_image("Calinou3.png") bck_pos = [0, 0] screen = thorpy.get_screen() def menureac(): if bck_pos[0] - W <= -space_img.get_width(): bck_pos[0] = 0 if bck_pos[1] - H <= -space_img.get_height(): bck_pos[1] = 0 bck_pos[0] -= 0.3 bck_pos[1] -= 0.2 ## bck_pos[1] += sgny * 0.2 screen.blit(space_img, bck_pos) e.blit() pygame.display.flip() e_start.add_reaction( thorpy.ConstantReaction(thorpy.THORPY_EVENT, menureac, {"id": thorpy.constants.EVENT_TIME})) e = thorpy.Ghost.make( elements=[title, e_start, e_options, e_credits, e_quit]) thorpy.store(e) e.center() # m = thorpy.Menu(e, fps=80) m.play() # parameters.SOUND = vs.get_value("sound") parameters.NSMOKE = vs.get_value("smokes") parameters.DEBRIS = vs.get_value("debris")
def draw_main_menu(screen): button1 = thorpy.make_button("Poop", test_butt) button2 = thorpy.make_button('F**k', ) button1.set_size((200, 200)) box = thorpy.Box.make(elements=[button1, button2]) # we regroup all elements on a menu, even if we do not launch the menu # important : set the screen as surface for all elements # use the elements normally... box.set_topleft((300, 300)) box.blit() box.update() #unclick = thorpy.Reaction(reacts_to=thorpy.constants.THORPY_EVENT, # reac_func=test_butt, event_args={"id":thorpy.constants.EVENT_UNPRESS}) #background = thorpy.Background.make(color=(255, 255, 255), image='paper background.png', # elements=[button1, button2]) button_menu = thorpy.Menu(box) for element in button_menu.get_population(): element.surface = screen #background.add_reaction(unclick) #add my_reaction to background's reaction selecting = True while selecting: for event in pg.event.get(): if event.type == pg.QUIT: pg.quit() sys.exit() button_menu.react(event) if event.type == thorpy.constants.THORPY_EVENT: if event.el == button1: pass if event.el == button2: selecting = False
def create_instructions(self): self.ins_buttons = [ thorpy.make_button(txt, func=self.ins_func[txt]) for txt in self.ins_func.keys() ] [button.set_font_size(30) for button in self.ins_buttons] [button.scale_to_title() for button in self.ins_buttons] self.ins_box = thorpy.Box(self.ins_buttons) self.ins_box.set_main_color((0, 0, 0, 0)) thorpy.store(self.ins_box, mode="h", gap=40) self.ins_box.set_topleft((170, 540)) self.ins_box.fit_children() return thorpy.Menu(self.ins_box)
def get_games_list(self, event): player_name = event.el.get_value() r = Api.getPlayerInfo(player_name) games_list = [id for id in r["games"]] if r is not None else [] label = thorpy.OneLineText.make("Here's a list of games " + player_name + " is in:") self.gamesListEdit = thorpy.DropDownList.make(games_list, size=(250,150), x=5) self.gamesListEdit.finish() gameSelectReaction = thorpy.Reaction(reacts_to=thorpy.constants.THORPY_EVENT, reac_func=self.start_game_join, event_args={"id": thorpy.constants.EVENT_DDL}) self.gamesListEdit.add_reaction(gameSelectReaction) goBackButton = thorpy.make_button("Go Back", func=self.start_menu) self.replace_elements([label, self.gamesListEdit, goBackButton])