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

probeControl_MapView.py (12306B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\inflight\probeControl_MapView.py
      2 import uthread
      3 from carbon.client.script.environment.AudioUtil import PlaySound
      4 from carbon.common.script.util.mathUtil import ClampRotation
      5 from carbonui.uianimations import animations
      6 from carbonui.uicore import uicore
      7 from eve.client.script.ui.shared.mapView.mapViewConst import SOLARSYSTEM_SCALE, MODIFY_POSITION, MODIFY_RANGE, MODIFY_SPREAD
      8 import trinity
      9 import carbonui.const as uiconst
     10 import geo2
     11 import random
     12 import math
     13 from eve.client.script.environment import nodemanager
     14 import blue
     15 BASE_PROBE_COLOR = (0.45098039215686275, 0.9411764705882353, 1.0, 0)
     16 CURSOR_COLOR_PARAMETER_INDEX = 2
     17 CURSOR_IDLE_COLOR = BASE_PROBE_COLOR
     18 CURSOR_ACTIVE_COLOR = (2.0, 2.0, 2.0, 1.0)
     19 TR2TM_LOOK_AT_CAMERA = 3
     20 ANIM_DURATION = 0.15
     21 
     22 class BaseProbeControl(object):
     23     formationCenter = None
     24     STATE_IDLE = 0
     25     STATE_ACTIVE = 1
     26     STATE_ACTIVE_SINGLE = 2
     27     spreadCursor = None
     28     rangeCursor = None
     29     _cursorState = None
     30 
     31     def __init__(self, uniqueID, parent):
     32         self.parent = parent
     33         locator = trinity.EveTransform()
     34         locator.name = 'spherePar_%s' % uniqueID
     35         try:
     36             self.parent.children.append(locator)
     37         except:
     38             self.parent.objects.append(locator)
     39 
     40         CURSOR_SCALE_ARG_1 = 2000000.0
     41         CURSOR_SCALE = SOLARSYSTEM_SCALE * 250000000000.0
     42         cursor = trinity.Load('res:/Model/UI/probeCursor.red')
     43         cursor.scaling = (CURSOR_SCALE, CURSOR_SCALE, CURSOR_SCALE)
     44         cursor.useDistanceBasedScale = True
     45         cursor.distanceBasedScaleArg1 = CURSOR_SCALE_ARG_1
     46         cursor.distanceBasedScaleArg2 = 0.0
     47         cursor.translation = (0.0, 0.0, 0.0)
     48         cursor.display = False
     49         self.arrowX0 = nodemanager.FindNode(cursor, 'cursorX_0', 'trinity.EveTransform')
     50         self.arrowX1 = nodemanager.FindNode(cursor, 'cursorX_1', 'trinity.EveTransform')
     51         self.arrowY0 = nodemanager.FindNode(cursor, 'cursorY_0', 'trinity.EveTransform')
     52         self.arrowY1 = nodemanager.FindNode(cursor, 'cursorY_1', 'trinity.EveTransform')
     53         self.arrowZ0 = nodemanager.FindNode(cursor, 'cursorZ_0', 'trinity.EveTransform')
     54         self.arrowZ1 = nodemanager.FindNode(cursor, 'cursorZ_1', 'trinity.EveTransform')
     55         for c in cursor.children:
     56             c.name += '_' + str(uniqueID)
     57 
     58         locator.children.append(cursor)
     59         self.uniqueID = uniqueID
     60         self.cursor = cursor
     61         self.locator = locator
     62 
     63     def SetFormationCenter(self, centerPosition):
     64         self.formationCenter = centerPosition
     65         q = geo2.QuaternionRotationArc((0.0, 0.0, 1.0), geo2.Vec3Normalize(geo2.Vec3Subtract(self.formationCenter, self.locator.translation)))
     66         if self.spreadCursor:
     67             self.spreadCursor.rotation = q
     68         if self.rangeCursor:
     69             self.rangeCursor.rotation = q
     70 
     71     def SetPosition(self, position, animate = False):
     72         position = geo2.Vector(*position)
     73         if animate:
     74             animations.MorphVector3(self.locator, 'translation', self.locator.translation, position, duration=ANIM_DURATION)
     75         else:
     76             self.locator.translation = position
     77 
     78     def GetPosition(self):
     79         return geo2.Vector(self.locator.translation)
     80 
     81     def GetWorldPosition(self):
     82         return geo2.Vector(self.locator.worldTransform[3][:3])
     83 
     84     def SetCursorState(self, cursorState, hiliteAxis = None):
     85         if self._cursorState == (cursorState, hiliteAxis):
     86             return
     87         self._cursorState = (cursorState, hiliteAxis)
     88         if cursorState == self.STATE_ACTIVE:
     89             PlaySound('msg_newscan_probe_feedback_play')
     90             color = CURSOR_ACTIVE_COLOR
     91         else:
     92             color = CURSOR_IDLE_COLOR
     93         for each in self.cursor.children:
     94             if hiliteAxis and cursorState == self.STATE_ACTIVE:
     95                 cursorName, side, probeID = each.name.split('_')
     96                 cursorAxis = cursorName[6:].lower()
     97                 if hiliteAxis == cursorAxis:
     98                     each.mesh.opaqueAreas[0].effect.parameters[CURSOR_COLOR_PARAMETER_INDEX].value = CURSOR_ACTIVE_COLOR
     99                 else:
    100                     each.mesh.opaqueAreas[0].effect.parameters[CURSOR_COLOR_PARAMETER_INDEX].value = CURSOR_IDLE_COLOR
    101             else:
    102                 each.mesh.opaqueAreas[0].effect.parameters[CURSOR_COLOR_PARAMETER_INDEX].value = color
    103 
    104         if self.spreadCursor:
    105             for each in self.spreadCursor.children:
    106                 each.mesh.opaqueAreas[0].effect.parameters[CURSOR_COLOR_PARAMETER_INDEX].value = color
    107 
    108         if self.rangeCursor:
    109             for each in self.rangeCursor.children:
    110                 each.mesh.opaqueAreas[0].effect.parameters[CURSOR_COLOR_PARAMETER_INDEX].value = color
    111 
    112     def UpdateArrowOrientation(self, camera):
    113         if not self.IsVisible():
    114             return
    115         yaw = camera.GetYaw()
    116         yaw = ClampRotation(yaw)
    117         self.arrowY0.rotation = geo2.QuaternionRotationSetYawPitchRoll(yaw, math.pi / 2, 0)
    118         self.arrowY1.rotation = geo2.QuaternionRotationSetYawPitchRoll(yaw, -math.pi / 2, 0)
    119         pitch = camera.GetPitch()
    120         if yaw < math.pi / 2 or yaw > 3 * math.pi / 2:
    121             pitch = math.pi - pitch
    122         quat = geo2.QuaternionRotationAxis((1, 0, 0), pitch)
    123         self.arrowX0.rotation = geo2.QuaternionMultiply((0.0, 0.7071068, 0.0, 0.7071068), quat)
    124         self.arrowX1.rotation = geo2.QuaternionMultiply((0.0, -0.7071068, 0.0, 0.7071068), quat)
    125         pitch = camera.GetPitch()
    126         if yaw > math.pi:
    127             pitch = math.pi - pitch
    128         quat = geo2.QuaternionRotationAxis((0, 0, 1), pitch)
    129         self.arrowZ0.rotation = geo2.QuaternionMultiply((0.0, 1.0, 0.0, 0.0), quat)
    130         self.arrowZ1.rotation = quat
    131 
    132     def IsVisible(self):
    133         return self.cursor.display
    134 
    135     def UpdateArrowVisibility(self, camera):
    136         if not self.IsVisible():
    137             return
    138         dir = geo2.Vec3Scale(camera.GetLookAtDirection(), -1)
    139         self.arrowX0.display = self._IsArrowVisible((1, 0, 0), dir)
    140         self.arrowX1.display = self._IsArrowVisible((-1, 0, 0), dir)
    141         self.arrowY1.display = self._IsArrowVisible((0, 1, 0), dir)
    142         self.arrowY0.display = self._IsArrowVisible((0, -1, 0), dir)
    143         self.arrowZ1.display = self._IsArrowVisible((0, 0, 1), dir)
    144         self.arrowZ0.display = self._IsArrowVisible((0, 0, -1), dir)
    145 
    146     def _IsArrowVisible(self, dir, camDir):
    147         try:
    148             return math.acos(geo2.Vec3Dot(dir, camDir)) < 2.9
    149         except ValueError:
    150             return True
    151 
    152     def Remove(self, *args):
    153         if self.locator in self.parent.children:
    154             self.parent.children.remove(self.locator)
    155         self.parent = None
    156 
    157 
    158 class ProbeControl(BaseProbeControl):
    159 
    160     def __init__(self, probeID, probe, parent):
    161         scanSvc = sm.GetService('scanSvc')
    162         BaseProbeControl.__init__(self, probeID, parent)
    163         sphere = trinity.Load('res:/dx9/model/UI/Scanbubbledoteffect.red')
    164         self.locator.children.append(sphere)
    165         self.sphere = sphere
    166         scanbubble = nodemanager.FindNode(sphere, 'Scanbubble', 'trinity.EveTransform')
    167         for each in scanbubble.children:
    168             each.scaling = tuple([ (100 if scaling > 0 else -100) for scaling in each.scaling ])
    169 
    170         self.spreadCursor = self.ConstructSpreadCursor(probeID)
    171         self.rangeCursor = self.ConstructRangeCursor(probeID)
    172         self.scanRanges = scanSvc.GetScanRangeStepsByTypeID(probe.typeID)
    173         self.probeID = probeID
    174         self.scanrangeCircles = None
    175         self._highlighted = True
    176         self.HighlightBorder(0)
    177         animations.MorphVector3(self.locator, 'scaling', startVal=(0.0, 0.0, 0.0), endVal=(1.0, 1.0, 1.0), duration=0.5, curveType=uiconst.ANIM_OVERSHOT, timeOffset=random.random() * 0.5)
    178 
    179     def ConstructRangeCursor(self, probeID):
    180         cursor = trinity.Load('res:/Model/UI/probeRangeCursor.red')
    181         for c in cursor.children:
    182             c.scaling = (250.0, 250.0, 250.0)
    183             c.name += '_' + str(probeID)
    184             c.mesh.geometryResPath = 'res:/Graphics/generic/vortex/Cone2.gr2'
    185             c.rotation = geo2.QuaternionRotationSetYawPitchRoll(0.0, math.pi * 0.5, 0.0)
    186 
    187         cursor.display = False
    188         self.locator.children.append(cursor)
    189         return cursor
    190 
    191     def ConstructSpreadCursor(self, probeID):
    192         CURSOR_SCALE_ARG_1 = 2000000.0
    193         CURSOR_SCALE = SOLARSYSTEM_SCALE * 250000000000.0
    194         cursor = trinity.Load('res:/Model/UI/probeSpreadCursor.red')
    195         cursor.scaling = (CURSOR_SCALE, CURSOR_SCALE, CURSOR_SCALE)
    196         cursor.useDistanceBasedScale = True
    197         cursor.distanceBasedScaleArg1 = CURSOR_SCALE_ARG_1
    198         cursor.distanceBasedScaleArg2 = 0.0
    199         cursor.translation = (0.0, 0.0, 0.0)
    200         cursor.display = False
    201         for c in cursor.children:
    202             c.name += '_' + str(probeID)
    203 
    204         self.locator.children.append(cursor)
    205         return cursor
    206 
    207     def Remove(self, animate = False):
    208         uthread.new(self._Remove, animate)
    209 
    210     def _Remove(self, animate):
    211         if animate:
    212             self.SetRange(0.0, animate=True)
    213             blue.synchro.SleepWallclock(ANIM_DURATION * 1000)
    214         BaseProbeControl.Remove(self)
    215 
    216     def SetScanDronesState(self, state):
    217         scanEffectTf = nodemanager.FindNode(self.sphere, 'scanLines', 'trinity.EveTransform')
    218         if scanEffectTf:
    219             scanEffectTf.display = state
    220             if state:
    221                 scanLinesCurveSet = nodemanager.FindNode(scanEffectTf, 'ScanCurveSet', 'trinity.TriCurveSet')
    222                 if scanLinesCurveSet:
    223                     scanLinesCurveSet.Play()
    224 
    225     def SetRange(self, probeRange, animate = False):
    226         scaling = (probeRange, probeRange, probeRange)
    227         if animate:
    228             animations.MorphVector3(self.sphere, 'scaling', self.sphere.scaling, scaling, duration=ANIM_DURATION)
    229         else:
    230             self.sphere.scaling = scaling
    231         transform = self.rangeCursor.children[0]
    232         translation = (0.0, 0.0, -probeRange + 250.0)
    233         if animate:
    234             animations.MorphVector3(transform, 'translation', transform.translation, translation, duration=ANIM_DURATION)
    235         else:
    236             transform.translation = translation
    237 
    238     def ScaleRange(self, scale):
    239         scale = self.sphere.scaling[0] * scale
    240         self.SetRange((scale, scale, scale))
    241 
    242     def GetRange(self):
    243         return self.sphere.scaling[0]
    244 
    245     def HighlightBorder(self, on = 1):
    246         if bool(on) == self._highlighted:
    247             return
    248         self._highlighted = bool(on)
    249         curveSets = self.sphere.Find('trinity.TriCurveSet')
    250         curveSet = None
    251         for each in curveSets:
    252             if getattr(each, 'name', None) == 'Highlight':
    253                 curveSet = each
    254                 break
    255 
    256         if curveSet:
    257             curveSet.Stop()
    258             if on:
    259                 curveSet.scale = 10.0
    260                 curveSet.Play()
    261             else:
    262                 curveSet.scale = -1.0
    263                 curveSet.PlayFrom(curveSet.GetMaxCurveDuration())
    264 
    265     def HideScanRanges(self):
    266         if self.scanrangeCircles is not None:
    267             self.scanrangeCircles.display = False
    268 
    269     def ShowScanRanges(self):
    270         if self.scanrangeCircles is None:
    271             par = trinity.EveTransform()
    272             self.scanrangeCircles = par
    273             par.modifier = TR2TM_LOOK_AT_CAMERA
    274             self.locator.children.append(par)
    275             for r in self.scanRanges:
    276                 r *= 100.0
    277                 sr = trinity.Load('res:/Model/UI/probeRange.red')
    278                 sr.scaling = (r, r, r)
    279                 par.children.append(sr)
    280 
    281         self.scanrangeCircles.display = True
    282 
    283     def HighlightProbe(self):
    284         self.HighlightBorder(1)
    285 
    286     def StopHighlightProbe(self):
    287         self.HighlightBorder(0)
    288 
    289     def IsVisible(self):
    290         return BaseProbeControl.IsVisible(self) or self.rangeCursor.display or self.spreadCursor.display
    291 
    292     def SetEditMode(self, editMode):
    293         SHIFT = uicore.uilib.Key(uiconst.VK_SHIFT)
    294         self.spreadCursor.display = editMode == MODIFY_SPREAD
    295         self.cursor.display = editMode == MODIFY_POSITION and SHIFT
    296         self.rangeCursor.display = editMode == MODIFY_RANGE