Ticket #3915: visualrange_v0.1.patch

File visualrange_v0.1.patch, 4.5 KB (added by Sandarac, 8 years ago)

WIP patch that shows the maximum range of defensive structures when hovered or selected. Based on the code used to display the debug range overlay.

  • binaries/data/mods/public/simulation/components/GuiInterface.js

     
    845845GuiInterface.prototype.SetSelectionHighlight = function(player, cmd)
    846846{
    847847    let playerColors = {}; // cache of owner -> color map
     848    let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
    848849
    849850    for each (let ent in cmd.entities)
    850851    {
     
    868869            playerColors[owner] = color;
    869870        }
    870871
     872        let cmpIdentity = Engine.QueryInterface(ent, IID_Identity);
     873
     874        if (cmpIdentity.HasClass("Defensive") && owner == player)
     875            cmpRangeManager.ShowRangeOverlay(ent, cmd.selected);
     876
    871877        cmpSelectable.SetSelectionHighlight({ "r": color.r, "g": color.g, "b": color.b, "a": cmd.alpha }, cmd.selected);
    872878    }
    873879};
  • source/simulation2/components/CCmpRangeManager.cpp

     
    304304    bool m_DebugOverlayDirty;
    305305    std::vector<SOverlayLine> m_DebugOverlayLines;
    306306
     307    bool m_ShowRangeOverlayEnabled;
     308    std::vector<SOverlayLine> m_RangeOverlayLines;
     309
    307310    // Deserialization flag. A lot of different functions are called by Deserialize()
    308311    // and we don't want to pass isDeserializing bool arguments to all of them...
    309312    bool m_Deserializing;
     
    12851288
    12861289    void RenderSubmit(SceneCollector& collector)
    12871290    {
     1291        if (m_ShowRangeOverlayEnabled)
     1292            for (size_t i = 0; i < m_RangeOverlayLines.size(); ++i)
     1293                collector.Submit(&m_RangeOverlayLines[i]);
     1294
    12881295        if (!m_DebugOverlayEnabled)
    12891296            return;
    12901297        static CColor disabledRingColor(1, 0, 0, 1);    // red
     
    14211428            collector.Submit(&m_DebugOverlayLines[i]);
    14221429    }
    14231430
     1431    virtual void ShowRangeOverlay(entity_id_t ent, bool enabled)
     1432    {
     1433        m_ShowRangeOverlayEnabled = enabled;
     1434        static CColor rangeRingColor(1, 1, 1, 1); // TODO: should be player color
     1435
     1436        m_RangeOverlayLines.clear();
     1437        if (enabled)
     1438        {
     1439            for (std::map<tag_t, Query>::iterator it = m_Queries.begin(); it != m_Queries.end(); ++it)
     1440            {
     1441                Query& q = it->second;
     1442
     1443                CmpPtr<ICmpPosition> cmpSourcePosition(q.source);
     1444                if (!cmpSourcePosition || !cmpSourcePosition->IsInWorld() || q.source.GetId() != ent)
     1445                    continue;
     1446
     1447                CFixedVector2D pos = cmpSourcePosition->GetPosition2D();
     1448
     1449                m_RangeOverlayLines.push_back(SOverlayLine());
     1450                m_RangeOverlayLines.back().m_Color = rangeRingColor;
     1451                SimRender::ConstructCircleOnGround(GetSimContext(), pos.X.ToFloat(), pos.Y.ToFloat(), q.maxRange.ToFloat(), m_RangeOverlayLines.back(), true);
     1452            }
     1453        }
     1454    }
     1455
    14241456    virtual u8 GetEntityFlagMask(const std::string& identifier)
    14251457    {
    14261458        if (identifier == "normal")
  • source/simulation2/components/ICmpRangeManager.cpp

     
    4848DEFINE_INTERFACE_METHOD_1("GetEntitiesByPlayer", std::vector<entity_id_t>, ICmpRangeManager, GetEntitiesByPlayer, player_id_t)
    4949DEFINE_INTERFACE_METHOD_0("GetNonGaiaEntities", std::vector<entity_id_t>, ICmpRangeManager, GetNonGaiaEntities)
    5050DEFINE_INTERFACE_METHOD_1("SetDebugOverlay", void, ICmpRangeManager, SetDebugOverlay, bool)
     51DEFINE_INTERFACE_METHOD_2("ShowRangeOverlay", void, ICmpRangeManager, ShowRangeOverlay, entity_id_t, bool)
    5152DEFINE_INTERFACE_METHOD_1("ExploreAllTiles", void, ICmpRangeManager, ExploreAllTiles, player_id_t)
    5253DEFINE_INTERFACE_METHOD_0("ExploreTerritories", void, ICmpRangeManager, ExploreTerritories)
    5354DEFINE_INTERFACE_METHOD_2("SetLosRevealAll", void, ICmpRangeManager, SetLosRevealAll, player_id_t, bool)
  • source/simulation2/components/ICmpRangeManager.h

     
    204204    virtual void SetDebugOverlay(bool enabled) = 0;
    205205
    206206    /**
     207    * Display the range of a building/unit.
     208    */
     209    virtual void ShowRangeOverlay(entity_id_t ent, bool enabled) = 0;
     210
     211    /**
    207212     * Returns the mask for the specified identifier.
    208213     */
    209214    virtual u8 GetEntityFlagMask(const std::string& identifier) = 0;