示例#1
0
 def set_text(self, new_text):
     if isinstance(new_text, str):
         if '\n' in new_text:
             self.texts = [core.Text(s) for s in new_text.split('\n')]
             self.text_rects = [
                 t.font.render(t.value, 1, core.WHITE) for t in self.texts
             ]
         else:
             self.text = core.Text(new_text)
             self.text_rect = self.text.font.render(self.text.value, 1,
                                                    core.WHITE)
     else:
         if '\n' in new_text.value:
             self.texts = [
                 core.Text(s.lstrip(' '), new_text.size, new_text.color,
                           new_text.font_name, new_text.bold,
                           new_text.italic)
                 for s in new_text.value.split('\n')
             ]
             self.text_rects = [
                 t.font.render(t.value, 1, t.color) for t in self.texts
             ]
         else:
             self.text = new_text
             self.text_rect = self.text.font.render(self.text.value, 1,
                                                    new_text.color)
     self.half_w = self.dimensions[0] / 2
     self.half_h = self.dimensions[1] / 2
     if not self.text_rects:
         self.text_w = self.text_rect.get_rect().width
         self.text_h = self.text_rect.get_rect().height
         self.half_text_w = self.text_w / 2
         self.half_text_h = self.text_h / 2
示例#2
0
 def __init__(self):
     self.panel = widgets.Panel(
         core.Grid((3, 9),
                   (options["RESOLUTION"][0], options["RESOLUTION"][1])),
         None, None, (0, 0))
     self.panel.set_color(core.BLACK)
     self.title = widgets.TextLabel(
         self.panel, (0, 0),
         core.Text("ArcRacer", TITLE_SIZE, MENU_COLOR, MENU_FONT, MENU_BOLD,
                   True))
     self.title.text.font.set_bold(True)
     self.title.set_alignment(widgets.TextLabel.ALIGN_CENTER)
     self.title.set_span((2, 1))
     self.buttons = [
         widgets.TextButton(
             self.panel, (1, 3),
             core.Text("Single Player", MENU_SIZE, MENU_COLOR, MENU_FONT,
                       MENU_BOLD)),
         widgets.TextButton(
             self.panel, (1, 4),
             core.Text("Multiplayer", MENU_SIZE, MENU_COLOR, MENU_FONT,
                       MENU_BOLD)),
         widgets.TextButton(
             self.panel, (1, 5),
             core.Text("Custom Game", MENU_SIZE, MENU_COLOR, MENU_FONT,
                       MENU_BOLD)),
         widgets.TextButton(
             self.panel, (1, 6),
             core.Text("Exit", MENU_SIZE, MENU_COLOR, MENU_FONT, MENU_BOLD))
     ]
     [b.set_color(core.BLACK) for b in self.buttons]
     [b.set_alignment(widgets.TextLabel.ALIGN_CENTER) for b in self.buttons]
     [b.set_border(core.WHITE, 16) for b in self.buttons]
示例#3
0
    def __init__(self, parent, position_in_grid, values=[], default_index=0):
        Panel.__init__(
            self,
            core.Grid((6, 1),
                      (parent.get_cell_width(), parent.get_cell_height())),
            parent=parent,
            position_in_grid=position_in_grid,
            pos=None)
        # self.set_color(core.TRANSPARENT)

        self.previous_button = RectButton(self, (0, 0))
        self.previous_button.set_color(core.TRANSPARENT)
        self.previous_button.set_image(
            os.path.join(os.path.dirname(os.path.abspath(__file__)),
                         "gfx/gray_arrow_0.png"))
        self.values = values
        self.index = default_index
        if (self.values):
            self.current_value = self.values[self.index]
        else:
            self.current_value = "Undefined"
        self.text_size = 32
        self.text_color = core.WHITE
        self.font_name = "monospace"
        self.bold = False
        self.italic = False
        self.label = TextLabel(self, (0, 0), core.Text(self.current_value))
        self.label.set_span((5, 0))
        self.label.set_color(core.TRANSPARENT)
        self.forward_button = RectButton(self, (5, 0))
        self.forward_button.set_color(core.TRANSPARENT)
        self.forward_button.set_image(
            os.path.join(os.path.dirname(os.path.abspath(__file__)),
                         "gfx/gray_arrow_1.png"))
