Ticket #3915: visualrange_v0.2.patch
File visualrange_v0.2.patch, 7.2 KB (added by , 8 years ago) |
---|
-
binaries/data/mods/public/simulation/components/GuiInterface.js
867 867 color = cmpPlayer.GetColor(); 868 868 playerColors[owner] = color; 869 869 } 870 let cmpIdentity = Engine.QueryInterface(ent, IID_Identity); 871 let showRange = cmpIdentity.HasClass("Defensive") && owner == player; 870 872 871 cmpSelectable.SetSelectionHighlight({ "r": color.r, "g": color.g, "b": color.b, "a": cmd.alpha }, cmd.selected );873 cmpSelectable.SetSelectionHighlight({ "r": color.r, "g": color.g, "b": color.b, "a": cmd.alpha }, cmd.selected, showRange); 872 874 } 873 875 }; 874 876 -
source/simulation2/components/CCmpSelectable.cpp
38 38 #include "simulation2/components/ICmpOwnership.h" 39 39 #include "simulation2/components/ICmpPlayer.h" 40 40 #include "simulation2/components/ICmpPlayerManager.h" 41 #include "simulation2/components/ICmpVision.h" 41 42 #include "simulation2/components/ICmpWaterManager.h" 42 43 #include "simulation2/helpers/Render.h" 43 44 #include "simulation2/system/Component.h" … … 64 65 65 66 CCmpSelectable() 66 67 : m_DebugBoundingBoxOverlay(NULL), m_DebugSelectionBoxOverlay(NULL), 67 m_BuildingOverlay(NULL), m_ UnitOverlay(NULL),68 m_BuildingOverlay(NULL), m_RangeOverlay(NULL), m_UnitOverlay(NULL), 68 69 m_FadeBaselineAlpha(0.f), m_FadeDeltaAlpha(0.f), m_FadeProgress(0.f), 69 m_Selected(false), m_Cached(false), m_Visible(false) 70 m_Selected(false), m_Cached(false), m_Visible(false), m_ShowRange(false) 70 71 { 71 72 m_Color = CColor(0, 0, 0, m_FadeBaselineAlpha); 72 73 } … … 76 77 delete m_DebugBoundingBoxOverlay; 77 78 delete m_DebugSelectionBoxOverlay; 78 79 delete m_BuildingOverlay; 80 delete m_RangeOverlay; 79 81 delete m_UnitOverlay; 80 82 } 81 83 … … 167 169 168 170 virtual void HandleMessage(const CMessage& msg, bool UNUSED(global)); 169 171 170 virtual void SetSelectionHighlight(const CColor& color, bool selected )172 virtual void SetSelectionHighlight(const CColor& color, bool selected, bool showRange = false) 171 173 { 172 174 m_Selected = selected; 173 175 m_Color.r = color.r; 174 176 m_Color.g = color.g; 175 177 m_Color.b = color.b; 178 m_ShowRange = showRange; 176 179 177 180 // Always-visible overlays will be desaturated if their parent unit is deselected. 178 181 if (m_AlwaysVisible && !selected) … … 247 250 private: 248 251 SOverlayDescriptor m_OverlayDescriptor; 249 252 SOverlayTexturedLine* m_BuildingOverlay; 253 SOverlayTexturedLine* m_RangeOverlay; 250 254 SOverlayQuad* m_UnitOverlay; 251 255 252 256 SOverlayLine* m_DebugBoundingBoxOverlay; … … 275 279 float m_FadeDeltaAlpha; 276 280 /// Linear time progress of the fade, between 0 and m_FadeDuration. 277 281 float m_FadeProgress; 282 /// Whether visual range will be shown. 283 bool m_ShowRange; 278 284 279 285 /// Total duration of a single fade, in seconds. Assumed constant for now; feel free to change this into 280 286 /// a member variable if you need to adjust it per component. … … 340 346 // Update the highlight color, while keeping the current alpha target value intact 341 347 // (i.e. baseline + delta), so that any ongoing fades simply continue with the new color. 342 348 CColor color = cmpPlayer->GetColor(); 343 SetSelectionHighlight(CColor(color.r, color.g, color.b, m_FadeBaselineAlpha + m_FadeDeltaAlpha), m_Selected );349 SetSelectionHighlight(CColor(color.r, color.g, color.b, m_FadeBaselineAlpha + m_FadeDeltaAlpha), m_Selected, m_ShowRange); 344 350 345 351 InvalidateStaticOverlay(); 346 352 break; … … 400 406 void CCmpSelectable::InvalidateStaticOverlay() 401 407 { 402 408 SAFE_DELETE(m_BuildingOverlay); 409 SAFE_DELETE(m_RangeOverlay); 410 403 411 } 404 412 405 413 void CCmpSelectable::UpdateStaticOverlay() … … 449 457 m_BuildingOverlay->m_TextureBase = g_Renderer.GetTextureManager().CreateTexture(texturePropsBase); 450 458 m_BuildingOverlay->m_TextureMask = g_Renderer.GetTextureManager().CreateTexture(texturePropsMask); 451 459 460 m_RangeOverlay = new SOverlayTexturedLine; 461 m_RangeOverlay->m_AlwaysVisible = false; 462 m_RangeOverlay->m_Closed = true; 463 m_RangeOverlay->m_SimContext = &GetSimContext(); 464 m_RangeOverlay->m_Thickness = m_OverlayDescriptor.m_LineThickness; 465 m_RangeOverlay->m_TextureBase = g_Renderer.GetTextureManager().CreateTexture(texturePropsBase); 466 m_RangeOverlay->m_TextureMask = g_Renderer.GetTextureManager().CreateTexture(texturePropsMask); 467 452 468 CVector2D origin(position.X.ToFloat(), position.Y.ToFloat()); 453 469 470 float rangeRadius; 471 472 if (m_ShowRange) 473 { 474 CmpPtr<ICmpVision> cmpVision(GetSimContext(), GetEntityId()); 475 if (!cmpVision) 476 return; 477 rangeRadius = cmpVision->GetRange().ToFloat(); 478 479 float stepAngle; 480 unsigned numSteps; 481 SimRender::AngularStepFromChordLen(TERRAIN_TILE_SIZE / 3.f, rangeRadius, stepAngle, numSteps); 482 483 for (unsigned i = 0; i < numSteps; i++) 484 { 485 float angle = i * stepAngle; 486 float px = origin.X + rangeRadius * sinf(angle); 487 float pz = origin.Y + rangeRadius * cosf(angle); 488 489 m_RangeOverlay->PushCoords(px, pz); 490 } 491 } 492 454 493 switch (fpShape) 455 494 { 456 495 case ICmpFootprint::SQUARE: … … 617 656 } 618 657 color.a = m_FadeBaselineAlpha + m_FadeDeltaAlpha; 619 658 620 SetSelectionHighlight(color, m_Selected );659 SetSelectionHighlight(color, m_Selected, m_ShowRange); 621 660 m_Cached = true; 622 661 } 623 662 … … 628 667 UpdateStaticOverlay(); 629 668 m_BuildingOverlay->m_Color = m_Color; // done separately so alpha changes don't require a full update call 630 669 collector.Submit(m_BuildingOverlay); 670 m_RangeOverlay->m_Color = m_Color; 671 collector.Submit(m_RangeOverlay); 631 672 } 632 673 break; 633 674 case DYNAMIC_QUAD: -
source/simulation2/components/ICmpSelectable.cpp
24 24 #include "ps/Shapes.h" 25 25 26 26 BEGIN_INTERFACE_WRAPPER(Selectable) 27 DEFINE_INTERFACE_METHOD_ 2("SetSelectionHighlight", void, ICmpSelectable, SetSelectionHighlight, CColor, bool)27 DEFINE_INTERFACE_METHOD_3("SetSelectionHighlight", void, ICmpSelectable, SetSelectionHighlight, CColor, bool, bool) 28 28 END_INTERFACE_WRAPPER(Selectable) 29 29 30 30 bool ICmpSelectable::ms_EnableDebugOverlays = false; -
source/simulation2/components/ICmpSelectable.h
57 57 * The highlight is typically a circle/square overlay around the unit. 58 58 * @param color color and alpha of the selection highlight. Set color.a = 0 to hide the highlight. 59 59 * @param selected whether the entity is selected; affects desaturation for always visible highlights. 60 * @param showRange whether visual range will be shown. 60 61 */ 61 virtual void SetSelectionHighlight(const CColor& color, bool selected ) = 0;62 virtual void SetSelectionHighlight(const CColor& color, bool selected, bool showRange = false) = 0; 62 63 63 64 /** 64 65 * Enables or disables rendering of an entity's selectable.