예제 #1
0
 def __init__(self, enable, sid, *a, **k):
     Button.__init__(self, width=71, height=20, *a, **k)
     self.selected = False
     self.state = Button.NORMAL if enable else Button.DISABLED
     self.color = Colors.blue
     self.sid = sid
     self.update()
예제 #2
0
 def __init__(self, enable, sid, *a, **k):
     Button.__init__(self, width=71, height=20, *a, **k)
     self.selected = False
     self.state = Button.NORMAL if enable else Button.DISABLED
     self.color = Colors.blue
     self.sid = sid
     self.update()
예제 #3
0
 def __init__(self, skill, sid, enable, view, *a, **k):
     Button.__init__(self, skill.ui_meta.name, width=71, height=20, *a, **k)
     self._selected = False
     self.state = Button.NORMAL if enable else Button.DISABLED
     self.color = Colors.blue
     self.skill = skill
     self.sid = sid
     self.view = view
     self.params_ui = None
     self.update()
예제 #4
0
 def __init__(self, skill, sid, enable, view, *a, **k):
     Button.__init__(self, skill.ui_meta.name, width=71, height=20, *a, **k)
     self._selected = False
     self.state = Button.NORMAL if enable else Button.DISABLED
     self.color = Colors.blue
     self.skill = skill
     self.sid = sid
     self.view = view
     self.params_ui = None
     self.update()
예제 #5
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, [])
예제 #6
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'])
예제 #7
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)
예제 #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.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()
예제 #9
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()
예제 #10
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')
예제 #11
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)
예제 #12
0
파일: screens.py 프로젝트: hycxa/thbattle
            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()
예제 #13
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)
예제 #14
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)
예제 #15
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)
예제 #16
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)
예제 #17
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()
예제 #18
0
파일: view.py 프로젝트: npk/thbattle
    def __init__(self, game, *a, **k):
        self.game = game
        game.event_observer = UIEventHook

        Control.__init__(self, *a, **k)

        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
예제 #19
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
예제 #20
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()
예제 #21
0
파일: screens.py 프로젝트: hycxa/thbattle
        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)
예제 #22
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)
예제 #23
0
    class RoomControlPanel(Control):
        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.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()

        def draw(self):
            self.draw_subcontrols()

        def on_message(self, _type, *args):
            if _type == 'player_change':
                self.update_portrait(args[0])
            elif _type == 'kick_request':
                u1, u2, count = args[0]
                self.parent.chat_box.append(
                    u'|B|R>> |c0000ffff%s|r希望|c0000ffff|B%s|r离开游戏,已有%d人请求\n' % (
                        u1[1], u2[1], count
                    )
                )
            elif _type == 'game_joined':
                self.ready = False
                self.btn_getready.caption = u'准备'
                self.btn_getready.state = Button.NORMAL

        def update_portrait(self, pl):
            def players():
                return {
                    p.account.username
                    for p in self.portraits
                    if p.account
                }

            orig_players = players()
            full = True

            for i, p in enumerate(pl):
                accdata = p['account']
                acc = Account.parse(accdata) if accdata else None
                if not accdata: full = False

                port = self.portraits[i]
                port.account = acc
                port.ready = (p['state'] == 'ready')

                port.update()

            curr_players = players()

            for player in (orig_players - curr_players):
                self.parent.chat_box.append(
                    u'|B|R>> |r玩家|c0000ffff|B%s|r已离开游戏\n' % player
                )

            for player in (curr_players - orig_players):
                self.parent.chat_box.append(
                    u'|B|R>> |r玩家|c0000ffff|B%s|r已进入游戏\n' % player
                )

            if not self.ready and full and orig_players != curr_players:
                from utils import notify
                notify(u'东方符斗祭 - 满员提醒', u'房间已满员,请准备。')
