예제 #1
0
    def __init__(self, g, *a, **k):
        Panel.__init__(self, width=550, height=340, zindex=15, *a, **k)
        parent = self.parent
        self.x = (parent.width - 550) // 2
        self.y = (parent.height - 340) // 2
        self.textarea = ta = TextArea(
            parent=self, x=30, y=30, width=550-30, height=340-60,
            font_size=12,
        )
        ta.text = u''
        winners = g.winners
        for p in g.players:
            s = u'|G%s|r(|R%s|r, |c0000ffff%s|r, %s)\n' % (
                p.ui_meta.name, p.account.username.replace('|', '||'),
                g.ui_meta.identity_table[p.identity.type],
                u'|R胜利|r' if p in winners else u'失败'
            )
            ta.append(s)

        if g.me in winners:
            self.pic = L('thb-win')
        else:
            self.pic = L('thb-lose')

        close = Button(
            u'关闭', parent=self, x=440, y=25, width=90, height=40, zindex=10,
        )

        @close.event
        def on_click():
            self.delete()
예제 #2
0
    def __init__(self, *args, **kwargs):
        Screen.__init__(self, *args, **kwargs)
        self.bg = common_res.bg_login.get()
        self.bg_alpha = LinearInterp(0, 1.0, 1.5)
        self.dialog = LoginScreen.LoginDialog(parent=self)
        try_game = Button(
            parent=self, caption=u'试玩',
            x=750, y=50, width=100, height=30, color=Colors.orange,
        )

        @try_game.event
        def on_click():
            text = (
                u'试玩的玩家有以下限制:\n'
                u'\n'
                u'随机的id,不记录游戏数和节操\n'
                u'固定的头像、自定义签名\n'
                u'无法使用文文新闻和邀请功能\n'
                u'无法断线重连'
            )

            confirm = ConfirmBox(text, buttons=ConfirmBox.Presets.OKCancel, parent=self)

            @confirm.event
            def on_confirm(val):
                val and Executive.call('auth', ui_message, ['-1', 'guest'])
예제 #3
0
    def __init__(self, game, *args, **kwargs):
        Screen.__init__(self, *args, **kwargs)

        self.backdrop = common_res.bg_ingame.get()
        self.flash_alpha = 0.0

        self.game = game
        self.ui_class = game.ui_meta.ui_class
        self.gameui = self.ui_class(
            parent=False, game=game,
            **r2d((0, 0, 820, 720))
        )  # add when game starts

        self.events_box = GameScreen.EventsBox(parent=self)
        self.chat_box = GameScreen.ChatBox(parent=self)
        self.panel = GameScreen.RoomControlPanel(parent=self)
        self.btn_exit = Button(
            parent=self, caption=u'退出房间', zindex=1,
            **r2d((730, 670, 75, 25))
        )

        VolumeTuner(parent=self, x=690, y=665)

        @self.btn_exit.event
        def on_click():
            box = ConfirmBox(u'真的要离开吗?', buttons=ConfirmBox.Presets.OKCancel, parent=self)

            @box.event
            def on_confirm(val):
                if val:
                    Executive.call('exit_game', ui_message, [])
예제 #4
0
        def __init__(self, game_id, *a, **k):
            Panel.__init__(
                self, width=550, height=340,
                zindex=10000,
                *a, **k
            )
            self.game_id = game_id
            self.x = (self.overlay.width - 550) // 2
            self.y = (self.overlay.height - 340) // 2

            self.btncancel = btncancel = Button(
                u'关闭', parent=self, x=440, y=25, width=90, height=40
            )

            self.labels = pyglet.graphics.Batch()

            Label(
                u'邀请游戏', font_size=12, x=275, y=306,
                anchor_x='center', anchor_y='bottom',
                color=Colors.green.heavy + (255, ),
                shadow=(2, 207, 240, 156, 204),
                batch=self.labels,
            )

            @btncancel.event
            def on_click():
                self.delete()

            Executive.call('get_hallinfo', ui_message, None)
