예제 #1
0
    def init(self):
        settings = self.settings
        config = self.config
        gtkrc = self.datadir + "/interface/table/gtkrc"
        if exists(gtkrc):
            gtk.rc_parse(gtkrc)
        glade_file = self.datadir + "/interface/table/mockup.glade"
        glade = gtk.glade.XML(glade_file)
        glade.signal_autoconnect(self)
        from gamewindow import GameWindowGlade
        self.glade = GameWindowGlade(glade)
        self.glade.signal_autoconnect(self)
        self.actions = {
            "call": self.glade.get_widget("call"),
            "raise": self.glade.get_widget("raise"),
            "raise_range": self.glade.get_widget("raise_range"),
            "raise_increase": self.glade.get_widget("raise_increase"),
            "raise_decrease": self.glade.get_widget("raise_decrease"),
            "raise_increase_bb": self.glade.get_widget("raise_increase_bb"),
            "raise_decrease_bb": self.glade.get_widget("raise_decrease_bb"),
            "raise_pot": self.glade.get_widget("raise_pot"),
            "raise_half_pot": self.glade.get_widget("raise_half_pot"),
            "check": self.glade.get_widget("check"),
            "fold": self.glade.get_widget("fold"),
            }
        self.switch = self.glade.get_widget("switch")
#        self.actions['check'].add_accelerator("clicked", gtk.AccelGroup(), gtk.gdk.keyval_from_name("p"), gtk.gdk.MOD1_MASK, gtk.ACCEL_VISIBLE)

        self.animations = pokeranimation2d.create(self.glade, config, settings)
예제 #2
0
class PokerDisplay2D(PokerDisplay):

    def __init__(self, *args, **kwargs):
        PokerDisplay.__init__(self, *args, **kwargs)
        if ( self.settings.headerGet("/settings/sound") == "yes" or
             self.settings.headerGet("/settings/sound") == "on" ):
            try:
                pygame.mixer.init()
                self.sound = True
            except:
                if self.settings.headerGetInt("/settings/@verbose") > 0:
                    print_exc()
                self.sound = False
        else:
            self.sound = False
        self.settings.notifyUpdates(self.settingsUpdated)
        self.settingsUpdated(self.settings)
        self.id2table = {}

    def __del__(self):
        if self.sound:
            pygame.mixer.quit()

    def settingsUpdated(self, settings):
        self.verbose = settings.headerGetInt("/settings/@verbose")
        self.datadir = settings.headerGet("/settings/data/@path")
        self.event2sound = None
        if self.sound:
            sounddir = settings.headerGet("/settings/data/@sounds")
            #
            # Load event to sound map
            #
            self.event2sound = {}
            for (event, file) in self.config.headerGetProperties("/sequence/sounds")[0].iteritems():
                soundfile = sounddir + "/" + file
                if exists(soundfile):
                    sound = pygame.mixer.Sound(sounddir + "/" + file)
                    self.event2sound[event] = sound
                else:
                    self.error(soundfile + " file does not exist")

    def message(self, string):
        print "[PokerDisplay2D] " + string

    def error(self, string):
        self.message("ERROR " + string)

    def setProtocol(self, protocol):
        PokerDisplay.setProtocol(self, protocol)
        window = self.glade.get_widget("game_window")
        interface = self.factory.interface
        (width, height) = window.size_request()
        x = ( interface.width - width ) / 2
        y = ( interface.height - height ) / 2
        interface.screen.put(window, x, y)
        self.accelerators()
        window.show()
        
    def accelerators(self):
        action_group = gtk.AccelGroup()
        for key in self.settings.headerGetProperties('/settings/keys/key'):
            name = key['name']
            letter = key['control_key']
            if self.verbose > 1: self.message(name + " is bound to Ctrl+" + letter)
            self.actions[name].add_accelerator("clicked", action_group, gtk.gdk.keyval_from_name(letter), gtk.gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE)
        self.factory.interface.window.add_accel_group(action_group)

    def init(self):
        settings = self.settings
        config = self.config
        gtkrc = self.datadir + "/interface/table/gtkrc"
        if exists(gtkrc):
            gtk.rc_parse(gtkrc)
        glade_file = self.datadir + "/interface/table/mockup.glade"
        glade = gtk.glade.XML(glade_file)
        glade.signal_autoconnect(self)
        from gamewindow import GameWindowGlade
        self.glade = GameWindowGlade(glade)
        self.glade.signal_autoconnect(self)
        self.actions = {
            "call": self.glade.get_widget("call"),
            "raise": self.glade.get_widget("raise"),
            "raise_range": self.glade.get_widget("raise_range"),
            "raise_increase": self.glade.get_widget("raise_increase"),
            "raise_decrease": self.glade.get_widget("raise_decrease"),
            "raise_increase_bb": self.glade.get_widget("raise_increase_bb"),
            "raise_decrease_bb": self.glade.get_widget("raise_decrease_bb"),
            "raise_pot": self.glade.get_widget("raise_pot"),
            "raise_half_pot": self.glade.get_widget("raise_half_pot"),
            "check": self.glade.get_widget("check"),
            "fold": self.glade.get_widget("fold"),
            }
        self.switch = self.glade.get_widget("switch")
