Exemplo n.º 1
0
 def resetVars(self):
     self.calculateGeometry()
     self.drawingQueue = Queue()
     self.mousePressed = False
     self.guiState = None
     self.widgets = list()
     self.chessboard = None
     self.chessPieceImageRaw = None
     self.chessPieceImages = None
     self.hasPopUp = False
     self.popUp = None
     self.AI = None
     self.boardAngle = 0
     self.currentBoardAngle = 0
     self.resetSettings()
     self.waitingTime = 0
     self.guiWidgets = {
             GUI.MAIN: lambda: [widget.Image(width / 2.0, height / 2.0, width, height, loadImage("mainImage.jpg"), False), \
                                widget.Button(3 * self.xUnit, 4 * self.yUnit, 4 * self.xUnit, self.yUnit, "2 Players", 0.45 * self.yUnit, color(0), color(255), color(0), 5, \
                                             lambda: self.createSettingsPopUp(), True), \
                                widget.Button(3 * self.xUnit, 5.2 * self.yUnit, 4 * self.xUnit, self.yUnit, "Player vs Computer", 0.45 * self.yUnit, color(0), color(255), color(0), 5, \
                                             lambda: self.settings.__setitem__("AI", True) or self.createSettingsPopUp(), True)],
             GUI.LOAD: lambda: [],
             GUI.GAME: lambda: [widget.Button(0.8 * self.xUnit, 9.45 * self.yUnit, 1.2 * self.xUnit, 0.7 * self.yUnit, "To Menu", 0.3 * self.yUnit, color(0), color(255), color(0), 5, \
                                             lambda: self.switchTo(GUI.MAIN), True),
                                widget.Button(9.2 * self.xUnit, 9.45 * self.yUnit, 1.2 * self.xUnit, 0.7 * self.yUnit, "Rotate", 0.3 * self.yUnit, color(0), color(255), color(0), 5, \
                                             lambda: self.rotate(PI), True)]
             }
Exemplo n.º 2
0
    def createSettingsPopUp(self):
        self.hasPopUp = True
        self.popUp = [widget.Rect(width / 2.0, height / 2.0, width, height, color(1, 200), color(1, 200), 0, False), \  # Tinted Background  
                      \
                      \  # Play Button and Back Button
                      widget.Button(width / 2.0, 8 * self.yUnit, 3 * self.xUnit, self.yUnit, "Play", 0.45 * self.yUnit, color(0), color(255), color(0), 5, \
                                    lambda: self.drawingQueue.put(lambda: image(loadImage("loadingImage.jpg"), width / 2.0, height / 2.0, width, height)) or \
                                    self.drawingQueue.put(lambda: self.destroyPopUp()) or self.drawingQueue.put(lambda: self.switchTo(GUI.LOAD)), True),
                      widget.Button(9 * self.xUnit, 9.5 * self.yUnit, 1.8 * self.xUnit, 0.8 * self.yUnit, "Back", 0.35 * self.yUnit, color(0), color(255), color(0), 5, \
                                    lambda: self.resetSettings() or self.drawingQueue.put(lambda: self.destroyPopUp()), True)]

        self.addThemeChoicesToSettingsPopUp()
        self.addColorChoicesToSettingsPopUp()
        if not self.settings["AI"]:  # Stockfish AI can only play in standard variant
            self.addVariantChoicesToSettingsPopUp()
Exemplo n.º 3
0
    def __init__(self, parent=None, config=None, *a, **k):
        super(RulesOptionsDialog, self).__init__(parent=parent, *a, **k)

        self.separation = 25
        self._config = config

        title_text(self, "> Rules configuration")

        self._options = widget.VBox(self)
        self._options.separation = 10
        self._opt_use_on_attack = widget.CheckedText(
            self._options, "Troops get tired on attack.")
        self._opt_use_on_move = widget.CheckedText(
            self._options, "Troops get tired on movement.")

        if config.child('use-on-attack').value:
            self._opt_use_on_attack.check.select()
        if config.child('use-on-move').value:
            self._opt_use_on_move.check.select()

        self._but_ok = widget.Button(self,
                                     'Done',
                                     'data/icon/accept-small.png',
                                     vertical=False)

        self._but_ok.on_click += self.on_dialog_exit

        self._opt_use_on_attack.check.on_toggle += self._update_use_on_attack
        self._opt_use_on_move.check.on_toggle += self._update_use_on_move