示例#4
0
 def __init__(self):
     self.panel = widgets.Panel(
         core.Grid((1, 1),
                   (options["RESOLUTION"][0], options["RESOLUTION"][1])),
         None, None, (0, 0))
     self.title = widgets.TextLabel(
         self.panel, (0, 0),
         core.Text("Paused", 64, core.WHITE, "arial", True, True))
示例#5
0
 def set_text(self, value, size):
     self.text_value = value
     self.text_size = size
     self.half_w = self.dimensions[0] / 2
     self.half_h = self.dimensions[1] / 2
     self.text = core.Text(self.text_value, self.text_size)
     self.text_rect = self.text.font.render(self.text.value, 1,
                                            self.text.color)
     self.half_text_w = self.text_rect.get_rect().width / 2
     self.half_text_h = self.text_rect.get_rect().height / 2
示例#6
0
 def __init__(self, gm):
     self.panel = widgets.Panel(
         core.Grid((6, 12),
                   (options["RESOLUTION"][0], options["RESOLUTION"][1])),
         None, None, (0, 0))
     self.panel.set_color(core.BLACK)
     self.title = widgets.TextLabel(
         self.panel, (0, 0),
         core.Text("Race Options", TITLE_SIZE, RACE_OPTIONS_MENU_COLOR,
                   RACE_OPTIONS_MENU_FONT, RACE_OPTIONS_MENU_BOLD,
                   MENU_ITALIC))
     self.title.text.font.set_bold(True)
     self.title.set_alignment(widgets.TextLabel.ALIGN_CENTER)
     self.title.set_span((5, 1))
     self.components = [
         widgets.TextButton(
             self.panel, (1, 3),
             core.Text("Start Race", RACE_OPTIONS_MENU_SIZE,
                       RACE_OPTIONS_MENU_COLOR, RACE_OPTIONS_MENU_FONT,
                       RACE_OPTIONS_MENU_BOLD, RACE_OPTIONS_MENU_ITALIC)),
         widgets.TextLabel(
             self.panel, (1, 4),
             core.Text("Players", RACE_OPTIONS_MENU_SIZE,
                       RACE_OPTIONS_MENU_COLOR, RACE_OPTIONS_MENU_FONT,
                       RACE_OPTIONS_MENU_BOLD, RACE_OPTIONS_MENU_ITALIC)),
         widgets.OptionChooser(self.panel, (3, 4),
                               [str(n) for n in range(0, 6)]),
         widgets.TextLabel(
             self.panel, (1, 5),
             core.Text("Humans", RACE_OPTIONS_MENU_SIZE,
                       RACE_OPTIONS_MENU_COLOR, RACE_OPTIONS_MENU_FONT,
                       RACE_OPTIONS_MENU_BOLD, RACE_OPTIONS_MENU_ITALIC)),
         widgets.OptionChooser(self.panel, (3, 5),
                               [str(n) for n in range(0, 3)]),
         widgets.TextLabel(
             self.panel, (1, 6),
             core.Text("Difficulty", RACE_OPTIONS_MENU_SIZE,
                       RACE_OPTIONS_MENU_COLOR, RACE_OPTIONS_MENU_FONT,
                       RACE_OPTIONS_MENU_BOLD, RACE_OPTIONS_MENU_ITALIC)),
         widgets.OptionChooser(
             self.panel, (3, 6),
             ["Easy", "Normal", "Hard", "Insane", "Arcturian"], 1),
         widgets.TextLabel(
             self.panel, (1, 7),
             core.Text("Laps", RACE_OPTIONS_MENU_SIZE,
                       RACE_OPTIONS_MENU_COLOR, RACE_OPTIONS_MENU_FONT,
                       RACE_OPTIONS_MENU_BOLD, RACE_OPTIONS_MENU_ITALIC)),
         widgets.OptionChooser(
             self.panel, (3, 7),
             ["5", "10", "15", "20", "25", "30", "35", "40", "45", "50"],
             2),
         widgets.TextLabel(
             self.panel, (1, 8),
             core.Text("Track", RACE_OPTIONS_MENU_SIZE,
                       RACE_OPTIONS_MENU_COLOR, RACE_OPTIONS_MENU_FONT,
                       RACE_OPTIONS_MENU_BOLD, RACE_OPTIONS_MENU_ITALIC)),
         widgets.OptionChooser(self.panel, (3, 8), gm.get_track_list()),
         widgets.TextButton(
             self.panel, (1, 9),
             core.Text("Return", RACE_OPTIONS_MENU_SIZE,
                       RACE_OPTIONS_MENU_COLOR, RACE_OPTIONS_MENU_FONT,
                       RACE_OPTIONS_MENU_BOLD, RACE_OPTIONS_MENU_ITALIC))
     ]
     [c.set_color(core.BLACK) for c in self.components]
     [
         c.set_alignment(widgets.TextLabel.ALIGN_CENTER)
         if not isinstance(c, widgets.OptionChooser) else
         c.label.set_alignment(widgets.TextLabel.ALIGN_CENTER)
         for c in self.components
     ]
     [
         c.set_span((1, 0)) if c != self.components[0]
         and c != self.components[len(self.components) - 1] else c.set_span(
             (3, 0)) for c in self.components
     ]
     [c.set_border(core.WHITE, 16) for c in self.components]
