Exemplo n.º 1
0
 def init_thorpy(self):
     res_trees = thorpy.OneLineText("Trees: " + str(
         len(
             self.ai_player.entities_where(
                 lambda e: isinstance(e, entities.Tree)))))
     self.box = thorpy.Box(elements=[res_trees])
     self.box_u = thorpy.Box(elements=[res_trees])
     self.box_r = thorpy.Box(elements=[res_trees])
     #we regroup all elements on a menu, even if we do not launch the menu
     menu = thorpy.Menu([self.box, self.box_u])
     #important : set the screen as surface for all elements
     for element in menu.get_population():
         element.surface = self.screen
     #use the elements normally...
     self.box.set_topleft((0, 0))
Exemplo n.º 2
0
    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
Exemplo n.º 3
0
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
Exemplo n.º 4
0
 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
Exemplo n.º 5
0
 def set_up(self):
     self.info_box = thorpy.Box(self.elements)
     self.menu = thorpy.Menu(self.info_box)
     #Can't start the network stuff until all the gui elements are created
     self.make_save_score_thread() #start saving score in a separate thread
     self.render()
     self.start()
Exemplo n.º 6
0
    def game_status(self, window, screen_width: int):
        """
        Display the game status for the main indexes
        :param window - Surface it wil be created on
        :param screen_width - Width of the surface
        :return:
        """
        title = thorpy.OneLineText('Game Status')
        title.set_font_size(15)
        title.set_font_color(self.white)

        cfc = thorpy.Element("CFC: 8%")
        cfc.set_font_size(10)
        cfc.set_size((60, 25))

        sf9 = thorpy.Element("SF9: 9%")
        sf9.set_font_size(10)
        sf9.set_size((60, 25))

        methane = thorpy.Hoverable("Methane: 100%")
        methane.set_font_size(10)
        methane.set_size((100, 25))

        box = thorpy.Box(elements=[title, cfc, sf9, methane])
        box.surface = window
        box.set_topleft((screen_width - 220, self.distance_from_border))
        box.set_main_color(self.status_color)
        box.blit()
        box.update()
Exemplo n.º 7
0
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()
Exemplo n.º 8
0
 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)
Exemplo n.º 9
0
 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)
Exemplo n.º 10
0
 def create_menu(self):
     self.background_image()
     thorpy.set_theme("round")
     b_text = ["Start Game", "Load Game", "Instructions", "Quit"]
     buttons = [
         thorpy.make_button(txt, func=self.menu_func[txt]) for txt in b_text
     ]
     [button.set_font_size(30) for button in buttons]
     [button.scale_to_title() for button in buttons]
     self.menu_box = thorpy.Box(buttons)
     menu = thorpy.Menu(self.menu_box)
     self.proper_display(menu, self.menu_box)
     pg.display.update()
     return menu
Exemplo n.º 11
0
 def environmental_indexes(self, window, screen_height: int, index: str):
     """
     Creates the social object box
     :param window - Surface it wil be created on
     :param screen_height - Height of the surface
     :param index - Which index will be displayed
     :return:
     """
     text = thorpy.MultilineText(index, (75, screen_height / 4))
     title = thorpy.OneLineText('Environmental')
     box = thorpy.Box(elements=[title, text])
     box.surface = window
     box.set_topleft((self.distance_from_border, screen_height / 2))
     box.set_main_color(self.purple)
     box.blit()
     box.update()
Exemplo n.º 12
0
 def news_box(self, window, screen_width: int, news: str, color: tuple):
     """
     Creates a news box object
     :param window - Surface it will be created on
     :param screen_width - Width of the surface
     :param news - Which news will be displayed
     :param color - Which  color will be used, based on the news level
     :return:
     """
     text = thorpy.MultilineText(news, (screen_width / 2, 70))
     box = thorpy.Box(elements=[text])
     box.surface = window
     box.set_topleft((screen_width / 4, self.distance_from_border))
     box.set_main_color(color)
     box.blit()
     box.update()
