def newInit(self, transition='inRight', originWidget=None): if originWidget is not None: self._transitionOut = 'outScale' scaleOrigin = originWidget.getScreenSpaceCenter() transition = 'inScale' else: self._transitionOut = 'outRight' scaleOrigin = None width = 600 if gSmallUI else 600 height = 360 if gSmallUI else 435 self._gOnlyHeight = height if any([b.textOnly for b in buttons]): if len(textbuttonlayouts[sum([b.textOnly for b in buttons])]) > 1: height += 80 if gSmallUI else 120 else: height += 60 if gSmallUI else 80 self._width, self._height = width, height buttonHeight = 42 R = bs.getResource('settingsWindow') topExtra = 20 if gSmallUI else 0 if originWidget is not None: self._rootWidget = bs.containerWidget(size=(width,height+topExtra),transition=transition, scaleOriginStackOffset=scaleOrigin, scale=1.75 if gSmallUI else 1.35 if gMedUI else 1.0, stackOffset=(0,-8) if gSmallUI else (0,0)) else: self._rootWidget = bs.containerWidget(size=(width,height+topExtra),transition=transition, scale=1.75 if gSmallUI else 1.35 if gMedUI else 1.0, stackOffset=(0,-8) if gSmallUI else (0,0)) self._backButton = b = bs.buttonWidget(parent=self._rootWidget,autoSelect=True,position=(40,height-55),size=(130,60),scale=0.8,textScale=1.2, label=bs.getResource('backText'),buttonType='back',onActivateCall=self._doBack) bs.containerWidget(edit=self._rootWidget, cancelButton=b) t = bs.textWidget(parent=self._rootWidget, position=(0, height-44), size=(width,25), text=R.titleText, color=gTitleColor, hAlign="center", vAlign="center", maxWidth=130) if gDoAndroidNav: bs.buttonWidget(edit=b, buttonType='backSmall', size=(60, 60), label=bs.getSpecialChar('logoFlat')) bs.textWidget(edit=t, hAlign='left', position=(93, height-44)) icon_buttons = sorted([b for b in buttons if b.icon], key=lambda b: b.sorting_position) for i, button in enumerate(icon_buttons): x, y = button._create_icon_button(self, i) text_buttons = sorted([b for b in buttons if b.textOnly], key=lambda b: b.sorting_position) for i, button in enumerate(text_buttons): button._create_text_button(self, i, y) for button in buttons: button.setLocals(self) self._restoreState()
def newInit(self, transition='inRight', originWidget=None): if originWidget is not None: self._transitionOut = 'outScale' scaleOrigin = originWidget.getScreenSpaceCenter() transition = 'inScale' else: self._transitionOut = 'outRight' scaleOrigin = None width = 600 if gSmallUI else 600 height = 360 if gSmallUI else 435 self._gOnlyHeight = height if any([b.textOnly for b in buttons]): if len(textbuttonlayouts[sum([b.textOnly for b in buttons])]) > 1: height += 80 if gSmallUI else 120 else: height += 60 if gSmallUI else 80 self._width, self._height = width, height R = bs.Lstr(resource='settingsWindow') topExtra = 20 if gSmallUI else 0 if originWidget is not None: self._rootWidget = bs.containerWidget( size=(width, height + topExtra), transition=transition, scaleOriginStackOffset=scaleOrigin, scale=1.75 if gSmallUI else 1.35 if gMedUI else 1.0, stackOffset=(0, -8) if gSmallUI else (0, 0)) else: self._rootWidget = bs.containerWidget( size=(width, height + topExtra), transition=transition, scale=1.75 if gSmallUI else 1.35 if gMedUI else 1.0, stackOffset=(0, -8) if gSmallUI else (0, 0)) self._backButton = b = bs.buttonWidget(parent=self._rootWidget, autoSelect=True, position=(40, height - 55), size=(130, 60), scale=0.8, textScale=1.2, label=bs.Lstr(resource='backText'), buttonType='back', onActivateCall=self._doBack) bs.containerWidget(edit=self._rootWidget, cancelButton=b) t = bs.textWidget(parent=self._rootWidget, position=(0, height - 44), size=(width, 25), text=bs.Lstr(resource='settingsWindow.titleText'), color=gTitleColor, hAlign="center", vAlign="center", maxWidth=130) if gDoAndroidNav: bs.buttonWidget(edit=b, buttonType='backSmall', size=(60, 60), label=bs.getSpecialChar('logoFlat')) bs.textWidget(edit=t, hAlign='left', position=(93, height - 44)) icon_buttons = sorted([b for b in buttons if b.icon], key=lambda b: b.sorting_position) for i, button in enumerate(icon_buttons): x, y = button._create_icon_button(self, i) text_buttons = sorted([b for b in buttons if b.textOnly], key=lambda b: b.sorting_position) for i, button in enumerate(text_buttons): button._create_text_button(self, i, y) for button in buttons: button.setLocals(self) self._restoreState()
def __init__(self, lobby): canSwitchTeams = (len(lobby._teams) > 1) self._state = 0 pressToPunch = bs.getSpecialChar('leftButton') pressToPickup = bs.getSpecialChar('topButton') pressToBomb = bs.getSpecialChar('rightButton') # if we have a keyboard, grab keys for punch and pickup # FIXME - this of course is only correct locally; # will need to change this for net games kb = bsInternal._getInputDevice('Keyboard', '#1', exceptionOnNone=False) if kb is not None: punchKey = kb.getButtonName( bsUI.getControllerValue(kb, 'buttonPunch')) pressToPunch = bs.Lstr(resource='orText', subs=[('${A}', bs.Lstr(value='\'${K}\'', subs=[('${K}', punchKey) ])), ('${B}', pressToPunch)]) bombKey = kb.getButtonName( bsUI.getControllerValue(kb, 'buttonBomb')) pressToBomb = bs.Lstr(resource='orText', subs=[('${A}', bs.Lstr(value='\'${K}\'', subs=[('${K}', bombKey) ])), ('${B}', pressToBomb)]) joinStr = bs.Lstr( value='${A} < ${B} >', subs=[('${A}', bs.Lstr(resource='pressPunchToJoinText')), ('${B}', pressToPunch)]) else: joinStr = bs.Lstr(resource='pressAnyButtonToJoinText') self._text = bs.NodeActor( bs.newNode('text', attrs={ 'position': (0, 5), 'hAttach': 'center', 'vAttach': 'bottom', 'hAlign': 'center', 'color': gLobbyTextColor, 'flatness': 1.0 if bs.getEnvironment()['vrMode'] else 0.0, 'text': joinStr })) if bsUtils.gRunningKioskModeGame: self._messages = [joinStr] else: m1 = bs.Lstr(resource='pressToSelectProfileText', subs=[ ('${BUTTONS}', bs.getSpecialChar('upArrow') + ' ' + bs.getSpecialChar('downArrow')) ]) m2 = bs.Lstr(resource='pressToOverrideCharacterText', subs=[('${BUTTONS}', bs.Lstr(resource='bombBoldText'))]) m3 = bs.Lstr(value='${A} < ${B} >', subs=[('${A}', m2), ('${B}', pressToBomb)]) self._messages = (([ bs.Lstr(resource='pressToSelectTeamText', subs=[('${BUTTONS}', bs.getSpecialChar('leftArrow') + ' ' + bs.getSpecialChar('rightArrow'))]) ] if canSwitchTeams else []) + [m1] + [m3] + [joinStr]) self._timer = bs.Timer(4000, bs.WeakCall(self._update), repeat=True)
def _getName(self, full=False): nameRaw = name = self.profileNames[self.profileIndex] clamp = False if name == '_random': try: inputDevice = self._player.getInputDevice() except Exception: inputDevice = None if inputDevice is not None: name = inputDevice._getDefaultPlayerName() else: name = 'Invalid' if not full: clamp = True elif name == '__account__': try: inputDevice = self._player.getInputDevice() except Exception: inputDevice = None if inputDevice is not None: name = inputDevice._getAccountName(full) else: name = 'Invalid' if not full: clamp = True elif name == '_edit': # FIXME - this causes problems as an Lstr, but its ok to # explicitly translate for now since this is only shown on the host. name = (bs.Lstr( resource='createEditPlayerText', fallbackResource='editProfileWindow.titleNewText').evaluate()) else: # if we have a regular profile marked as global with an icon, # use it (for full only) if full: try: if self.profiles[nameRaw].get('global', False): icon = (bs.uni( self.profiles[nameRaw]['icon'] if 'icon' in self. profiles[nameRaw] else bs.getSpecialChar('logo'))) name = icon + name except Exception: bs.printException('Error applying global icon') else: # we now clamp non-full versions of names so there's at # least some hope of reading them in-game clamp = True try: for i in self.markers: if i in name: name = name.replace(i, '') except: pass if clamp: # in python < 3.5 some unicode chars can have length 2, so we need # to convert to raw int vals for safe trimming nameChars = bs.uniToInts(name) if len(nameChars) > 10: name = bs.uniFromInts(nameChars[:10]) + '...' return name
def showCompletionBanner(self, sound=True): global gLastAchievementDisplayTime gLastAchievementDisplayTime = bs.getRealTime() # just piggy-back onto any current activity... # (should we use the session instead?..) activity = bs.getActivity(exceptionOnNone=False) # if this gets called while this achievement is occupying a slot # already, ignore it.. (probably should never happen in real # life but whatevs..) if self._completionBannerSlot is not None: return if activity is None: print 'showCompletionBanner() called with no current activity!' return if sound: bs.playSound(bs.getSound('achievement'), hostOnly=True) else: bs.gameTimer( 500, bs.Call(bs.playSound, bs.getSound('ding'), hostOnly=True)) yOffs = 0 inTime = 300 outTime = 3500 baseVRDepth = 200 # find the first free slot i = 0 while True: if not i in gCompletionBannerSlots: #print 'ADDING SLOT',i,'FOR',self gCompletionBannerSlots.add(i) self._completionBannerSlot = i # remove us from that slot when we close.. # use a real-timer in the UI context so the removal runs even # if our activity/session dies with bs.Context('UI'): bs.realTimer(inTime + outTime, self._removeBannerSlot) break i += 1 yOffs = 110 * self._completionBannerSlot objs = [] obj = bsUtils.Image(bs.getTexture('shadow'), position=(-30, 30 + yOffs), front=True, attach='bottomCenter', transition='inBottom', vrDepth=baseVRDepth - 100, transitionDelay=inTime, transitionOutDelay=outTime, color=(0.0, 0.1, 0, 1), scale=(1000, 300)).autoRetain() objs.append(obj) obj.node.hostOnly = True obj = bsUtils.Image(bs.getTexture('light'), position=(-180, 60 + yOffs), front=True, attach='bottomCenter', vrDepth=baseVRDepth, transition='inBottom', transitionDelay=inTime, transitionOutDelay=outTime, color=(1.8, 1.8, 1.0, 0.0), scale=(40, 300)).autoRetain() objs.append(obj) obj.node.hostOnly = True obj.node.premultiplied = True c = bs.newNode('combine', owner=obj.node, attrs={'size': 2}) bsUtils.animate( c, 'input0', { inTime: 0, inTime + 400: 30, inTime + 500: 40, inTime + 600: 30, inTime + 2000: 0 }) bsUtils.animate( c, 'input1', { inTime: 0, inTime + 400: 200, inTime + 500: 500, inTime + 600: 200, inTime + 2000: 0 }) c.connectAttr('output', obj.node, 'scale') bsUtils.animate(obj.node, 'rotate', {0: 0.0, 350: 360.0}, loop=True) obj = bsUtils.Image(self.getIconTexture(True), position=(-180, 60 + yOffs), attach='bottomCenter', front=True, vrDepth=baseVRDepth - 10, transition='inBottom', transitionDelay=inTime, transitionOutDelay=outTime, scale=(100, 100)).autoRetain() objs.append(obj) obj.node.hostOnly = True # flash color = self.getIconColor(True) c = bs.newNode('combine', owner=obj.node, attrs={'size': 3}) keys = { inTime: 1.0 * color[0], inTime + 400: 1.5 * color[0], inTime + 500: 6.0 * color[0], inTime + 600: 1.5 * color[0], inTime + 2000: 1.0 * color[0] } bsUtils.animate(c, 'input0', keys) keys = { inTime: 1.0 * color[1], inTime + 400: 1.5 * color[1], inTime + 500: 6.0 * color[1], inTime + 600: 1.5 * color[1], inTime + 2000: 1.0 * color[1] } bsUtils.animate(c, 'input1', keys) keys = { inTime: 1.0 * color[2], inTime + 400: 1.5 * color[2], inTime + 500: 6.0 * color[2], inTime + 600: 1.5 * color[2], inTime + 2000: 1.0 * color[2] } bsUtils.animate(c, 'input2', keys) c.connectAttr('output', obj.node, 'color') obj = bsUtils.Image(bs.getTexture('achievementOutline'), modelTransparent=bs.getModel('achievementOutline'), position=(-180, 60 + yOffs), front=True, attach='bottomCenter', vrDepth=baseVRDepth, transition='inBottom', transitionDelay=inTime, transitionOutDelay=outTime, scale=(100, 100)).autoRetain() obj.node.hostOnly = True # flash color = (2, 1.4, 0.4, 1) c = bs.newNode('combine', owner=obj.node, attrs={'size': 3}) keys = { inTime: 1.0 * color[0], inTime + 400: 1.5 * color[0], inTime + 500: 6.0 * color[0], inTime + 600: 1.5 * color[0], inTime + 2000: 1.0 * color[0] } bsUtils.animate(c, 'input0', keys) keys = { inTime: 1.0 * color[1], inTime + 400: 1.5 * color[1], inTime + 500: 6.0 * color[1], inTime + 600: 1.5 * color[1], inTime + 2000: 1.0 * color[1] } bsUtils.animate(c, 'input1', keys) keys = { inTime: 1.0 * color[2], inTime + 400: 1.5 * color[2], inTime + 500: 6.0 * color[2], inTime + 600: 1.5 * color[2], inTime + 2000: 1.0 * color[2] } bsUtils.animate(c, 'input2', keys) c.connectAttr('output', obj.node, 'color') objs.append(obj) obj = bsUtils.Text(bs.Lstr(value='${A}:', subs=[('${A}', bs.Lstr(resource='achievementText')) ]), position=(-120, 91 + yOffs), front=True, vAttach='bottom', vrDepth=baseVRDepth - 10, transition='inBottom', flatness=0.5, transitionDelay=inTime, transitionOutDelay=outTime, color=(1, 1, 1, 0.8), scale=0.65).autoRetain() objs.append(obj) obj.node.hostOnly = True obj = bsUtils.Text(self.getDisplayString(), position=(-120, 50 + yOffs), front=True, vAttach='bottom', transition='inBottom', vrDepth=baseVRDepth, flatness=0.5, transitionDelay=inTime, transitionOutDelay=outTime, flash=True, color=(1, 0.8, 0, 1.0), scale=1.5).autoRetain() objs.append(obj) obj.node.hostOnly = True obj = bsUtils.Text(bs.getSpecialChar('ticket'), position=(-120 - 170 + 5, 75 + yOffs - 20), front=True, vAttach='bottom', hAlign='center', vAlign='center', transition='inBottom', vrDepth=baseVRDepth, transitionDelay=inTime, transitionOutDelay=outTime, flash=True, color=(0.5, 0.5, 0.5, 1), scale=3.0).autoRetain() objs.append(obj) obj.node.hostOnly = True obj = bsUtils.Text('+' + str(self.getAwardTicketValue()), position=(-120 - 180 + 5, 80 + yOffs - 20), vAttach='bottom', front=True, hAlign='center', vAlign='center', transition='inBottom', vrDepth=baseVRDepth, flatness=0.5, shadow=1.0, transitionDelay=inTime, transitionOutDelay=outTime, flash=True, color=(0, 1, 0, 1), scale=1.5).autoRetain() objs.append(obj) obj.node.hostOnly = True # add the 'x 2' if we've got pro if bsUtils._havePro(): obj = bsUtils.Text('x 2', position=(-120 - 180 + 45, 80 + yOffs - 50), vAttach='bottom', front=True, hAlign='center', vAlign='center', transition='inBottom', vrDepth=baseVRDepth, flatness=0.5, shadow=1.0, transitionDelay=inTime, transitionOutDelay=outTime, flash=True, color=(0.4, 0, 1, 1), scale=0.9).autoRetain() objs.append(obj) obj.node.hostOnly = True obj = bsUtils.Text(self.getDescriptionComplete(), position=(-120, 30 + yOffs), front=True, vAttach='bottom', transition='inBottom', vrDepth=baseVRDepth - 10, flatness=0.5, transitionDelay=inTime, transitionOutDelay=outTime, color=(1.0, 0.7, 0.5, 1.0), scale=0.8).autoRetain() objs.append(obj) obj.node.hostOnly = True for obj in objs: bs.gameTimer(outTime + 1000, bs.WeakCall(obj.handleMessage, bs.DieMessage()))
def createDisplay(self, x, y, delay, outDelay=None, color=None, style='postGame'): if style == 'postGame': inGameColors = False inMainMenu = False hAttach = vAttach = attach = 'center' elif style == 'inGame': inGameColors = True inMainMenu = False hAttach = 'left' vAttach = 'top' attach = 'topLeft' elif style == 'news': inGameColors = True inMainMenu = True hAttach = 'center' vAttach = 'top' attach = 'topCenter' else: raise Exception('invalid style "' + style + '"') # attempt to determine what campaign we're in # (so we know whether to show "hard mode only") if inMainMenu: hmo = False else: try: hmo = (self._hardModeOnly and bs.getSession()._campaignInfo['campaign'] == 'Easy') except Exception: bs.printException("unable to determine campaign") hmo = False activity = bs.getActivity() if inGameColors: objs = [] outDelayFin = (delay + outDelay) if outDelay is not None else None if color is not None: c1 = (2.0 * color[0], 2.0 * color[1], 2.0 * color[2], color[3]) c2 = color else: c1 = (1.5, 1.5, 2, 1.0) c2 = (0.8, 0.8, 1.0, 1.0) if hmo: c1 = (c1[0], c1[1], c1[2], c1[3] * 0.6) c2 = (c2[0], c2[1], c2[2], c2[3] * 0.2) objs.append( bsUtils.Image(self.getIconTexture(False), hostOnly=True, color=c1, position=(x - 25, y + 5), attach=attach, transition='fadeIn', transitionDelay=delay, vrDepth=4, transitionOutDelay=outDelayFin, scale=(40, 40)).autoRetain()) txt = self.getDisplayString() txtS = 0.85 txtMaxW = 300 objs.append( bsUtils.Text(txt, hostOnly=True, maxWidth=txtMaxW, position=(x, y + 2), transition='fadeIn', scale=txtS, flatness=0.6, shadow=0.5, hAttach=hAttach, vAttach=vAttach, color=c2, transitionDelay=delay + 50, transitionOutDelay=outDelayFin).autoRetain()) txt2S = 0.62 txt2MaxW = 400 objs.append( bsUtils.Text(self.getDescriptionFull() if inMainMenu else self.getDescription(), hostOnly=True, maxWidth=txt2MaxW, position=(x, y - 14), transition='fadeIn', vrDepth=-5, hAttach=hAttach, vAttach=vAttach, scale=txt2S, flatness=1.0, shadow=0.5, color=c2, transitionDelay=delay + 100, transitionOutDelay=outDelayFin).autoRetain()) if hmo: t = bsUtils.Text(bs.Lstr(resource='difficultyHardOnlyText'), hostOnly=True, maxWidth=txt2MaxW * 0.7, position=(x + 60, y + 5), transition='fadeIn', vrDepth=-5, hAttach=hAttach, vAttach=vAttach, hAlign='center', vAlign='center', scale=txtS * 0.8, flatness=1.0, shadow=0.5, color=(1, 1, 0.6, 1), transitionDelay=delay + 100, transitionOutDelay=outDelayFin).autoRetain() t.node.rotate = 10 objs.append(t) # ticket-award awardX = -100 objs.append( bsUtils.Text(bs.getSpecialChar('ticket'), hostOnly=True, position=(x + awardX + 33, y + 7), transition='fadeIn', scale=1.5, hAttach=hAttach, vAttach=vAttach, hAlign='center', vAlign='center', color=(1, 1, 1, 0.2 if hmo else 0.4), transitionDelay=delay + 50, transitionOutDelay=outDelayFin).autoRetain()) objs.append( bsUtils.Text('+' + str(self.getAwardTicketValue()), hostOnly=True, position=(x + awardX + 28, y + 16), transition='fadeIn', scale=0.7, flatness=1, hAttach=hAttach, vAttach=vAttach, hAlign='center', vAlign='center', color=(c2), transitionDelay=delay + 50, transitionOutDelay=outDelayFin).autoRetain()) else: complete = self.isComplete() objs = [] cIcon = self.getIconColor(complete) if hmo and not complete: cIcon = (cIcon[0], cIcon[1], cIcon[2], cIcon[3] * 0.3) objs.append( bsUtils.Image(self.getIconTexture(complete), hostOnly=True, color=cIcon, position=(x - 25, y + 5), attach=attach, vrDepth=4, transition='inRight', transitionDelay=delay, transitionOutDelay=None, scale=(40, 40)).autoRetain()) if complete: objs.append( bsUtils.Image( bs.getTexture('achievementOutline'), hostOnly=True, modelTransparent=bs.getModel('achievementOutline'), color=(2, 1.4, 0.4, 1), vrDepth=8, position=(x - 25, y + 5), attach=attach, transition='inRight', transitionDelay=delay, transitionOutDelay=None, scale=(40, 40)).autoRetain()) else: if not complete: awardX = -100 objs.append( bsUtils.Text(bs.getSpecialChar('ticket'), hostOnly=True, position=(x + awardX + 33, y + 7), transition='inRight', scale=1.5, hAttach=hAttach, vAttach=vAttach, hAlign='center', vAlign='center', color=(1, 1, 1, 0.4) if complete else (1, 1, 1, (0.1 if hmo else 0.2)), transitionDelay=delay + 50, transitionOutDelay=None).autoRetain()) objs.append( bsUtils.Text('+' + str(self.getAwardTicketValue()), hostOnly=True, position=(x + awardX + 28, y + 16), transition='inRight', scale=0.7, flatness=1, hAttach=hAttach, vAttach=vAttach, hAlign='center', vAlign='center', color=((0.8, 0.93, 0.8, 1.0) if complete else (0.6, 0.6, 0.6, (0.2 if hmo else 0.4))), transitionDelay=delay + 50, transitionOutDelay=None).autoRetain()) # show 'hard-mode-only' only over incomplete achievements # when that's the case.. if hmo: t = bsUtils.Text( bs.Lstr(resource='difficultyHardOnlyText'), hostOnly=True, maxWidth=300 * 0.7, position=(x + 60, y + 5), transition='fadeIn', vrDepth=-5, hAttach=hAttach, vAttach=vAttach, hAlign='center', vAlign='center', scale=0.85 * 0.8, flatness=1.0, shadow=0.5, color=(1, 1, 0.6, 1), transitionDelay=delay + 50, transitionOutDelay=None).autoRetain() t.node.rotate = 10 objs.append(t) objs.append( bsUtils.Text(self.getDisplayString(), hostOnly=True, maxWidth=300, position=(x, y + 2), transition='inRight', scale=0.85, flatness=0.6, hAttach=hAttach, vAttach=vAttach, color=((0.8, 0.93, 0.8, 1.0) if complete else (0.6, 0.6, 0.6, (0.2 if hmo else 0.4))), transitionDelay=delay + 50, transitionOutDelay=None).autoRetain()) objs.append( bsUtils.Text(self.getDescriptionComplete() if complete else self.getDescription(), hostOnly=True, maxWidth=400, position=(x, y - 14), transition='inRight', vrDepth=-5, hAttach=hAttach, vAttach=vAttach, scale=0.62, flatness=1.0, color=((0.6, 0.6, 0.6, 1.0) if complete else (0.6, 0.6, 0.6, (0.2 if hmo else 0.4))), transitionDelay=delay + 100, transitionOutDelay=None).autoRetain()) return objs