示例#7
0
    def __init__(self, gm):
        self.panel = widgets.Panel(
            core.Grid((6, 16),
                      (options["RESOLUTION"][0], options["RESOLUTION"][1])),
            None, None, (0, 0))
        self.panel.set_color(core.BLACK)

        self.title = widgets.TextLabel(
            self.panel, (0, 1),
            core.Text("RESULTS", TITLE_SIZE, MENU_COLOR, MENU_FONT, MENU_BOLD,
                      True), widgets.TextLabel.ALIGN_CENTER)
        self.title.set_span((5, 0))
        self.components = [
            widgets.TextLabel(
                self.panel, (1, 4),
                core.Text("Player 1: ", RESULTS_SIZE, MENU_COLOR, RESULTS_FONT,
                          MENU_BOLD, True)),
            widgets.TextLabel(
                self.panel, (2, 4),
                core.Text("", RESULTS_SIZE, MENU_COLOR, RESULTS_FONT,
                          MENU_BOLD, True)),  # Player 1 Time (Index 1)
            widgets.TextLabel(
                self.panel, (3, 4),
                core.Text("", RESULTS_SIZE, MENU_COLOR, RESULTS_FONT,
                          MENU_BOLD, True)),  # Player 1 Result (Index 2)
            widgets.TextLabel(
                self.panel, (1, 5),
                core.Text("Player 2: ", RESULTS_SIZE, MENU_COLOR, RESULTS_FONT,
                          MENU_BOLD, True)),
            widgets.TextLabel(
                self.panel, (2, 5),
                core.Text("", RESULTS_SIZE, MENU_COLOR, RESULTS_FONT,
                          MENU_BOLD, True)),  # Player 2 Time (Index 4)
            widgets.TextLabel(
                self.panel, (3, 4),
                core.Text("", RESULTS_SIZE, MENU_COLOR, RESULTS_FONT,
                          MENU_BOLD, True)),  # Player 2 Result (Index 5)
            widgets.TextLabel(
                self.panel, (1, 6),
                core.Text("Player 3: ", RESULTS_SIZE, MENU_COLOR, RESULTS_FONT,
                          MENU_BOLD, True)),
            widgets.TextLabel(
                self.panel, (2, 6),
                core.Text("", RESULTS_SIZE, MENU_COLOR, RESULTS_FONT,
                          MENU_BOLD, True)),  # Player 3 Time (Index 7)
            widgets.TextLabel(
                self.panel, (3, 4),
                core.Text("", RESULTS_SIZE, MENU_COLOR, RESULTS_FONT,
                          MENU_BOLD, True)),  # Player 3 Result (Index 8)
            widgets.TextLabel(
                self.panel, (1, 7),
                core.Text("Player 4: ", RESULTS_SIZE, MENU_COLOR, RESULTS_FONT,
                          MENU_BOLD, True)),
            widgets.TextLabel(
                self.panel, (2, 7),
                core.Text("", RESULTS_SIZE, MENU_COLOR, RESULTS_FONT,
                          MENU_BOLD, True)),  # Player 4 Time (Index 10)
            widgets.TextLabel(
                self.panel, (3, 4),
                core.Text("", RESULTS_SIZE, MENU_COLOR, RESULTS_FONT,
                          MENU_BOLD, True)),  # Player 4 Result (Index 11)
            widgets.TextLabel(
                self.panel, (1, 8),
                core.Text("Player 5: ", RESULTS_SIZE, MENU_COLOR, RESULTS_FONT,
                          MENU_BOLD, True)),
            widgets.TextLabel(
                self.panel, (2, 8),
                core.Text("", RESULTS_SIZE, MENU_COLOR, RESULTS_FONT,
                          MENU_BOLD, True)),  # Player 5 Time (Index 13)
            widgets.TextLabel(self.panel, (3, 4),
                              core.Text("", RESULTS_SIZE, MENU_COLOR,
                                        RESULTS_FONT, MENU_BOLD,
                                        True))  # Player 5 Result (Index 14)
        ]
        self.buttons = [
            widgets.TextButton(
                self.panel, (2, 12),
                core.Text("Restart", MENU_SIZE, MENU_COLOR, MENU_FONT,
                          MENU_BOLD)),
            widgets.TextButton(
                self.panel, (2, 13),
                core.Text("Quit", MENU_SIZE, MENU_COLOR, MENU_FONT, MENU_BOLD))
        ]
        [b.set_color(core.BLACK) for b in self.buttons]
        [b.set_alignment(widgets.TextLabel.ALIGN_CENTER) for b in self.buttons]
        [b.set_span((1, 0)) for b in self.buttons]
        [b.set_border(core.WHITE, 4) for b in self.buttons]
