Пример #1
0
 def dropCurrentItemInSection(self, section, kind):
     if g_currentVehicle.isLocked():
         SystemMessages.pushI18nMessage(
             SYSTEM_MESSAGES.CUSTOMIZATION_VEHICLE_LOCKED,
             type=SystemMessages.SM_TYPE.Error)
         return
     elif g_currentVehicle.isBroken():
         SystemMessages.pushI18nMessage(
             SYSTEM_MESSAGES.customization_vehicle(
                 g_currentVehicle.item.getState()),
             type=SystemMessages.SM_TYPE.Error)
         return
     else:
         dialog = 'customization/{0:>s}Drop'.format(section)
         isConfirmed = yield DialogsInterface.showI18nConfirmDialog(dialog)
         if isConfirmed:
             interface = self.__interfaces.get(section)
             if interface is not None:
                 self.__returnHangar = False
                 self.__lockUpdate = True
                 Waiting.show('customizationDrop')
                 interface.drop(g_currentVehicle.invID, kind)
             else:
                 LOG_ERROR('Drop operation, section not found', section)
         return
 def dropCurrentItemInSection(self, section, kind):
     if g_currentVehicle.isLocked():
         SystemMessages.pushI18nMessage(SYSTEM_MESSAGES.CUSTOMIZATION_VEHICLE_LOCKED, type=SystemMessages.SM_TYPE.Error)
         return
     elif g_currentVehicle.isBroken():
         SystemMessages.pushI18nMessage(SYSTEM_MESSAGES.customization_vehicle(g_currentVehicle.item.getState()), type=SystemMessages.SM_TYPE.Error)
         return
     else:
         dialog = 'customization/{0:>s}Drop'.format(section)
         isConfirmed = yield DialogsInterface.showI18nConfirmDialog(dialog)
         if isConfirmed:
             interface = self.__interfaces.get(section)
             if interface is not None:
                 self.__returnHangar = False
                 self.__lockUpdate = True
                 Waiting.show('customizationDrop')
                 interface.drop(g_currentVehicle.invID, kind)
             else:
                 LOG_ERROR('Drop operation, section not found', section)
         return
    def applyCustomization(self, sections):
        if g_currentVehicle.isLocked():
            SystemMessages.pushI18nMessage(SYSTEM_MESSAGES.CUSTOMIZATION_VEHICLE_LOCKED, type=SystemMessages.SM_TYPE.Error)
            yield lambda callback = None: callback
        if g_currentVehicle.isBroken():
            SystemMessages.pushI18nMessage(SYSTEM_MESSAGES.customization_vehicle(g_currentVehicle.item.getState()), type=SystemMessages.SM_TYPE.Error)
            yield lambda callback = None: callback
        notSelected = []
        selected = []
        remove = []
        selectedNames = []
        totalGold = 0
        totalCredits = 0
        newItemsByType = defaultdict(list)
        for section in sections:
            interface = self.__interfaces.get(section.sectionName)
            if interface is not None:
                newItems = interface.getNewItems()
                if newItems is not None:
                    self.__updateNewItemsByType(newItemsByType, newItems, interface._type)

        for section in sections:
            interface = self.__interfaces.get(section.sectionName)
            if interface is not None:
                newItems = interface.getNewItems()
                if newItems is not None:
                    removeStr = None
                    hasMatches = self.__hasNewItemsDuplicates(newItemsByType, newItems, interface._type)
                    if not hasMatches:
                        costValue = interface.getSelectedItemCost()
                        if isinstance(costValue, list):
                            for price in costValue:
                                cost = price.get('cost')
                                isGold = price.get('isGold')
                                if cost > 0:
                                    if isGold and section.isGold:
                                        totalGold += cost
                                    elif not isGold and not section.isGold:
                                        totalCredits += cost

                        else:
                            cost, isGold = costValue
                            if cost > 0:
                                if isGold:
                                    totalGold += cost
                                else:
                                    totalCredits += cost
                    if section.sectionName not in selectedNames:
                        selected.append(i18n.makeString('#menu:customization/change/{0:>s}'.format(section.sectionName)))
                        selectedNames.append(section.sectionName)
                        removeStr = interface.getCurrentItemRemoveStr()
                    if removeStr is not None:
                        remove.extend(removeStr)
                else:
                    notSelected.append(i18n.makeString('#menu:customization/items/{0:>s}'.format(section.sectionName)))
            else:
                LOG_ERROR('Section not found', section.sectionName)

        if len(notSelected) > 0:
            DialogsInterface.showI18nInfoDialog('customization/selectNewItems', lambda success: None, I18nInfoDialogMeta('customization/selectNewItems', messageCtx={'items': ', '.join(notSelected)}))
            yield lambda callback = None: callback
        if totalGold or totalCredits:
            titleKey = DIALOGS.CUSTOMIZATION_CHANGECONFIRMATION_BUY
        else:
            titleKey = DIALOGS.CUSTOMIZATION_CHANGECONFIRMATION_CHANGE
        isConfirmed = yield DialogsInterface.showDialog(I18nConfirmDialogMeta('customization/changeConfirmation', titleCtx={'action': i18n.makeString(titleKey)}, messageCtx={'selected': ', '.join(selected),
         'remove': '\n'.join(remove)}))
        if isConfirmed:
            creditsNotEnough = totalCredits > self.__credits
            goldNotEnough = totalGold > self.__gold
            if creditsNotEnough or goldNotEnough:
                if creditsNotEnough and goldNotEnough:
                    key = SYSTEM_MESSAGES.CUSTOMIZATION_CREDITS_AND_GOLD_NOT_ENOUGH
                elif goldNotEnough:
                    key = SYSTEM_MESSAGES.CUSTOMIZATION_GOLD_NOT_ENOUGH
                else:
                    key = SYSTEM_MESSAGES.CUSTOMIZATION_CREDITS_NOT_ENOUGH
                SystemMessages.pushI18nMessage(key, type=SystemMessages.SM_TYPE.Error)
                yield lambda callback = None: callback
            self.__returnHangar = True
            vehInvID = g_currentVehicle.invID
            self.__steps = 0
            self.__messages = []
            self.flashObject.applyButton.disabled = True
            if len(sections) > 0:
                Waiting.show('customizationApply')
                self.__lockUpdate = True
            selectedNames = []
            for section in sections:
                interface = self.__interfaces.get(section.sectionName)
                if interface is not None:
                    newItems = interface.getNewItems()
                    if newItems is not None:
                        hasMatches = self.__hasNewItemsDuplicates(newItemsByType, newItems, interface._type)
                        self.__steps += interface.getSelectedItemsCount(section.isGold)
                        if section.sectionName not in selectedNames:
                            interface.change(vehInvID, section, hasMatches)
                            selectedNames.append(section.sectionName)
                else:
                    LOG_ERROR('Change operation, section not found', section)
                    self.__steps -= 1

            if not self.__steps:
                self.__onServerResponsesReceived()
        return
    def applyCustomization(self, sections):
        if g_currentVehicle.isLocked():
            SystemMessages.pushI18nMessage(SYSTEM_MESSAGES.CUSTOMIZATION_VEHICLE_LOCKED, type=SystemMessages.SM_TYPE.Error)
            yield lambda callback = None: callback
        if g_currentVehicle.isBroken():
            SystemMessages.pushI18nMessage(SYSTEM_MESSAGES.customization_vehicle(g_currentVehicle.item.getState()), type=SystemMessages.SM_TYPE.Error)
            yield lambda callback = None: callback
        notSelected = []
        selected = []
        remove = []
        selectedNames = []
        totalGold = 0
        totalCredits = 0
        for section in sections:
            interface = self.__interfaces.get(section.sectionName)
            if interface is not None:
                if interface.isNewItemSelected():
                    costValue = interface.getSelectedItemCost()
                    if type(costValue) is list:
                        for price in costValue:
                            cost = price.get('cost')
                            isGold = price.get('isGold')
                            if cost > 0:
                                if isGold and section.isGold:
                                    totalGold += cost
                                elif not isGold and not section.isGold:
                                    totalCredits += cost

                    else:
                        cost, isGold = costValue
                        if cost > 0:
                            if isGold:
                                totalGold += cost
                            else:
                                totalCredits += cost
                    if section.sectionName not in selectedNames:
                        selected.append(i18n.makeString('#menu:customization/change/{0:>s}'.format(section.sectionName)))
                        selectedNames.append(section.sectionName)
                    if interface.isCurrentItemRemove():
                        remove.append(gui.makeHtmlString('html_templates:lobby/customization', 'remove-{0:>s}'.format(section.sectionName)))
                else:
                    notSelected.append(i18n.makeString('#menu:customization/items/{0:>s}'.format(section.sectionName)))
            else:
                LOG_ERROR('Section not found', section.sectionName)

        if len(notSelected) > 0:
            DialogsInterface.showI18nInfoDialog('customization/selectNewItems', lambda success: None, I18nInfoDialogMeta('customization/selectNewItems', messageCtx={'items': ', '.join(notSelected)}))
            yield lambda callback = None: callback
        isConfirmed = yield DialogsInterface.showDialog(I18nConfirmDialogMeta('customization/changeConfirmation', messageCtx={'selected': ', '.join(selected),
         'remove': '\n'.join(remove)}))
        if isConfirmed:
            creditsNotEnough = totalCredits > self.__credits
            goldNotEnough = totalGold > self.__gold
            if creditsNotEnough or goldNotEnough:
                if creditsNotEnough and goldNotEnough:
                    key = SYSTEM_MESSAGES.CUSTOMIZATION_CREDITS_AND_GOLD_NOT_ENOUGH
                elif goldNotEnough:
                    key = SYSTEM_MESSAGES.CUSTOMIZATION_GOLD_NOT_ENOUGH
                else:
                    key = SYSTEM_MESSAGES.CUSTOMIZATION_CREDITS_NOT_ENOUGH
                SystemMessages.pushI18nMessage(key, type=SystemMessages.SM_TYPE.Error)
                yield lambda callback = None: callback
            self.__returnHangar = True
            vehInvID = g_currentVehicle.invID
            self.__steps = 0
            self.__messages = []
            self.flashObject.applyButton.disabled = True
            if len(sections) > 0:
                Waiting.show('customizationApply')
                self.__lockUpdate = True
            selectedNames = []
            for section in sections:
                interface = self.__interfaces.get(section.sectionName)
                if interface is not None:
                    self.__steps += interface.getSelectedItemsCount(section.isGold)
                    if section.sectionName not in selectedNames:
                        interface.change(vehInvID, section)
                        selectedNames.append(section.sectionName)
                else:
                    LOG_ERROR('Change operation, section not found', section)
                    self.__steps -= 1

            if not self.__steps:
                self.__onServerResponsesReceived()
        return