예제 #24
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()
예제 #25
0
    class RoomControlPanel(Control):
        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)

        def draw(self):
            self.draw_subcontrols()

        def on_message(self, _type, *args):
            if _type == 'player_change':
                self.update_portrait(args[0])
            elif _type == 'kick_request':
                u1, u2, count = args[0]
                self.parent.chat_box.append(
                    u'|B|R>> |c0000ffff%s|r希望|c0000ffff|B%s|r离开游戏,已有%d人请求\n' % (
                        u1[1], u2[1], count
                    )
                )
            elif _type == 'game_joined':
                self.ready = False
                self.btn_getready.caption = u'准备'
                self.btn_getready.state = Button.NORMAL

        def update_portrait(self, pl):
            def players():
                return {
                    p.account.username
                    for p in self.portraits
                    if p.account
                }

            orig_players = players()
            full = True

            for i, p in enumerate(pl):
                accdata = p['account']
                acc = Account.parse(accdata) if accdata else None
                if not accdata: full = False

                port = self.portraits[i]
                port.account = acc
                port.ready = (p['state'] == 'ready')

                port.update()

            curr_players = players()

            for player in (orig_players - curr_players):
                self.parent.chat_box.append(
                    u'|B|R>> |r玩家|c0000ffff|B%s|r已离开游戏\n' % player
                )

            for player in (curr_players - orig_players):
                self.parent.chat_box.append(
                    u'|B|R>> |r玩家|c0000ffff|B%s|r已进入游戏\n' % player
                )

            if not self.ready and full and orig_players != curr_players:
                from utils import notify
                notify(u'东方符斗祭 - 满员提醒', u'房间已满员,请准备。')
예제 #26
0
파일: view.py 프로젝트: AojiaoZero/thbattle
class THBattleUI(Control):
    portrait_location = [
        (60, 300, Colors.blue),
        (250, 450, Colors.orange),
        (450, 450, Colors.blue),
        (640, 300, Colors.orange),
        (450, 150, Colors.blue),
        (250, 150, Colors.orange),
    ]

    gcp_location = [
        (3, 1, 'me', Colors.blue),
        (669, 280, 'left', Colors.orange),
        (155+180+180, 520, 'bottom', Colors.blue),
        (155+180, 520, 'bottom', Colors.orange),
        (155, 520, 'bottom', Colors.blue),
        (3, 280, 'right', Colors.orange),
    ]

    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

    def init(self):
        ports = self.char_portraits = [
            GameCharacterPortrait(parent=self, color=color, x=x, y=y, tag_placement=tp)
            for x, y, tp, color in self.gcp_location[:len(self.game.players)]
        ]

        pl = self.game.players
        shift = pl.index(self.game.me)
        for i, c in enumerate(ports):
            p = pl[(shift + i) % self.game.n_persons]
            c.player = p
            c.update()

        ports[0].equipcard_area.selectable = True  # it's TheChosenOne

        self.begin_select_player()
        self.end_select_player()
        self.skill_box = SkillSelectionBox(
            parent=self, x=161, y=9, width=70, height=22*6-4
        )

        SoundManager.switch_bgm(gres.bgm_game)

        self.more_init()

    def more_init(self):
        pass

    def player2portrait(self, p):
        from gamepack.thb.characters.baseclasses import Character
        if isinstance(p, Character):
            p = p.player

        for port in self.char_portraits:
            if port.player == p:
                break
        else:
            raise ValueError(p)
        return port

    def update_skillbox(self):
        g = self.game
        skills = getattr(g.me, 'skills', None)
        if skills is None:
            # before girl chosen
            return

        skills = [
            (i, s, s.ui_meta.clickable(g))
            for i, s in enumerate(skills)
            if not getattr(s.ui_meta, 'no_display', False)
        ]

        skills.sort(key=lambda i: -i[2])

        self.skill_box.set_skills(
            (s.ui_meta.name, i, e) for i, s, e in skills
        )

    PORT_UPDATE_MESSAGES = {
        'evt_game_begin',
        'evt_switch_character',
    }

    def update_portraits(self):
        for port in self.char_portraits:
            port.update()

    def on_message(self, _type, *args):
        if _type == 'evt_action_before' and isinstance(args[0], actions.PlayerTurn):
            self.current_turn = args[0].target

        elif _type == 'player_change':
            for i, pd in enumerate(args[0]):
                p = self.game.players[i]
                port = self.player2portrait(p)
                port.dropped = (pd['state'] in ('dropped', 'fleed'))
                port.fleed = (pd['state'] == 'fleed')
                port.update()

        elif _type in self.PORT_UPDATE_MESSAGES:
            self.update_portraits()

        elif _type == 'evt_action_after':
            act = args[0]
            meta = getattr(act, 'ui_meta', None)
            if meta and getattr(meta, 'update_portrait', None):
                pl = set()
                if act.source:
                    pl.add(act.source)

                if hasattr(act, 'target_list'):
                    pl.update(act.target_list)
                elif act.target:
                    pl.add(act.target)

                for p in pl:
                    self.player2portrait(p).update()

        self.more_on_message(_type, args)

        if _type.startswith('evt_'):
            effects.handle_event(self, _type[4:], args[0])
            inputs.handle_event(self, _type[4:], args[0])

    def more_on_message(self, _type, args):
        pass

    def on_text(self, text):
        # The easter egg
        ks = self.keystrokes
        ks = (ks + text)[:40]
        self.keystrokes = ks

        from gamepack.thb.characters import characters as chars

        for c in chars:
            try:
                alter = c.ui_meta.figure_image_alter
            except:
                continue

            for i in xrange(len(ks)):
                if alter.decrypt(ks[-i:]):
                    SoundManager.play(cres.sound.input)

    def draw(self):
        self.draw_subcontrols()

    def ray(self, f, t):
        if f == t: return
        sp = self.player2portrait(f)
        dp = self.player2portrait(t)
        x0, y0 = sp.x + sp.width/2, sp.y + sp.height/2
        x1, y1 = dp.x + dp.width/2, dp.y + dp.height/2
        Ray(x0, y0, x1, y1, parent=self, zindex=10)

    def prompt(self, s):
        self.prompt_raw(u'|B|cff0000ff>> |r' + unicode(s) + u'\n')

    def prompt_raw(self, s):
        self.parent.events_box.append(s)

    def begin_select_player(self, disables=[]):
        #if self.selecting_player: return
        self.selecting_player = True
        #self.selected_players = []
        for p in self.game.players:
            port = self.player2portrait(p)

            if p in disables:
                port.disabled = True
                port.selected = False
                try:
                    self.selected_players.remove(p)
                except ValueError:
                    pass
            else:
                port.disabled = False

    def get_selected_players(self):
        return self.selected_players

    def set_selected_players(self, players):
        for p in self.char_portraits:
            p.selected = False

        for p in players:
            self.player2portrait(p).selected = True

        self.selected_players = players[:]

    def end_select_player(self):
        #if not self.selecting_player: return
        self.selecting_player = False
        self.selected_players = []
        for p in self.char_portraits:
            p.selected = False
            p.disabled = False

    def get_selected_cards(self):
        return [
            cs.associated_card
            for cs in self.handcard_area.cards
            if cs.hca_selected
        ] + [
            cs.associated_card
            for cs in self.player2portrait(self.game.me).equipcard_area.cards
            if cs.selected
        ]

    def get_selected_skills(self):
        skills = self.game.me.skills
        return sorted([
            skills[i] for i in self.skill_box.get_selected_index()
        ], key=lambda s: s.sort_index)

    def on_mouse_click(self, x, y, button, modifier):
        c = self.control_frompoint1_recursive(x, y)
        if isinstance(c, GameCharacterPortrait) and self.selecting_player and not c.disabled:
            char = c.character
            if not char: return True
            sel = c.selected
            psel = self.selected_players
            if sel:
                c.selected = False
                psel.remove(char)
            else:
                c.selected = True
                psel.append(char)
            self.dispatch_event('on_selection_change')
        return True

    def get_game_screen(self):
        assert self.parent
        return self.parent

    @staticmethod
    def show_result(g):
        ResultPanel(g, parent=Overlay.cur_overlay)