Exemplo n.º 13
0
    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
Exemplo n.º 14
0
def Menu():
    '''Создает окно запуска'''
    button_play = thorpy.make_button("Play",start_execution)
    timer = thorpy.OneLineText("Seconds passed")
    box = thorpy.Box(elements=[
        button_play,
        timer])
    my_reaction = thorpy.Reaction(reacts_to=thorpy.constants.THORPY_EVENT,
                                  reac_func=start_execution)
    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
Exemplo n.º 15
0
def launch_menu(choices):
    title = thorpy.make_text("Выбери уровень", 14, (0, 0, 0))

    def at_press(what):
        global picked_level
        picked_level = what
        thorpy.functions.quit_menu_func()

    elements = []
    for text in choices:
        element1 = thorpy.make_button(text, func=at_press)
        element1.user_params = {"what": text}
        elements.append(element1)
    box1 = thorpy.Box([title] + elements)
    box1.set_main_color((200, 200, 200, 150))
    box1.center()
    m = thorpy.Menu(box1)
    m.play()
Exemplo n.º 16
0
 def turn_number(self, window, screen_width: int, turn_number: int):
     """
     :param window - Surface it wil be created on
     :param screen_width - Width of the surface
     :param turn_number - Number of the turn the players is on
     :return:
     """
     title = thorpy.OneLineText('Turn')
     title.set_font_color(self.white)
     title.set_font_size(18)
     text = thorpy.OneLineText(
         str(turn_number))  # Turn number must be transformed to string
     text.set_font_size(30)
     text.set_font_color(self.white)
     box = thorpy.Box(elements=[title, text])
     box.surface = window
     box.set_topleft((screen_width - 53, self.distance_from_border))
     box.set_main_color(self.turn_main_color)
     box.blit()
     box.update()
Exemplo n.º 17
0
    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
Exemplo n.º 18
0
def launch_menu(choices):
    title = thorpy.make_text("Choose something", 14, (255, 0, 0))

    #now define the behaviour of clicked elements
    def at_press(what):
        some_text.set_text(what)  #change the element content (see below)
        thorpy.functions.quit_menu_func()  #exit the menu
        thorpy.store(background)  #align the elements (size has changed)
        background.unblit_and_reblit()

    #dynamically create elements
    elements = []
    for text in choices:
        element = thorpy.make_button(text, func=at_press)
        element.user_params = {"what": text}
        elements.append(element)
    #box to store everything
    box = thorpy.Box([title] + elements)
    box.set_main_color((200, 200, 200, 150))
    box.center()
    m = thorpy.Menu(box)
    m.play()
Exemplo n.º 19
0
    def givePrizesLoader(self):
        #This page prints the number of prizes the pupil gets
        print("Reached Here - Prize loader page")
        if self.correctQns == 0:
            self.encouragementText = thorpy.make_text(
                'Good try, but you did not get \nany questions correct.', 50,
                (0, 0, 0, 100))
        else:
            self.encouragement = 'Great job! You got ' + str(
                self.correctQns) + ' question(s) correct!'
            self.encouragementText = thorpy.make_text(self.encouragement, 50,
                                                      (0, 0, 0, 100))

        self.encouragementText.center()
        self.encouragementText.set_topleft((None, 6))

        self.prizesToGive = self.correctQns
        if self.correctQns == 2:
            self.prizesToGive = self.prizesToGive + 1
        self.textPrizesToGive = 'You get ' + str(
            self.prizesToGive) + ' prize(s)!'
        self.prizesToGiveElement = thorpy.make_text(self.textPrizesToGive, 40,
                                                    (4, 2, 158, 100))

        self.givePrizesBox = thorpy.Box(
            elements=[self.prizesToGiveElement, self.OKbutton2])
        self.givePrizesBox.fit_children(margins=(10,
                                                 10))  #We want small margins
        self.givePrizesBox.center()  #Center on screen
        self.givePrizesBox.set_topleft((None, 60))
        self.givePrizesBox.set_main_color(
            (220, 220, 220, 180))  #set box color and opacity

        self.givePrize = thorpy.Background(
            image="prize.jpg",
            elements=[self.encouragementText, self.givePrizesBox])

        self.givePrizePage = thorpy.Menu(self.givePrize)
        self.givePrizePage.play()