예제 #5
0
        def __init__(self, *a, **k):
            Frame.__init__(
                self, u'登陆', x=350, y=165,
                width=325, height=184,
                bot_reserve=50, *a, **k
            )

            def L(text, x, y, *a, **k):
                self.add_label(
                    text, x=x, y=y,
                    font_size=9, color=(0, 0, 0, 255),
                    bold=True, anchor_x='left', anchor_y='bottom',
                    *a, **k
                )

            L(u'用户名:', 368 - 350, 286 - 165)
            L(u'密码:', 368 - 350, 250 - 165)

            self.txt_username = TextBox(
                parent=self, x=438-350, y=282-165, width=220, height=20,
                text=UserSettings.last_id,
            )
            self.txt_pwd = PasswordTextBox(
                parent=self, x=438-350, y=246-165, width=220, height=20,
                text='',
            )
            self.btn_login = Button(
                parent=self, caption=u'进入幻想乡',
                x=50, y=10, width=100, height=30
            )
            self.btn_reg = Button(
                parent=self, caption=u'乡民登记',
                color=Colors.orange,
                x=175, y=10, width=100, height=30
            )

            @self.btn_login.event
            def on_click():
                self.do_login()

            @self.txt_pwd.event
            def on_enter():
                self.do_login()

            @self.btn_reg.event  # noqa
            def on_click():
                openurl('http://www.thbattle.net')