示例#8
0
from PyGameWidgets import widgets

# Text label example.

WINDOW_WIDTH = 1024
WINDOW_HEIGHT = 728

pygame.init()
pygame.font.init
screen = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
clock = pygame.time.Clock()
FPS = 60
running = True

if __name__ == "__main__":
    text = widgets.TextLabel(None, None, core.Text("Hello World!", 32,
                                                   core.RED))
    text.pos = [200, 300]
    button = widgets.RectButton(None, None)
    button.pos = [
        500,
        400,
    ]
    button.dimensions = [128, 128]
    button.set_color(core.GREEN)

    def redraw():
        pygame.display.flip()
        screen.fill(core.BLACK)
        text.draw(screen)
        button.draw(screen)
示例#9
0
 def update_text(self):
     self.text = core.Text(self.current_value, self.text_size,
                           self.text_color, self.font_name, self.bold,
                           self.italic)
     self.label.set_text(self.text)
示例#10
0
 def __init__(self, gm):
     self.gm = gm
     self.panel = widgets.Panel(
         core.Grid((HUD.WIDTH, HUD.HEIGHT),
                   (options["RESOLUTION"][0], options["RESOLUTION"][1])),
         None, None, (0, 0))
     self.player1_info_panel = widgets.Panel(
         core.Grid((3, HUD.PLAYER_INFO_PANEL_LABELS),
                   self.panel.grid.cell_size), self.panel, (1, 0), None)
     self.player1_info_panel_labels = [
         widgets.TextLabel(
             self.player1_info_panel, (0, 2),
             core.Text("Player 1", HUD.FONT_SIZE, HUD.COLOR, HUD.FONT,
                       HUD.BOLD, HUD.ITALIC)),
         widgets.TextLabel(
             self.player1_info_panel, (0, 4),
             core.Text("Lap:", HUD.FONT_SIZE, HUD.COLOR, HUD.FONT, HUD.BOLD,
                       HUD.ITALIC)),
         widgets.TextLabel(
             self.player1_info_panel, (2, 4),
             core.Text("", HUD.FONT_SIZE, HUD.COLOR, HUD.FONT, HUD.BOLD,
                       HUD.ITALIC)),
         widgets.TextLabel(
             self.player1_info_panel, (0, 6),
             core.Text("Time:", HUD.FONT_SIZE, HUD.COLOR, HUD.FONT,
                       HUD.BOLD, HUD.ITALIC)),
         widgets.TextLabel(
             self.player1_info_panel, (2, 6),
             core.Text("", int(HUD.FONT_SIZE / 2), HUD.COLOR, HUD.FONT,
                       HUD.BOLD, HUD.ITALIC))
     ]
     self.player2_info_panel = widgets.Panel(
         core.Grid((3, HUD.PLAYER_INFO_PANEL_LABELS),
                   self.panel.grid.cell_size), self.panel,
         (HUD.WIDTH - 3, 0), None)
     self.player2_info_panel_labels = [
         widgets.TextLabel(
             self.player2_info_panel, (0, 2),
             core.Text("Player 2", HUD.FONT_SIZE, HUD.COLOR, HUD.FONT,
                       HUD.BOLD, HUD.ITALIC)),
         widgets.TextLabel(
             self.player2_info_panel, (0, 4),
             core.Text("Lap:", HUD.FONT_SIZE, HUD.COLOR, HUD.FONT, HUD.BOLD,
                       HUD.ITALIC)),
         widgets.TextLabel(
             self.player2_info_panel, (2, 4),
             core.Text("", HUD.FONT_SIZE, HUD.COLOR, HUD.FONT, HUD.BOLD,
                       HUD.ITALIC)),
         widgets.TextLabel(
             self.player2_info_panel, (0, 6),
             core.Text("Time:", HUD.FONT_SIZE, HUD.COLOR, HUD.FONT,
                       HUD.BOLD, HUD.ITALIC)),
         widgets.TextLabel(
             self.player2_info_panel, (2, 6),
             core.Text("", int(HUD.FONT_SIZE / 2), HUD.COLOR, HUD.FONT,
                       HUD.BOLD, HUD.ITALIC))
     ]
     self.player1_info_panel_labels[0].set_span((1, 0))
     [
         label.set_color(core.TRANSPARENT)
         for label in self.player1_info_panel_labels
     ]
     self.player2_info_panel_labels[0].set_span((1, 0))
     [
         label.set_color(core.TRANSPARENT)
         for label in self.player2_info_panel_labels
     ]