Exemplo n.º 20
0
	def __init__(self, **args):
		COLOR = (0, 0, 0)
		TFUENTE = 10

		self._elementos = args['elementos']
		self._etiquetas = OrderedDict()
		if 'elementos' in args:
			self._elementos = args['elementos']
			#por cada elemento en el arreglo, hacer un texto y asignarselo a ese elemento
			for elemento in args['elementos']:
				self._etiquetas[elemento] = thorpy.make_text(elemento, TFUENTE, COLOR)

		#asinaciones específicas
		if 'particula' in args:
			self._particula = args['particula']
		else:
			self._particula = None

		if 'posicion' in args:
			posicion = args['posicion']
		else:
			posicion = (150, 0)

		if 'tamano' in args:
			tamano = args['tamano']
		else:
			pass#tamano = (500, 200)

		self._caja = thorpy.Box(elements=[e for e in self._etiquetas.values()],
			size=tamano)
		self._caja.set_topleft(posicion)
		self._caja.blit()
		self._caja.update()

		self._menu = thorpy.Menu()
		self._menu.add_to_population(self._caja)
Exemplo n.º 21
0
def run():
    import thorpy
    application = thorpy.Application((600, 600), "ThorPy test")

    ##thorpy.theme.set_theme("human")

    #### SIMPLE ELEMENTS ####

    ghost = thorpy.Ghost()
    ghost.finish()

    element = thorpy.Element("Element")
    element.finish()
    thorpy.makeup.add_basic_help(
        element, "Element instance:\nMost simple graphical element.")

    clickable = thorpy.Clickable("Clickable")
    clickable.finish()
    clickable.add_basic_help(
        "Clickable instance:\nCan be hovered and pressed.")

    draggable = thorpy.Draggable("Draggable")
    draggable.finish()
    thorpy.makeup.add_basic_help(draggable,
                                 "Draggable instance:\nYou can drag it.")

    #### SIMPLE Setters ####

    checker_check = thorpy.Checker("Checker")
    checker_check.finish()
    thorpy.makeup.add_basic_help(
        checker_check, "Checker instance:\nHere it is of type 'checkbox'.")

    checker_radio = thorpy.Checker("Radio", typ="radio")
    checker_radio.finish()
    thorpy.makeup.add_basic_help(
        checker_radio, "Checker instance:\nHere it is of type 'radio'.")

    browser = thorpy.Browser("../../", text="Browser")
    browser.finish()
    browser.set_prison()

    browserlauncher = thorpy.BrowserLauncher(browser,
                                             name_txt="Browser",
                                             file_txt="Nothing selected",
                                             launcher_txt="...")
    browserlauncher.finish()
    browserlauncher.scale_to_title()
    thorpy.makeup.add_basic_help(
        browserlauncher,
        "Browser instance:\nA way for user to find a file or" +
        "\na folder on the computer.")

    dropdownlist = thorpy.DropDownListLauncher(
        name_txt="DropDownListLauncher",
        file_txt="Nothing selected",
        titles=[str(i) for i in range(1, 9)])
    dropdownlist.finish()
    dropdownlist.scale_to_title()
    thorpy.makeup.add_basic_help(dropdownlist,
                                 "DropDownList:\nDisplay a list of choices.")

    slider = thorpy.SliderX(120, (5, 12),
                            "Slider: ",
                            typ=float,
                            initial_value=8.4)
    slider.finish()
    thorpy.makeup.add_basic_help(
        slider, "SliderX:\nA way for user to select a value." +
        "\nCan select any type of number (int, float, ..).")
    slider.set_center

    inserter = thorpy.Inserter(name="Inserter: ", value="Write here.")
    inserter.finish()
    thorpy.makeup.add_basic_help(
        inserter, "Inserter:\nA way for user to insert a value.")

    text_title = thorpy.make_text("Test Example", 25, (0, 0, 255))

    central_box = thorpy.Box("", [
        ghost, element, clickable, draggable, checker_check, checker_radio,
        dropdownlist, browserlauncher, slider, inserter
    ])
    central_box.finish()
    central_box.center()
    central_box.add_lift()
    central_box.set_main_color((200, 200, 255, 120))

    background = thorpy.Background(color=(200, 200, 200),
                                   elements=[text_title, central_box])
    background.finish()

    thorpy.store(background)

    menu = thorpy.Menu(background)
    menu.play()

    application.quit()
