NovaBryan/EVE_Dump
Log | Files | 📦 下载最新源码 (.zip) | Refs | README

avatarHeaderPreview.py (5823B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\neocom\avatarHeaderPreview.py
      2 import logging
      3 from carbonui.util.color import Color
      4 from eve.client.script.ui.shared.preview import PreviewContainer, CharacterSceneContext, PreviewSceneContainer, PreviewNavigation
      5 from eve.common.lib import appConst as const
      6 import blue
      7 import carbonui.const as uiconst
      8 import charactercreator.const as ccConst
      9 import trinity
     10 import uthread
     11 stdlog = logging.getLogger(__name__)
     12 
     13 class AvatarHeaderPreview(PreviewContainer):
     14     __notifyevents__ = ['OnUIColorsChanged', 'OnGraphicSettingsChanged', 'OnSetDevice']
     15 
     16     def __init__(self, **kwargs):
     17         self.previewCharThread = None
     18         super(AvatarHeaderPreview, self).__init__(**kwargs)
     19 
     20     def ApplyAttributes(self, attributes):
     21         PreviewContainer.ApplyAttributes(self, attributes)
     22         sm.RegisterNotify(self)
     23         dna = sm.RemoteSvc('paperDollServer').GetPaperDollData(session.charid)
     24         if not self.previewCharThread:
     25             self.previewCharThread = uthread.new(self.PreviewCharacter, session.charid, dna=dna)
     26 
     27     def PreviewCharacter(self, charID, dna = None, apparel = None, background = None):
     28         if self.destroyed:
     29             self.previewCharThread = None
     30             return
     31         context = AvatarHeaderPreviewContext(charID, dna=dna, apparel=apparel)
     32         self.LoadScene(context)
     33         self.previewCharThread = None
     34 
     35     def LoadScene(self, context, force = False):
     36         while self.sceneContainer.viewport.width == 1 or self.sceneContainer.viewport.height == 1:
     37             blue.synchro.Yield()
     38 
     39         PreviewContainer.LoadScene(self, context, force)
     40         if not self.destroyed:
     41             self.UpdateLights()
     42 
     43     def UpdateLights(self):
     44         lights = self.sceneContainer.scene.lights
     45         color = sm.GetService('uiColor').GetUIColor(uiconst.COLORTYPE_UIHILIGHTGLOW)
     46         lights[0].color = Color(*color).SetSaturation(0.05).GetRGBA()
     47         lights[2].color = sm.GetService('uiColor').GetUIColor(uiconst.COLORTYPE_UIHILIGHTGLOW)
     48         lights[3].color = sm.GetService('uiColor').GetUIColor(uiconst.COLORTYPE_UIHILIGHTGLOW)
     49 
     50     def _OnResize(self, *args, **kw):
     51         if not self.previewCharThread:
     52             self.UpdateViewPort()
     53 
     54     def OnUIColorsChanged(self):
     55         self.UpdateLights()
     56 
     57     def OnSetDevice(self):
     58         if hasattr(self, 'sceneContainer') and self.sceneContainer is not None and hasattr(self.sceneContainer, 'renderJob') and self.sceneContainer.renderJob is not None:
     59             self.sceneContainer.renderJob.RebuildPostprocess()
     60         if not self.previewCharThread:
     61             self.UpdateViewPort()
     62 
     63     def DisableRender(self):
     64         if not self.previewCharThread:
     65             self.sceneContainer.renderJob.Disable()
     66 
     67     def EnableRender(self):
     68         if not self.previewCharThread:
     69             self.sceneContainer.renderJob.Enable(schedule=False)
     70 
     71     def ConstructSceneContainer(self):
     72         self.sceneContainer = AvatarHeaderSceneContainer(parent=self, align=uiconst.TOALL)
     73 
     74     def _Cleanup(self):
     75         try:
     76             self.sceneContainer = None
     77             self.ConstructSceneContainer()
     78             self.sceneContainer.Startup()
     79             self.navigation = None
     80             self.navigation = PreviewNavigation(parent=self)
     81             self.navigation.Startup(self.sceneContainer)
     82             if self.previewCharThread:
     83                 self.previewCharThread.kill()
     84                 self.previewCharThread = None
     85         except TaskletExit:
     86             pass
     87 
     88         super(AvatarHeaderPreview, self)._Cleanup()
     89 
     90 
     91 class AvatarHeaderSceneContainer(PreviewSceneContainer):
     92 
     93     def UpdateViewPort(self, *args):
     94         self.camera.fov = self.viewport.height / 4000.0
     95         PreviewSceneContainer.UpdateViewPort(self, *args)
     96 
     97 
     98 class AvatarHeaderPreviewContext(CharacterSceneContext):
     99 
    100     def SetupCamera(self, sceneContainer):
    101         CharacterSceneContext.SetupCamera(self, sceneContainer)
    102         cam = sceneContainer.camera
    103         cam.verticalOffset = -1.0
    104         if self.character.doll.gender == 'female':
    105             cam.SetEyePosition((-0.24811527132987976, 1.4142124235630034, 5.934291362762451))
    106             cam.SetAtPosition((0.011998310685157776, 1.8277159810066221, -0.020278582349419594))
    107         else:
    108             cam.SetEyePosition((-0.3404092073440552, 1.5400760936737061, 7.255154972076416))
    109             cam.SetAtPosition((-0.01654062792658806, 1.9754442143440247, -0.01789170503616333))
    110 
    111     def PrepareCharacterAnimation(self, avatar, gender):
    112 
    113         def _Prepare():
    114             trinity.WaitForResourceLoads()
    115             while not animation.IsFullyLoaded():
    116                 blue.synchro.Yield()
    117 
    118             animation.InstantiateCharacter()
    119             avatar.animationUpdater = animation
    120 
    121         animation = trinity.Tr2GStateAnimation()
    122         genderStr = 'Female' if gender == ccConst.GENDERID_FEMALE else 'Male'
    123         animation.gStateResPath = str('res:/Animation/CharacterCreatorV2/Gstate/%s_CharacterSheet.gsf' % genderStr)
    124         uthread.new(_Prepare)
    125 
    126     def GetSceneFile(self, charInfo):
    127         if charInfo.raceID == const.raceAmarr:
    128             return 'res:/Graphics/Interior/characterSheet/CharacterSheetAmarr.red'
    129         elif charInfo.raceID == const.raceCaldari:
    130             return 'res:/Graphics/Interior/characterSheet/CharacterSheetCaldari.red'
    131         elif charInfo.raceID == const.raceGallente:
    132             return 'res:/Graphics/Interior/characterSheet/CharacterSheetGallente.red'
    133         elif charInfo.raceID == const.raceMinmatar:
    134             return 'res:/Graphics/Interior/characterSheet/CharacterSheetMinmatar.red'
    135         else:
    136             return super(AvatarHeaderPreviewContext, self).GetSceneFile(charInfo)
    137 
    138     def GetBackground(self):
    139         return None