예제 #27
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)
예제 #28
0
class THBattleUI(Control):
    portrait_location = [
        (60, 300, Colors.blue),
        (250, 450, Colors.orange),
        (450, 450, Colors.blue),
        (640, 300, Colors.orange),
        (450, 150, Colors.blue),
        (250, 150, Colors.orange),
    ]

    gcp_location = [
        (3, 1, 'me', Colors.blue),
        (669, 280, 'left', Colors.orange),
        (155 + 180 + 180, 520, 'bottom', Colors.blue),
        (155 + 180, 520, 'bottom', Colors.orange),
        (155, 520, 'bottom', Colors.blue),
        (3, 280, 'right', Colors.orange),
    ]

    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

    def init(self):
        ports = self.char_portraits = [
            GameCharacterPortrait(parent=self,
                                  color=color,
                                  x=x,
                                  y=y,
                                  tag_placement=tp)
            for x, y, tp, color in self.gcp_location[:len(self.game.players)]
        ]

        pl = self.game.players
        shift = pl.index(self.game.me)
        for i, c in enumerate(ports):
            p = pl[(shift + i) % self.game.n_persons]
            c.player = p
            c.update()

        ports[0].equipcard_area.selectable = True  # it's TheChosenOne

        self.begin_select_player()
        self.end_select_player()
        self.skill_box = SkillSelectionBox(parent=self,
                                           x=161,
                                           y=9,
                                           width=70,
                                           height=22 * 6 - 4)

        SoundManager.switch_bgm(gres.bgm_game)

        self.more_init()

    def more_init(self):
        pass

    def player2portrait(self, p):
        from gamepack.thb.characters.baseclasses import Character
        if isinstance(p, Character):
            p = p.player

        for port in self.char_portraits:
            if port.player == p:
                break
        else:
            raise ValueError(p)
        return port

    def update_skillbox(self):
        g = self.game
        skills = getattr(g.me, 'skills', None)
        if skills is None:
            # before girl chosen
            return

        skills = [(i, s, s.ui_meta.clickable(g)) for i, s in enumerate(skills)
                  if not getattr(s.ui_meta, 'no_display', False)]

        skills.sort(key=lambda i: -i[2])

        self.skill_box.set_skills((s.ui_meta.name, i, e) for i, s, e in skills)

    PORT_UPDATE_MESSAGES = {
        'evt_game_begin',
        'evt_switch_character',
    }

    def update_portraits(self):
        for port in self.char_portraits:
            port.update()

    def on_message(self, _type, *args):
        if _type == 'evt_action_before' and isinstance(args[0],
                                                       actions.PlayerTurn):
            self.current_turn = args[0].target

        elif _type == 'player_change':
            for i, pd in enumerate(args[0]):
                p = self.game.players[i]
                port = self.player2portrait(p)
                port.dropped = (pd['state'] in ('dropped', 'fleed'))
                port.fleed = (pd['state'] == 'fleed')
                port.update()

        elif _type in self.PORT_UPDATE_MESSAGES:
            self.update_portraits()

        elif _type == 'evt_action_after':
            act = args[0]
            meta = getattr(act, 'ui_meta', None)
            if meta and getattr(meta, 'update_portrait', None):
                pl = set()
                if act.source:
                    pl.add(act.source)

                if hasattr(act, 'target_list'):
                    pl.update(act.target_list)
                elif act.target:
                    pl.add(act.target)

                for p in pl:
                    self.player2portrait(p).update()

        self.more_on_message(_type, args)

        if _type.startswith('evt_'):
            effects.handle_event(self, _type[4:], args[0])
            inputs.handle_event(self, _type[4:], args[0])

    def more_on_message(self, _type, args):
        pass

    def on_text(self, text):
        # The easter egg
        ks = self.keystrokes
        ks = (ks + text)[:40]
        self.keystrokes = ks

        from gamepack.thb.characters import characters as chars

        for c in chars:
            try:
                alter = c.ui_meta.figure_image_alter
            except:
                continue

            for i in xrange(len(ks)):
                if alter.decrypt(ks[-i:]):
                    SoundManager.play(cres.sound.input)

    def draw(self):
        self.draw_subcontrols()

    def ray(self, f, t):
        if f == t: return
        sp = self.player2portrait(f)
        dp = self.player2portrait(t)
        x0, y0 = sp.x + sp.width / 2, sp.y + sp.height / 2
        x1, y1 = dp.x + dp.width / 2, dp.y + dp.height / 2
        Ray(x0, y0, x1, y1, parent=self, zindex=10)

    def prompt(self, s):
        self.prompt_raw(u'|B|cff0000ff>> |r' + unicode(s) + u'\n')

    def prompt_raw(self, s):
        self.parent.events_box.append(s)

    def begin_select_player(self, disables=[]):
        #if self.selecting_player: return
        self.selecting_player = True
        #self.selected_players = []
        for p in self.game.players:
            port = self.player2portrait(p)

            if p in disables:
                port.disabled = True
                port.selected = False
                try:
                    self.selected_players.remove(p)
                except ValueError:
                    pass
            else:
                port.disabled = False

    def get_selected_players(self):
        return self.selected_players

    def set_selected_players(self, players):
        for p in self.char_portraits:
            p.selected = False

        for p in players:
            self.player2portrait(p).selected = True

        self.selected_players = players[:]

    def end_select_player(self):
        #if not self.selecting_player: return
        self.selecting_player = False
        self.selected_players = []
        for p in self.char_portraits:
            p.selected = False
            p.disabled = False

    def get_selected_cards(self):
        return [
            cs.associated_card
            for cs in self.handcard_area.cards if cs.hca_selected
        ] + [
            cs.associated_card
            for cs in self.player2portrait(self.game.me).equipcard_area.cards
            if cs.selected
        ]

    def get_selected_skills(self):
        skills = self.game.me.skills
        return sorted([skills[i] for i in self.skill_box.get_selected_index()],
                      key=lambda s: s.sort_index)

    def on_mouse_click(self, x, y, button, modifier):
        c = self.control_frompoint1_recursive(x, y)
        if isinstance(c, GameCharacterPortrait
                      ) and self.selecting_player and not c.disabled:
            char = c.character
            if not char: return True
            sel = c.selected
            psel = self.selected_players
            if sel:
                c.selected = False
                psel.remove(char)
            else:
                c.selected = True
                psel.append(char)
            self.dispatch_event('on_selection_change')
        return True

    def get_game_screen(self):
        assert self.parent
        return self.parent

    @staticmethod
    def show_result(g):
        ResultPanel(g, parent=Overlay.cur_overlay)
