Ticket #3699: 3699_tooltip.2.patch

File 3699_tooltip.2.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 map with predefined landscape."),
    189190            "Default": true
    190191        },
    191192        {
    192193            "Name": "random",
    193             "Title": translateWithContext("map", "Random")
     194            "Title": translateWithContext("map", "Random"),
     195            "Description": translate("A randomly generated map.")
    194196        },
    195197        {
    196198            "Name": "scenario",
    197             "Title": translateWithContext("map", "Scenario")
     199            "Title": translateWithContext("map", "Scenario"),
     200            "Description": translate("A map with predefined landscape, civilizations and players.")
    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        mapTypes.tooltip = g_MapTypes.Description[this.hovered_item] ||
     327            translate("Select a map type.");
     328    }
    325329    if (g_IsController)
    326330        mapTypes.selected = g_MapTypes.Default;
    327331}
     
    459463
    460464        updateGameAttributes();
    461465    };
     466    victoryConditions.onHoverChange = function() {
     467        victoryConditions.tooltip = g_VictoryConditions.Description[this.hovered_item] ||
     468            translate("Select victory condition.");
     469    };
    462470    victoryConditions.selected = g_VictoryConditions.Default;
    463471}
    464472
  • 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
    54     GUI<bool>::SetSetting(this, "scrollbar", false);
     55    GUI<bool>::SetSetting(this,             "scrollbar", false);
     56    GUI<int>::SetSetting(this,              "selected", -1);
     57    GUI<int>::SetSetting(this,              "hovered_item", -1);
    5558
    56     // Nothing is selected as default.
    57     GUI<int>::SetSetting(this, "selected", -1);
    58 
    5959    // Add scroll-bar
    6060    CGUIScrollBarVertical* bar = new CGUIScrollBarVertical();
    6161    bar->SetRightAligned(true);
     
    228228        break;
    229229    }
    230230
     231    case GUIM_MOUSE_LEAVE:
     232    {
     233        GUI<int>::SetSetting(this, "hovered_item", -1);
     234        ScriptEvent("hoverchange");
     235        break;
     236    }
     237
     238    case GUIM_MOUSE_OVER:
     239    {
     240        bool scrollbar;
     241        CGUIList* pList;
     242        GUI<bool>::GetSetting(this, "scrollbar", scrollbar);
     243        GUI<CGUIList>::GetSettingPointer(this, "list", pList);
     244        float scroll = 0.f;
     245        if (scrollbar)
     246            scroll = GetScrollBar(0).GetPos();
     247
     248        CRect rect = GetListRect();
     249        CPos mouse = GetMousePos();
     250        mouse.y += scroll;
     251        int set = -1;
     252        for (int i = 0; i < (int)pList->m_Items.size(); ++i)
     253        {
     254            if (mouse.y >= rect.top + m_ItemsYPositions[i] &&
     255                mouse.y < rect.top + m_ItemsYPositions[i + 1] &&
     256                // mouse is not over scroll-bar
     257                (!scrollbar || !GetScrollBar(0).IsVisible() ||
     258                mouse.x < GetScrollBar(0).GetOuterRect().left ||
     259                mouse.x > GetScrollBar(0).GetOuterRect().right))
     260            {
     261                set = i;
     262            }
     263        }
     264
     265        GUI<int>::SetSetting(this, "hovered_item", set);
     266        ScriptEvent("hoverchange");
     267        break;
     268    }
     269
    231270    case GUIM_LOAD:
    232271    {
    233272        CStr scrollbar_style;