Exemplo n.º 4
0
    def __init__(self, parent=None, save_folder='', *a, **k):
        super(LoadGameDialog, self).__init__(parent, *a, **k)

        self.separation = 20
        title_text(self, '> Load Game')

        extension = '.' + save_game_ext

        contents = [
            (
                'data/icon/save-small.png',
                "%%22%%%s\n%%14%%%s" % (
                    s[:-len(extension)],
                    time.asctime(
                        #"%b %e  %Y",
                        time.localtime(
                            stat(path.join(save_folder, s)).st_mtime))),
                path.join(save_folder, s)) for s in listdir(save_folder)
            if s[-len(extension):] == extension
        ]
        print contents
        print listdir(save_folder)
        self._save_list = widget.List(parent=self,
                                      num_slots=6,
                                      contents=contents,
                                      button_size=(450, 56))

        self._but_box = widget.HBox(self)
        self._but_box.separation = 15

        self._but_load = widget.Button(self._but_box,
                                       'Load',
                                       'data/icon/load-small.png',
                                       vertical=False)
        self._but_delete = widget.Button(self._but_box,
                                         'Delete',
                                         'data/icon/cancel-small.png',
                                         vertical=False)
        self._but_back = widget.Button(self._but_box,
                                       'Back',
                                       'data/icon/undo-small.png',
                                       vertical=False)

        self._but_load.on_click += self._on_load_game
        self._but_delete.on_click += self._on_delete_game
        self._but_back.on_click += self._on_go_back
Exemplo n.º 5
0
    def __init__(self, parent=None, *a, **k):
        super(MainActions, self).__init__(parent, center=True, *a, **k)
        self.separation = 20

        # title_text (self, '> Actions ')

        self.play = widget.Button(self,
                                  'Play',
                                  'data/icon/troops-small.png',
                                  vertical=False)
        self.load = widget.Button(self,
                                  'Load',
                                  'data/icon/load-small.png',
                                  vertical=False)
        self.quit = widget.Button(self,
                                  'Quit',
                                  'data/icon/quit-small.png',
                                  vertical=False)
Exemplo n.º 6
0
    def __init__(self, parent=None, config=GlobalConf(), *a, **k):

        super(ProfileManager, self).__init__(parent, center=True, *a, **k)

        self._cfg_root = config
        self._cfg_profiles = config.child('profiles')

        profile_name = config.child('current-profile').value
        if profile_name is None:
            profile_name = 'default'
            config.child('current-profile').value = profile_name

        if self._cfg_profiles.has_child(profile_name):
            self._cfg_current = self._cfg_profiles.child(profile_name)
        else:
            self._cfg_current = self._cfg_root.child('profiles').adopt(
                create_default_profile(), profile_name)

        title_text(self, '> Profile ')

        self._edit_profile = widget.LineEdit(self,
                                             text=profile_name,
                                             theme=theme.small_button_green)
        self._edit_profile.activate()
        self._edit_profile.on_edit += self._on_profile_rename

        self.add_profile = widget.Button(self,
                                         'Add',
                                         'data/icon/add-tiny.png',
                                         vertical=False,
                                         theme=theme.small_button_green)
        self.del_profile = widget.Button(self,
                                         'Delete',
                                         'data/icon/cancel-tiny.png',
                                         vertical=False,
                                         theme=theme.small_button_green)
        self.change_profile = widget.Button(self,
                                            'Change',
                                            'data/icon/retreat-tiny.png',
                                            vertical=False,
                                            theme=theme.small_button_green)

        self.separation = 15