Пример #5
0
    def applyCustomization(self, sections):
        if g_currentVehicle.isLocked():
            SystemMessages.pushI18nMessage(
                SYSTEM_MESSAGES.CUSTOMIZATION_VEHICLE_LOCKED,
                type=SystemMessages.SM_TYPE.Error)
            yield lambda callback=None: callback
        if g_currentVehicle.isBroken():
            SystemMessages.pushI18nMessage(
                SYSTEM_MESSAGES.customization_vehicle(
                    g_currentVehicle.item.getState()),
                type=SystemMessages.SM_TYPE.Error)
            yield lambda callback=None: callback
        notSelected = []
        selected = []
        remove = []
        selectedNames = []
        totalGold = 0
        totalCredits = 0
        for section in sections:
            interface = self.__interfaces.get(section.sectionName)
            if interface is not None:
                if interface.isNewItemSelected():
                    costValue = interface.getSelectedItemCost()
                    if type(costValue) is list:
                        for price in costValue:
                            cost = price.get('cost')
                            isGold = price.get('isGold')
                            if cost > 0:
                                if isGold and section.isGold:
                                    totalGold += cost
                                elif not isGold and not section.isGold:
                                    totalCredits += cost

                    else:
                        cost, isGold = costValue
                        if cost > 0:
                            if isGold:
                                totalGold += cost
                            else:
                                totalCredits += cost
                    if section.sectionName not in selectedNames:
                        selected.append(
                            i18n.makeString(
                                '#menu:customization/change/{0:>s}'.format(
                                    section.sectionName)))
                        selectedNames.append(section.sectionName)
                    if interface.isCurrentItemRemove():
                        remove.append(
                            gui.makeHtmlString(
                                'html_templates:lobby/customization',
                                'remove-{0:>s}'.format(section.sectionName)))
                else:
                    notSelected.append(
                        i18n.makeString(
                            '#menu:customization/items/{0:>s}'.format(
                                section.sectionName)))
            else:
                LOG_ERROR('Section not found', section.sectionName)

        if len(notSelected) > 0:
            DialogsInterface.showI18nInfoDialog(
                'customization/selectNewItems', lambda success: None,
                I18nInfoDialogMeta(
                    'customization/selectNewItems',
                    messageCtx={'items': ', '.join(notSelected)}))
            yield lambda callback=None: callback
        isConfirmed = yield DialogsInterface.showDialog(
            I18nConfirmDialogMeta('customization/changeConfirmation',
                                  messageCtx={
                                      'selected': ', '.join(selected),
                                      'remove': '\n'.join(remove)
                                  }))
        if isConfirmed:
            creditsNotEnough = totalCredits > self.__credits
            goldNotEnough = totalGold > self.__gold
            if creditsNotEnough or goldNotEnough:
                if creditsNotEnough and goldNotEnough:
                    key = SYSTEM_MESSAGES.CUSTOMIZATION_CREDITS_AND_GOLD_NOT_ENOUGH
                elif goldNotEnough:
                    key = SYSTEM_MESSAGES.CUSTOMIZATION_GOLD_NOT_ENOUGH
                else:
                    key = SYSTEM_MESSAGES.CUSTOMIZATION_CREDITS_NOT_ENOUGH
                SystemMessages.pushI18nMessage(
                    key, type=SystemMessages.SM_TYPE.Error)
                yield lambda callback=None: callback
            self.__returnHangar = True
            vehInvID = g_currentVehicle.invID
            self.__steps = 0
            self.__messages = []
            self.flashObject.applyButton.disabled = True
            if len(sections) > 0:
                Waiting.show('customizationApply')
                self.__lockUpdate = True
            selectedNames = []
            for section in sections:
                interface = self.__interfaces.get(section.sectionName)
                if interface is not None:
                    self.__steps += interface.getSelectedItemsCount(
                        section.isGold)
                    if section.sectionName not in selectedNames:
                        interface.change(vehInvID, section)
                        selectedNames.append(section.sectionName)
                else:
                    LOG_ERROR('Change operation, section not found', section)
                    self.__steps -= 1

            if not self.__steps:
                self.__onServerResponsesReceived()
        return
