Ticket #1365: hero-overlay-alpha-desaturate-3.patch
File hero-overlay-alpha-desaturate-3.patch, 13.3 KB (added by , 12 years ago) |
---|
-
source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp
148 148 } 149 149 } 150 150 151 cmpSelectable->SetSelectionHighlight(colour );151 cmpSelectable->SetSelectionHighlight(colour, true); 152 152 } 153 153 } 154 154 -
source/simulation2/components/ICmpSelectable.h
56 56 * Set the color of the selection highlight (typically a circle/square 57 57 * around the unit). Set a = 0 to disable the highlight. 58 58 */ 59 virtual void SetSelectionHighlight(CColor color ) = 0;59 virtual void SetSelectionHighlight(CColor color, bool selected) = 0; 60 60 61 61 /** 62 62 * Set the alpha of the selection highlight. Set to 0 to disable the highlight. -
source/simulation2/components/ICmpSelectable.cpp
24 24 #include "ps/Overlay.h" 25 25 26 26 BEGIN_INTERFACE_WRAPPER(Selectable) 27 DEFINE_INTERFACE_METHOD_ 1("SetSelectionHighlight", void, ICmpSelectable, SetSelectionHighlight, CColor)27 DEFINE_INTERFACE_METHOD_2("SetSelectionHighlight", void, ICmpSelectable, SetSelectionHighlight, CColor, bool) 28 28 END_INTERFACE_WRAPPER(Selectable) 29 29 30 30 bool ICmpSelectable::ms_EnableDebugOverlays = false; -
source/simulation2/components/CCmpSelectable.cpp
59 59 CCmpSelectable() 60 60 : m_DebugBoundingBoxOverlay(NULL), m_DebugSelectionBoxOverlay(NULL), 61 61 m_BuildingOverlay(NULL), m_UnitOverlay(NULL), 62 m_FadeBaselineAlpha(0.f), m_FadeDeltaAlpha(0.f), m_FadeProgress(0.f) 62 m_FadeBaselineAlpha(0.f), m_FadeDeltaAlpha(0.f), m_FadeProgress(0.f), 63 m_Selected(false), m_Cached(false) 63 64 { 64 65 m_Color = CColor(0, 0, 0, m_FadeBaselineAlpha); 65 66 } … … 83 84 "</element>" 84 85 "</optional>" 85 86 "<element name='Overlay' a:help='Specifies the type of overlay to be displayed when this entity is selected'>" 87 "<optional>" 88 "<element name='AlwaysVisible' a:help='If this element is present, the minimum alpha of the overlay will be 50%'>" 89 "<empty/>" 90 "</element>" 91 "</optional>" 86 92 "<choice>" 87 93 "<element name='Texture' a:help='Displays a texture underneath the entity.'>" 88 94 "<element name='MainTexture' a:help='Texture to display underneath the entity. Filepath relative to art/textures/selection/.'><text/></element>" … … 101 107 { 102 108 m_EditorOnly = paramNode.GetChild("EditorOnly").IsOk(); 103 109 110 // Certain special units always have their selection overlay shown. 111 m_AlphaMin = paramNode.GetChild("Overlay").GetChild("AlwaysVisible").IsOk() ? .5 : 0.; 112 if (m_AlphaMin > 0.) 113 m_Color.a = m_AlphaMin; 114 104 115 const CParamNode& textureNode = paramNode.GetChild("Overlay").GetChild("Texture"); 105 116 const CParamNode& outlineNode = paramNode.GetChild("Overlay").GetChild("Outline"); 106 117 … … 141 152 142 153 virtual void HandleMessage(const CMessage& msg, bool UNUSED(global)); 143 154 144 virtual void SetSelectionHighlight(CColor color )155 virtual void SetSelectionHighlight(CColor color, bool selected) 145 156 { 157 m_Selected = selected; 146 158 m_Color.r = color.r; 147 159 m_Color.g = color.g; 148 160 m_Color.b = color.b; 161 162 // Always-visible overlays will be desaturated if their parent unit is deselected. 163 if (m_AlphaMin > 0. && !selected) 164 { 165 float max; 166 167 // Reduce saturation by one-third, the quick-and-dirty way. 168 if (m_Color.r > m_Color.b) 169 max = (m_Color.r > m_Color.g) ? m_Color.r : m_Color.g; 170 else 171 max = (m_Color.b > m_Color.g) ? m_Color.b : m_Color.g; 172 173 m_Color.r += (max - m_Color.r) / 3.; 174 m_Color.g += (max - m_Color.g) / 3.; 175 m_Color.b += (max - m_Color.b) / 3.; 176 } 177 149 178 SetSelectionHighlightAlpha(color.a); 150 179 } 151 180 152 181 virtual void SetSelectionHighlightAlpha(float alpha) 153 182 { 183 alpha = std::max(m_AlphaMin, alpha); 184 154 185 // set up fading from the current value (as the baseline) to the target value 155 186 m_FadeBaselineAlpha = m_Color.a; 156 187 m_FadeDeltaAlpha = alpha - m_FadeBaselineAlpha; … … 191 222 /// Is this entity selectable only in the editor? 192 223 bool m_EditorOnly; 193 224 225 226 /// Whether the parent entity is selected (caches GUI's selection state). 227 bool m_Selected; 194 228 /// Current selection overlay color. Alpha component is subject to fading. 195 229 CColor m_Color; 230 /// Whether the selectable's player colour has been cached for rendering. 231 bool m_Cached; 232 /// Minimum value for current selection overlay alpha. 233 float m_AlphaMin; 196 234 /// Baseline alpha value to start fading from. Constant during a single fade. 197 235 float m_FadeBaselineAlpha; 198 236 /// Delta between target and baseline alpha. Constant during a single fade. Can be positive or negative. … … 260 298 // Update the highlight color, while keeping the current alpha target value intact 261 299 // (i.e. baseline + delta), so that any ongoing fades simply continue with the new color. 262 300 CColor color = cmpPlayer->GetColour(); 263 SetSelectionHighlight(CColor(color.r, color.g, color.b, m_FadeBaselineAlpha + m_FadeDeltaAlpha) );301 SetSelectionHighlight(CColor(color.r, color.g, color.b, m_FadeBaselineAlpha + m_FadeDeltaAlpha), m_Selected); 264 302 } 265 303 // fall-through 266 304 case MT_PositionChanged: … … 473 511 // don't render selection overlay if it's not gonna be visible 474 512 if (m_Color.a > 0) 475 513 { 514 if (!m_Cached) 515 { 516 // Try to initialize m_Color to the owning player's colour. 517 CmpPtr<ICmpPlayerManager> cmpPlayerManager(GetSimContext(), SYSTEM_ENTITY); 518 if (!cmpPlayerManager) 519 return; 520 521 CmpPtr<ICmpOwnership> cmpOwnership(GetSimContext(), GetEntityId()); 522 if (!cmpOwnership) 523 return; 524 525 player_id_t owner = cmpOwnership->GetOwner(); 526 if (owner == INVALID_PLAYER) 527 return; 528 529 CmpPtr<ICmpPlayer> cmpPlayer(GetSimContext(), cmpPlayerManager->GetPlayerByID(owner)); 530 if (!cmpPlayer) 531 return; 532 533 CColor color = cmpPlayer->GetColour(); 534 color.a = m_FadeBaselineAlpha + m_FadeDeltaAlpha; 535 536 SetSelectionHighlight(color, m_Selected); 537 m_Cached = true; 538 } 539 476 540 switch (m_OverlayDescriptor.m_Type) 477 541 { 478 542 case STATIC_OUTLINE: -
binaries/data/mods/public/gui/session/selection.js
1 1 const MAX_SELECTION_SIZE = 200; // Limits selection size 2 2 3 function _setHighlight(ents, alpha )3 function _setHighlight(ents, alpha, selected) 4 4 { 5 5 if (ents.length) 6 Engine.GuiInterfaceCall("SetSelectionHighlight", { "entities":ents, "alpha":alpha });6 Engine.GuiInterfaceCall("SetSelectionHighlight", { "entities":ents, "alpha":alpha, "selected":selected }); 7 7 } 8 8 9 9 function _setStatusBars(ents, enabled) … … 214 214 if (entState.visibility == "hidden") 215 215 { 216 216 // Disable any highlighting of the disappeared unit 217 _setHighlight([ent], 0 );217 _setHighlight([ent], 0, false); 218 218 _setStatusBars([ent], false); 219 219 _setMotionOverlay([ent], false); 220 220 … … 280 280 } 281 281 } 282 282 283 _setHighlight(added, 1 );283 _setHighlight(added, 1, true); 284 284 _setStatusBars(added, true); 285 285 _setMotionOverlay(added, this.motionDebugOverlay); 286 286 if (added.length) … … 304 304 } 305 305 } 306 306 307 _setHighlight(removed, 0 );307 _setHighlight(removed, 0, false); 308 308 _setStatusBars(removed, false); 309 309 _setMotionOverlay(removed, false); 310 310 … … 313 313 314 314 EntitySelection.prototype.reset = function() 315 315 { 316 _setHighlight(this.toList(), 0 );316 _setHighlight(this.toList(), 0, false); 317 317 _setStatusBars(this.toList(), false); 318 318 _setMotionOverlay(this.toList(), false); 319 319 this.selected = {}; … … 349 349 if (!this.highlighted[ent] && !this.selected[ent]) 350 350 added.push(+ent); 351 351 352 _setHighlight(removed, 0 );352 _setHighlight(removed, 0, false); 353 353 _setStatusBars(removed, false); 354 354 355 _setHighlight(added, 0.5 );355 _setHighlight(added, 0.5, true); 356 356 _setStatusBars(added, true); 357 357 358 358 // Store the new highlight list -
binaries/data/mods/public/simulation/components/GuiInterface.js
591 591 return false; 592 592 }; 593 593 594 GuiInterface.prototype.SetSelectionHighlight = function(player, cmd )594 GuiInterface.prototype.SetSelectionHighlight = function(player, cmd, selected) 595 595 { 596 596 var cmpPlayerMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager); 597 597 var playerColours = {}; // cache of owner -> colour map … … 618 618 playerColours[owner] = colour; 619 619 } 620 620 621 cmpSelectable.SetSelectionHighlight({"r":colour.r, "g":colour.g, "b":colour.b, "a":cmd.alpha} );621 cmpSelectable.SetSelectionHighlight({"r":colour.r, "g":colour.g, "b":colour.b, "a":cmd.alpha}, cmd.selected); 622 622 } 623 623 }; 624 624 -
binaries/data/mods/public/simulation/templates/template_unit_hero_cavalry_archer.xml
62 62 </Minimap> 63 63 <Selectable> 64 64 <Overlay> 65 <AlwaysVisible/> 65 66 <Texture> 66 67 <MainTexture>star/256x256.png</MainTexture> 67 68 <MainTextureMask>star/256x256_mask.png</MainTextureMask> -
binaries/data/mods/public/simulation/templates/template_unit_hero_infantry.xml
51 51 </Minimap> 52 52 <Selectable> 53 53 <Overlay> 54 <AlwaysVisible/> 54 55 <Texture> 55 56 <MainTexture>star/256x256.png</MainTexture> 56 57 <MainTextureMask>star/256x256_mask.png</MainTextureMask> -
binaries/data/mods/public/simulation/templates/template_unit_hero.xml
49 49 </Minimap> 50 50 <Selectable> 51 51 <Overlay> 52 <AlwaysVisible/> 52 53 <Texture> 53 54 <MainTexture>star/256x256.png</MainTexture> 54 55 <MainTextureMask>star/256x256_mask.png</MainTextureMask> -
binaries/data/mods/public/simulation/templates/template_unit_hero_infantry_archer.xml
54 54 </Minimap> 55 55 <Selectable> 56 56 <Overlay> 57 <AlwaysVisible/> 57 58 <Texture> 58 59 <MainTexture>star/256x256.png</MainTexture> 59 60 <MainTextureMask>star/256x256_mask.png</MainTextureMask> -
binaries/data/mods/public/simulation/templates/template_unit_hero_infantry_javelinist.xml
58 58 </Minimap> 59 59 <Selectable> 60 60 <Overlay> 61 <AlwaysVisible/> 61 62 <Texture> 62 63 <MainTexture>star/256x256.png</MainTexture> 63 64 <MainTextureMask>star/256x256_mask.png</MainTextureMask> -
binaries/data/mods/public/simulation/templates/template_unit_hero_cavalry_javelinist.xml
52 52 </Minimap> 53 53 <Selectable> 54 54 <Overlay> 55 <AlwaysVisible/> 55 56 <Texture> 56 57 <MainTexture>star/256x256.png</MainTexture> 57 58 <MainTextureMask>star/256x256_mask.png</MainTextureMask> -
binaries/data/mods/public/simulation/templates/template_unit_hero_cavalry.xml
53 53 </Minimap> 54 54 <Selectable> 55 55 <Overlay> 56 <AlwaysVisible/> 56 57 <Texture> 57 58 <MainTexture>star/256x256.png</MainTexture> 58 59 <MainTextureMask>star/256x256_mask.png</MainTextureMask>