예제 #29
0
 def delete(self):
     self.params_ui and self.params_ui.delete()
     Button.delete(self)
예제 #30
0
파일: screens.py 프로젝트: hycxa/thbattle
    class RoomControlPanel(Control):
        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)

        def draw(self):
            self.draw_subcontrols()

        def on_message(self, _type, *args):
            if _type == "player_change":
                self.update_portrait(args[0])
            elif _type == "kick_request":
                u1, u2, count = args[0]
                self.parent.chat_box.append(
                    u"|B|R>> |c0000ffff%s|r希望|c0000ffff|B%s|r离开游戏,已有%d人请求\n" % (u1[1], u2[1], count)
                )
            elif _type == "game_joined":
                self.ready = False
                self.btn_getready.caption = u"准备"
                self.btn_getready.state = Button.NORMAL

        def update_portrait(self, pl):
            def players():
                return {p.account.username for p in self.portraits if p.account}

            orig_players = players()
            full = True

            for i, p in enumerate(pl):
                accdata = p["account"]
                acc = Account.parse(accdata) if accdata else None
                if not accdata:
                    full = False

                port = self.portraits[i]
                port.account = acc
                port.ready = p["state"] == "ready"

                port.update()

            curr_players = players()

            for player in orig_players - curr_players:
                self.parent.chat_box.append(u"|B|R>> |r玩家|c0000ffff|B%s|r已离开游戏\n" % player)

            for player in curr_players - orig_players:
                self.parent.chat_box.append(u"|B|R>> |r玩家|c0000ffff|B%s|r已进入游戏\n" % player)

            if not self.ready and full and orig_players != curr_players:
                from utils import notify

                notify(u"东方符斗祭 - 满员提醒", u"房间已满员,请准备。")