Exemplo n.º 7
0
 def start(self):
     """Start user interface by generating widgets and objects."""
     add_new_btn = widget.Button("button_normal", "New")
     is_done_btn = widget.Button("button_light", "0")
     is_done_btn.on_click(self.__action.all_items, *(self, "show"))
     self._is_done_btn = is_done_btn
     c_height, c_width = self.__config.height_and_width
     height = c_height if c_height > 0 else DEFAULT_HEIGHT
     width = c_width if c_width > 0 else DEFAULT_WIDTH
     main_window = widget.Window("Main", "MTodo", None, width, height, {
         add_new_btn: "left",
         is_done_btn: "left"
     }, True)
     main_window.set_icon(self.__config.software_icon_file)
     main_window.on_resize(self.__action.reload_items, *(self, "refresh"))
     main_window.delegate("on_resize", self._update_preferences)
     self.__windows.update({"main_window": main_window})
     add_new_btn.on_click(self.__action.add_item, *(self, "new"))
     self.refresh(main_window)
     self.render()
Exemplo n.º 8
0
    def __init__(self, *a, **k):
        super(IngameMenu, self).__init__(*a, **k)

        self.on_quit_game = signal.Signal()
        self.on_save_game = signal.Signal()
        self.on_close_menu = signal.Signal()
        self.on_show_help = signal.Signal()

        self.set_position_rel(0.5, 0.5)
        self.set_center_rel(0.5, 0.5)
        self.padding_left = 20

        self._but_close = widget.Button(self, 'Close', 'data/icon/close.png')
        self._but_save = widget.Button(self, 'Save', 'data/icon/save.png')
        self._but_help = widget.Button(self, 'Help', 'data/icon/help.png')
        self._but_quit = widget.Button(self, 'Quit', 'data/icon/quit.png')

        self._but_close.on_click += lambda ev: self.on_close_menu()
        self._but_help.on_click += lambda ev: self.on_show_help()
        self._but_save.on_click += lambda ev: self.on_save_game()
        self._but_quit.on_click += lambda ev: self.on_quit_game()
Exemplo n.º 9
0
    def __init__(self, parent=None, message=None, *a, **k):
        super(YesNoDialog, self).__init__(parent, center=True, *a, **k)

        self.separation = 30
        self.message = widget.Text(self, unicode(message))
        self.message.set_size(50)

        self._but_box = widget.HBox(self)
        self._but_box.separation = 20

        self.yes_button = widget.Button(self._but_box,
                                        'Yes',
                                        'data/icon/accept.png',
                                        vertical=False)
        self.no_button = widget.Button(self._but_box,
                                       'No',
                                       'data/icon/no.png',
                                       vertical=False)

        self.yes_button.on_click += lambda _: self.on_dialog_exit(ret='yes')
        self.no_button.on_click += lambda _: self.on_dialog_exit(ret='no')
Exemplo n.º 10
0
    def createResultPopUp(self):
        if self.result == RESULT.BLACK:
            heading = "Black Wins!"
        elif self.result == RESULT.WHITE:
            heading = "White Wins!"
        else:
            heading = "Stalemate"

        self.master.createPopUp([widget.Rect(width / 2.0, height / 2.0, width, height, color(1, 200), color(1, 200), 0, False), \
                    widget.TXT(width / 2.0, self.master.yUnit * 2, heading, 1 * self.master.yUnit, color(255), False), \
                    widget.Button(width / 2.0, height / 2.0, 5 * self.master.xUnit, 1.5 * self.master.yUnit, "Return to Menu", 0.7 * self.master.yUnit, color(0), \
                                color(255, 200), color(0), 5, lambda: self.master.destroyPopUp() or self.master.switchTo(chess.GUI.MAIN), True)])