Exemplo n.º 22
0
    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
Exemplo n.º 23
0
    def update_thorpy(self):
        # tasks
        if self.draw_ui_tasks:
            goal = thorpy.MultilineText(str(self.ai_player.current_goal),
                                        (220, 50))
            task = thorpy.MultilineText(str(self.ai_player.current_task),
                                        (220, 50))
            task_list = thorpy.MultilineText(
                str(self.ai_player.task_list.elements), (220, 600))
            self.box = thorpy.Box(elements=[goal, task, task_list])
            self.box.blit()
            self.box.update()

        # resources
        if self.draw_ui_resources:
            resources = thorpy.MultilineText(
                "Trees: " + str(
                    len(
                        self.ai_player.entities_where(
                            lambda e: isinstance(e, entities.Tree)))) +
                "          Coal: " + str(
                    len(
                        self.ai_player.entities_where(
                            lambda e: isinstance(e, entities.Coal)))) +
                "          IronOre: " + str(
                    len(
                        self.ai_player.entities_where(
                            lambda e: isinstance(e, entities.IronOre)))) +
                "          IronBar: " + str(
                    len(
                        self.ai_player.entities_where(
                            lambda e: isinstance(e, entities.IronBar)))) +
                "          Swords: " + str(
                    len(
                        self.ai_player.entities_where(
                            lambda e: isinstance(e, entities.Sword)))),
                (600, 30))
            self.box_r = thorpy.Box(elements=[resources])
            self.box_r.set_topleft((230, 0))
            self.box_r.blit()
            self.box_r.update()

        # units
        if self.draw_ui_entities:
            units = thorpy.MultilineText(
                "Workers: " + str(
                    len(
                        self.ai_player.entities_where(
                            lambda e: isinstance(e, entities.UnitWorker)))) +
                "          Explorers: " + str(
                    len(
                        self.ai_player.entities_where(
                            lambda e: isinstance(e, entities.UnitExplorer)))) +
                "          Artisans: " + str(
                    len(
                        self.ai_player.entities_where(
                            lambda e: isinstance(e, entities.UnitArtisan)))) +
                "          Soldiers: " + str(
                    len(
                        self.ai_player.entities_where(
                            lambda e: isinstance(e, entities.UnitSoldier)))),
                (500, 30))
            self.box_u = thorpy.Box(elements=[units])
            self.box_u.set_topleft((230, 40))
            self.box_u.blit()
            self.box_u.update()
Exemplo n.º 24
0
 def set_up_thorpy(self):
     self.jump_bar = thorpy.LifeBar("jump cool-down")
     self.jump_box = thorpy.Box([self.jump_bar])
     self.main_box = thorpy.Box([self.jump_box])
     #other_box = thorpy.Box()
     menu = thorpy.Menu(self.main_box)
Exemplo n.º 25
0
 def set_up(self):
     self.info_box = thorpy.Box(self.elements)
     self.menu = thorpy.Menu(self.info_box)
     self.render()
     self.start()