#        self.actions['check'].add_accelerator("clicked", gtk.AccelGroup(), gtk.gdk.keyval_from_name("p"), gtk.gdk.MOD1_MASK, gtk.ACCEL_VISIBLE)

        self.animations = pokeranimation2d.create(self.glade, config, settings)
        
    def on_switch_clicked(self, button):
        self.renderer.rotateTable()

    def on_sit_seat0_clicked(self, button):
        self.on_sit_clicked(button)
    def on_sit_seat1_clicked(self, button):
        self.on_sit_clicked(button)
    def on_sit_seat2_clicked(self, button):
        self.on_sit_clicked(button)
    def on_sit_seat3_clicked(self, button):
        self.on_sit_clicked(button)
    def on_sit_seat4_clicked(self, button):
        self.on_sit_clicked(button)
    def on_sit_seat5_clicked(self, button):
        self.on_sit_clicked(button)
    def on_sit_seat6_clicked(self, button):
        self.on_sit_clicked(button)
    def on_sit_seat7_clicked(self, button):
        self.on_sit_clicked(button)
    def on_sit_seat8_clicked(self, button):
        self.on_sit_clicked(button)
    def on_sit_seat9_clicked(self, button):
        self.on_sit_clicked(button)
    def on_sit_clicked(self, button):
        seat = int(button.get_name()[-1])
        protocol = self.protocol
        self.renderer.getSeat(PacketPokerSeat(game_id = protocol.getCurrentGameId(),
                                              serial = protocol.getSerial(),
                                              seat = seat))

    def on_quit_clicked(self, button):
        self.renderer.wantToLeave()

    def on_rebuy_clicked(self, button):
        protocol = self.protocol
        self.renderer.changeState("user_info", "rebuy", self.factory.getGame(protocol.getCurrentGameId()))

    def on_fold_clicked(self, button):
        protocol = self.protocol
        self.renderer.interactorSelected(PacketPokerFold(game_id = protocol.getCurrentGameId(),
                                                         serial = protocol.getSerial()))
    
    def on_check_clicked(self, button):
        protocol = self.protocol
        self.renderer.interactorSelected(PacketPokerCheck(game_id = protocol.getCurrentGameId(),
                                                          serial = protocol.getSerial()))
    
    def on_call_clicked(self, button):
        protocol = self.protocol
        self.renderer.interactorSelected(PacketPokerCall(game_id = protocol.getCurrentGameId(),
                                                         serial = protocol.getSerial()))

    def on_raise_increase_clicked(self, button):
        #
        # There seem to be a gtk bug when the slider displacement for a given
        # value is less than a pixel. In this case the slider does not have to move
        # which is normal. However, it seems to have a undesirable side effect : the
        # displayed value is not updated.
        #
        range = self.actions['raise_range']
        adjustment = range.get_adjustment()
        range.set_value(range.get_value() + adjustment.get_property('step-increment'))

    def on_raise_decrease_clicked(self, button):
        range = self.actions['raise_range']
        adjustment = range.get_adjustment()
        range.set_value(range.get_value() - adjustment.get_property('step-increment'))

    def on_raise_increase_bb_clicked(self, button):
        game_id = self.protocol.getCurrentGameId()
        bb = self.id2table[game_id].game.bigBlind()
        if bb:
            range = self.actions['raise_range']
            range.set_value(range.get_value() + (bb / 100.0))

    def on_raise_decrease_bb_clicked(self, button):
        game_id = self.protocol.getCurrentGameId()
        bb = self.id2table[game_id].game.bigBlind()
        if bb:
            range = self.actions['raise_range']
            range.set_value(range.get_value() - (bb / 100.0))

    def on_raise_pot_clicked(self, button):
        game_id = self.protocol.getCurrentGameId()
        bet_limit = self.id2table[game_id].bet_limit
        range = self.actions['raise_range']
        adjustment = range.get_adjustment()
        range.set_value(min(adjustment.get_property('upper'), bet_limit.pot / 100.0))

    def on_raise_half_pot_clicked(self, button):
        game_id = self.protocol.getCurrentGameId()
        bet_limit = self.id2table[game_id].bet_limit
        range = self.actions['raise_range']
        adjustment = range.get_adjustment()
        range.set_value(min(adjustment.get_property('upper'), ( bet_limit.pot / 2.0 ) / 100.0))

    def on_raise_clicked(self, button):
        raise_range = self.actions["raise_range"]
        protocol = self.protocol
        self.renderer.interactorSelected(PacketPokerRaise(game_id = protocol.getCurrentGameId(),
                                                          serial = protocol.getSerial(),
                                                          amount = int(raise_range.get_value() * 100)))

    def on_raise_range_value_changed(self, raise_range):
        value = int(raise_range.get_value() * 100)
        game_id = self.protocol.getCurrentGameId()
        bet_limit = self.id2table[game_id].bet_limit
        remainder = value % bet_limit.step
        if remainder:
            value -= remainder
            raise_range.set_value(value / 100.0)

    def deleteTable(self, game_id):
        table = self.id2table[game_id]
        del table.display
        del table.glade
        del self.id2table[game_id]

    def updateAction(self, packet):
        game_id = self.protocol.getCurrentGameId()
        game = self.factory.getGame(game_id)
        serial = self.protocol.getSerial()
        table = self.id2table[game_id]

        if not packet.style:
            self.actions[packet.name].hide()
            self.actions[packet.name].set_active(False)
            if packet.name == "raise":
                self.actions["raise_range"].hide()
            return
                
        if packet.name == "check" or packet.name == "fold" or packet.name == "call" or packet.name == "raise":
            action = self.actions[packet.name]
            action.show()
            action.set_label(packet.style)
            if packet.name == "raise":
                range = self.actions['raise_range']
                bet_limit = table.bet_limit
                range.set_value(bet_limit.min / 100.0)
                if bet_limit.min != bet_limit.max:
                    range.show()
                    if packet.selection and packet.selection.type == PACKET_POKER_RAISE:
                        self.updateRaiseRange(packet.selection.amount / 100.0)
                    else:
                        self.updateRaiseRange(bet_limit.min / 100.0)
                else:
                    range.hide()
        else:
            self.error("updateAction %s: unexpected name " % packet.name)

    def updateRaiseRange(self, selected_amount):
        range = self.actions['raise_range']
        if range.get_property('visible'):
            game_id = self.protocol.getCurrentGameId()
            game = self.factory.getGame(game_id)
            serial = self.protocol.getSerial()
            table = self.id2table[game_id]

            bet_limit = table.bet_limit
            range.set_range(bet_limit.min / 100.0, bet_limit.max / 100.0)
            range.set_increments(bet_limit.step / 100.0, bet_limit.step / 100.0)
            if selected_amount:
                range.set_value(selected_amount / 100.0)

    def render(self, packet):
        if self.verbose > 3: self.message(str(packet))

        if packet.type == PACKET_QUIT:
            reactor.stop()
            return

        if not self.protocol or not self.protocol.getCurrentGameId():
            return

        if self.event2sound:
            soundfile = self.event2sound.get(PacketNames[packet.type], None)
            playsound = False
            if soundfile:
                if ( packet.type == PACKET_POKER_TIMEOUT_WARNING or
                     packet.type == PACKET_POKER_TIMEOUT_NOTICE ):
                    if packet.serial == self.protocol.getSerial():
                        playsound = True
                else:
                    playsound = True
            if playsound:
                soundfile.play()
            
        game = self.factory.packet2game(packet)
        if game:
            self.id2table[game.id].render(packet)
            
        elif packet.type == PACKET_POKER_DISPLAY_NODE:
            self.updateAction(packet)
            
        elif packet.type == PACKET_POKER_TABLE:
            if not self.id2table.has_key(packet.id):
                self.id2table[packet.id] = PokerTable2D(packet, self)
            self.id2table[packet.id].reset()

        elif packet.type == PACKET_POKER_TABLE_QUIT:
            self.deleteTable(packet.id)
            
        elif packet.type == PACKET_POKER_TABLE_DESTROY:
            self.deleteTable(packet.game_id)

        elif packet.type == PACKET_POKER_CURRENT_GAMES:
            if packet.count < 2:
                self.switch.hide()
            else:
                self.switch.show()

        elif packet.type == PACKET_POKER_CHAT_HISTORY:
            if packet.show == "yes":
                self.renderer.chatHistoryShow()
            else:
                self.renderer.chatHistoryHide()