Exemplo n.º 11
0
    def todo_item(self,
                  todo_id=None,
                  title=None,
                  description=None,
                  is_done=None,
                  is_important=None):
        """New item window."""
        window_subtitle = "New Item"
        save_btn = widget.Button("button_blue", "Save")
        header_btns = {save_btn: "left"}
        if todo_id is not None:
            del_btn = widget.Button("button_red", "Delete")
            del_btn.on_click(self.__action.del_item, *(self, "del", todo_id))
            header_btns.update({del_btn: "left"})
            window_subtitle = "Edit Item"

        window = widget.Window("Main", "MTodo", window_subtitle, 500, 480,
                               header_btns, False)
        self.__windows["todo_item"] = window
        box = widget.Box("new_data", True)
        switch_box = widget.Box("switch_data", True)

        title_text = widget.Input("title", "Title", False)
        title_text.set_text(title)

        description_text = widget.Input("description", "Description", True)
        description_text.set_text(description)

        is_done_switch = widget.Switch("is_done")
        is_done_switch.set_value(is_done)
        is_done_label = widget.Label("is_done_label", "Is done")
        is_done_box = widget.Box("is_done_data", False)

        is_important_switch = widget.Switch("is_important")
        is_important_switch.set_value(is_important)
        is_important_label = widget.Label("is_important_label", "Is Important")
        is_important_box = widget.Box("is_important_data", False)

        is_done_box.join(is_done_label, True, True)
        is_done_box.join(is_done_switch)

        is_important_box.join(is_important_label, True, True)
        is_important_box.join(is_important_switch)

        box.join(title_text)
        box.join(description_text)
        switch_box.join(is_important_box)
        switch_box.join(is_done_box)

        if todo_id is None:
            save_btn.on_click(
                self.__action.add_item,
                *(self, "save", title_text, description_text, is_done_switch,
                  is_important_switch))
        else:
            save_btn.on_click(
                self.__action.edit_item,
                *(self, "save", todo_id, title_text, description_text,
                  is_done_switch, is_important_switch))
        window.join(box)
        window.join(switch_box)
        window.render()
Exemplo n.º 12
0
    def __init__(self, parent=None, player=None, *a, **k):
        super(PlayerComponent, self).__init__(parent, center=True, *a, **k)

        self.player = player
        self._can_change_cards = False
        self._menu_enabled = False
        move_to_player_position(self, player)

        # Area for windows
        self._menu_area = ui.FreeformContainer(self)
        self._menu_area.width = 1024  # HACK
        self._menu_area.height = 768

        # The main button
        self._but_theme = theme.copy_button_theme(theme.small_button)
        pc = theme.player_color[player.color]
        self._but_theme.active.color = pc
        if (pc.r + pc.g + pc.b) / 3. > 64:
            self._but_theme.active.border = sf.Color(pc.r * .4, pc.g * .4,
                                                     pc.b * .4)
        else:
            self._but_theme.active.border = sf.Color(pc.r + 40, pc.g + 40,
                                                     pc.b + 40)

        self._but_main = widget.Button(self,
                                       None,
                                       'data/icon/small.png',
                                       theme=self._but_theme)
        self._but_main.on_click += lambda ev: self.on_toggle_menu(self)

        self._txt_troops = ui.String(self._but_main, player.troops or '')
        self._txt_troops.set_center_rel(0.5, 0.5)
        self._txt_troops.set_position(28, 26)
        self._txt_troops.set_size(20)
        self._txt_troops._sprite.SetStyle(sf.String.Bold)

        player.on_set_player_troops += self._on_set_player_troops
        player.on_add_player_card += self._on_cards_change
        player.on_del_player_card += self._on_cards_change

        # The main menu
        self._menu_main = widget.VBox(self._menu_area)
        self._but_pass = widget.SmallButton(self._menu_main, None,
                                            'data/icon/next-small.png')
        self._but_cards = widget.SmallButton(self._menu_main, None,
                                             'data/icon/troops-small.png')
        self._but_mission = widget.SmallButton(self._menu_main, None,
                                               'data/icon/world-small.png')
        # self._but_undo = widget.SmallButton (
        #    self._menu_main, None, 'data/icon/undo-small.png')

        self.padding_bottom = 0
        self._menu_main.padding_bottom = 6
        self._menu_main.set_visible(self._menu_enabled)
        self._position_menu(self._menu_main)

        self._but_mission.on_click += self._on_show_mission
        self._but_cards.on_click += self._on_show_cards

        self._but_pass.deactivate()

        self._but_pass.on_click += self.on_toggle_menu
        self._current_menu = self._menu_main
