Ejemplo n.º 1
0
class BattleSessionList(PrebattlesListWindow, BattleSessionListMeta):
    lobbyContext = dependency.descriptor(ILobbyContext)

    def __init__(self, ctx=None):
        super(BattleSessionList, self).__init__(LAZY_CHANNEL.SPECIAL_BATTLES)
        self.__listRequester = AutoInvitesRequester()

    def requestToJoinTeam(self, prbID, prbType):
        item = self.__listRequester.getItem(prbID)
        if self.lobbyContext.isAnotherPeriphery(item.peripheryID):
            self.fireEvent(events.LoadViewEvent(
                PREBATTLE_ALIASES.AUTO_INVITE_WINDOW_PY, ctx={'prbID': prbID}),
                           scope=EVENT_BUS_SCOPE.LOBBY)
        else:
            self.__requestToJoin(prbID, prbType)

    def getClientID(self):
        return channel_num_gen.getClientID4LazyChannel(
            LAZY_CHANNEL.SPECIAL_BATTLES)

    def onFocusIn(self, alias):
        self.fireEvent(
            FocusEvent(FocusEvent.COMPONENT_FOCUSED,
                       {'clientID': self.getClientID()}))

    def _populate(self):
        super(BattleSessionList, self)._populate()
        self.__listRequester.start(self.__onBSListReceived)
        self.__listRequester.request()

    def _dispose(self):
        self.__listRequester.stop()
        super(BattleSessionList, self)._dispose()

    @process
    def __requestToJoin(self, prbID, prbType):
        yield self.prbDispatcher.join(
            JoinBattleSessionCtx(prbID, prbType, 'prebattle/join'))

    def __onBSListReceived(self, sessions):
        result = []
        for bs in sessions:
            result.append({
                'prbID':
                bs.prbID,
                'prbType':
                bs.prbType,
                'descr':
                formatters.getPrebattleFullDescription(bs.description),
                'opponents':
                formatters.getPrebattleOpponentsString(bs.description),
                'startTime':
                formatters.getBattleSessionStartTimeString(bs.startTime)
            })

        self.as_refreshListS(result)
class SpecModeSelectorItem(ModeSelectorLegacyItem):
    __slots__ = ('__requester', )
    __guiLoader = dependency.descriptor(IGuiLoader)

    def handleClick(self):
        if self.__guiLoader.windowsManager.getViewByLayoutID(
                BattleSessionView.layoutID):
            return
        g_eventBus.handleEvent(LoadGuiImplViewEvent(
            GuiImplViewLoadParams(BattleSessionView.layoutID,
                                  BattleSessionView,
                                  ScopeTemplates.LOBBY_SUB_SCOPE)),
                               scope=EVENT_BUS_SCOPE.LOBBY)

    def _getIsDisabled(self):
        return False

    def _onInitializing(self):
        super(SpecModeSelectorItem, self)._onInitializing()
        self.__requester = AutoInvitesRequester()
        self.__requester.start(self.__onListReceived)
        self.__requester.request()

    def _onDisposing(self):
        self.__requester.stop()

    def __onListReceived(self, sessions):
        item = first(sorted(sessions, key=operator.attrgetter('startTime')))
        if item:
            self.viewModel.setStatusActive(
                backport.text(
                    R.strings.mode_selector.mode.specBattlesList.call.c_2(),
                    date=backport.getShortDateFormat(item.startTime),
                    time=backport.getShortTimeFormat(item.startTime)))
        else:
            self.viewModel.setStatusActive(
                backport.text(
                    R.strings.mode_selector.mode.specBattlesList.call.c_1()))
 def _onInitializing(self):
     super(SpecModeSelectorItem, self)._onInitializing()
     self.__requester = AutoInvitesRequester()
     self.__requester.start(self.__onListReceived)
     self.__requester.request()
Ejemplo n.º 4
0
 def __init__(self, ctx=None):
     super(BattleSessionList, self).__init__(LAZY_CHANNEL.SPECIAL_BATTLES)
     self.__listRequester = AutoInvitesRequester()
Ejemplo n.º 5
0
class BattleSessionList(PrebattlesListWindow, BattleSessionListMeta):
    lobbyContext = dependency.descriptor(ILobbyContext)
    __webCtrl = dependency.descriptor(IWebController)

    def __init__(self, ctx=None):
        super(BattleSessionList, self).__init__(LAZY_CHANNEL.SPECIAL_BATTLES)
        self.__listRequester = AutoInvitesRequester()

    def requestToJoinTeam(self, prbID, prbType):
        item = self.__listRequester.getItem(prbID)
        if self.lobbyContext.isAnotherPeriphery(item.peripheryID):
            self.fireEvent(events.LoadViewEvent(SFViewLoadParams(PREBATTLE_ALIASES.AUTO_INVITE_WINDOW_PY), ctx={'prbID': prbID}), scope=EVENT_BUS_SCOPE.LOBBY)
        else:
            self.__requestToJoin(prbID, prbType)

    def getClientID(self):
        return channel_num_gen.getClientID4LazyChannel(LAZY_CHANNEL.SPECIAL_BATTLES)

    def onFocusIn(self, alias):
        self.fireEvent(FocusEvent(FocusEvent.COMPONENT_FOCUSED, {'clientID': self.getClientID()}))

    def _populate(self):
        super(BattleSessionList, self)._populate()
        self.addListener(events.HideWindowEvent.HIDE_SPECIAL_BATTLE_WINDOW, self.__hideWindow, scope=EVENT_BUS_SCOPE.LOBBY)
        self.__listRequester.start(self.__onBSListReceived)
        self.__listRequester.request()

    def _dispose(self):
        self.__listRequester.stop()
        self.removeListener(events.HideWindowEvent.HIDE_SPECIAL_BATTLE_WINDOW, self.__hideWindow, scope=EVENT_BUS_SCOPE.LOBBY)
        super(BattleSessionList, self)._dispose()

    def __hideWindow(self, _):
        self.destroy()

    @process
    def __requestToJoin(self, prbID, prbType):
        yield self.prbDispatcher.join(JoinBattleSessionCtx(prbID, prbType, 'prebattle/join'))

    def __onBSListReceived(self, sessions):
        result = []
        clanDBID = self.__webCtrl.getClanDbID()
        for bs in sessions:
            detachment, vehicleLvl, _ = formatters.getBattleSessionDetachment(bs.description, clanDBID)
            if bs.prbType == PREBATTLE_TYPE.CLAN:
                startTime = self.__getClanBattleStartTime(bs)
            else:
                startTime = formatters.getBattleSessionStartTimeString(bs.startTime)
            result.append({'prbID': bs.prbID,
             'prbType': bs.prbType,
             'descr': formatters.getPrebattleFullDescription(bs.description),
             'opponents': formatters.getPrebattleOpponentsString(bs.description),
             'startTime': startTime,
             'unitName': detachment,
             'vehicleLevel': vehicleLvl})

        self.as_refreshListS(result)

    def __getClanBattleStartTime(self, battleSession):
        arenaName = getArenaShortName(battleSession.arenaTypeID) or ''
        peripheryName = self.lobbyContext.getPeripheryName(battleSession.peripheryID, checkAnother=False, useShortName=True)
        if peripheryName is None:
            peripheryName = ''
        startTimeString = formatters.getPrebattleStartTimeString(battleSession.startTime)
        return backport.text(R.strings.prebattle.title.battleSession.clanBattle.startTime(), startTime=startTimeString, peripheryName=peripheryName, arenaName=arenaName)