예제 #6
0
    def process_user_input(self, ilet):
        g = Game.getgame()
        me = g.me
        choices = ilet.mapping[me]
        for i, c in enumerate(choices):
            c._choice_index = i

        w, h = CharacterSorterControl.expected_size(1, ilet.num)
        w = 20 + w + 20
        h = 60 + h + 50

        def lbl(text, x, y):
            Label(
                text=text,
                font_size=12,
                x=x,
                y=y,
                color=(255, 255, 160, 255),
                shadow=(2, 0, 0, 0, 190),
                anchor_x='center',
                anchor_y='center',
                batch=self.lbls,
            )

        lbl(u'请拖动调整角色的出场顺序', w // 2, h - 25)

        parent = self.parent
        self.x, self.y = (parent.width - w) // 2, (parent.height - h) // 2
        self.width, self.height = w, h
        self.update()

        self.sorter = sorter = CharacterSorterControl(ilet.num,
                                                      ilet.limit,
                                                      parent=self,
                                                      x=20,
                                                      y=60)
        selectors = []
        for i, c in enumerate(choices):
            selectors.append(GirlSelector(c, selectors, parent=sorter))
        sorter.init()

        btn = Button(parent=self,
                     caption=u'调整完成',
                     x=w - 120,
                     y=15,
                     width=100,
                     height=30)

        @btn.event
        def on_click(*a, **k):
            gslist, = self.sorter.get_result()
            index = [c.choice._choice_index for c in gslist]
            ilet.set_result(index)
            ilet.done()
            end_transaction(self.trans)

        b = BigProgressBar(parent=self, x=100, y=15, width=250)
        b.value = LinearInterp(1.0, 0.0, ilet.timeout, on_done=on_click)
예제 #7
0
    def process_user_input(self, ilet):
        cards = ilet.cards

        w, h = RanProphetControl.expected_size()
        w = 100 + w + 20
        h = 60 + h + 50

        def lbl(text, x, y):
            Label(
                text=text,
                x=x,
                y=y,
                font_size=12,
                anchor_x='center',
                anchor_y='center',
                color=(255, 255, 160, 255),
                shadow=(2, 0, 0, 0, 230),
                batch=self.lbls,
            )

        lbl(u'牌堆底', 50, 122)
        lbl(u'牌堆顶', 50, 277)
        lbl(u'请拖动调整牌的位置', w // 2, h - 25)

        parent = self.parent
        self.x, self.y = (parent.width - w) // 2, (parent.height - h) // 2
        self.width, self.height = w, h
        self.update()

        self.rpc = rpc = RanProphetControl(parent=self, x=100, y=60)
        for i, c in enumerate(cards):
            cs = CardSprite(c, parent=rpc)
            cs.associated_card = c

        rpc.init()

        btn = Button(parent=self,
                     caption=u'调整完成',
                     x=w - 120,
                     y=15,
                     width=100,
                     height=30)

        @btn.event
        def on_click(*a):
            up, down = self.rpc.get_result()
            up = [c.associated_card for c in up]
            down = [c.associated_card for c in down]
            ilet.set_result(up, down)
            ilet.done()
            end_transaction(self.trans)

        b = BigProgressBar(parent=self, x=100, y=15, width=250)
        b.value = LinearInterp(1.0, 0.0, ilet.timeout, on_done=on_click)
예제 #8
0
        def __init__(self, parent=None):
            Control.__init__(self, parent=parent, **r2d((0, 0, 820, 720)))
            self.btn_getready = Button(
                parent=self, caption=u'准备', **r2d((360, 80, 100, 35))
            )

            self.btn_invite = Button(
                parent=self, caption=u'邀请', **r2d((360, 40, 100, 35))
            )

            self.ready = False

            l = []

            class MyPP(PlayerPortrait):
                # this class is INTENTIONALLY put here
                # to make cached avatars get gc'd
                cached_avatar = {}

            for x, y, color in parent.ui_class.portrait_location:
                l.append(MyPP('NONAME', parent=self, x=x, y=y, color=color))
            self.portraits = l

            @self.btn_getready.event
            def on_click():
                if self.ready:
                    Executive.call('cancel_ready', ui_message, [])
                    self.ready = False
                    self.btn_getready.caption = u'准备'
                    self.btn_getready.update()
                else:
                    Executive.call('get_ready', ui_message, [])
                    #self.btn_getready.state = Button.DISABLED
                    self.ready = True
                    self.btn_getready.caption = u'取消准备'
                    self.btn_getready.update()

            @self.btn_invite.event  # noqa
            def on_click():
                GameScreen.InvitePanel(self.parent.game.gameid, parent=self)
예제 #9
0
        def __init__(self, p):
            Frame.__init__(
                self, parent=p, caption=u'当前大厅内的游戏',
                x=35, y=220, width=700, height=420,
                bot_reserve=30, bg=common_res.bg_gamelist.get(),
            )

            gl = self.gamelist = ListView(parent=self, x=2, y=30, width=696, height=420-30-25)
            gl.set_columns([
                (u'No.', 100),
                (u'游戏名称', 200),
                (u'游戏类型', 200),
                (u'人数', 50),
                (u'当前状态', 80),
            ])

            self.btn_create = Button(parent=self, caption=u'创建游戏', x=690-270, y=6, width=70, height=20)
            self.btn_quickstart = Button(parent=self, caption=u'快速加入', x=690-180, y=6, width=70, height=20)
            self.btn_refresh = Button(parent=self, caption=u'刷新列表', x=690-90, y=6, width=70, height=20)

            @self.btn_create.event
            def on_click():
                self.CreateGamePanel(parent=self.overlay)

            @self.btn_quickstart.event  # noqa
            def on_click():
                Executive.call('quick_start_game', ui_message, 'THBattle')

            @self.btn_refresh.event  # noqa
            def on_click():
                Executive.call('get_hallinfo', ui_message, None)

            @self.gamelist.event
            def on_item_dblclick(li):
                # TODO:
                if li.started:
                    #Executive.call('observe_user', ui_message, li.game_id)
                    self.ObserveGamePanel(li.game_id, parent=self.overlay)
                else:
                    Executive.call('join_game', ui_message, li.game_id)
예제 #10
0
    def process_user_input(self, ilet):
        cards = ilet.cards

        w, h = KokoroHopeMaskControl.expected_size()
        w = 100 + w + 20
        h = 60 + h + 50

        def lbl(text, x, y):
            Label(
                text=text, x=x, y=y, font_size=12,
                anchor_x='center', anchor_y='center',
                color=(255, 255, 160, 255), shadow=(2, 0, 0, 0, 230),
                batch=self.lbls,
            )

        lbl(u'请拖动调整牌的位置', w // 2, h - 25)
        lbl(u'牌堆顶', 50, 277)
        lbl(u'展示并获得', 50, 122)

        parent = self.parent
        self.x, self.y = (parent.width - w)//2, (parent.height - h)//2
        self.width, self.height = w, h
        self.update()

        self.ctrl = ctrl = KokoroHopeMaskControl(parent=self, x=100, y=60)
        for i, c in enumerate(cards):
            cs = CardSprite(c, parent=ctrl)
            cs.associated_card = c

        ctrl.init()

        btn = Button(parent=self, caption=u'完成', x=w-120, y=15, width=100, height=30)

        @btn.event
        def on_click(*a):
            ilet.done()
            end_transaction(self.trans)

        @ctrl.event
        def on_update():
            putback, acquire = self.ctrl.get_result()
            putback = [c.associated_card for c in putback]
            acquire = [c.associated_card for c in acquire]
            if ilet.is_valid(putback, acquire):
                ilet.set_result(putback, acquire)
                btn.state = Button.NORMAL
            else:
                btn.state = Button.DISABLED

        b = BigProgressBar(parent=self, x=100, y=15, width=250)
        b.value = LinearInterp(1.0, 0.0, ilet.timeout, on_done=on_click)
예제 #11
0
        def on_message(self, _type, *args):
            if _type == 'current_users':
                ul = args[0]
                ul = [(uid, uname) for uid, uname, state in ul if state in ('hang', 'observing')]

                for i, (uid, uname) in enumerate(ul):
                    y, x = divmod(i, 5)
                    x, y = 30 + 100*x, 250 - 60*y
                    s = Button(
                        uname,
                        color=Colors.orange,
                        parent=self, x=x, y=y,
                        width=95, height=30,
                    )

                    @s.event
                    def on_click(s=s, uid=uid, un=uname):
                        Executive.call('invite_user', ui_message, uid)
                        self.overlay.chat_box.append(u'|R已经邀请了%s,请等待回应……|r\n' % un)
                        s.state = Button.DISABLED
예제 #12
0
            def __init__(self, text, *a, **k):
                Panel.__init__(self, *a, **k)
                self.zindex = 100
                w, h = self.width, self.height
                ta = TextArea(
                    parent=self,
                    font_size=12,
                    x=2, y=60,
                    width=w-4, height=h-4-60
                )
                ta.append(text)
                btn = Button(
                    u'关闭',
                    parent=self,
                    x=(w-120)//2, y=20,
                    width=120, height=40,
                )

                @btn.event
                def on_click():
                    self.delete()
예제 #13
0
            def on_message(self, _type, *args):
                if _type == 'gameinfo':
                    gid, ul = args[0]
                    if gid != self.game_id: return

                    ul = [i for i in ul if i['state'] not in ('dropped', 'fleed')]

                    for i, p in enumerate(ul):
                        y, x = divmod(i, 5)
                        x, y = 30 + 100*x, 250 - 60*y
                        acc = Account.parse(p['account'])
                        s = Button(
                            acc.username,
                            color=Colors.orange,
                            parent=self, x=x, y=y,
                            width=95, height=30,
                        )
                        s.userid = acc.userid

                        @s.event
                        def on_click(uid=acc.userid, un=acc.username):
                            Executive.call('observe_user', ui_message, uid)
                            self.overlay.chat_box.append(u'|R已经向%s发送了旁观请求,请等待回应……|r\n' % un)
                            self.delete()
예제 #14
0
    def __init__(self, *args, **kwargs):
        Screen.__init__(self, *args, **kwargs)
        self.bg = common_res.bg_gamehall.get()

        self.gamelist = self.GameList(self)

        chat = self.chat_box = GameHallScreen.ChatBox(parent=self)
        chat.text = u'您现在处于游戏大厅!\n'
        self.playerlist = GameHallScreen.OnlineUsers(parent=self)
        self.noticebox = GameHallScreen.NoticeBox(parent=self)
        self.statusbox = GameHallScreen.StatusBox(parent=self)

        VolumeTuner(parent=self, x=850, y=660)

        b = Button(parent=self,
            x=750, y=660, width=80, height=35,
            color=Colors.orange, caption=u'卡牌查看器',
        )

        @b.event
        def on_click():
            openurl('http://thb.io')

        Executive.call('get_hallinfo', ui_message, None)
예제 #15
0
    def __init__(self, game, *a, **k):
        self.game = game
        game.event_observer = UIEventHook

        Control.__init__(self, can_focus=True, *a, **k)

        self.keystrokes = '\x00'
        self.char_portraits = None

        self.deck_indicator = DeckIndicator(
            parent=self,
            x=30,
            y=680,
            width=50,
            height=25,
        )

        self.handcard_area = HandCardArea(
            parent=self,
            x=238,
            y=9,
            zindex=3,
            width=93 * 5 + 42,
            height=145,
        )

        self.deck_area = PortraitCardArea(
            parent=self,
            width=1,
            height=1,
            x=self.width // 2,
            y=self.height // 2,
            zindex=4,
        )

        self.btn_afk = Button(parent=self,
                              caption=u'让⑨帮你玩',
                              zindex=1,
                              color=Colors.blue,
                              **r2d((730, 640, 75, 25)))

        self.gameintro_icon = GameIntroIcon(parent=self,
                                            game=game,
                                            **r2d((780, 610, 25, 25)))

        self.afk = False

        @self.btn_afk.event
        def on_click():
            v = not self.afk
            self.afk = v
            self.btn_afk.color = (Colors.blue, Colors.orange)[v]
            self.btn_afk.update()

        @self.handcard_area.event
        def on_selection_change():
            self.dispatch_event('on_selection_change')

        self.dropcard_area = DropCardArea(
            parent=self,
            x=0,
            y=324,
            zindex=3,
            width=820,
            height=125,
        )

        class Animations(pyglet.graphics.Batch, Control):
            def __init__(self, **k):
                pyglet.graphics.Batch.__init__(self)
                Control.__init__(self,
                                 x=0,
                                 y=0,
                                 width=0,
                                 height=0,
                                 zindex=2,
                                 **k)

            def hit_test(self, x, y):
                return False

        self.animations = Animations(parent=self)
        self.selecting_player = 0
예제 #16
0
    def __init__(self,
                 x=0.0,
                 y=0.0,
                 color=Colors.blue,
                 tag_placement='me',
                 *args,
                 **kwargs):
        self.player = None
        self.character = None
        self._disabled = False
        self._selected = False
        self.taganims = []
        self.tag_placement = tag_placement
        self._color = color
        self.bg = None
        self._last_balloon = None

        Frame.__init__(self,
                       width=149,
                       height=195,
                       bot_reserve=20,
                       color=color,
                       thin_shadow=True,
                       **kwargs)
        self.x, self.y = x, y

        self.charname_lbl = self.add_label(
            u'',
            7,
            self.height - 30,
            width=16,
            multiline=True,
            font_size=9,
            anchor_x='left',
            anchor_y='top',
            color=(255, 255, 255, 255),
            shadow=(1, 0, 0, 0, 179),
        )

        from .view import THBattleUI
        v = self.parent
        while not isinstance(v, THBattleUI):
            v = v.parent
        self.view = v

        self.portcard_area = PortraitCardArea(
            parent=self.view,
            x=self.x,
            y=self.y,
            width=self.width,
            height=self.height,
            zindex=100,
        )
        self.equipcard_area = EquipCardArea(
            parent=self,
            x=3,
            y=6,
        )

        w, h = self.width, self.height

        self.identity_btn = b = Button(
            u'?',
            parent=self,
            x=w - 42 - 4,
            y=h - 24 - 10 - 18,
            width=42,
            height=18,
        )

        self.cur_idtag = 0

        @b.event
        def on_click():
            g = Game.getgame()
            tbl = g.ui_meta.identity_table
            colortbl = g.ui_meta.identity_color
            keys = tbl.keys()
            try:
                i = (keys.index(self.cur_idtag) + 1) % len(keys)
            except ValueError:
                i = 0
            next = keys[i]
            b.caption = tbl[next]
            color = getattr(Colors, colortbl[next])
            b.color = color
            self.set_color(color)
            b.update()
            self.update()
            self.cur_idtag = next

        @self.equipcard_area.event
        def on_selection_change():
            self.view.dispatch_event('on_selection_change')

        def tagarrange_bottom():
            x, y = self.x, self.y
            w, h = self.width, self.height
            x += w + 1
            y -= 27
            for a in self.taganims:  # they are pyglet.sprite.Sprite instances
                x -= 27
                a.set_position(x, y)

        def tagarrange_me():
            x, y = self.x, self.y
            w, h = self.width, self.height
            x += w + 6
            y += 142
            for a in self.taganims:  # they are pyglet.sprite.Sprite instances
                a.set_position(x, y)
                x += 27

        def tagarrange_right():
            x, y = self.x, self.y
            w, h = self.width, self.height
            x += w + 3
            y += 1
            for a in self.taganims:  # they are pyglet.sprite.Sprite instances
                a.set_position(x, y)
                y += 27

        def tagarrange_left():
            x, y = self.x, self.y
            w, h = self.width, self.height
            x -= 28
            y += 1
            for a in self.taganims:  # they are pyglet.sprite.Sprite instances
                a.set_position(x, y)
                y += 27

        self._tagarrange_funcs = {
            'bottom': tagarrange_bottom,
            'me': tagarrange_me,
            'left': tagarrange_left,
            'right': tagarrange_right,
        }

        showncard_btn = ImageButton(
            common_res.buttons.port_showncard,
            parent=self,
            x=self.width - 22,
            y=90,
        )

        @showncard_btn.event  # noqa
        def on_click():
            p = self.character
            if not p: return
            if not p.showncardlists: return  # before the 'real' game_start
            last = ShownCardPanel.current
            if last:
                last.delete()
                if last.character is p:
                    return

            ShownCardPanel(p, parent=self.view)
예제 #17
0
            def __init__(self, *a, **k):
                w, h = 550, 485
                Panel.__init__(
                    self, width=w, height=h,
                    zindex=1000,
                    *a, **k
                )
                self.x = (self.overlay.width - w) // 2
                self.y = (self.overlay.height - h) // 2

                self.btncreate = btncreate = Button(
                    u'创建游戏', parent=self, x=440, y=75, width=90, height=40
                )
                self.btncancel = btncancel = Button(
                    u'取消', parent=self, x=440, y=25, width=90, height=40
                )
                btncreate.state = Button.DISABLED

                txtbox = self.txtgamename = TextBox(
                    parent=self, x=95, y=395, width=420, height=22,
                )
                uname = Executive.gamemgr.account.username

                f = pyglet.font.load('AncientPix', 9)

                un1 = textsnap(uname, f, 140)

                if un1 != uname:
                    uname = textsnap(uname, f, 120) + u'…'
                txtbox.text = uname + u'的游戏'

                self.labels = batch = pyglet.graphics.Batch()
                Label(
                    u'创建游戏房间', font_size=12, x=275, y=431,
                    anchor_x='center', anchor_y='bottom',
                    color=Colors.green.heavy + (255, ),
                    shadow=(1, 207, 240, 156, 204),
                    batch=batch,
                ),
                Label(
                    u'房间名称:', font_size=9, x=30, y=400,
                    anchor_x='left', anchor_y='bottom',
                    color=Colors.green.heavy + (255, ),
                    shadow=(1, 207, 240, 156, 204),
                    batch=batch,
                )

                from gamepack import gamemodes as modes

                self.selectors = selectors = []

                def on_select():
                    btncreate.state = Button.NORMAL

                for i, (gname, gcls) in enumerate(modes.items()):
                    y, x = divmod(i, 3)
                    x, y = 30 + 170*x, 275 - 125*y
                    s = ImageSelector(
                        gcls.ui_meta.logo, selectors,
                        parent=self, x=x, y=y
                    )
                    intro = getattr(gcls.ui_meta, 'description', None)
                    intro and s.init_balloon(intro, width=480)
                    s.gametype = gname
                    s.event(on_select)
                    selectors.append(s)

                @btncreate.event
                def on_click():
                    gtype = ImageSelector.get_selected(selectors).gametype
                    f = pyglet.font.load('AncientPix', 9)
                    roomname = textsnap(txtbox.text, f, 200)
                    Executive.call('create_game', ui_message, [gtype, roomname])

                @btncancel.event  # noqa
                def on_click():
                    self.delete()