Exemplo n.º 26
0
    screen = pygame.display.set_mode(size)
    pygame.display.set_caption('Not Meat Boy')
    screen.fill('blue')

    # Флаги, связанные с запуском уровня
    picked_level = None
    level_has_started = False
    level_has_just_ended = False
    start_next_level = False

    # Интерфейс с thorpy
    exit_button = thorpy.make_button('Выход', thorpy.functions.quit_func)
    choices = [str(i + 1) for i in range(8)]
    button = thorpy.make_button("Начать игру", launch_menu,
                                {"choices": choices})
    box = thorpy.Box(elements=[button, exit_button])
    box.center()
    menu = thorpy.Menu(box)

    for element in menu.get_population():
        element.surface = screen

    box.set_topleft((197, 208))
    box.blit()
    box.update()

    clock = pygame.time.Clock()
    FPS = 60

    tile_images = {
        'wall': load_image('ground.png'),
Exemplo n.º 27
0
def make_thorpy_interface():
    TE = gui_properties['THORPY_ELEMENTS']
    DOUBLE_CLICK_TIME, TOOLBOX_COLOR, TOOLBOX_HEIGHT, TOOLBOX_WIDTH, COLOR_BOX_COLORS, COLOR_BOX_RECT_TUPLES = gui_properties[
        'DOUBLE_CLICK_TIME'], gui_properties['TOOLBOX_COLOR'], gui_properties[
            'TOOLBOX_HEIGHT'], gui_properties['TOOLBOX_WIDTH'], gui_properties[
                'COLOR_BOX_COLORS'], gui_properties['COLOR_BOX_RECT_TUPLES']
    SELECTED_COLOR_INDEX_SINGLE_CLICK, SELECTED_COLOR_INDEX_DOUBLE_CLICK, SELECTED_COLOR, SMOKE_COLOR = gui_properties[
        'SELECTED_COLOR_INDEX_SINGLE_CLICK'], gui_properties[
            'SELECTED_COLOR_INDEX_DOUBLE_CLICK'], gui_properties[
                'SELECTED_COLOR'], gui_properties['SMOKE_COLOR']
    PYGAME_ELEMENTS, COLOR_BOX_EVENT = gui_properties[
        'PYGAME_ELEMENTS'], gui_properties['COLOR_BOX_EVENT']

    TE['clear_clickable'] = thorpy.make_button("Clear", func=clear_data)
    TE['exit_clickable'] = thorpy.make_button("Exit",
                                              func=thorpy.functions.quit_func)
    TE['vel_clickable'] = thorpy.make_button("Show Velocity", func=None)
    if webbrowser_available:
        TE['help_clickable'] = thorpy.make_button("Help", func=None)
        TE['help_clickable'].set_size((TOOLBOX_WIDTH - 10, 40))
    TE['viscosity_slider'] = thorpy.SliderX(length=123,
                                            limvals=(0, 999),
                                            text="Visc:",
                                            type_=int)
    TE['force_slider'] = thorpy.SliderX(length=120,
                                        limvals=(0, 999),
                                        text="Force:",
                                        type_=int)
    TE['buoyancy_text'] = thorpy.OneLineText(text="Buoyant Force:",
                                             elements=None)
    TE['buoyancy_text'].set_font_size(16)
    TE['red_buoyancy_slider'] = thorpy.SliderX(length=126,
                                               limvals=(-300, 300),
                                               text="Red:",
                                               type_=int)
    TE['green_buoyancy_slider'] = thorpy.SliderX(length=116,
                                                 limvals=(-300, 300),
                                                 text="Green:",
                                                 type_=int)
    TE['blue_buoyancy_slider'] = thorpy.SliderX(length=125,
                                                limvals=(-300, 300),
                                                text="Blue:",
                                                type_=int)
    TE['dissipation_text'] = thorpy.OneLineText(text="Dissipation:",
                                                elements=None)
    TE['dissipation_text'].set_font_size(16)
    TE['red_dissipation_slider'] = thorpy.SliderX(length=127,
                                                  limvals=(0, 1.5),
                                                  text="Red:",
                                                  type_=float)
    TE['green_dissipation_slider'] = thorpy.SliderX(length=120,
                                                    limvals=(0, 1.5),
                                                    text="Green:",
                                                    type_=float)
    TE['blue_dissipation_slider'] = thorpy.SliderX(length=127,
                                                   limvals=(0, 1.5),
                                                   text="Blue:",
                                                   type_=float)
    TE['force_slider'].set_value(simulation_properties['force'] * 50)
    TE['viscosity_slider'].set_value(gui_properties['VISC_SLIDER_VALUE'])
    TE['red_buoyancy_slider'].set_value(
        simulation_properties['temp_source_red'])
    TE['green_buoyancy_slider'].set_value(
        simulation_properties['temp_source_green'])
    TE['blue_buoyancy_slider'].set_value(
        simulation_properties['temp_source_blue'])
    TE['red_dissipation_slider'].set_value(
        simulation_properties['smoke_diff_away_red'])
    TE['green_dissipation_slider'].set_value(
        simulation_properties['smoke_diff_away_green'])
    TE['blue_dissipation_slider'].set_value(
        simulation_properties['smoke_diff_away_blue'])
    TE['cs'] = thorpy.ColorSetter(
        "Choose a color",
        value=COLOR_BOX_COLORS[SELECTED_COLOR_INDEX_DOUBLE_CLICK])
    TE['cs'].set_size((TOOLBOX_WIDTH - 10, 135))
    TE['clear_clickable'].set_size((TOOLBOX_WIDTH - 10, 40))
    TE['exit_clickable'].set_size((TOOLBOX_WIDTH - 10, 40))
    TE['vel_clickable'].set_size((TOOLBOX_WIDTH - 10, 40))

    TE['cs_clickable'] = thorpy.make_button("Set Color")
    TE['cs_clickable'].set_size((TOOLBOX_WIDTH - 10, 40))

    elements = [
        TE['cs'], TE['cs_clickable'], TE['vel_clickable'],
        TE['viscosity_slider'], TE['force_slider'], TE['buoyancy_text'],
        TE['red_buoyancy_slider'], TE['green_buoyancy_slider'],
        TE['blue_buoyancy_slider'], TE['dissipation_text'],
        TE['red_dissipation_slider'], TE['green_dissipation_slider'],
        TE['blue_dissipation_slider'], TE['clear_clickable'],
        TE['exit_clickable'], TE['help_clickable']
    ]
    TE['central_box'] = thorpy.Box(elements=elements)
    central_box_color = tuple(list(TOOLBOX_COLOR) +
                              [255])  #need to add an alpha value
    TE['central_box'].set_main_color(
        central_box_color)  #set box color and opacity
    TE['menu'] = thorpy.Menu(TE['central_box'])
    for element in TE['menu'].get_population():
        element.surface = gui_properties['SCREEN']

    TE['central_box'].set_topleft((0, 53))
    TE['central_box'].set_size((TOOLBOX_WIDTH, TOOLBOX_HEIGHT + 70))

    TE['central_box'].blit()
    TE['central_box'].update()
Exemplo n.º 28
0
timerLineInserter = thorpy.Inserter("Timer Line Keybind",
                                    value=str(pygame.key.name(timerLine)),
                                    size=(100, 20))
timerResetInserter = thorpy.Inserter("Timer Reset Keybind",
                                     value=str(pygame.key.name(timerReset)),
                                     size=(100, 20))
timerPauseInserter = thorpy.Inserter("Timer Pause Keybind",
                                     value=str(pygame.key.name(timerPause)),
                                     size=(100, 20))
timerEraseInserter = thorpy.Inserter("Timer Erase Keybind",
                                     value=str(pygame.key.name(timerErase)),
                                     size=(100, 20))
measureEraseInserter = thorpy.Inserter("Measure Erase Keybind",
                                       value=str(
                                           pygame.key.name(measureErase)),
                                       size=(100, 20))
simPauseInserter = thorpy.Inserter("Pause Simulation Keybind",
                                   value=str(pygame.key.name(simPause)),
                                   size=(100, 20))
bgColourSelector = thorpy.ColorSetter("Background Colour",
                                      value=[255, 255, 255])
exitButton = thorpy.make_button("Exit Program", leave)
container = thorpy.Box(elements=[
    forceInserter, scaleInserter, timerLineInserter, timerResetInserter,
    timerPauseInserter, timerEraseInserter, measureEraseInserter,
    simPauseInserter, bgColourSelector, exitButton
],
                       size=(850, 650))
container.set_main_color([100, 100, 100])
menu = thorpy.Menu(elements=[container])
menu.play()
Exemplo n.º 29
0
def run():
    application = thorpy.Application((800, 600), "ThorPy Overview")

    element = thorpy.Element("Element")
    thorpy.makeup.add_basic_help(element,
                                 "Element:\nMost simple graphical element.")

    clickable = thorpy.Clickable("Clickable")
    thorpy.makeup.add_basic_help(clickable,
                                 "Clickable:\nCan be hovered and pressed.")

    draggable = thorpy.Draggable("Draggable")
    thorpy.makeup.add_basic_help(draggable, "Draggable:\nYou can drag it.")

    checker_check = thorpy.Checker("Checker")

    checker_radio = thorpy.Checker("Radio", type_="radio")

    browser = thorpy.Browser("../../", text="Browser")

    browserlauncher = thorpy.BrowserLauncher.make(browser,
                                                  const_text="Choose file:",
                                                  var_text="")
    browserlauncher.max_chars = 20  #limit size of browser launcher

    dropdownlist = thorpy.DropDownListLauncher(
        const_text="Choose number:",
        var_text="",
        titles=[str(i) * i for i in range(1, 9)])
    dropdownlist.scale_to_title()
    dropdownlist.max_chars = 20  #limit size of drop down list

    slider = thorpy.SliderX(80, (5, 12),
                            "Slider: ",
                            type_=float,
                            initial_value=8.4)

    inserter = thorpy.Inserter(name="Inserter: ", value="Write here.")

    quit = thorpy.make_button("Quit", func=thorpy.functions.quit_menu_func)

    title_element = thorpy.make_text("Overview example", 22, (255, 255, 0))

    elements = [
        element, clickable, draggable, checker_check, checker_radio,
        dropdownlist, browserlauncher, slider, inserter, quit
    ]
    central_box = thorpy.Box(elements=elements)
    central_box.fit_children(margins=(30, 30))  #we want big margins
    central_box.center()  #center on screen
    central_box.add_lift()  #add a lift (useless since box fits children)
    central_box.set_main_color(
        (220, 220, 220, 180))  #set box color and opacity

    background = thorpy.Background.make(image=thorpy.style.EXAMPLE_IMG,
                                        elements=[title_element, central_box])
    thorpy.store(background)

    menu = thorpy.Menu(background)
    menu.play()

    application.quit()
Exemplo n.º 30
0
#screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
pygame.display.set_caption('Ball Game')

balls = pygame.sprite.Group()
clock = pygame.time.Clock()

maxMass = 75
minMass = 10

massSlider = thorpy.SliderX(maxMass - minMass, [minMass, maxMass],
                            'Mass slider             ',
                            type_=int)
massSlider.set_font_size(14)
quitButton = thorpy.make_button('Quit', func=thorpy.functions.quit_func)
quitButton.set_font_size(14)
box = thorpy.Box(elements=[massSlider, quitButton])

box.set_main_color([255, 255, 255])
box_xsize = 100
box_ysize = 5
box.enlarge([box_xsize, box_ysize])
menu = thorpy.Menu(box)

for element in menu.get_population():
    element.surface = screen

box.set_topleft([
    SCREEN_WIDTH / 2 - box_xsize,
    SCREEN_HEIGHT - (SCREEN_HEIGHT - PLAYCREEN_HEIGHT) + box_ysize
])