示例#1
0
文件: menu.py 项目: gitGNU/gnu_jagsat
    def __init__(self, parent=None, config=create_default_profile()):

        super(GameOptions, self).__init__(parent)

        self.on_start_game = signal.Signal()
        self.on_quit_program = signal.Signal()
        self._config = config

        self._box_left = widget.VBox(self)
        self._box_left.separation = 15

        title_text(self._box_left, '> Player options')

        self._box_players = widget.VBox(self._box_left)
        self._player_options = \
            [ PlayerOptions (self._box_players, config.child ('player-%i' % i))
              for i in range (6) ]
        self._box_players.separation = 10

        txt = title_text(self._box_left, '> Game options')
        txt.padding_top = 10
        self._box_extra = widget.HBox(self._box_left)
        self._box_extra.separation = 10

        self.rules = widget.SmallButton(self._box_extra,
                                        'Rules',
                                        'data/icon/world-small.png',
                                        vertical=False)

        self._but_music = widget.SelectButton(
            self._box_extra,
            text='Music',
            vertical=False,
            selected_img='data/icon/music-small.png',
            unselected_img='data/icon/nomusic-small.png')
        # HACK
        if GlobalConf().child('global-music').value:
            self._but_music.select()
        self._but_music.on_select += self._update_music
        self._but_music.on_unselect += self._update_music

        self._box_map = widget.VBox(self)
        title_text(self._box_map, '> War map')
        self._box_map.separation = 10

        self._map_selector = MapSelector(parent=self._box_map)
        self._map_selector.on_change_select += self._update_map
        try:
            self._map_selector.select(config.child('map').value)
        except Exception:
            try:
                self._map_selector.select(self._map_selector._contents[0][2])
            except Exception:
                pass

        self.separation = 50
示例#2
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()
示例#3
0
    def __init__ (self,
                  parent = None,
                  world  = None,
                  audio  = None, 
                  *a, **k):
        assert parent
        assert world
        
        super (WorldComponent, self).__init__ (
            parent = parent,
            fname  = path.join (path.dirname (world.map.file_name),
                                world.map.background),
            *a, **k)

        self.operation = map_op.none
        self.audio = audio
        self.allow_repick = True
        self.on_click_region = signal.Signal ()
        self.on_pick_regions = signal.Signal ()
        
        self.picked = None
        self.new_picked = None # A bit hackish just to let the
                               # on_pick_regions callback choose a new
                               # pick
        
        self._pick_cond_fst = None
        self._pick_cond_snd = None
        self.click_cond = lambda r: True
        self.set_enable_hitting(True)
        self.model  = world

        self._build_continents ()
        self._build_regions ()
        
        self._last_pan_pos = None
        self.set_center_rel (.5, .5)
        self.set_position_rel (.5, .5)
        self.set_scale (1./world.map.zoom, 1./world.map.zoom)
示例#4
0
    def __init__ (self,
                  parent = None,
                  model  = None,
                  zoom   = 1.,
                  *a, **k):
        assert parent
        assert model
        super (RegionComponent, self).__init__ (parent = parent,
                                                radius = region_radius,
                                                *a, **k)

        self.on_click = signal.Signal ()
        self.signal_click.add (lambda ev: self.on_click (self))

        self.set_enable_hitting (True)
        
        self.model = model
        model.connect (self)

        self._outline_width = 2.0
        self._outline_color = sf.Color (0, 0, 0)
        self._fill_color    = region_free_color
        self._rebuild_sprite ()

        self._txt_troops = ui.String (self, u"0")
        self._txt_used   = ui.String (self, u"0/0")
        
        self._txt_troops.set_size (25)
        self._txt_troops.set_center_rel (0.5, 0.5)
        self._txt_troops.set_position_rel (0.5, 0.45)
        self._txt_troops.set_color (sf.Color (255, 255, 255))
        self._txt_troops._sprite.SetStyle (sf.String.Bold)
        
        self._txt_used.set_size (20)
        self._txt_used.set_center_rel (0.5, 0.5)
        self._txt_used.set_position_rel (0.5, 0.45)
        self._txt_used.set_color (sf.Color (255, 255, 255))
        self._txt_used.set_visible (False)

        self._txt_name = widget.String (self, model.definition.name.title ())
        self._txt_name.set_center_rel (.5, -1.3)
        self._txt_name.set_position_rel (.5, .45)
        self._txt_name.set_color (sf.Color (255, 255, 255, 128))
        self._txt_name.set_size (15)
        
        self.set_scale (zoom, zoom)
        self.set_center_rel (.5, .5)

        self._update_troops ()
        self._update_owner ()
示例#5
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