Ticket #57: POC.diff

File POC.diff, 6.5 KB (added by wraitii, 7 years ago)

proof of concept

  • binaries/data/mods/public/gui/session/minimap_panel.xml

    diff --git a/binaries/data/mods/public/gui/session/minimap_panel.xml b/binaries/data/mods/public/gui/session/minimap_panel.xml
    index ae8d207..f0639f9 100644
    a b  
    1919            <action on="MouseLeftRelease">if (g_HasIdleWorker) Engine.GetGUIObjectByName("idleOverlay").sprite = "stretched:session/minimap-idle-highlight.png";</action>
    2020        </object>
    2121    </object>
     22
     23    <!-- select option -->
     24    <object size="5 5 80 80">
     25        <object type="button"
     26            name="selectButton"
     27            tooltip_style="sessionToolTip"
     28        >
     29            <action on="Press">Engine.GetGUIObjectByName("minimapDetailsPanel").hidden = !Engine.GetGUIObjectByName("minimapDetailsPanel").hidden</action>
     30        </object>
     31    </object>
     32
    2233    <!-- Minimap -->
    2334    <object name="minimap"
    2435        type="minimap" z="20"
     
    2940    <!-- Overlays -->
    3041    <object name="minimapOverlay" size="4 4 100%-4 100%-4" type="image" sprite="stretched:session/minimap_circle_modern.png" ghost="true"/>
    3142    <object name="idleOverlay" z="100" size="100%-125 100%-125 100%-5 100%-5" type="image" sprite="stretched:session/minimap-idle.png" ghost="true"/>
     43
     44<object
     45    name="minimapDetailsPanel"
     46    size="0 100%-400 212 100%-212"
     47    type="image"
     48    sprite="supplementalDetailsPanel"
     49    hidden="true"
     50>
     51    <object name="minimapLayerResourcesCheckbox" size="0 0 100% 20" type="checkbox" style="ModernTickBox" checked="true">
     52        <action on="Press">Engine.GetGUIObjectByName("minimap").show_resources = !Engine.GetGUIObjectByName("minimap").show_resources;</action>
     53    </object>
     54    <object name="minimapLayerResourcesLabel" size="20 0 100%-20 20" type="text" style="ModernLabelText" text_align="left">
     55            <translatableAttribute id="caption">Resources</translatableAttribute>
     56    </object>
     57    <object name="minimapLayerResourcesSoloButton" size="100%-20 0 100% 20" type="image" sprite="iconInfoWhite"/><!-- TODO: add a magnifying glass sprite or something -->
     58
     59    <object name="minimapLayerUnitsCheckbox" size="0 24 100% 44" type="checkbox" style="ModernTickBox" checked="true">
     60        <action on="Press">Engine.GetGUIObjectByName("minimap").show_units = !Engine.GetGUIObjectByName("minimap").show_units;</action>
     61    </object>
     62    <object name="minimapLayerUnitsLabel" size="20 24 100%-20 44" type="text" style="ModernLabelText" text_align="left">
     63            <translatableAttribute id="caption">Units</translatableAttribute>
     64    </object>
     65    <object name="minimapLayerUnitsSoloButton" size="100%-20 24 100% 44" type="image" sprite="iconInfoWhite"/><!-- TODO: add a magnifying glass sprite or something -->
     66</object>
     67
    3268</object>
  • source/gui/MiniMap.cpp

    diff --git a/source/gui/MiniMap.cpp b/source/gui/MiniMap.cpp
    index d15f150..c71fbc0 100644
    a b CMiniMap::CMiniMap() :  
    7070    AddSetting(GUIST_CColor,    "fov_wedge_color");
    7171    AddSetting(GUIST_CStrW,     "tooltip");
    7272    AddSetting(GUIST_CStr,      "tooltip_style");
     73
     74    AddSetting(GUIST_bool,      "show_resources");
     75    AddSetting(GUIST_bool,      "show_units");
     76
     77    GUI<bool>::SetSetting(this, "show_resources", true);
     78    GUI<bool>::SetSetting(this, "show_units", true);
     79
     80    GUI<bool>::GetSetting(this, "show_units", m_ShowUnits);
     81    GUI<bool>::GetSetting(this, "show_resources", m_ShowResources);
    7382    m_Clicking = false;
    7483    m_MouseHovering = false;
    7584
    void CMiniMap::HandleMessage(SGUIMessage& Message)  
    143152{
    144153    switch (Message.type)
    145154    {
     155    case GUIM_SETTINGS_UPDATED:
     156        GUI<bool>::GetSetting(this, "show_units", m_ShowUnits);
     157        GUI<bool>::GetSetting(this, "show_resources", m_ShowResources);
     158        break;
    146159    case GUIM_MOUSE_PRESS_LEFT:
    147160        if (m_MouseHovering)
    148161        {
    void CMiniMap::Draw()  
    529542        for (CSimulation2::InterfaceList::const_iterator it = ents.begin(); it != ents.end(); ++it)
    530543        {
    531544            ICmpMinimap* cmpMinimap = static_cast<ICmpMinimap*>(it->second);
     545            if (!cmpMinimap->ShouldRender(m_ShowResources, m_ShowUnits))
     546                continue;
    532547            if (cmpMinimap->GetRenderData(v.r, v.g, v.b, posX, posZ))
    533548            {
    534549                ICmpRangeManager::ELosVisibility vis = cmpRangeManager->GetLosVisibility(it->first, g_Game->GetSimulation2()->GetSimContext().GetCurrentDisplayedPlayer());
  • source/gui/MiniMap.h

    diff --git a/source/gui/MiniMap.h b/source/gui/MiniMap.h
    index 17f76c5..804b839 100644
    a b protected:  
    107107    double m_HalfBlinkDuration;
    108108    double m_NextBlinkTime;
    109109    bool m_BlinkState;
     110
     111    // activate/deactivate layers
     112    bool m_ShowResources;
     113    bool m_ShowUnits;
    110114};
    111115
    112116#endif // INCLUDED_MINIMAP
  • source/simulation2/components/CCmpMinimap.cpp

    diff --git a/source/simulation2/components/CCmpMinimap.cpp b/source/simulation2/components/CCmpMinimap.cpp
    index 045573d..a1cc126 100644
    a b public:  
    4545
    4646    u8 m_R, m_G, m_B; // static template state if m_UsePlayerColor false; dynamic state if true
    4747
     48    enum Type: u8
     49    {
     50        FOOD,
     51        WOOD,
     52        STONE,
     53        METAL,
     54        STRUCTURE,
     55        SETTLEMENT,
     56        UNIT,
     57        SUPPORT,
     58        HERO
     59    };
     60
    4861    // Dynamic state:
    4962
    5063    bool m_Active;
    5164    entity_pos_t m_X, m_Z; // cache the latest position for more efficient rendering; only valid when m_Active true
    5265
     66    Type m_Type;
     67
    5368    // Not serialized (based on renderer timing):
    5469    // TODO: eventually ping state should be serialized and tied into simulation time, but currently lag causes too many problems
    5570    double m_PingEndTime;
    public:  
    108123            m_G = 0;
    109124            m_B = 255;
    110125        }
     126        CStr type = paramNode.GetChild("Type").ToUTF8();
     127        if (type == "food" || type == "wood" || type == "stone" || type=="metal")
     128            m_Type = Type::FOOD;
     129        else
     130            m_Type = Type::HERO;
     131        std::cout << m_Type << std::endl;
    111132    }
    112133
    113134    virtual void Deinit()
    public:  
    220241        return true;
    221242    }
    222243
     244    virtual bool ShouldRender(bool showResources, bool showUnits)
     245    {
     246        if (m_Type == Type::FOOD && !showResources)
     247            return false;
     248        else if (m_Type != Type::FOOD && !showUnits)
     249            return false;
     250        return true;
     251    }
     252
    223253    virtual bool CheckPing(double currentTime, double pingDuration)
    224254    {
    225255        if (!m_Active || !m_IsPinging)
  • source/simulation2/components/ICmpMinimap.h

    diff --git a/source/simulation2/components/ICmpMinimap.h b/source/simulation2/components/ICmpMinimap.h
    index 2cfeab3..9b38936 100644
    a b public:  
    3535     */
    3636    virtual bool GetRenderData(u8& r, u8& g, u8& b, entity_pos_t& x, entity_pos_t& z) = 0;
    3737
     38    virtual bool ShouldRender(bool showResources, bool showUnits) = 0;
     39
    3840    /**
    3941     * Return true if entity is actively pinging based on the current time
    4042     */