コード例 #1
0
class GUI(clientApi.GetScreenNodeCls()):
    def SetVisible(self, widget, on):
        if widget in self.clocks:
            if on:
                sec = self.clocks[widget]
                if sec is None and self.countdown is not None:
                    self.clocks[widget] = self.countdown
                    self.SetText(widget + '/sec', str(self.countdown))
            elif self.clocks[widget] is not None:
                self.clocks[widget] = None
        super(GUI, self).SetVisible(widget, on)

    def Update(self):
        if self.tasks:
            for i in xrange(len(self.tasks) - 1, -1, -1):
                task = self.tasks[i]
                task.loop()
                if task.done():
                    del self.tasks[i]

    def Create(self):
        self.AddTouchEventHandler(self.homepage + '/classic', self.classic)  # flip
        self.AddTouchEventHandler(self.c + '/classical', self.classical)  # flip
        self.AddTouchEventHandler(self.cc + '/rookie', self.rookie)  # flip
        self.AddTouchEventHandler(self.room + '/match', self.match)  # room
        self.AddTouchEventHandler(self.room + '/bot', self.bot)  # room
        self.AddTouchEventHandler(self.auto + '/resume', self.resume)  # room
        origins = []
        for i in xrange(20):
            h = self.mh + '/m{}'.format(i)
            origins.append(self.GetPosition(h))
            self.AddTouchEventHandler(h, self.select)
        self.origins = tuple(origins)
        self.AddTouchEventHandler(self.court + '/showhand', self.showhand)  # room
        self.AddTouchEventHandler(self.gang + '/fightover', self.fightover)  # room
        self.AddTouchEventHandler(self.gang + '/giveup', self.giveup)  # room
        self.AddTouchEventHandler(self.plus + '/su', self.su)  # room
        self.AddTouchEventHandler(self.plus + '/sup', self.sup)  # room
        self.AddTouchEventHandler(self.plus + '/calm', self.calm)  # room
        self.AddTouchEventHandler(self.turn + '/pass', self.skip)  # room
        self.AddTouchEventHandler(self.turn + '/propose', self.propose)  # room
        self.AddTouchEventHandler(self.turn + '/play', self.play)  # room
        self.AddTouchEventHandler(self.turn + '/sh', self.showhand)  # room
        self.AddTouchEventHandler(self.turn + '/hint', self.propose)  # room
        self.AddTouchEventHandler(self.turn + '/slay', self.play)  # room

    # <editor-fold desc="widgets">
    # region room
    @property
    def msup(self):
        return self.infobar + '/msup'

    @property
    def msu(self):
        return self.infobar + '/msu'

    @property
    def msh(self):
        return self.infobar + '/msh'

    @property
    def mclock(self):
        return self.court + '/mclock'

    @property
    def clock(self):
        return self.court + '/clock'

    @property
    def m(self):
        return self.court + '/m'

    @property
    def notice(self):
        return self.court + '/notice'

    @property
    def choice(self):
        return self.court + '/choice'

    @property
    def auto(self):
        return self.court + '/auto'

    @property
    def rrobot(self):
        return self.ricon + '/robot'

    @property
    def rchoice(self):
        return self.right + '/rchoice'

    @property
    def rclock(self):
        return self.right + '/rclock'

    @property
    def r(self):
        return self.right + '/r'

    @property
    def rh(self):
        return self.right + '/rh'

    @property
    def rsup(self):
        return self.right + '/rsup'

    @property
    def rsu(self):
        return self.right + '/rsu'

    @property
    def rcount(self):
        return self.right + '/rblank/count'

    @property
    def rbanker(self):
        return self.right + '/rbanker'

    @property
    def rreal(self):
        return self.right + '/rreal'

    @property
    def rname(self):
        return self.right + '/rname'

    @property
    def rplate(self):
        return self.right + '/rplate'

    @property
    def ricon(self):
        return self.right + '/ricon'

    @property
    def right(self):
        return self.court + '/right'

    @property
    def lrobot(self):
        return self.licon + '/robot'

    @property
    def lchoice(self):
        return self.left + '/lchoice'

    @property
    def lclock(self):
        return self.left + '/lclock'

    @property
    def l(self):
        return self.left + '/l'

    @property
    def lh(self):
        return self.left + '/lh'

    @property
    def lsup(self):
        return self.left + '/lsup'

    @property
    def lsu(self):
        return self.left + '/lsu'

    @property
    def lcount(self):
        return self.left + '/lblank/count'

    @property
    def lbanker(self):
        return self.left + '/lbanker'

    @property
    def lreal(self):
        return self.left + '/lreal'

    @property
    def lname(self):
        return self.left + '/lname'

    @property
    def lplate(self):
        return self.left + '/lplate'

    @property
    def licon(self):
        return self.left + '/licon'

    @property
    def left(self):
        return self.court + '/left'

    @property
    def mh(self):
        return self.court + '/mh'

    @property
    def turn(self):
        return self.court + '/turn'

    @property
    def plus(self):
        return self.court + '/plus'

    @property
    def gang(self):
        return self.court + '/gang'

    @property
    def court(self):
        return self.room + '/court'

    @property
    def utmost(self):
        return self.tag + '/utmost'

    @property
    def fee(self):
        return self.tag + '/fee'

    @property
    def tag(self):
        return self.room + '/tag'

    @property
    def room(self):
        return self.real + '/room'

    # endregion

    # region flip
    @property
    def cc(self):
        return self.flip + '/c-c'

    @property
    def c(self):
        return self.flip + '/c'

    @property
    def homepage(self):
        return self.flip + '/homepage'

    @property
    def flip(self):
        return self.real + '/flip'

    # endregion

    # region bottom
    @property
    def times(self):
        return self.infobar + '/times'

    @property
    def balance(self):
        return self.infobar + '/balance'

    @property
    def shorty(self):
        return self.infobar + '/shorty'

    @property
    def plate(self):
        return self.infobar + '/plate'

    @property
    def og(self):
        return self.icon + '/og'

    @property
    def icon(self):
        return self.infobar + '/icon'

    @property
    def infobar(self):
        return self.bottom + '/infobar'

    @property
    def toolbar(self):
        return self.bottom + '/toolbar'

    @property
    def bottom(self):
        return self.real + '/bottom'

    # endregion

    # region top
    @property
    def rank(self):
        return self.top + '/rank'

    @property
    def top(self):
        return self.real + '/top'

    # endregion
    # </editor-fold>

    @property
    def real(self):
        return self.prefix + '/4real'

    @real.setter
    def real(self, info):
        self.SetText(self.balance, info['real'])
        self.SetText(self.top + '/real', info['real'])
        self.SetText(self.shorty, COLOR_CODE_MAPPING[0].format(info['name']))
        self.SetText(self.top + '/name', COLOR_CODE_MAPPING[0].format(info['name']))
        self.SetSprite(self.plate, info['rank'])
        self.SetSprite(self.rank, info['rank'])
        self.SetSprite(self.icon, info['icon'])
        self.SetSprite(self.top + '/head/default', info['icon'])
        self.SetSprite(self.top + '/head/hover', info['icon'])
        self.SetSprite(self.top + '/head/pressed', info['icon'])

    @property
    def duel(self):
        return self._duel

    @duel.setter
    def duel(self, args):
        if not self.debut:
            self.debut = True
        if self.duel is args is None:
            self.SetVisible(self.mh, False)
            self.SetVisible(self.court, False)
            self.SetVisible(self.room, False)
            self.SetVisible(self.real, True)
            return
        if self.retreat:
            pass
        if self.duel is None:
            self._duel = Duel(self, *args)
            self.tasks.append(Task(self.sec, 30))
            self.SetVisible(self.room + '/change', False)
            self.SetVisible(self.room + '/match', False)
            self.SetVisible(self.room + '/bot', True)
            self.SetVisible(self.court, True)
        else:
            self.duel.catch_up(*args)

    def __init__(self, *args):
        super(GUI, self).__init__(*args)
        self.debut = False
        self.retreat = False
        self.prefix = (
            '/variables_button_mappings_and_controls'
            '/safezone_screen_matrix'
            '/inner_matrix'
            '/safezone_screen_panel'
            '/root_screen_panel'
        )
        self.clocks = {
            self.clock: None,
            self.mclock: None,
            self.rclock: None,
            self.lclock: None,
        }
        self.tasks = []
        self.selected = set()
        self.last_result = None,
        self.proposals = None
        self.last_proposal = None
        self.origins = None
        self.countdown = None
        self._court = None
        self._duel = None

    def sec(self):
        for clock, sec in self.clocks.iteritems():
            if sec is not None:
                if sec:
                    sec -= 1
                    self.clocks[clock] = sec
                    self.SetText(clock + '/sec', str(sec))

    def standby(self):
        self.SetVisible(self.real, False)

    def classic(self, kws):
        if kws["TouchEvent"] == clientApi.GetMinecraftEnum().TouchEvent.TouchUp:
            self.SetVisible(self.homepage, False)
            self.SetVisible(self.c, True)

    def classical(self, kws):
        if kws["TouchEvent"] == clientApi.GetMinecraftEnum().TouchEvent.TouchUp:
            self.SetVisible(self.c, False)
            self.SetVisible(self.cc, True)

    def rookie(self, kws):
        if kws["TouchEvent"] == clientApi.GetMinecraftEnum().TouchEvent.TouchUp:
            if self.retreat:
                pass
            elif self._court is None:
                self._court = 0
                self.SetText(self.fee, '996')
                self.SetText(self.utmost, '4396万')
                self.SetVisible(self.top, False)
                self.SetVisible(self.flip, False)
                self.SetVisible(self.toolbar, False)
                self.SetVisible(self.infobar, True)
                self.SetVisible(self.room, True)

    def match(self, kws):
        if kws["TouchEvent"] == clientApi.GetMinecraftEnum().TouchEvent.TouchUp:
            if self._court is not None:
                self._cli.NotifyToServer('G_MATCH', {
                    'pid': clientApi.GetLocalPlayerId(),
                    'court': self._court
                })

    def select(self, kws):
        if kws["TouchEvent"] == clientApi.GetMinecraftEnum().TouchEvent.TouchMoveIn:
            if self.duel:
                i = int(kws['ButtonPath'][::-1].split('/', 1)[0][:-1][::-1])
                if i in self.duel.gamblers[self.duel.uid].cards:
                    x, y = self.origins[i]
                    if i in self.selected:
                        self.selected.discard(i)
                        self.SetPosition(kws['ButtonPath'], (x, y))
                    else:
                        self.selected.add(i)
                        self.SetPosition(kws['ButtonPath'], (x, y - 14.0))

    def bot(self, kws):
        if kws["TouchEvent"] == clientApi.GetMinecraftEnum().TouchEvent.TouchUp:
            self._cli.NotifyToServer('G_COURT', {
                'pid': clientApi.GetLocalPlayerId(),
                'name': 'bot',
                'args': [1]
            })

    def resume(self, kws):
        if kws["TouchEvent"] == clientApi.GetMinecraftEnum().TouchEvent.TouchUp:
            self._cli.NotifyToServer('G_COURT', {
                'pid': clientApi.GetLocalPlayerId(),
                'name': 'bot',
                'args': [0]
            })

    def showhand(self, kws):
        if kws["TouchEvent"] == clientApi.GetMinecraftEnum().TouchEvent.TouchUp:
            self._cli.NotifyToServer('G_COURT', {
                'pid': clientApi.GetLocalPlayerId(),
                'name': 'show_hand',
                'args': []
            })

    def fightover(self, kws):
        if kws["TouchEvent"] == clientApi.GetMinecraftEnum().TouchEvent.TouchUp:
            self._cli.NotifyToServer('G_COURT', {
                'pid': clientApi.GetLocalPlayerId(),
                'name': 'choose',
                'args': [1]
            })

    def giveup(self, kws):
        if kws["TouchEvent"] == clientApi.GetMinecraftEnum().TouchEvent.TouchUp:
            self._cli.NotifyToServer('G_COURT', {
                'pid': clientApi.GetLocalPlayerId(),
                'name': 'choose',
                'args': [0]
            })

    def calm(self, kws):
        if kws["TouchEvent"] == clientApi.GetMinecraftEnum().TouchEvent.TouchUp:
            self._cli.NotifyToServer('G_COURT', {
                'pid': clientApi.GetLocalPlayerId(),
                'name': 'times',
                'args': [1]
            })

    def su(self, kws):
        if kws["TouchEvent"] == clientApi.GetMinecraftEnum().TouchEvent.TouchUp:
            self._cli.NotifyToServer('G_COURT', {
                'pid': clientApi.GetLocalPlayerId(),
                'name': 'times',
                'args': [2]
            })

    def sup(self, kws):
        if kws["TouchEvent"] == clientApi.GetMinecraftEnum().TouchEvent.TouchUp:
            self._cli.NotifyToServer('G_COURT', {
                'pid': clientApi.GetLocalPlayerId(),
                'name': 'times',
                'args': [4]
            })

    def skip(self, kws):
        if kws["TouchEvent"] == clientApi.GetMinecraftEnum().TouchEvent.TouchUp:
            self._cli.NotifyToServer('G_COURT', {
                'pid': clientApi.GetLocalPlayerId(),
                'name': 'play',
                'args': [{}]
            })

    def propose(self, kws):
        if kws["TouchEvent"] == clientApi.GetMinecraftEnum().TouchEvent.TouchUp:
            if self.duel and self.duel.chain:
                phase = self.duel.chain.phase
                track = self.duel.chain.track
                if phase.turn == self.duel.uid and phase.name == 'MainPhase':
                    if self.proposals is None:
                        self.last_proposal = None
                        cards = {}
                        for card in self.duel.gamblers[self.duel.uid].cards.itervalues():
                            cards.setdefault(card[0], []).append(card)
                        duo = list(track[-2:])
                        duo.extend(None for _ in xrange(2 - len(track)))
                        if duo == [None, None]:
                            combo = None
                        else:
                            try:
                                duo.remove(None)
                            except ValueError:
                                pass
                            combo = duo[-1]
                        self.proposals = Combo.propose(cards, combo)
                        if not self.proposals:
                            self.SetVisible(self.notice, True)
                    proposals = self.proposals  # type: list
                    if proposals:
                        if len(proposals) != 1 or self.last_proposal != self.selected:
                            self.SetVisible(self.notice, False)
                            proposals.append(proposals.pop(0))
                            proposal = proposals[-1][-1].copy()
                            cards = self.duel.gamblers[self.duel.uid].cards
                            for i in xrange(max(cards), min(cards) - 1, -1):
                                x, y = self.origins[i]
                                h = self.mh + '/m{}'.format(i)
                                if cards[i][0] in proposal:
                                    k = cards[i][0]
                                    proposal[k] -= 1
                                    if not proposal[k]:
                                        del proposal[k]
                                    self.selected.add(i)
                                    self.SetPosition(h, (x, y - 14.0))
                                else:
                                    self.selected.discard(i)
                                    self.SetPosition(h, (x, y))
                            if not self.last_proposal and len(proposals) == 1:
                                self.last_proposal = self.selected.copy()

    def play(self, kws):
        if kws["TouchEvent"] == clientApi.GetMinecraftEnum().TouchEvent.TouchUp:
            if self.duel and self.duel.chain:
                phase = self.duel.chain.phase
                if self.selected and phase.turn == self.duel.uid and phase.name == 'MainPhase':
                    if self.last_result[0] != self.selected:
                        cards = {}
                        gambler = self.duel.gamblers[self.duel.uid]
                        for i in self.selected:
                            card = gambler.cards[i]
                            cards.setdefault(card[0], []).append(card)
                        valid = Combo.fromcards(cards, None)
                        self.last_result = self.selected.copy(), valid and cards
                        if not valid:
                            self.SetVisible(self.notice, True)
                    cards = self.last_result[1]
                    if cards:
                        self._cli.NotifyToServer('G_COURT', {
                            'pid': clientApi.GetLocalPlayerId(),
                            'name': 'play',
                            'args': [cards]
                        })