예제 #31
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
예제 #32
0
 def delete(self):
     self.params_ui and self.params_ui.delete()
     Button.delete(self)
예제 #33
0
파일: view.py 프로젝트: npk/thbattle
class THBattleUI(Control):
    portrait_location = [
        (60, 300, Colors.blue),
        (250, 450, Colors.orange),
        (450, 450, Colors.blue),
        (640, 300, Colors.orange),
        (450, 150, Colors.blue),
        (250, 150, Colors.orange),
    ]

    gcp_location = [
        (3, 1, "me", Colors.blue),
        (669, 280, "left", Colors.orange),
        (155 + 180 + 180, 520, "bottom", Colors.blue),
        (155 + 180, 520, "bottom", Colors.orange),
        (155, 520, "bottom", Colors.blue),
        (3, 280, "right", Colors.orange),
    ]

    def __init__(self, game, *a, **k):
        self.game = game
        game.event_observer = UIEventHook

        Control.__init__(self, *a, **k)

        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

    def init(self):
        ports = self.char_portraits = [
            GameCharacterPortrait(parent=self, color=color, x=x, y=y, tag_placement=tp)
            for x, y, tp, color in self.gcp_location[: len(self.game.players)]
        ]

        pl = self.game.players
        shift = pl.index(self.game.me)
        for i, c in enumerate(ports):
            p = pl[(shift + i) % self.game.n_persons]
            c.player = p
            c.update()

        ports[0].equipcard_area.selectable = True  # it's TheChosenOne

        self.begin_select_player()
        self.end_select_player()
        self.skill_box = SkillSelectionBox(parent=self, x=161, y=9, width=70, height=22 * 6 - 4)

        SoundManager.switch_bgm(gres.bgm_game)

    def player2portrait(self, p):
        for port in self.char_portraits:
            if port.player == p:
                break
        else:
            raise ValueError(p)
        return port

    def update_skillbox(self):
        g = self.game
        skills = getattr(g.me, "skills", None)
        if skills is None:
            # before girl chosen
            return

        skills = [
            (i, s, s.ui_meta.clickable(g)) for i, s in enumerate(skills) if not getattr(s.ui_meta, "no_display", False)
        ]

        skills.sort(key=lambda i: -i[2])

        self.skill_box.set_skills((s.ui_meta.name, i, e) for i, s, e in skills)

    PORT_UPDATE_MESSAGES = {"evt_game_begin", "evt_kof_next_character"}

    def update_portraits(self):
        for port in self.char_portraits:
            port.update()

    def on_message(self, _type, *args):
        if _type == "evt_action_before" and isinstance(args[0], actions.PlayerTurn):
            self.current_turn = args[0].target

        elif _type == "player_change":
            for i, pd in enumerate(args[0]):
                p = self.game.players[i]
                port = self.player2portrait(p)
                port.dropped = pd["state"] in ("dropped", "fleed")
                port.fleed = pd["state"] == "fleed"
                port.update()

        elif _type in self.PORT_UPDATE_MESSAGES:
            self.update_portraits()

        elif _type == "evt_action_after":
            act = args[0]
            meta = getattr(act, "ui_meta", None)
            if meta and getattr(meta, "update_portrait", None):
                pl = set()
                if act.source:
                    pl.add(act.source)

                if hasattr(act, "target_list"):
                    pl.update(act.target_list)
                elif act.target:
                    pl.add(act.target)

                for p in pl:
                    self.player2portrait(p).update()

        if _type.startswith("evt_"):
            effects.handle_event(self, _type[4:], args[0])
            inputs.handle_event(self, _type[4:], args[0])

    def draw(self):
        self.draw_subcontrols()

    def ray(self, f, t):
        if f == t:
            return
        sp = self.player2portrait(f)
        dp = self.player2portrait(t)
        x0, y0 = sp.x + sp.width / 2, sp.y + sp.height / 2
        x1, y1 = dp.x + dp.width / 2, dp.y + dp.height / 2
        Ray(x0, y0, x1, y1, parent=self, zindex=10)

    def prompt(self, s):
        self.prompt_raw(u"|B|cff0000ff>> |r" + unicode(s) + u"\n")

    def prompt_raw(self, s):
        self.parent.events_box.append(s)

    def begin_select_player(self, disables=[]):
        # if self.selecting_player: return
        self.selecting_player = True
        # self.selected_players = []
        for p in self.game.players:
            port = self.player2portrait(p)

            if p in disables:
                port.disabled = True
                port.selected = False
                try:
                    self.selected_players.remove(p)
                except ValueError:
                    pass
            else:
                port.disabled = False

    def get_selected_players(self):
        return self.selected_players

    def set_selected_players(self, players):
        for p in self.char_portraits:
            p.selected = False

        for p in players:
            self.player2portrait(p).selected = True

        self.selected_players = players[:]

    def end_select_player(self):
        # if not self.selecting_player: return
        self.selecting_player = False
        self.selected_players = []
        for p in self.char_portraits:
            p.selected = False
            p.disabled = False

    def get_selected_cards(self):
        return [cs.associated_card for cs in self.handcard_area.cards if cs.hca_selected] + [
            cs.associated_card for cs in self.player2portrait(self.game.me).equipcard_area.cards if cs.selected
        ]

    def get_selected_skills(self):
        skills = self.game.me.skills
        return sorted([skills[i] for i in self.skill_box.get_selected_index()], key=lambda s: s.sort_index)

    def on_mouse_click(self, x, y, button, modifier):
        c = self.control_frompoint1_recursive(x, y)
        if isinstance(c, GameCharacterPortrait) and self.selecting_player and not c.disabled:
            sel = c.selected
            psel = self.selected_players
            if sel:
                c.selected = False
                psel.remove(c.player)
            else:
                c.selected = True
                psel.append(c.player)
            self.dispatch_event("on_selection_change")
        return True

    def get_game_screen(self):
        assert self.parent
        return self.parent

    @staticmethod
    def show_result(g):
        ResultPanel(g, parent=Overlay.cur_overlay)