Esempio n. 1
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()
Esempio n. 2
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
Esempio n. 3
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()
Esempio n. 4
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))
Esempio n. 5
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()
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
Esempio n. 7
0
def apploop(DISPLAY):
    global display_height, display_width
    #main app loo
    pygame.display.set_caption('Planetbox')
    pygame.display.set_icon(ico)

    display_width, display_height = DISPLAY.get_size()
    DISPLAY.fill(RICHBLUE)

    #display background
    Bg = Background('../imgs/bg.jpg', [0, 0])
    DISPLAY.blit(
        pygame.transform.scale(Bg.image, (display_width, display_height)),
        Bg.rect)

    #display sky preview
    Skyprev = SkyPrev(DISPLAY)

    #update
    pygame.display.update()

    #thorpy elements

    #logo
    logo = pygame.image.load('../imgs/logo300.png')

    def radius_check(radius, type):
        if (type == "terrestrial"):
            if (radius < 300):
                return 0
            else:
                return 1
        elif (type == "ice" or type == "gas"):
            if (radius < 200):
                return 0
            else:
                return 1

    # checks if the density is ok
    def density_check(ptype, pmass, prad):
        # pmass: 10^22 kg, prad: km
        rad = prad * 100000  # radius in cm
        vol = (4 / 3) * math.pi * rad * rad * rad  # cm3
        mass = pmass * pow(10, 25)  # g
        g = mass / vol  # g/cm3

        if ptype == "terrestrial":
            if (g < 3.6):  # not sure about this one
                return 0
            elif (g > 28):
                return 1
            else:
                return 2
        elif ptype == "gas" or ptype == "ice":
            if (g < 0.2):  # not sure about this one
                return 0
            elif (g > 17):
                return 1
            else:
                return 2

    #Reading inputs functions

    def read_inserter_func(
            event):  #Reactions functions must take an event as first arg
        global prad, pmass, pname, pdist
        try:
            if (event.el == p_rad):
                prad = event.el.get_value()
                prad = int(prad)
            elif (event.el == p_dist):
                pdist = event.el.get_value()
                pdist = float(pdist)
            elif (event.el == p_mass):
                pmass = event.el.get_value()
                pmass = int(pmass)
            elif (event.el == p_name):
                pname = event.el.get_value()
            elif (event.el == p_kind):
                ptype = event.el.get_value()
        except:  # handling errors
            AlertBox.AlertBox(1, "valueError")
            p_rad.set_value("")
            p_dist.set_value("")
            p_mass.set_value("")
            p_rad.unblit_and_reblit()
            p_dist.unblit_and_reblit()
            p_mass.unblit_and_reblit()

    def reset_simulation():
        simulation.Planets = []
        simulation.PlanetsCord = []
        SkyPrev(DISPLAY)

    # pressing add planet btn reaction
    def readPlanet():
        global prad, pmass, pname, ptype, simulation, pdist
        ptype = p_kind.get_selected().get_text()
        den_val = density_check(ptype, pmass, prad)
        rad_val = radius_check(prad, ptype)
        if den_val == 0 or den_val == 1:  # wrong density
            AlertBox.AlertBox(den_val, "density")
        elif rad_val == 0:  # radius too small
            AlertBox.AlertBox(rad_val, "radius")
        else:
            #print(ptype)
            # create a new planet
            # clean the inserters
            p_rad.set_value("")
            p_rad.unblit_and_reblit()

            p_dist.set_value("")
            p_dist.unblit_and_reblit()

            p_mass.set_value("")
            p_mass.unblit_and_reblit()

            p_name.set_value("")
            p_name.unblit_and_reblit()

            planet = Planet.Planet(prad, pmass, ptype, pdist, pname)
            simulation.AddPlanet(planet)
            # update preview
            SkyPrev(DISPLAY)

    def startExplorer():
        #print("Starting explorer...")
        planetExp.pe_main()

    def startSimulation():
        #simulation.CreateMoons()
        #print("Starting simulation...")
        print(simulation.PrintPlanets())
        simulation_gui.create(simulation)

    # add button: adds planet to a list and updates prev
    addBtn = thorpy.make_button("Add planet", func=readPlanet)
    addBtn.set_size((120, 20))
    addBtn.set_main_color(RICHBLUE)
    addBtn.set_font_color(WHITE)

    # new window: starts simulation
    startBtn = thorpy.make_button("Start simulation", func=startSimulation)
    startBtn.set_size((120, 20))
    startBtn.set_main_color(RICHBLUE)
    startBtn.set_font_color(WHITE)

    # explore planets: lets u choose a planet and prints info about it and moons simulation
    prevBtn = thorpy.make_button("Explore the planets", func=startExplorer)
    prevBtn.set_size((120, 20))
    prevBtn.set_main_color(RICHBLUE)
    prevBtn.set_font_color(WHITE)

    # reset simulation
    resBtn = thorpy.make_button("Reset simulation", func=reset_simulation)
    resBtn.set_size((120, 20))
    resBtn.set_main_color(RICHBLUE)
    resBtn.set_font_color(WHITE)

    # radius input
    p_rad_txt = thorpy.OneLineText(text="Radius of the planet(km):")
    p_rad = thorpy.Inserter(name="", value="", size=(100, 20))

    radReact = thorpy.Reaction(reacts_to=thorpy.constants.THORPY_EVENT,
                               reac_func=read_inserter_func,
                               event_args={
                                   "id": thorpy.constants.EVENT_INSERT,
                                   "el": p_rad
                               })

    p_rad.add_reaction(radReact)

    # distance to the sun input
    p_dist_txt = thorpy.OneLineText(text="Distance to the sun (AU):")
    p_dist = thorpy.Inserter(name="", value="", size=(100, 20))

    distReact = thorpy.Reaction(reacts_to=thorpy.constants.THORPY_EVENT,
                                reac_func=read_inserter_func,
                                event_args={
                                    "id": thorpy.constants.EVENT_INSERT,
                                    "el": p_dist
                                })

    p_dist.add_reaction(distReact)

    # name input
    p_name_txt = thorpy.OneLineText(text="Name of the planet: ")
    p_name = thorpy.Inserter(name="", value="", size=(100, 20))
    nameReact = thorpy.Reaction(reacts_to=thorpy.constants.THORPY_EVENT,
                                reac_func=read_inserter_func,
                                event_args={
                                    "id": thorpy.constants.EVENT_INSERT,
                                    "el": p_name
                                })

    p_name.add_reaction(nameReact)

    # mass input
    p_mass_txt = thorpy.OneLineText(text="Mass of the planet (10^22 kg):")
    p_mass = thorpy.Inserter(name="", value="", size=(100, 20))
    massReact = thorpy.Reaction(reacts_to=thorpy.constants.THORPY_EVENT,
                                reac_func=read_inserter_func,
                                event_args={
                                    "id": thorpy.constants.EVENT_INSERT,
                                    "el": p_mass
                                })

    p_mass.add_reaction(massReact)

    # type of planet input
    radio_txt = thorpy.make_text("Type of the planet: ")
    radios = [
        thorpy.Checker("gas", type_="radio"),
        thorpy.Checker("ice", type_="radio"),
        thorpy.Checker("terrestrial", type_="radio")
    ]
    p_kind = thorpy.RadioPool(radios, first_value=radios[1], always_value=True)

    # title above the preview
    prev_txt = thorpy.make_text("Preview of the planetary system: ", 24, WHITE)
    prev_txt.set_font("Ubuntu.ttf")
    prev_txt.set_topleft((420, 200))

    # blit thingies
    entries = [
        p_rad_txt, p_rad, p_mass_txt, p_mass, p_dist_txt, p_dist, p_name_txt,
        p_name
    ]
    txts = [radio_txt]
    buttons = [addBtn, prevBtn, startBtn, resBtn]
    elements = entries + txts + radios + buttons
    boxBtn = thorpy.Box.make(elements=elements)
    boxBtn.set_main_color(WHITE)
    boxBtn.set_size((260, 500))

    thorpy.store(boxBtn, elements, align="center")

    menu = thorpy.Menu(elements=[prev_txt, boxBtn])

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

    boxBtn.set_topleft((40, 50))
    boxBtn.blit()
    boxBtn.update()
    prev_txt.blit()
    prev_txt.update()
    DISPLAY.blit(logo, (390, 20))
    pygame.display.flip()

    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()
            if event.type == pygame.VIDEORESIZE:
                DISPLAY = pygame.display.set_mode(
                    event.dict['size'],
                    pygame.HWSURFACE | pygame.DOUBLEBUF | pygame.RESIZABLE)
                DISPLAY.blit(
                    pygame.transform.scale(Bg.image, event.dict['size']),
                    (0, 0))
                display_width, display_height = event.dict['size']
                apploop(DISPLAY)
                pygame.display.flip()
            menu.react(event)
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()