コード例 #2
0
ファイル: answerUI.py プロジェクト: H0nGzA1/SXDtravlesMod
# -*- coding: utf-8 -*-


import client.extraClientApi as clientApi
from ModScripts.modTools import logger
import ModScripts.modConfig as modConfig
ViewBinder = clientApi.GetViewBinderCls()
ViewRequest = clientApi.GetViewViewRequestCls()
ScreenNode = clientApi.GetScreenNodeCls()


class answerUIScreen(ScreenNode):
    def __init__(self, namespace, name, param):
        ScreenNode.__init__(self, namespace, name, param)
        self.PlayerId = clientApi.GetLocalPlayerId()
        self.TextCount = 0
        self.score = 0
        self._textLabelPath = "/bg_img/main_text"
        self.problemsText = {
            1: "铜铃是商代的文物吗?",
            2: "青铜鸡是古代神话中呼唤日出的”天鸡”的象征物吗?",
            3: "以下说法请判断对错\n三星堆青铜神树不是世界上最早、树株最高的青铜神树 ",
            4: "三星堆青铜大立人像被称为铜像之王吗?",
            5: "青铜纵目面具不是为世界上年代最早,形体最大的青铜面具。",
            6: "青铜戴冠纵目面具是完整的。",
            7: "太阳是轮作为太阳的象征接受人们顶礼膜拜的。",
            8: "兽面是二号祭祀坑出土的?",
            9: "以下说法请判断对错\n三星堆金杖不是世界上最早的金杖。",
            10: "戴金面罩青铜人头像是四川广汉三星堆遗址是我国迄今发现的最早的大规模青铜人像遗址出土的?"
        }
コード例 #3
0
ファイル: gui.py プロジェクト: Yamstrip/mcpy-
#Author: YmStrip
#Hint: Unauthorized use is prohibited
#Github: github.com/YamStrip/mcpy/gui.py
#Website: www.pomelors.com

#UI encapsulation plug-in

#Introduce client.extraClientApi
import client.extraClientApi as cl

vb = cl.GetViewBinderCls()
vr = cl.GetViewViewRequestCls()
sn = cl.GetScreenNodeCls()
from functools import wraps

#Create a UI object
#uilib = cl .GetScreenNodeCls ( )

#Gpl protocol

#Category
"""
class fa ( uilib ):
	def __init__ ( self , names , name , p ):
		cl .__init__ ( self , names , name , p )
"""


#ast
def ast(data):
    """