def setTextFields(own): '''Party Text''' partyText = objectControl.getFromScene('text_party', 'partyCreate') partyText.text = own['party'] '''Name Text''' nameText = objectControl.getFromScene('text_name', 'partyCreate') nameText.text = own['units'][0]['name'] '''Class Text''' classText = objectControl.getFromScene('text_class', 'partyCreate') # TODO(kgeffen) Change 'model' to 'class' everywhere classText.text = own['units'][0]['model'].capitalize() '''Add Skill Text''' addSkillText = objectControl.getFromScene('text_addSkill', 'partyCreate') command = own['addSkill'][0] addSkillText.text = commandControl.name(command) # Add skill removeSkillText = objectControl.getFromScene('text_removeSkill', 'partyCreate') commands = own['units'][0]['commands'][0] if len(commands) != 0: removeSkillText.text = commandControl.name(commands[0]) else: removeSkillText.text = ''
def update(cont): own = cont.owner keyboard = logic.keyboard # Display each field's current choice for field in FIELDS: # Start is a button, not a field if field != 'start': obj = objectControl.getFromScene('text_' + field, 'main') obj.text = own[field][0] # Scale down the arrows if they are enlarged for arrowName in ['leftArrow', 'rightArrow']: arrow = objectControl.getFromScene(arrowName, 'main') if arrow.localScale.x > 1: arrow.localScale -= Vector((0.035, 0.035, 0.035)) if keyboard.events[events.MKEY] == ACTIVE: soundControl.toggleMute() elif keyboard.events[events.UPARROWKEY] == ACTIVE: moveVertical(own, up = True) elif keyboard.events[events.DOWNARROWKEY] == ACTIVE: moveVertical(own, up = False) elif keyboard.events[events.LEFTARROWKEY] == ACTIVE: moveHorizontal(own, left = True) elif keyboard.events[events.RIGHTARROWKEY] == ACTIVE: moveHorizontal(own, left = False) elif keyboard.events[events.SPACEKEY] == ACTIVE: select(own)
def do(): cursor = objectControl.getFromScene('cursor', 'battlefield') cursorHeight = cursor.worldPosition[2] heightInDm = round( cursorHeight * 10 ) text = str(heightInDm) + ' dm' heightDisplay = objectControl.getFromScene(HEIGHT_DISPLAY_NAME, OVERLAY_SCENE_NAME) heightDisplay['Text'] = text
def dsahjkdsa(): soundControl.play('navigate') if left: objectControl.getFromScene('leftArrow2', 'partyCreate').worldScale = [1.5, 1.5, 1.5] # Cycle list entry = own[field].pop() own[field].insert(0, entry) else: objectControl.getFromScene('rightArrow2', 'partyCreate').worldScale = [1.5, 1.5, 1.5] # Cycle list entry = own[field].pop(0) own[field].append(entry)
def do(): cursor = objectControl.getFromScene('cursor', 'battlefield') cursorPosition = cursor.worldPosition # The type of selection being made status = logic.globalDict['cursor'] if status == 'selecting': cursorSelect.unit.attempt(cursorPosition) elif status == 'move': # NOTE(kgeffen) When user is selecting a space to move unit, # is user selects unit, commandSelect opens unitPosition = logic.globalDict['actor']['position'] # If cursor is not over unit, move unit to space cursor is on if not check.eq2D(cursorPosition, unitPosition): cursorSelect.move.attempt(cursorPosition) # Else, open commandSelect screen else: cursorSelect.actor.attempt() else: # Selecting the target for a command cursorSelect.target.attempt(cursorPosition)
def endDisplay(): textObj = objectControl.getFromScene('commandResult', 'battlefield') # NOTE(kgeffen) Can't use objectControl.hide because object doesn't become deactivated, # just waits until messaged (And must be actively awaiting the message) textObj.setVisible(False) textObj.state = logic.KX_STATE1
def attempt(cont): if cont.sensors['iKey'].positive: # Get unit under cursor, if any cursor = objectControl.getFromScene('cursor', 'battlefield') unit = unitControl.get.inSpace(cursor.worldPosition) if unit is not None: do(unit)
def switchMapMesh(filepath): # Load the mesh into bge memory logic.LibLoad(filepath + 'ground.blend', 'Mesh') ground = objectControl.getFromScene('ground', 'battlefield') # Replace the mesh with the ground mesh loaded from the blend file in the stage dir ground.replaceMesh('ground')
def alignmentText(align): text = alignControl.name(align) # Get text object obj = objectControl.getFromScene(ALIGNMENT_TEXT_OBJECT_NAME, 'info') # Set that object's text obj['Text'] = text
def getTargetAtCursor(): cursor = objectControl.getFromScene('cursor', 'battlefield') cursorPosition = cursor.worldPosition for target in logic.globalDict['spaceTarget']: # If target happens on same space as given position, return it if check.eq2D(cursorPosition, target['space']): return target
def playEffects(): textObj = objectControl.getFromScene('commandResult', 'battlefield') # Raise textObj.worldPosition += Vector((0.0, 0.0, 0.01)) # Fade text from 1.0 to 0.0 alpha for each result changePerTic = 1/TICS_PER_RESULT textObj.color -= Vector((0, 0, 0, changePerTic))
def moveHorizontal(own, left): field = FIELDS[ own['fieldNum'] ] # Start is a button, has no field if field == 'start': return soundControl.play('navigate') if left: objectControl.getFromScene('leftArrow', 'main').worldScale = [1.5, 1.5, 1.5] # Cycle list entry = own[field].pop() own[field].insert(0, entry) else: objectControl.getFromScene('rightArrow', 'main').worldScale = [1.5, 1.5, 1.5] # Cycle list entry = own[field].pop(0) own[field].append(entry)
def moveVertical(own, up): soundControl.play('navigate') if up: # Move up unless at top, otherwise loop to bottom if own['fieldNum'] != 0: own.worldPosition.y += D_HEIGHT own['fieldNum'] -= 1 else: # How many fields own must move down to get to bottom movesDown = len(FIELDS) - 1 own.worldPosition.y -= D_HEIGHT * movesDown own['fieldNum'] = movesDown else: # Move down unless at bottom, otherwise loop to top if own['fieldNum'] != len(FIELDS) - 1: own.worldPosition.y -= D_HEIGHT own['fieldNum'] += 1 else: # How many fields own must move up to get to top movesUp = len(FIELDS) - 1 own.worldPosition.y += D_HEIGHT * movesUp own['fieldNum'] = 0 # Reset all fields to black/Ensure arrows visible for field in FIELDS: objectControl.getFromScene('text_' + field, 'main').color = (0, 0, 0, 1) # Make selected field white field = FIELDS[ own['fieldNum'] ] objectControl.getFromScene('text_' + field, 'main').color = (1, 1, 1, 1) # If selection is start button, make arrows invisible if field == 'start': objectControl.getFromScene('leftArrow', 'main').setVisible(False) objectControl.getFromScene('rightArrow', 'main').setVisible(False) else: objectControl.getFromScene('leftArrow', 'main').setVisible(True) objectControl.getFromScene('rightArrow', 'main').setVisible(True)
def updateTextFields(own): setTextFields(own) # Reset all fields to black for field in FIELDS: if field != 'button': objectControl.getFromScene('text_' + field, 'partyCreate').color = (0, 0, 0, 1) else: # Make all buttons black for buttonName in BUTTONS: objectControl.getFromScene('text_button_' + buttonName, 'partyCreate').color = (0, 0, 0, 1) # Make selected field white # If button is selected, make correct button white field = FIELDS[ own['fieldNum'] ] if field != 'button': objectControl.getFromScene('text_' + field, 'partyCreate').color = (1, 1, 1, 1) else: button = BUTTONS[ own['buttonNum'] ] objectControl.getFromScene('text_button_' + button, 'partyCreate').color = (1, 1, 1, 1)
def moveToPosition(position): cursor = objectControl.getFromScene('cursor', 'battlefield') cursorAlreadyInPosition = check.eq2D(position, cursor.worldPosition) if cursorAlreadyInPosition: return False # Movement did not happen else: cursor.worldPosition = position return True # Movement happened
def attempt(cont): cursor = objectControl.getFromScene('cursor', 'battlefield') aKey = cont.sensors['aKey'].positive dKey = cont.sensors['dKey'].positive if aKey: cursor.applyRotation([0.0, 0.0, -pi/2]) elif dKey: cursor.applyRotation([0.0, 0.0, pi/2])
def listText(): # Get the first list of commands commands = getCommandsList()[0] # Form list of all commands in first list seperated by newlines text = "" for command in commands: text += commandControl.name(command) + "\n" # Set the text of the object object = objectControl.getFromScene(LIST_OBJECT_NAME, SCENE_NAME) object["Text"] = text
def adjustRotation(resultDisplay): # The object whose rotation the display copies obj = objectControl.getFromScene(OBJECT_NAME_ROTATION_COPY, 'battlefield') orientation = obj.orientation # Adjustments have to be made to the orientation xAdjust = Matrix.Rotation(radians(90.0), 3, 'X') zAdjust = Matrix.Rotation(radians(-45.0), 3, 'Z') orientation *= zAdjust * xAdjust # NOTE(kgeffen) Order matters, don't change order resultDisplay.orientation = orientation
def extentText(): # Get the command currently being considered command = getCommandsList()[0][0] text = "" if commandControl.hasTag(command, "extends"): extent = logic.globalDict["extent"] text = "Extent: " + str(extent) # Set the text of the object object = objectControl.getFromScene(EXTENT_OBJECT_NAME, SCENE_NAME) object["Text"] = text
def updateDisplay(own): # Update each text field updateTextFields(own) # Scale down the arrows if they are enlarged for arrowName in ['leftArrow2', 'rightArrow2']: arrow = objectControl.getFromScene(arrowName, 'partyCreate') if arrow.localScale.x > 1: arrow.localScale -= Vector((0.035, 0.035, 0.035)) # Hide arrows if necessary field = FIELDS[ own['fieldNum'] ] if field not in FIELDS_W_ARROWS: objectControl.getFromScene('leftArrow2', 'partyCreate').setVisible(False) objectControl.getFromScene('rightArrow2', 'partyCreate').setVisible(False) else: objectControl.getFromScene('leftArrow2', 'partyCreate').setVisible(True) objectControl.getFromScene('rightArrow2', 'partyCreate').setVisible(True)
def descriptionText(): # Get the first list of commands commands = getCommandsList()[0] # Get description text text = "" if len(commands) != 0: # Only if there are commands to describe text = commandControl.description(commands[0]) text = textControl.wrap(text, WRAP_AT) # Set the text of the object obj = objectControl.getFromScene(DESCRIPTION_OBJECT_NAME, SCENE_NAME) obj["Text"] = text
def statsText(unit): # <unitName> # <alignment> # hp: <hp>/<health> # sp: <sp>/<spirit> # MV_ICON x<mv> ACT_ICON x<act text = unit['name'] + '\n' text += alignControl.name(unit['align']) + '\n\n' text += 'hp: ' + str(unit['hp']) + '/' + str(unit['health']) + '\n' text += 'sp: ' + str(unit['sp']) + '/' + str(unit['spirit']) + '\n' text += ' x' + str(unit['mv']) + ' x' + str(unit['act']) obj = objectControl.getFromScene(TEXT_OBJECT_NAME, 'basicInfo') obj['Text'] = text
def moveHorizontal(own, left): field = FIELDS[ own['fieldNum'] ] callDict = { 'party' : cycleParty, 'name' : cycleName, 'class' : cycleClass, 'addSkill' : cycleAddSkill, 'removeSkill' : cycleRemoveSkill, 'button' : cycleButton } method = callDict[field] method(own, left) # Scale up arrow chosen if left: objectControl.getFromScene('leftArrow2', 'partyCreate').worldScale = [1.5, 1.5, 1.5] else: objectControl.getFromScene('rightArrow2', 'partyCreate').worldScale = [1.5, 1.5, 1.5] # Play sound soundControl.play('navigate')
def do(): text = logic.globalDict['time'].asString() # Only display first N lines of text croppedText = '' for line in text.split('\n'): # If text has less lines than max, add another line if croppedText.count('\n') <= MAX_LINES: croppedText += line + '\n' else: break timeDisplay = objectControl.getFromScene(TIME_DISPLAY_NAME, OVERLAY_SCENE_NAME) timeDisplay['Text'] = croppedText
def attempt(): cursor = objectControl.getFromScene('cursor', 'battlefield') cursorPosition = cursor.worldPosition describedUnit = unitControl.get.inSpace(cursorPosition) scene = sceneControl.get('basicInfo') if describedUnit is not None: do(describedUnit) for obj in scene.objects: obj.setVisible(True) else: for obj in scene.objects: obj.setVisible(False)
def mpmpfempmf(): return if field == 'start': # Set all globalDicts based on fields logic.globalDict['stage'] = own['stages'][0] logic.globalDict['party1'] = own['party1'][0] logic.globalDict['party2'] = own['party2'][0] # 'players' must be handled a little differently # Start battlefield path = logic.expandPath('battlefield.blend') logic.startGame(path) elif field == 'party1' or field == 'party2': screen1 = objectControl.getFromScene('screen1', 'main') screen1.worldPosition.z += 1.5
def iconImage(): iconObject = objectControl.getFromScene(ICON_OBJECT_NAME, SCENE_NAME) # Get the first list of commands commands = getCommandsList()[0] if len(commands) == 0: # No commands to display icon for, make icon invisible iconObject.setVisible(False) else: iconObject.setVisible(True) filename = commandControl.icon(commands[0]) # The path to the icon's image file path = logic.expandPath("//images/icons/" + filename) dynamicMaterial.switchMaterialsImage(path, ICON_OBJECT_NAME)
def typeText(): # Setup each of the text objects objNumbers = [2, 3] for i in objNumbers: text = '' for statType in STATS[i]: text += statType.capitalize() text += '\n' # Get text object TYPE_SUFFIX = '_type' objectName = TEXT_OBJECT_NAME_BASE + str(i) + TYPE_SUFFIX obj = objectControl.getFromScene(objectName, 'info') # Set that object's text obj['Text'] = text
def choiceText(): # Get the command currently being considered command = getCommandsList()[0][0] choices = logic.globalDict["commandChoices"] if choices == []: # Form list of choices for command, if any commandControl.determineChoices(command) # Display choice, if any # NOTE(kgeffen) determineChoices may have populated choices text = "" if choices != []: text = choices[0]["display"] # Set the text of the object object = objectControl.getFromScene(CHOICE_OBJECT_NAME, SCENE_NAME) object["Text"] = text
def statText(unit): # Setup each text object # Each list of stats displayed by a different text object quantityTextObjects = len(STATS) for i in range(0, quantityTextObjects): # Get text that object will display text = statsInLines(unit, STATS[i]) # Description must be wrapped - Special case if STATS[i] == ['descript']: text = textControl.wrap(text, WRAP_AT) # Get text object objectName = TEXT_OBJECT_NAME_BASE + str(i) obj = objectControl.getFromScene(objectName, 'info') # Set that object's text obj['Text'] = text