Ticket #3699: 3699_tooltip.patch

File 3699_tooltip.patch, 3.7 KB (added by Vladislav Belov, 7 years ago)

Adds the victory condition and the map type tooltips

  • binaries/data/mods/public/gui/common/settings.js

     
    186186        {
    187187            "Name": "skirmish",
    188188            "Title": translateWithContext("map", "Skirmish"),
     189            "Description": translate("A battle map."),
    189190            "Default": true
    190191        },
    191192        {
    192193            "Name": "random",
    193             "Title": translateWithContext("map", "Random")
     194            "Title": translateWithContext("map", "Random"),
     195            "Description": translate("A random generated map.")
    194196        },
    195197        {
    196198            "Name": "scenario",
    197             "Title": translateWithContext("map", "Scenario")
     199            "Title": translateWithContext("map", "Scenario"),
     200            "Description": translate("A map with scenario.")
    198201        }
    199202    ];
    200203}
  • binaries/data/mods/public/gui/gamesetup/gamesetup.js

     
    322322        if (this.selected != -1)
    323323            selectMapType(this.list_data[this.selected]);
    324324    };
     325    mapTypes.onHoverChange = function() {
     326        if (this.hovered_item != -1)
     327            mapTypes.tooltip = g_MapTypes.Description[this.hovered_item];
     328        else
     329            mapTypes.tooltip = translate("Select a map type.");
     330    }
    325331    if (g_IsController)
    326332        mapTypes.selected = g_MapTypes.Default;
    327333}
     
    459465
    460466        updateGameAttributes();
    461467    };
     468    victoryConditions.onHoverChange = function() {
     469        if (this.hovered_item != -1)
     470            victoryConditions.tooltip = g_VictoryConditions.Description[this.hovered_item];
     471        else
     472            victoryConditions.tooltip = translate("Select victory condition.");
     473    };
    462474    victoryConditions.selected = g_VictoryConditions.Default;
    463475}
    464476
  • source/gui/CList.cpp

     
    5050    // Each list item has both a name (in 'list') and an associated data string (in 'list_data')
    5151    AddSetting(GUIST_CGUIList,              "list");
    5252    AddSetting(GUIST_CGUIList,              "list_data"); // TODO: this should be a list of raw strings, not of CGUIStrings
     53    AddSetting(GUIST_int,                   "hovered_item");
    5354
    5455    GUI<bool>::SetSetting(this, "scrollbar", false);
    5556
     
    5657    // Nothing is selected as default.
    5758    GUI<int>::SetSetting(this, "selected", -1);
    5859
     60    // Nothing is covered as default
     61    GUI<int>::SetSetting(this, "hovered_item", -1);
     62
    5963    // Add scroll-bar
    6064    CGUIScrollBarVertical* bar = new CGUIScrollBarVertical();
    6165    bar->SetRightAligned(true);
     
    228232        break;
    229233    }
    230234
     235    case GUIM_MOUSE_LEAVE:
     236    {
     237        GUI<int>::SetSetting(this, "hovered_item", -1);
     238        ScriptEvent("hoverchange");
     239        break;
     240    }
     241
     242    case GUIM_MOUSE_OVER:
     243    {
     244        bool scrollbar;
     245        CGUIList* pList;
     246        GUI<bool>::GetSetting(this, "scrollbar", scrollbar);
     247        GUI<CGUIList>::GetSettingPointer(this, "list", pList);
     248        float scroll = 0.f;
     249        if (scrollbar)
     250            scroll = GetScrollBar(0).GetPos();
     251
     252        CRect rect = GetListRect();
     253        CPos mouse = GetMousePos();
     254        mouse.y += scroll;
     255        int set = -1;
     256        for (int i = 0; i < (int)pList->m_Items.size(); ++i)
     257        {
     258            if (mouse.y >= rect.top + m_ItemsYPositions[i] &&
     259                mouse.y < rect.top + m_ItemsYPositions[i + 1] &&
     260                // mouse is not over scroll-bar
     261                (!scrollbar || !GetScrollBar(0).IsVisible() ||
     262                mouse.x < GetScrollBar(0).GetOuterRect().left ||
     263                mouse.x > GetScrollBar(0).GetOuterRect().right))
     264            {
     265                set = i;
     266            }
     267        }
     268
     269        GUI<int>::SetSetting(this, "hovered_item", set);
     270        ScriptEvent("hoverchange");
     271        break;
     272    }
     273
    231274    case GUIM_LOAD:
    232275    {
    233276        CStr scrollbar_style;