Exemplo n.º 13
0
    def __init__(self,
                 parent=None,
                 attacker=None,
                 defender=None,
                 audio=None,
                 use_on_attack=True,
                 *a,
                 **k):
        super(AttackComponent, self).__init__(parent, *a, **k)

        self.on_attack = signal.Signal()
        self.on_retreat = signal.Signal()
        self.on_continue = signal.Signal()

        self.width = 1024
        self.height = 768
        self.audio = audio
        self.use_on_attack = use_on_attack

        self._dice_enabled = False
        self._sprite = None

        self.attacker = attacker
        self.defender = defender

        self._attacker_dices = DiceBox(self, 'data/icon/rdice%i.png', .58)
        self._defender_dices = DiceBox(self, 'data/icon/bdice%i.png', .42)

        if self.use_on_attack:
            self.attacker.used += 1
            self.attacker.troops -= 1

        self._but_continue = widget.Button(self, 'Continue',
                                           'data/icon/next.png')
        self._but_continue.set_center_rel(.5, .5)
        self._but_continue.set_position_rel(.9, .5)
        self._but_continue.set_visible(False)
        self._but_continue.on_click += self._dispatch_continue

        self._box_attacker = widget.VBox(self)

        if use_on_attack:
            self._txt_attacker = ui.String(
                self._box_attacker,
                unicode(self.attacker.definition.name.title() + ": %i/%i" %
                        (self.attacker.troops, self.attacker.used)))
        else:
            self._txt_attacker = ui.String(
                self._box_attacker,
                unicode(self.attacker.definition.name.title() + ": %i" %
                        (self.attacker.troops)))

        set_attacker_text_style(self._txt_attacker)

        self._box_attacker_a = widget.HBox(self._box_attacker)
        self._box_attacker_b = widget.HBox(self._box_attacker)
        self._box_attacker.padding_bottom = 10
        self._box_attacker_a.padding_right = 10
        self._box_attacker_b.padding_right = 10

        self._box_defender = widget.VBox(self)
        self._box_defender_txt = widget.HBox(self._box_defender)
        self._box_defender_txt.padding_left = 10  # DIRTY HACK, bugs in TF
        self._txt_defender = ui.String(
            self._box_defender_txt,
            unicode(self.defender.definition.name.title() +
                    ": %i" % self.defender.troops))
        set_defender_text_style(self._txt_defender)

        self._box_defender_a = widget.HBox(self._box_defender)
        self._box_defender_b = widget.HBox(self._box_defender)
        self._box_defender.padding_bottom = 10
        self._box_defender_a.padding_left = 10
        self._box_defender_b.padding_left = 10
        self._box_defender_b.set_center_rel(-0.5, 0)
        self._box_defender_b.set_position_rel(0.5, 0)

        move_to_player_position(self._box_attacker, self.attacker.owner)
        move_to_player_position(self._box_defender, self.defender.owner)

        self._but_attacker_troops_inc = widget.SmallButton(
            self._box_attacker_a, None, 'data/icon/attacker-more.png')
        self._but_attacker_troops_dec = widget.SmallButton(
            self._box_attacker_a, None, 'data/icon/attacker-less.png')
        self._but_attacker_attack = widget.SmallButton(self._box_attacker_b,
                                                       None,
                                                       'data/icon/attack.png')
        self._but_attacker_retreat = widget.SmallButton(
            self._box_attacker_b, None, 'data/icon/retreat.png')

        self._but_defender_troops_inc = widget.SmallButton(
            self._box_defender_a, None, 'data/icon/defender-more.png')
        self._but_defender_troops_dec = widget.SmallButton(
            self._box_defender_a, None, 'data/icon/defender-less.png')
        self._but_defender_attack = widget.SmallButton(self._box_defender_b,
                                                       None,
                                                       'data/icon/attack.png')

        self._but_attacker_troops_inc.on_click += self._attacker_troops_inc
        self._but_attacker_troops_dec.on_click += self._attacker_troops_dec
        self._but_defender_troops_dec.on_click += self._defender_troops_dec
        self._but_defender_troops_inc.on_click += self._defender_troops_inc
        self._but_attacker_attack.on_click += self._on_attack_attacker
        self._but_defender_attack.on_click += self._on_attack_defender
        self._but_attacker_retreat.on_click += self._on_attack_retreat

        self.attacker.on_set_region_troops += self._on_change_attacker_txt
        self.attacker.on_set_region_used += self._on_change_attacker_txt
        self.defender.on_set_region_troops += self._on_change_defender_txt