Ticket #1365: hero-overlay-alpha-desaturate.patch

File hero-overlay-alpha-desaturate.patch, 11.3 KB (added by Deiz, 12 years ago)

Patch updated to remove spaces from XML elements (per Philip) and passed a boolean to confirm selection status, as suggested by historicbruno.

  • binaries/data/mods/public/simulation/templates/template_unit_hero.xml

    diff --git a/binaries/data/mods/public/simulation/templates/template_unit_hero.xml b/binaries/data/mods/public/simulation/templates/template_unit_hero.xml
    index f7e47eb..4b7b071 100644
    a b  
    4949  </Minimap>
    5050  <Selectable>
    5151    <Overlay>
     52      <AlwaysVisible/>
    5253      <Texture>
    5354        <MainTexture>star/256x256.png</MainTexture>
    5455        <MainTextureMask>star/256x256_mask.png</MainTextureMask>
  • binaries/data/mods/public/simulation/templates/template_unit_hero_cavalry.xml

    diff --git a/binaries/data/mods/public/simulation/templates/template_unit_hero_cavalry.xml b/binaries/data/mods/public/simulation/templates/template_unit_hero_cavalry.xml
    index 3db18aa..b5c1f15 100644
    a b  
    5353  </Minimap>
    5454  <Selectable>
    5555    <Overlay>
     56      <AlwaysVisible/>
    5657      <Texture>
    5758        <MainTexture>star/256x256.png</MainTexture>
    5859        <MainTextureMask>star/256x256_mask.png</MainTextureMask>
  • binaries/data/mods/public/simulation/templates/template_unit_hero_cavalry_archer.xml

    diff --git a/binaries/data/mods/public/simulation/templates/template_unit_hero_cavalry_archer.xml b/binaries/data/mods/public/simulation/templates/template_unit_hero_cavalry_archer.xml
    index 05a0a20..8032a51 100644
    a b Ranged attack 2x vs. spearmen. Ranged attack 1.5x vs. Swordsmen.</Tooltip>  
    6262  </Minimap>
    6363  <Selectable>
    6464    <Overlay>
     65      <AlwaysVisible/>
    6566      <Texture>
    6667        <MainTexture>star/256x256.png</MainTexture>
    6768        <MainTextureMask>star/256x256_mask.png</MainTextureMask>
  • binaries/data/mods/public/simulation/templates/template_unit_hero_cavalry_javelinist.xml

    diff --git a/binaries/data/mods/public/simulation/templates/template_unit_hero_cavalry_javelinist.xml b/binaries/data/mods/public/simulation/templates/template_unit_hero_cavalry_javelinist.xml
    index fa52c94..d39f071 100644
    a b  
    5252  </Minimap>
    5353  <Selectable>
    5454    <Overlay>
     55      <AlwaysVisible/>
    5556      <Texture>
    5657        <MainTexture>star/256x256.png</MainTexture>
    5758        <MainTextureMask>star/256x256_mask.png</MainTextureMask>
  • binaries/data/mods/public/simulation/templates/template_unit_hero_infantry.xml

    diff --git a/binaries/data/mods/public/simulation/templates/template_unit_hero_infantry.xml b/binaries/data/mods/public/simulation/templates/template_unit_hero_infantry.xml
    index 2bdeecb..56469ff 100644
    a b  
    5151  </Minimap>
    5252  <Selectable>
    5353    <Overlay>
     54      <AlwaysVisible/>
    5455      <Texture>
    5556        <MainTexture>star/256x256.png</MainTexture>
    5657        <MainTextureMask>star/256x256_mask.png</MainTextureMask>
  • binaries/data/mods/public/simulation/templates/template_unit_hero_infantry_archer.xml

    diff --git a/binaries/data/mods/public/simulation/templates/template_unit_hero_infantry_archer.xml b/binaries/data/mods/public/simulation/templates/template_unit_hero_infantry_archer.xml
    index 32ab5a9..6dbe0e2 100644
    a b Counters Swordsmen and Cavalry Spearmen. Countered by Skirmishers and other Cava  
    5454  </Minimap>
    5555  <Selectable>
    5656    <Overlay>
     57      <AlwaysVisible/>
    5758      <Texture>
    5859        <MainTexture>star/256x256.png</MainTexture>
    5960        <MainTextureMask>star/256x256_mask.png</MainTextureMask>
  • binaries/data/mods/public/simulation/templates/template_unit_hero_infantry_javelinist.xml

    diff --git a/binaries/data/mods/public/simulation/templates/template_unit_hero_infantry_javelinist.xml b/binaries/data/mods/public/simulation/templates/template_unit_hero_infantry_javelinist.xml
    index 6d7ba9b..3b0eb82 100644
    a b  
    5858  </Minimap>
    5959  <Selectable>
    6060    <Overlay>
     61      <AlwaysVisible/>
    6162      <Texture>
    6263        <MainTexture>star/256x256.png</MainTexture>
    6364        <MainTextureMask>star/256x256_mask.png</MainTextureMask>
  • source/simulation2/components/CCmpSelectable.cpp

    diff --git a/source/simulation2/components/CCmpSelectable.cpp b/source/simulation2/components/CCmpSelectable.cpp
    index 6650e35..72d5be0 100644
    a b public:  
    8484                "</element>"
    8585            "</optional>"
    8686            "<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>"
    8792                "<choice>"
    8893                    "<element name='Texture' a:help='Displays a texture underneath the entity.'>"
    8994                        "<element name='MainTexture' a:help='Texture to display underneath the entity. Filepath relative to art/textures/selection/.'><text/></element>"
    public:  
    102107    {
    103108        m_EditorOnly = paramNode.GetChild("EditorOnly").IsOk();
    104109
     110        // Certain special units always have their selection overlay shown.
     111        m_AlphaMin = paramNode.GetChild("Overlay").GetChild("AlwaysVisible").IsOk() ? .5 : 0.;
     112
    105113        const CParamNode& textureNode = paramNode.GetChild("Overlay").GetChild("Texture");
    106114        const CParamNode& outlineNode = paramNode.GetChild("Overlay").GetChild("Outline");
    107115
    public:  
    142150
    143151    virtual void HandleMessage(const CMessage& msg, bool UNUSED(global));
    144152
    145     virtual void SetSelectionHighlight(CColor color)
     153    virtual void SetSelectionHighlight(CColor color, bool selected)
    146154    {
    147155        m_Color.r = color.r;
    148156        m_Color.g = color.g;
    149157        m_Color.b = color.b;
     158
     159        // Always-visible overlays will be desaturated if their parent unit is deselected.
     160        if (m_AlphaMin > 0. && !selected)
     161        {
     162            float max;
     163
     164            // Reduce saturation by one-third, the quick-and-dirty way.
     165            if (m_Color.r > m_Color.b)
     166               max = (m_Color.r > m_Color.g) ? m_Color.r : m_Color.g;
     167            else
     168               max = (m_Color.b > m_Color.g) ? m_Color.b : m_Color.g;
     169
     170            m_Color.r += (max - m_Color.r) / 3.;
     171            m_Color.g += (max - m_Color.g) / 3.;
     172            m_Color.b += (max - m_Color.b) / 3.;
     173        }
     174
    150175        SetSelectionHighlightAlpha(color.a);
    151176    }
    152177
    153178    virtual void SetSelectionHighlightAlpha(float alpha)
    154179    {
     180        alpha = std::max(m_AlphaMin, alpha);
     181
    155182        // set up fading from the current value (as the baseline) to the target value
    156183        m_FadeBaselineAlpha = m_Color.a;
    157184        m_FadeDeltaAlpha = alpha - m_FadeBaselineAlpha;
    private:  
    193220   
    194221    /// Current selection overlay color. Alpha component is subject to fading.
    195222    CColor m_Color;
     223    /// Minimum value for current selection overlay alpha.
     224    float m_AlphaMin;
    196225    /// Baseline alpha value to start fading from. Constant during a single fade.
    197226    float m_FadeBaselineAlpha;
    198227    /// Delta between target and baseline alpha. Constant during a single fade. Can be positive or negative.
    void CCmpSelectable::HandleMessage(const CMessage& msg, bool UNUSED(global))  
    269298            // Update the highlight color, while keeping the current alpha target value intact
    270299            // (i.e. baseline + delta), so that any ongoing fades simply continue with the new color.
    271300            CColor color = cmpPlayer->GetColour();
    272             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), true);
    273302        }
    274303        // fall-through
    275304    case MT_PositionChanged:
  • source/simulation2/components/CCmpTemplateManager.cpp

    diff --git a/source/simulation2/components/CCmpTemplateManager.cpp b/source/simulation2/components/CCmpTemplateManager.cpp
    index d69cc36..72e6727 100644
    a b void CCmpTemplateManager::ConstructTemplateActor(const std::string& actorName, C  
    382382                          "<VisualActor><Actor>" + name + "</Actor></VisualActor>"
    383383                          "<Selectable>"
    384384                              "<EditorOnly/>"
    385                               "<Overlay><Texture><MainTexture>actor.png</MainTexture><MainTextureMask>actor_mask.png</MainTextureMask></Texture></Overlay>"
     385                                 "<Overlay><AlwaysVisible/><Texture><MainTexture>actor.png</MainTexture><MainTextureMask>actor_mask.png</MainTextureMask></Texture></Overlay>"
    386386                          "</Selectable>"
    387387                      "</Entity>";
    388388
  • source/simulation2/components/ICmpSelectable.cpp

    diff --git a/source/simulation2/components/ICmpSelectable.cpp b/source/simulation2/components/ICmpSelectable.cpp
    index 07c4b51..acc3cc0 100644
    a b  
    2424#include "ps/Overlay.h"
    2525
    2626BEGIN_INTERFACE_WRAPPER(Selectable)
    27 DEFINE_INTERFACE_METHOD_1("SetSelectionHighlight", void, ICmpSelectable, SetSelectionHighlight, CColor)
     27DEFINE_INTERFACE_METHOD_2("SetSelectionHighlight", void, ICmpSelectable, SetSelectionHighlight, CColor, bool)
    2828END_INTERFACE_WRAPPER(Selectable)
    2929
    3030bool ICmpSelectable::ms_EnableDebugOverlays = false;
  • source/simulation2/components/ICmpSelectable.h

    diff --git a/source/simulation2/components/ICmpSelectable.h b/source/simulation2/components/ICmpSelectable.h
    index 6ce4019..9382e00 100644
    a b public:  
    5656     * Set the color of the selection highlight (typically a circle/square
    5757     * around the unit). Set a = 0 to disable the highlight.
    5858     */
    59     virtual void SetSelectionHighlight(CColor color) = 0;
     59    virtual void SetSelectionHighlight(CColor color, bool selected) = 0;
    6060
    6161    /**
    6262     * Set the alpha of the selection highlight. Set to 0 to disable the highlight.
  • source/simulation2/tests/test_CmpTemplateManager.h

    diff --git a/source/simulation2/tests/test_CmpTemplateManager.h b/source/simulation2/tests/test_CmpTemplateManager.h
    index 0c3a0e5..0af29ed 100644
    a b public:  
    7878        const CParamNode* actor = tempMan->LoadTemplate(ent2, "actor|example1", -1);
    7979        TS_ASSERT(actor != NULL);
    8080        TS_ASSERT_WSTR_EQUALS(actor->ToXML(),
    81                 L"<Selectable><EditorOnly></EditorOnly><Overlay><Texture><MainTexture>actor.png</MainTexture><MainTextureMask>actor_mask.png</MainTextureMask></Texture></Overlay></Selectable>"
     81                L"<Selectable><EditorOnly></EditorOnly><Overlay><AlwaysVisible></AlwaysVisible><Texture><MainTexture>actor.png</MainTexture><MainTextureMask>actor_mask.png</MainTextureMask></Texture></Overlay></Selectable>"
    8282                L"<VisualActor><Actor>example1</Actor><SilhouetteDisplay>false</SilhouetteDisplay><SilhouetteOccluder>false</SilhouetteOccluder></VisualActor>");
    8383
    8484        const CParamNode* preview = tempMan->LoadTemplate(ent2, "preview|unit", -1);
  • source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp

    diff --git a/source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp b/source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp
    index 46cf352..03b1790 100644
    a b MESSAGEHANDLER(SetSelectionPreview)  
    148148            }
    149149        }
    150150
    151         cmpSelectable->SetSelectionHighlight(colour);
     151        cmpSelectable->SetSelectionHighlight(colour, true);
    152152    }
    153153}
    154154