示例#11
0
                def restart():
                    [p.default() for p in gm.players]
                    sm.change_scene(SceneManager.GAME)

                results.buttons[0].on_click(e, restart)
                results.buttons[1].on_click(e, sm.change_scene,
                                            SceneManager.MAIN_MENU)
            elif sm.scene == SceneManager.GAME:
                intercept_in_game(e)
            elif sm.scene == SceneManager.PAUSE:
                intercept_in_pause(e)
        if sm.scene == SceneManager.RACE_OPTIONS:
            race_options.components[2].current_value = str(
                gm.number_of_players)
            race_options.components[2].text = core.Text(
                gm.number_of_players, ui.RACE_OPTIONS_MENU_SIZE,
                ui.RACE_OPTIONS_MENU_COLOR, ui.RACE_OPTIONS_MENU_FONT,
                ui.RACE_OPTIONS_MENU_BOLD, ui.RACE_OPTIONS_MENU_ITALIC)
            race_options.components[2].update_text()
        elif sm.scene == SceneManager.GAME:
            if gm.players:
                for n in range(gm.number_of_humans):
                    gm.players[n].move()
                for player in gm.players:
                    player.track_time(ms)
                    if not player.reached_lap and player.crossed_lap:
                        # Updating the texts of the player info panels.
                        game_hud.player1_info_panel_labels[2].set_text(
                            core.Text(str(gm.players[0].current_lap),
                                      game_hud.FONT_SIZE, game_hud.COLOR,
                                      game_hud.FONT, game_hud.BOLD,
                                      game_hud.ITALIC))