Пример #6
0
    def applyCustomization(self, sections):
        if g_currentVehicle.isLocked():
            SystemMessages.pushI18nMessage(
                SYSTEM_MESSAGES.CUSTOMIZATION_VEHICLE_LOCKED,
                type=SystemMessages.SM_TYPE.Error)
            yield lambda callback=None: callback
        if g_currentVehicle.isBroken():
            SystemMessages.pushI18nMessage(
                SYSTEM_MESSAGES.customization_vehicle(
                    g_currentVehicle.item.getState()),
                type=SystemMessages.SM_TYPE.Error)
            yield lambda callback=None: callback
        notSelected = []
        selected = []
        remove = []
        selectedNames = []
        totalGold = 0
        totalCredits = 0
        newItemsByType = defaultdict(list)
        for section in sections:
            interface = self.__interfaces.get(section.sectionName)
            if interface is not None:
                newItems = interface.getNewItems()
                if newItems is not None:
                    self.__updateNewItemsByType(newItemsByType, newItems,
                                                interface._type)

        for section in sections:
            interface = self.__interfaces.get(section.sectionName)
            if interface is not None:
                newItems = interface.getNewItems()
                if newItems is not None:
                    removeStr = None
                    hasMatches = self.__hasNewItemsDuplicates(
                        newItemsByType, newItems, interface._type)
                    if not hasMatches:
                        costValue = interface.getSelectedItemCost()
                        if isinstance(costValue, list):
                            for price in costValue:
                                cost = price.get('cost')
                                isGold = price.get('isGold')
                                if cost > 0:
                                    if isGold and section.isGold:
                                        totalGold += cost
                                    elif not isGold and not section.isGold:
                                        totalCredits += cost

                        else:
                            cost, isGold = costValue
                            if cost > 0:
                                if isGold:
                                    totalGold += cost
                                else:
                                    totalCredits += cost
                    if section.sectionName not in selectedNames:
                        selected.append(
                            i18n.makeString(
                                '#menu:customization/change/{0:>s}'.format(
                                    section.sectionName)))
                        selectedNames.append(section.sectionName)
                        removeStr = interface.getCurrentItemRemoveStr()
                    if removeStr is not None:
                        remove.extend(removeStr)
                else:
                    notSelected.append(
                        i18n.makeString(
                            '#menu:customization/items/{0:>s}'.format(
                                section.sectionName)))
            else:
                LOG_ERROR('Section not found', section.sectionName)

        if len(notSelected) > 0:
            DialogsInterface.showI18nInfoDialog(
                'customization/selectNewItems', lambda success: None,
                I18nInfoDialogMeta(
                    'customization/selectNewItems',
                    messageCtx={'items': ', '.join(notSelected)}))
            yield lambda callback=None: callback
        if totalGold or totalCredits:
            titleKey = DIALOGS.CUSTOMIZATION_CHANGECONFIRMATION_BUY
        else:
            titleKey = DIALOGS.CUSTOMIZATION_CHANGECONFIRMATION_CHANGE
        isConfirmed = yield DialogsInterface.showDialog(
            I18nConfirmDialogMeta(
                'customization/changeConfirmation',
                titleCtx={'action': i18n.makeString(titleKey)},
                messageCtx={
                    'selected': ', '.join(selected),
                    'remove': '\n'.join(remove)
                }))
        if isConfirmed:
            creditsNotEnough = totalCredits > self.__credits
            goldNotEnough = totalGold > self.__gold
            if creditsNotEnough or goldNotEnough:
                if creditsNotEnough and goldNotEnough:
                    key = SYSTEM_MESSAGES.CUSTOMIZATION_CREDITS_AND_GOLD_NOT_ENOUGH
                elif goldNotEnough:
                    key = SYSTEM_MESSAGES.CUSTOMIZATION_GOLD_NOT_ENOUGH
                else:
                    key = SYSTEM_MESSAGES.CUSTOMIZATION_CREDITS_NOT_ENOUGH
                SystemMessages.pushI18nMessage(
                    key, type=SystemMessages.SM_TYPE.Error)
                yield lambda callback=None: callback
            self.__returnHangar = True
            vehInvID = g_currentVehicle.invID
            self.__steps = 0
            self.__messages = []
            self.flashObject.applyButton.disabled = True
            if len(sections) > 0:
                Waiting.show('customizationApply')
                self.__lockUpdate = True
            selectedNames = []
            for section in sections:
                interface = self.__interfaces.get(section.sectionName)
                if interface is not None:
                    newItems = interface.getNewItems()
                    if newItems is not None:
                        hasMatches = self.__hasNewItemsDuplicates(
                            newItemsByType, newItems, interface._type)
                        self.__steps += interface.getSelectedItemsCount(
                            section.isGold)
                        if section.sectionName not in selectedNames:
                            interface.change(vehInvID, section, hasMatches)
                            selectedNames.append(section.sectionName)
                else:
                    LOG_ERROR('Change operation, section not found', section)
                    self.__steps -= 1

            if not self.__steps:
                self.__onServerResponsesReceived()
        return