def ApplyAttributes(self, attributes): VisibleBase.ApplyAttributes(self, attributes) self.texture = trinity.Tr2Sprite2dTexture() texturePath = attributes.get('texturePath', self.default_texturePath) if texturePath: self.SetTexturePath(texturePath) secondaryPath = attributes.get('textureSecondaryPath', self.default_textureSecondaryPath) if secondaryPath: self.SetSecondaryTexturePath(secondaryPath) self.glowFactor = attributes.get('glowFactor', self.default_glowFactor) self.glowExpand = attributes.get('glowExpand', self.default_glowExpand) self.glowColor = attributes.get('glowColor', self.default_glowColor) self.shadowOffset = attributes.get('shadowOffset', self.default_shadowOffset) self.shadowColor = attributes.get('shadowColor', self.default_shadowColor) rectLeft = attributes.rectLeft if rectLeft: self.rectLeft = rectLeft rectTop = attributes.rectTop if rectTop: self.rectLeft = rectTop rectWidth = attributes.rectWidth if rectWidth: self.rectWidth = rectWidth rectHeight = attributes.rectHeight if rectHeight: self.rectHeight = rectHeight self.spriteEffect = attributes.get('spriteEffect', self.default_spriteEffect) self.rotation = attributes.get('rotation', self.default_rotation) self.tileX = attributes.get('tileX', self.default_tileX) self.tileY = attributes.get('tileY', self.default_tileY)
def SetSecondaryTexturePath(self, texturePath): """ Set secondary texture path """ if not self.textureSecondary: self.textureSecondary = trinity.Tr2Sprite2dTexture() self.textureSecondary.resPath = str(texturePath or '')
def ApplyAttributes(self, attributes): Sprite.ApplyAttributes(self, attributes) sm.RegisterNotify(self) self.textureRes = trinity.TriTextureRes() self.texture = trinity.Tr2Sprite2dTexture() self.player = None self.path = None self.audioTrack = 0 self.videoLoop = False self.emitter = None self._updateStep = None self._isFetchingFile = False RO = self.GetRenderObject() self.disableAudio = attributes.get('disableAudio', self.default_disableAudio) self._positionComponent = attributes.get('positionComponent', None) self.positionComponent = None if 'videoPath' in attributes and attributes[ 'videoPath'] and attributes.get('videoAutoPlay', self.default_videoAutoPlay): self.SetVideoPath( attributes['videoPath'], attributes.get('audioTrack', 0), attributes.get('videoLoop', self.default_videoLoop)) if 'pos' in attributes: pos = attributes.get('pos', (self.default_left, self.default_top, self.default_width, self.default_height)) RO.displayX, RO.displayY, RO.displayWidth, RO.displayHeight = pos
def CreateSprite(scale, size): sprite = trinity.Tr2Sprite2d() sprite.texturePrimary = trinity.Tr2Sprite2dTexture() sprite.texturePrimary.resPath = 'res:/Texture/Global/blackAlpha.dds' sprite.displayHeight = scale sprite.displayWidth = scale sprite.displayX = 0.5 * (1.0 - 1.0 / size) sprite.displayY = 0.5 * (1.0 - 1.0 / size) return sprite
def CreateRandomIcon(): sprite = trinity.Tr2Sprite2d() name = iconFiles[random.randint(0, len(iconFiles) - 1)] size = 64 name = 'res:/UI/Texture/Icons/icons' + name + '.dds' tex = trinity.Tr2Sprite2dTexture() tex.resPath = name sprite.texturePrimary = tex sprite.displayWidth = size sprite.displayHeight = size sprite.color = (1, 1, 1, 1) return sprite
def ApplyPixels(self, linewidth, lineHeight): self.sr.xMin = 0 if not self.sr.node.glyphString: return node = self.sr.node glyphstring = node.glyphString bBox = node.bBox sprite = self.GetSprite() if not bBox or bBox.Width() <= 0 or bBox.Height() <= 0: sprite.state = uiconst.UI_HIDDEN return surfaceWidth = bBox.Width() surfaceHeight = glyphstring.baseHeight sprite.left += bBox.xMin if glyphstring.shadow: sx, sy, scol = glyphstring.shadow[-1] surfaceWidth += sx surfaceHeight -= sy sprite.texture = None texturePrimary = trinity.Tr2Sprite2dTexture() texturePrimary.atlasTexture = uicore.uilib.CreateTexture( surfaceWidth, surfaceHeight) sprite.texture = texturePrimary sprite.useSizeFromTexture = True try: bufferData = texturePrimary.atlasTexture.LockBuffer() except AttributeError: if texturePrimary and texturePrimary.atlasTexture: texturePrimary.atlasTexture.UnlockBuffer() bufferData = texturePrimary.atlasTexture.LockBuffer() else: self.display = False return try: buf = SE_TextlineCore.TexResBuf(bufferData) trinity.fontMan.ClearBuffer(buf.data, buf.width, buf.height, buf.pitch) glyphstring.DrawToBuf( buf, -bBox.xMin, glyphstring.baseHeight - glyphstring.baseLine) finally: texturePrimary.atlasTexture.UnlockBuffer() sprite.top = 0 self.sr.xMin = bBox.xMin sprite.state = uiconst.UI_PICKCHILDREN
def GetPortraitTexture(self, portraitID): size = 512 sceneManager = sm.GetService('sceneManager') scene = sceneManager.GetActiveScene() backdropPath = self.backdropPath if backdropPath: backdropScene = trinity.Tr2Sprite2dScene() backdropScene.displayWidth = size backdropScene.displayHeight = size sprite = trinity.Tr2Sprite2d() sprite.texturePrimary = trinity.Tr2Sprite2dTexture() sprite.texturePrimary.resPath = backdropPath sprite.displayWidth = size sprite.displayHeight = size backdropScene.children.append(sprite) target = trinity.Tr2RenderTarget(size, size, 1, trinity.PIXEL_FORMAT.B8G8R8X8_UNORM) depth = trinity.Tr2DepthStencil(size, size, trinity.DEPTH_STENCIL_FORMAT.AUTO) renderJob = trinity.CreateRenderJob('TakeSnapShot') renderJob.PushRenderTarget(target) renderJob.PushDepthStencil(depth) projection = trinity.TriProjection() projection.PerspectiveFov(self.camera.fieldOfView, 1, 0.1, 5.0) view = self.camera.viewMatrix renderJob.Clear((0.0, 0.0, 0.0, 1.0), 1.0) renderJob.SetProjection(projection) renderJob.SetView(view) if backdropPath: renderJob.Update(backdropScene) renderJob.RenderScene(backdropScene) renderJob.RenderScene(scene) trinity.WaitForResourceLoads() renderJob.PopDepthStencil() renderJob.PopRenderTarget() renderJob.ScheduleOnce() renderJob.WaitForFinish() filename = self.GetPortraitSnapshotPath(portraitID) trinity.Tr2HostBitmap(target).Save(filename) path = 'cache:/Pictures/Portraits/PortraitSnapshot_%s_%s.jpg' % ( portraitID, session.userid) blue.motherLode.Delete(path) tex = blue.resMan.GetResource(path, 'atlas') return tex
def ApplyAttributes(self, attributes): uicls.VisibleBase.ApplyAttributes(self, attributes) self.texture = trinity.Tr2Sprite2dTexture() self.SetTexturePath(attributes.get('texturePath', self.default_texturePath)) secondaryPath = attributes.get('textureSecondaryPath', self.default_textureSecondaryPath) self.textureSecondary = None if secondaryPath: self.SetSecondaryTexturePath(secondaryPath) self.glowFactor = attributes.get('glowFactor', self.default_glowFactor) self.glowExpand = attributes.get('glowExpand', self.default_glowExpand) self.glowColor = attributes.get('glowColor', self.default_glowColor) self.shadowOffset = attributes.get('shadowOffset', self.default_shadowOffset) self.shadowColor = attributes.get('shadowColor', self.default_shadowColor) self.rectLeft = attributes.rectLeft or 0 self.rectTop = attributes.rectTop or 0 self.rectWidth = attributes.rectWidth or 0 self.rectHeight = attributes.rectHeight or 0 self.spriteEffect = attributes.get('spriteEffect', self.default_spriteEffect) self.rotation = attributes.get('rotation', self.default_rotation)
def ReturnTexture(self, path, width, height, bufferwidth, bufferheight): tex = trinity.Tr2Sprite2dTexture() tex.resPath = path return (tex, width, height)
def ErrorPic(self, sizeonly=0): if sizeonly: return (NONE_PATH, 32, 32, 32, 32) tex = trinity.Tr2Sprite2dTexture() tex.resPath = NONE_PATH return (tex, 32, 32)
def _AddTarget(): import trinity import uiconst import random import uicls par = uicls.Container(parent=uicore.desktop, left=256, top=random.randint(1, 500), align=uiconst.RELATIVE, width=300, height=128) curveSet = par.CreateCurveSet() curveSet.scale = 1.0 curve = trinity.TriPerlinCurve() curve.scale = 1000.0 curve.offset = -0.0 curve.N = 2 curve.speed = 1.0 curve.alpha = 1000.0 curve.beta = 5000.0 curveSet.curves.append(curve) binding = trinity.TriValueBinding() binding.sourceObject = curve binding.sourceAttribute = 'value' binding.destinationObject = par binding.destinationAttribute = 'displayY' binding.scale = 1 curveSet.bindings.append(binding) curve = trinity.TriPerlinCurve() curve.scale = 1200.0 curve.offset = -300.0 curve.N = 2 curve.speed = 1.0 curve.alpha = 1200.0 curve.beta = 8000.0 curveSet.curves.append(curve) binding = trinity.TriValueBinding() binding.sourceObject = curve binding.sourceAttribute = 'value' binding.destinationObject = par binding.destinationAttribute = 'displayX' binding.scale = 1 curveSet.bindings.append(binding) inTime = 0.5 mainParent = uicls.Container(parent=par, name='mainParent', align=uiconst.RELATIVE, width=200, height=64, top=32, left=96) maintext = uicls.Sprite(parent=mainParent, texturePath='res:/UICore/texture/text.dds', left=96.0, width=200, height=64, effect=trinity.S2D_RFX_BLUR) caption = uicls.Sprite(parent=mainParent, texturePath='res:/UICore/texture/caption.dds', left=50, top=56, width=160, height=32, effect=trinity.S2D_RFX_BLUR) bracket = uicls.Sprite(parent=mainParent, texturePath='res:/UICore/texture/brackettext.dds', left=200, top=56, width=100, height=32, effect=trinity.S2D_RFX_BLUR) scrolltext = uicls.Label(parent=mainParent, text='0123456789', align=uiconst.TOPLEFT, left=237, top=7, fontsize=9, color=(1.0, 1.0, 1.0, 0.5)) curve, binding = CreateColorCurve(bracket, curveSet, length=0.5, startValue=(1, 1, 1, 1), endValue=(1, 1, 1, 0), cycle=True) curve.AddKey(0.0, (1, 1, 1, 0.0)) curve.AddKey(0.1, (1, 1, 1, 1)) curve.AddKey(0.5, (1, 1, 1, 0.0)) AddBinding(curve, 'currentValue', caption, 'color', curveSet) curve, binding = CreateScalarCurve(mainParent, 'currentValue', 'displayX', curveSet, length=inTime, startValue=-500.0, endValue=0.0, endTangent=-1000.0, cycle=False) correction = -0.5 curve = trinity.TriPerlinCurve() curve.scale = 400.0 curve.offset = 200.0 curveSet.curves.append(curve) innerTransform = trinity.Tr2Sprite2dTransform() innerTransform.translation = (0, 0) innerTransform.rotationCenter = (64, 64) par.children.insert(0, innerTransform) inner = trinity.Tr2Sprite2d() innerTransform.children.append(inner) inner.displayWidth = inner.displayHeight = 128 inner.displayX = correction inner.displayY = correction inner.texturePrimary = trinity.Tr2Sprite2dTexture() inner.texturePrimary.resPath = 'res:/uicore/Texture/innercircles.dds' binding = trinity.TriValueBinding() binding.sourceObject = curve binding.sourceAttribute = 'value' binding.destinationObject = innerTransform binding.destinationAttribute = 'rotation' binding.scale = 0.025 curveSet.bindings.append(binding) curve = trinity.TriSineCurve() curve.scale = 500.0 curve.offset = 300.0 curve.speed = 0.3 curveSet.curves.append(curve) outerTransform = trinity.Tr2Sprite2dTransform() outerTransform.translation = (0, 0) outerTransform.rotationCenter = (64, 64) par.children.insert(0, outerTransform) outer = trinity.Tr2Sprite2d() outerTransform.children.append(outer) outer.displayWidth = outer.displayHeight = 128 outer.displayX = correction outer.displayY = correction outer.texturePrimary = trinity.Tr2Sprite2dTexture() outer.texturePrimary.resPath = 'res:/uicore/Texture/outercircles.dds' outer.effect = trinity.S2D_RFX_BLUR outer.blurFactor = 0.1 binding = trinity.TriValueBinding() binding.sourceObject = curve binding.sourceAttribute = 'value' binding.destinationObject = outerTransform binding.destinationAttribute = 'rotation' binding.scale = 0.00125 curveSet.bindings.append(binding) curveSet.Play()