Ticket #3905: 3905_COList_refresh_v4.patch

File 3905_COList_refresh_v4.patch, 29.5 KB (added by Imarok, 8 years ago)

Made all changes proposed in comment:7 besides the GetScrollBar(0) thing. COList don't requires a column "name" anymore. Some cleanup.

  • binaries/data/mods/mod/gui/common/modern/styles.xml

     
    3939    <style name = "ModernList"
    4040        buffer_zone = "5"
    4141        font = "sans-bold-stroke-14"
     42        heading_height="25"
    4243        scrollbar = "true"
    4344        scrollbar_style = "ModernScrollBar"
    4445        sprite = "ModernDarkBoxGoldNoTop"
  • binaries/data/mods/mod/gui/gui.rnc

     
    5252  attribute button_width { xsd:decimal }?&
    5353  attribute checked { bool }?&
    5454  attribute clip { bool }?&
    55   attribute default_column { text }?&
    56   attribute default_column_order { text }?&
    5755  attribute dropdown_size { xsd:decimal }?&
    5856  attribute dropdown_buffer { xsd:decimal }?&
    5957  attribute enabled { bool }?&
    6058  attribute font { text }?&
    6159  attribute fov_wedge_color { ccolor }?&
     60  attribute heading_height { text }?&
    6261  attribute hotkey { text }?&
    6362  attribute cell_id { xsd:integer }?&
    6463  attribute independent { bool }?&
     
    7271  attribute scrollbar { bool }?&
    7372  attribute scrollbar_style { text }?&
    7473  attribute scroll_bottom { bool }?&
     74  attribute selected_column { text }?&
     75  attribute selected_column_order { text }?&
    7576  attribute sortable { bool }?&
    7677  attribute sound_closed { text }?&
    7778  attribute sound_disabled { text }?&
     
    122123    ((object
    123124      | action
    124125      | \attribute
    125       | def
     126      | column
    126127      | \include
    127128      | item
    128129      | repeat
     
    143144    (keep | translate)*,
    144145    attribute id { text }
    145146  }
    146 def =
    147   element def {
     147column =
     148  element column {
    148149    translatableAttribute?,
    149150    (
    150151    attribute id { text }&
  • binaries/data/mods/mod/gui/gui.rng

     
    200200        </attribute>
    201201      </optional>
    202202      <optional>
    203         <attribute name="default_column"/>
    204       </optional>
    205       <optional>
    206         <attribute name="default_column_order"/>
    207       </optional>
    208       <optional>
    209203        <attribute name="dropdown_size">
    210204          <data type="decimal"/>
    211205        </attribute>
     
    229223        </attribute>
    230224      </optional>
    231225      <optional>
     226        <attribute name="heading_height"/>
     227      </optional>
     228      <optional>
    232229        <attribute name="hotkey"/>
    233230      </optional>
    234231      <optional>
     
    293290        </attribute>
    294291      </optional>
    295292      <optional>
     293        <attribute name="selected_column"/>
     294      </optional>
     295      <optional>
     296        <attribute name="selected_column_order"/>
     297      </optional>
     298      <optional>
    296299        <attribute name="sortable"/>
    297300      </optional>
    298301      <optional>
     
    446449            <ref name="object"/>
    447450            <ref name="action"/>
    448451            <ref name="attribute"/>
    449             <ref name="def"/>
     452            <ref name="column"/>
    450453            <ref name="include"/>
    451454            <ref name="item"/>
    452455            <ref name="repeat"/>
     
    480483      <attribute name="id"/>
    481484    </element>
    482485  </define>
    483   <define name="def">
    484     <element name="def">
     486  <define name="column">
     487    <element name="column">
    485488      <optional>
    486489        <ref name="translatableAttribute"/>
    487490      </optional>
  • binaries/data/mods/mod/gui/modmod/modmod.xml

     
    8686                <translatableAttribute id="caption">Available Mods</translatableAttribute>
    8787            </object>
    8888
    89             <object name="modsAvailableList" style="ModernList" type="olist" size="0 25 100%-2 100%" font="sans-stroke-13">
     89            <object name="modsAvailableList"
     90                style="ModernList"
     91                type="olist"
     92                size="0 25 100%-2 100%"
     93                font="sans-stroke-13"
     94            >
    9095                <action on="SelectionChange">showModDescription(this.name);</action>
    9196                <!-- List headers -->
    92                 <def id="name" color="100 100 200" width="10%">
     97                <column id="name" color="100 100 200" width="10%">
    9398                    <translatableAttribute id="heading">Name</translatableAttribute>
    94                 </def>
    95                 <def id="modVersion" color="128 128 128" width="7%">
     99                </column>
     100                <column id="modVersion" color="128 128 128" width="7%">
    96101                    <translatableAttribute id="heading">Version</translatableAttribute>
    97                 </def>
    98                 <def id="modFolderName" color="100 100 200" width="13%">
     102                </column>
     103                <column id="modFolderName" color="100 100 200" width="13%">
    99104                    <translatableAttribute id="heading">(Folder)</translatableAttribute>
    100                 </def>
    101                 <def id="modLabel" color="0 60 0" width="18%">
     105                </column>
     106                <column id="modLabel" color="0 60 0" width="18%">
    102107                    <translatableAttribute id="heading">Mod Label</translatableAttribute>
    103                 </def>
    104                 <def id="modType" color="0 128 128" width="12%">
     108                </column>
     109                <column id="modType" color="0 128 128" width="12%">
    105110                    <translatableAttribute id="heading">Mod Type</translatableAttribute>
    106                 </def>
    107                 <def id="modDependencies" color="128 128 128" width="20%">
     111                </column>
     112                <column id="modDependencies" color="128 128 128" width="20%">
    108113                    <translatableAttribute id="heading">Dependencies</translatableAttribute>
    109                 </def>
    110                 <def id="modURL" color="128 128 128" width="24%">
     114                </column>
     115                <column id="modURL" color="128 128 128" width="24%">
    111116                    <translatableAttribute id="heading">Website</translatableAttribute>
    112                 </def>
     117                </column>
    113118            </object>
    114119            <object name="globalModDescription" type="text" style="ModmodScrollbar" size="0 100%-28 100%-16 100%">
    115120                <attribute id="caption"><keep>[color="100 100 100"]</keep><translate>Description</translate><keep>[/color]</keep></attribute>
     
    127132                <translatableAttribute id="caption">Enabled Mods</translatableAttribute>
    128133            </object>
    129134
    130             <object name="modsEnabledList" style="ModernList" type="olist" size="0 25 96%-5 100%" font="sans-stroke-13" tooltip_style="pgToolTip">
     135            <object name="modsEnabledList"
     136                style="ModernList"
     137                type="olist"
     138                size="0 25 96%-5 100%"
     139                font="sans-stroke-13"
     140                tooltip_style="pgToolTip"
     141            >
    131142                <action on="SelectionChange">showModDescription(this.name);</action>
    132143                <!-- List headers -->
    133                 <def id="name" color="100 100 200" width="10%">
     144                <column id="name" color="100 100 200" width="10%">
    134145                    <translatableAttribute id="heading">Name</translatableAttribute>
    135                 </def>
    136                 <def id="modVersion" color="128 128 128" width="7%">
     146                </column>
     147                <column id="modVersion" color="128 128 128" width="7%">
    137148                    <translatableAttribute id="heading">Version</translatableAttribute>
    138                 </def>
    139                 <def id="modFolderName" color="100 100 200" width="13%">
     149                </column>
     150                <column id="modFolderName" color="100 100 200" width="13%">
    140151                    <translatableAttribute id="heading">(Folder)</translatableAttribute>
    141                 </def>
    142                 <def id="modLabel" color="0 60 0" width="18%">
     152                </column>
     153                <column id="modLabel" color="0 60 0" width="18%">
    143154                    <translatableAttribute id="heading">Mod Label</translatableAttribute>
    144                 </def>
    145                 <def id="modType" color="0 128 128" width="12%">
     155                </column>
     156                <column id="modType" color="0 128 128" width="12%">
    146157                    <translatableAttribute id="heading">Mod Type</translatableAttribute>
    147                 </def>
    148                 <def id="modDependencies" color="128 128 128" width="20%">
     158                </column>
     159                <column id="modDependencies" color="128 128 128" width="20%">
    149160                    <translatableAttribute id="heading">Dependencies</translatableAttribute>
    150                 </def>
    151                 <def id="modURL" color="128 128 128" width="20%">
     161                </column>
     162                <column id="modURL" color="128 128 128" width="20%">
    152163                    <translatableAttribute id="heading">Website</translatableAttribute>
    153                 </def>
     164                </column>
    154165            </object>
    155166
    156167            <object type="button" style="ModernButtonRed" size="96% 23 100% 40%+12">
  • binaries/data/mods/public/gui/lobby/lobby.xml

     
    2323
    2424        <!-- Left panel: Player list. -->
    2525        <object name="leftPanel" size="20 30 20% 100%-280">
    26             <object name="playersBox" style="ModernList" sprite_asc="ModernArrowDown" default_column="name" default_column_order="1" sprite_desc="ModernArrowUp" sprite_not_sorted="ModernNotSorted" type="olist" sortable="true" size="0 0 100% 100%" font="sans-bold-stroke-13">
    27                 <def id="status" width="26%">
     26            <object name="playersBox"
     27                style="ModernList"
     28                sprite_asc="ModernArrowDown"
     29                default_column="name"
     30                default_column_order="1"
     31                sprite_desc="ModernArrowUp"
     32                sprite_not_sorted="ModernNotSorted"
     33                type="olist"
     34                sortable="true"
     35                size="0 0 100% 100%"
     36                font="sans-bold-stroke-13"
     37            >
     38                <column id="status" width="26%">
    2839                    <translatableAttribute id="heading">Status</translatableAttribute>
    29                 </def>
    30                 <def id="name" width="48%">
     40                </column>
     41                <column id="name" width="48%">
    3142                    <translatableAttribute id="heading">Name</translatableAttribute>
    32                 </def>
    33                 <def id="rating" width="26%">
     43                </column>
     44                <column id="rating" width="26%">
    3445                    <translatableAttribute id="heading">Rating</translatableAttribute>
    35                 </def>
     46                </column>
    3647                <action on="SelectionChange">
    3748                    displayProfile("lobbylist");
    3849                </action>
     
    172183
    173184        <!-- Middle panel: Filters, game list, chat box. -->
    174185        <object name="middlePanel" size="20%+5 5% 100%-255 97.2%">
    175             <object name="gamesBox" style="ModernList" sprite_asc="ModernArrowDown" default_column="status" default_column_order="1" sprite_desc="ModernArrowUp" sprite_not_sorted="ModernNotSorted" type="olist" sortable="true" size="0 25 100% 48%" font="sans-stroke-13">
     186            <object name="gamesBox"
     187                style="ModernList"
     188                sprite_asc="ModernArrowDown"
     189                default_column="status"
     190                default_column_order="1"
     191                sprite_desc="ModernArrowUp"
     192                sprite_not_sorted="ModernNotSorted"
     193                type="olist"
     194                sortable="true"
     195                size="0 25 100% 48%"
     196                font="sans-stroke-13"
     197            >
    176198                <action on="SelectionChange">updateGameSelection();</action>
    177199                <action on="SelectionColumnChange">applyFilters();</action>
    178200                <action on="mouseleftdoubleclickitem">joinButton();</action>
    179                 <def id="name" color="0 60 0" width="27%">
     201                <column id="name" color="0 60 0" width="27%">
    180202                    <translatableAttribute id="heading">Name</translatableAttribute>
    181                 </def>
    182                 <!--<def id="ip" heading="IP" color="0 128 128" width="170"/>-->
    183                 <def id="mapName" color="128 128 128" width="25%">
     203                </column>
     204                <!--<column id="ip" heading="IP" color="0 128 128" width="170"/>-->
     205                <column id="mapName" color="128 128 128" width="25%">
    184206                    <translatableAttribute id="heading">Map Name</translatableAttribute>
    185                 </def>
    186                 <def id="mapSize" color="128 128 128" width="16%">
     207                </column>
     208                <column id="mapSize" color="128 128 128" width="16%">
    187209                    <translatableAttribute id="heading" context="map">Size</translatableAttribute>
    188                 </def>
    189                 <def id="mapType" color="0 128 128" width="16%">
     210                </column>
     211                <column id="mapType" color="0 128 128" width="16%">
    190212                    <translatableAttribute id="heading" context="map">Type</translatableAttribute>
    191                 </def>
    192                 <def id="nPlayers" color="0 128 128" width="16%">
     213                </column>
     214                <column id="nPlayers" color="0 128 128" width="16%">
    193215                    <translatableAttribute id="heading">Players</translatableAttribute>
    194                 </def>
     216                </column>
    195217            </object>
    196218
    197219            <object name="filterPanel" size="0 0 100% 24">
     
    254276                style="ModernList"
    255277                type="olist"
    256278                size="19 19 100%-19 100%-62">
    257                 <def id="rank" color="255 255 255" width="15%">
     279                <column id="rank" color="255 255 255" width="15%">
    258280                    <translatableAttribute id="heading">Rank</translatableAttribute>
    259                 </def>
    260                 <def id="name" color="255 255 255" width="55%">
     281                </column>
     282                <column id="name" color="255 255 255" width="55%">
    261283                    <translatableAttribute id="heading">Name</translatableAttribute>
    262                 </def>
    263                 <def id="rating" color="255 255 255" width="30%">
     284                </column>
     285                <column id="rating" color="255 255 255" width="30%">
    264286                    <translatableAttribute id="heading">Rating</translatableAttribute>
    265                 </def>
     287                </column>
    266288                <action on="SelectionChange">
    267289                    displayProfile("leaderboard");
    268290                </action>
  • binaries/data/mods/public/gui/replaymenu/replay_filters.js

     
    188188        let cmpA, cmpB;
    189189        switch (sortKey)
    190190        {
    191         case 'name':
     191        case 'months':
    192192            cmpA = +a.timestamp;
    193193            cmpB = +b.timestamp;
    194194            break;
  • binaries/data/mods/public/gui/replaymenu/replay_menu.js

     
    218218
    219219    // Push to GUI
    220220    replaySelection.selected = -1;
    221     replaySelection.list_name = list.months || [];
     221    replaySelection.list_months = list.months || [];
    222222    replaySelection.list_players = list.playerNames || [];
    223223    replaySelection.list_mapName = list.mapNames || [];
    224224    replaySelection.list_mapSize = list.mapSizes || [];
  • binaries/data/mods/public/gui/replaymenu/replay_menu.xml

     
    6363            </object>
    6464
    6565            <!-- Replay List in that left panel -->
    66             <object name="replaySelection" size="0 35 100% 100%" style="ModernList" type="olist" sortable="true" default_column="name" default_column_order="-1" sprite_asc="ModernArrowDown" sprite_desc="ModernArrowUp" sprite_not_sorted="ModernNotSorted" font="sans-stroke-13">
     66            <object name="replaySelection"
     67                size="0 35 100% 100%"
     68                style="ModernList"
     69                type="olist"
     70                sortable="true"
     71                selected_column="months"
     72                selected_column_order="-1"
     73                sprite_asc="ModernArrowDown"
     74                sprite_desc="ModernArrowUp"
     75                sprite_not_sorted="ModernNotSorted"
     76                font="sans-stroke-13"
     77            >
    6778
    6879                <action on="SelectionChange">displayReplayDetails();</action>
    6980                <action on="SelectionColumnChange">displayReplayList();</action>
     
    7081                <action on="mouseleftdoubleclickitem">startReplay();</action>
    7182
    7283                <!-- Columns -->
    73                 <!-- We have to call one "name" as the GUI expects one. -->
    74                 <def id="name" color="172 172 212" width="12%">
     84                <column id="months" color="172 172 212" width="12%">
    7585                    <translatableAttribute id="heading" context="replay">Date / Time</translatableAttribute>
    76                 </def>
     86                </column>
    7787
    78                 <def id="players" color="192 192 192" width="44%">
     88                <column id="players" color="192 192 192" width="44%">
    7989                    <translatableAttribute id="heading" context="replay">Players</translatableAttribute>
    80                 </def>
     90                </column>
    8191
    82                 <def id="mapName" color="192 192 192" width="14%">
     92                <column id="mapName" color="192 192 192" width="14%">
    8393                    <translatableAttribute id="heading" context="replay">Map Name</translatableAttribute>
    84                 </def>
     94                </column>
    8595
    86                 <def id="mapSize" color="192 192 192" width="10%">
     96                <column id="mapSize" color="192 192 192" width="10%">
    8797                    <translatableAttribute id="heading" context="replay">Size</translatableAttribute>
    88                 </def>
     98                </column>
    8999
    90                 <def id="popCapacity" color="192 192 192" width="10%">
     100                <column id="popCapacity" color="192 192 192" width="10%">
    91101                    <translatableAttribute id="heading" context="replay">Population</translatableAttribute>
    92                 </def>
     102                </column>
    93103
    94                 <def id="duration" color="192 192 192" width="10%">
     104                <column id="duration" color="192 192 192" width="10%">
    95105                    <translatableAttribute id="heading" context="replay">Duration</translatableAttribute>
    96                 </def>
     106                </column>
    97107
    98108            </object>
    99109
  • source/gui/COList.cpp

     
    2323#include "ps/CLogger.h"
    2424#include "soundmanager/ISoundManager.h"
    2525
    26 COList::COList()
    27     : CList(), m_HeadingHeight(30.f), m_SelectedDef(-1), m_SelectedColumnOrder(0)
     26COList::COList() : CList()
    2827{
    2928    AddSetting(GUIST_CGUISpriteInstance,    "sprite_heading");
     29    AddSetting(GUIST_float,                 "heading_height");
    3030    AddSetting(GUIST_bool,                  "sortable"); // The actual sorting is done in JS for more versatility
    3131    AddSetting(GUIST_CStr,                  "selected_column");
    3232    AddSetting(GUIST_int,                   "selected_column_order");
    33     AddSetting(GUIST_CStr,                  "default_column");
    34     AddSetting(GUIST_int,                   "default_column_order");
    35     AddSetting(GUIST_int,                   "selected_def");
    3633    AddSetting(GUIST_CGUISpriteInstance,    "sprite_asc");  // Show the order of sorting
    3734    AddSetting(GUIST_CGUISpriteInstance,    "sprite_desc");
    3835    AddSetting(GUIST_CGUISpriteInstance,    "sprite_not_sorted");
    3936
    40     GUI<CStr>::SetSetting(this, "selected_column", "");
    41     GUI<int>::SetSetting(this, "selected_column_order", 0);
    42     GUI<int>::SetSetting(this, "selected_def", -1);
     37    GUI<int>::SetSetting(this, "selected_column_order", 1);
    4338}
    4439
    4540void COList::SetupText()
     
    4843        return;
    4944
    5045    CGUIList* pList;
    51     GUI<CGUIList>::GetSettingPointer(this, "list_name", pList);
     46    GUI<CGUIList>::GetSettingPointer(this, "list", pList);
    5247
    5348    m_ItemsYPositions.resize(pList->m_Items.size() + 1);
    5449
     
    7368    if (scrollbar && GetScrollBar(0).GetStyle())
    7469        width -= GetScrollBar(0).GetStyle()->m_Width;
    7570
    76     m_TotalAvalibleColumnWidth = width;
     71    m_TotalAvailableColumnWidth = width;
    7772
    7873    float buffer_zone = 0.f;
    7974    GUI<float>::GetSetting(this, "buffer_zone", buffer_zone);
    8075
    81     CStr defaultColumn;
    82     GUI<CStr>::GetSetting(this, "default_column", defaultColumn);
    83     defaultColumn = "list_" + defaultColumn;
    84 
    85     for (size_t c = 0; c < m_ObjectsDefs.size(); ++c)
     76    for (COListColumn column : m_Columns)
    8677    {
    8778        SGUIText* text = new SGUIText();
    8879        CGUIString gui_string;
    89         gui_string.SetValue(m_ObjectsDefs[c].m_Heading);
     80        gui_string.SetValue(column.m_Heading);
    9081        *text = GetGUI()->GenerateText(gui_string, font, width, buffer_zone, this);
    9182        AddText(text);
    92 
    93         if (m_SelectedDef == (size_t)-1 && defaultColumn == m_ObjectsDefs[c].m_Id)
    94             m_SelectedDef = c;
    9583    }
    9684
    97     if (m_SelectedDef != (size_t)-1)
    98         GUI<CStr>::SetSetting(this, "selected_column", m_ObjectsDefs[m_SelectedDef].m_Id.substr(5));
    99 
    100     if (m_SelectedColumnOrder == 0)
    101     {
    102         GUI<int>::GetSetting(this, "default_column_order", m_SelectedColumnOrder);
    103         GUI<int>::SetSetting(this, "selected_column_order", m_SelectedColumnOrder);
    104     }
    105 
    10685    // Generate texts
    10786    float buffered_y = 0.f;
    10887
     
    10988    for (size_t i = 0; i < pList->m_Items.size(); ++i)
    11089    {
    11190        m_ItemsYPositions[i] = buffered_y;
    112         for (size_t c = 0; c < m_ObjectsDefs.size(); ++c)
     91        for (size_t c = 0; c < m_Columns.size(); ++c)
    11392        {
    11493            CGUIList* pList_c;
    115             GUI<CGUIList>::GetSettingPointer(this, m_ObjectsDefs[c].m_Id, pList_c);
     94            GUI<CGUIList>::GetSettingPointer(this, "list_" + m_Columns[c].m_Id, pList_c);
    11695            SGUIText* text = new SGUIText();
    11796            *text = GetGUI()->GenerateText(pList_c->m_Items[i], font, width, buffer_zone, this);
    11897            if (c == 0)
     
    125104
    126105    if (scrollbar)
    127106    {
     107        CRect rect = GetListRect();
    128108        GetScrollBar(0).SetScrollRange(m_ItemsYPositions.back());
    129         GetScrollBar(0).SetScrollSpace(GetListRect().GetHeight());
     109        GetScrollBar(0).SetScrollSpace(rect.GetHeight());
    130110
    131         CRect rect = GetListRect();
    132111        GetScrollBar(0).SetX(rect.right);
    133112        GetScrollBar(0).SetY(rect.top);
    134113        GetScrollBar(0).SetZ(GetBufferedZ());
     
    138117
    139118CRect COList::GetListRect() const
    140119{
    141     return m_CachedActualSize + CRect(0, m_HeadingHeight, 0, 0);
     120    float headingHeight;
     121    GUI<float>::GetSetting(this, "heading_height", headingHeight);
     122    return m_CachedActualSize + CRect(0, headingHeight, 0, 0);
    142123}
    143124
    144125void COList::HandleMessage(SGUIMessage& Message)
     
    159140        if (!m_CachedActualSize.PointInside(mouse))
    160141            return;
    161142
     143        CStr selectedColumn;
     144        GUI<CStr>::GetSetting(this, "selected_column", selectedColumn);
     145        int selectedColumnOrder;
     146        GUI<int>::GetSetting(this, "selected_column_order", selectedColumnOrder);
     147        float headingHeight;
     148        GUI<float>::GetSetting(this, "heading_height", headingHeight);
     149
    162150        float xpos = 0;
    163         for (size_t def = 0; def < m_ObjectsDefs.size(); ++def)
     151        for (COListColumn column : m_Columns)
    164152        {
    165             float width = m_ObjectsDefs[def].m_Width;
     153            float width = column.m_Width;
    166154            // Check if it's a decimal value, and if so, assume relative positioning.
    167             if (m_ObjectsDefs[def].m_Width < 1 && m_ObjectsDefs[def].m_Width > 0)
    168                 width *= m_TotalAvalibleColumnWidth;
     155            if (column.m_Width < 1 && column.m_Width > 0)
     156                width *= m_TotalAvailableColumnWidth;
    169157            CPos leftTopCorner = m_CachedActualSize.TopLeft() + CPos(xpos, 0);
    170158            if (mouse.x >= leftTopCorner.x &&
    171159                mouse.x < leftTopCorner.x + width &&
    172                 mouse.y < leftTopCorner.y + m_HeadingHeight)
     160                mouse.y < leftTopCorner.y + headingHeight)
    173161            {
    174                 if (def != m_SelectedDef)
     162                if (column.m_Id != selectedColumn)
    175163                {
    176                     m_SelectedColumnOrder = 1;
    177                     m_SelectedDef = def;
     164                    selectedColumnOrder = 1;
     165                    selectedColumn = column.m_Id;
    178166                }
    179167                else
    180                     m_SelectedColumnOrder = -m_SelectedColumnOrder;
    181                 GUI<CStr>::SetSetting(this, "selected_column", m_ObjectsDefs[def].m_Id.substr(5));
    182                 GUI<int>::SetSetting(this, "selected_column_order", m_SelectedColumnOrder);
    183                 GUI<int>::SetSetting(this, "selected_def", def);
     168                    selectedColumnOrder = -selectedColumnOrder;
     169                GUI<CStr>::SetSetting(this, "selected_column", column.m_Id);
     170                GUI<int>::SetSetting(this, "selected_column_order", selectedColumnOrder);
    184171                ScriptEvent("selectioncolumnchange");
    185172
    186173                CStrW soundPath;
     
    203190    #define ELMT(x) int elmt_##x = pFile->GetElementID(#x)
    204191    #define ATTR(x) int attr_##x = pFile->GetAttributeID(#x)
    205192    ELMT(item);
    206     ELMT(def);
     193    ELMT(column);
    207194    ELMT(translatableAttribute);
    208195    ATTR(id);
    209196    ATTR(context);
     
    213200        AddItem(child.GetText().FromUTF8(), child.GetText().FromUTF8());
    214201        return true;
    215202    }
    216     else if (child.GetNodeName() == elmt_def)
     203    else if (child.GetNodeName() == elmt_column)
    217204    {
    218         ObjectDef oDef;
     205        COListColumn column;
    219206
    220207        for (XMBAttribute attr : child.GetAttributes())
    221208        {
     
    227214                CColor color;
    228215                if (!GUI<CColor>::ParseString(attr_value.FromUTF8(), color))
    229216                    LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name.c_str(), attr_value.c_str());
    230                 else oDef.m_TextColor = color;
     217                else column.m_TextColor = color;
    231218            }
    232219            else if (attr_name == "id")
    233220            {
    234                 oDef.m_Id = "list_"+attr_value;
     221                column.m_Id = attr_value;
    235222            }
    236223            else if (attr_name == "width")
    237224            {
     
    243230                    // Check if it's a relative value, and save as decimal if so.
    244231                    if (attr_value.find("%") != std::string::npos)
    245232                        width = width / 100.f;
    246                     oDef.m_Width = width;
     233                    column.m_Width = width;
    247234                }
    248235            }
    249236            else if (attr_name == "heading")
    250237            {
    251                 oDef.m_Heading = attr_value.FromUTF8();
     238                column.m_Heading = attr_value.FromUTF8();
    252239            }
    253240        }
    254241
     
    258245                continue;
    259246
    260247            CStr attributeName(grandchild.GetAttributes().GetNamedItem(attr_id));
    261             // only the heading is translatable for list defs
     248            // only the heading is translatable for list column
    262249            if (attributeName.empty() || attributeName != "heading")
    263250            {
    264                 LOGERROR("GUI: translatable attribute in olist def that isn't a heading. (object: %s)", this->GetPresentableName().c_str());
     251                LOGERROR("GUI: translatable attribute in olist column that isn't a heading. (object: %s)", this->GetPresentableName().c_str());
    265252                continue;
    266253            }
    267254
     
    273260            if (!context.empty())
    274261            {
    275262                CStr translatedValue(g_L10n.TranslateWithContext(context, value));
    276                 oDef.m_Heading = translatedValue.FromUTF8();
     263                column.m_Heading = translatedValue.FromUTF8();
    277264            }
    278265            else
    279266            {
    280267                CStr translatedValue(g_L10n.Translate(value));
    281                 oDef.m_Heading = translatedValue.FromUTF8();
     268                column.m_Heading = translatedValue.FromUTF8();
    282269            }
    283270        }
    284271
    285         m_ObjectsDefs.push_back(oDef);
     272        m_Columns.push_back(column);
    286273
    287         AddSetting(GUIST_CGUIList, oDef.m_Id);
     274        AddSetting(GUIST_CGUIList, "list_" + column.m_Id);
    288275        SetupText();
    289276
    290277        return true;
     
    318305    GUI<int>::GetSetting(this, "cell_id", cell_id);
    319306
    320307    CGUIList* pList;
    321     GUI<CGUIList>::GetSettingPointer(this, "list_name", pList);
     308    GUI<CGUIList>::GetSettingPointer(this, "list", pList);
    322309
    323310    GetGUI()->DrawSprite(*sprite, cell_id, bz, rect);
    324311
     
    360347        }
    361348    }
    362349
    363     CColor color;
    364     GUI<CColor>::GetSetting(this, _textcolor, color);
     350    float headingHeight;
     351    GUI<float>::GetSetting(this, "heading_height", headingHeight);
    365352
    366353    // Draw line above column header
    367354    CGUISpriteInstance* sprite_heading = NULL;
    368355    GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_heading", sprite_heading);
    369356    CRect rect_head(m_CachedActualSize.left, m_CachedActualSize.top, m_CachedActualSize.right,
    370                                     m_CachedActualSize.top + m_HeadingHeight);
     357                                    m_CachedActualSize.top + headingHeight);
    371358    GetGUI()->DrawSprite(*sprite_heading, cell_id, bz, rect_head);
    372359
     360    int selectedColumnOrder;
     361    GUI<int>::GetSetting(this, "selected_column_order", selectedColumnOrder);
     362
    373363    CGUISpriteInstance* sprite_order;
    374364    CGUISpriteInstance* sprite_not_sorted;
    375     if (m_SelectedColumnOrder != -1)
     365    if (selectedColumnOrder != -1)
    376366        GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_asc", sprite_order);
    377367    else
    378368        GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_desc", sprite_order);
    379369    GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_not_sorted", sprite_not_sorted);
    380370
     371    CStr selectedColumn;
     372    GUI<CStr>::GetSetting(this, "selected_column", selectedColumn);
     373
     374    CColor color;
     375    GUI<CColor>::GetSetting(this, _textcolor, color);
    381376    // Draw column headers
    382377    float xpos = 0;
    383     for (size_t def = 0; def < m_ObjectsDefs.size(); ++def)
     378    for (size_t col = 0; col < m_Columns.size(); ++col)
    384379    {
    385380        // Check if it's a decimal value, and if so, assume relative positioning.
    386         float width = m_ObjectsDefs[def].m_Width;
    387         if (m_ObjectsDefs[def].m_Width < 1 && m_ObjectsDefs[def].m_Width > 0)
    388             width *= m_TotalAvalibleColumnWidth;
     381        float width = m_Columns[col].m_Width;
     382        if (m_Columns[col].m_Width < 1 && m_Columns[col].m_Width > 0)
     383            width *= m_TotalAvailableColumnWidth;
    389384
    390385        CPos leftTopCorner = m_CachedActualSize.TopLeft() + CPos(xpos, 0);
    391386
    392387        CGUISpriteInstance* sprite;
    393388        // If the list sorted by current column
    394         if (m_SelectedDef == def)
     389        if (selectedColumn == m_Columns[col].m_Id)
    395390            sprite = sprite_order;
    396391        else
    397392            sprite = sprite_not_sorted;
     
    400395        GetGUI()->DrawSprite(*sprite, cell_id, bz + 0.1f, CRect(leftTopCorner + CPos(width - 16, 0), leftTopCorner + CPos(width, 16)));
    401396
    402397        // Draw column header text
    403         DrawText(def, color, leftTopCorner + CPos(0, 4), bz + 0.1f, rect_head);
     398        DrawText(col, color, leftTopCorner + CPos(0, 4), bz + 0.1f, rect_head);
    404399        xpos += width;
    405400    }
    406401
    407402    // Draw list items for each column
    408     const size_t objectsCount = m_ObjectsDefs.size();
     403    const size_t objectsCount = m_Columns.size();
    409404    for (size_t i = 0; i < pList->m_Items.size(); ++i)
    410405    {
    411406        if (m_ItemsYPositions[i+1] - scroll < 0 ||
     
    430425
    431426        // Draw all items for that column
    432427        xpos = 0;
    433         for (size_t def = 0; def < objectsCount; ++def)
     428        for (size_t col = 0; col < objectsCount; ++col)
    434429        {
    435430            // Determine text position and width
    436431            const CPos textPos = rect.TopLeft() + CPos(xpos, -scroll + m_ItemsYPositions[i]);
    437432
    438             float width = m_ObjectsDefs[def].m_Width;;
     433            float width = m_Columns[col].m_Width;
    439434            // Check if it's a decimal value, and if so, assume relative positioning.
    440             if (m_ObjectsDefs[def].m_Width < 1 && m_ObjectsDefs[def].m_Width > 0)
    441                 width *= m_TotalAvalibleColumnWidth;
     435            if (m_Columns[col].m_Width < 1 && m_Columns[col].m_Width > 0)
     436                width *= m_TotalAvailableColumnWidth;
    442437
    443438            // Clip text to the column (to prevent drawing text into the neighboring column)
    444439            CRect cliparea2 = cliparea;
     
    446441            cliparea2.bottom = std::min(cliparea2.bottom, textPos.y + rowHeight);
    447442
    448443            // Draw list item
    449             DrawText(objectsCount * (i+/*Heading*/1) + def, m_ObjectsDefs[def].m_TextColor, textPos, bz+0.1f, cliparea2);
     444            DrawText(objectsCount * (i +/*Heading*/1) + col, m_Columns[col].m_TextColor, textPos, bz + 0.1f, cliparea2);
    450445            xpos += width;
    451446        }
    452447    }
  • source/gui/COList.h

     
    2323/**
    2424 * Represents a column.
    2525 */
    26 struct ObjectDef
     26struct COListColumn
    2727{
    2828  CColor m_TextColor;
    2929  CStr m_Id;
     
    6363    /**
    6464     * Available columns.
    6565     */
    66     std::vector<ObjectDef> m_ObjectsDefs;
     66    std::vector<COListColumn> m_Columns;
    6767
    68     /**
    69      * Index of the selected column.
    70      */
    71     size_t m_SelectedDef;
    72 
    73     /**
    74      * +1 for ascending, -1 for descending sort order.
    75      */
    76     int m_SelectedColumnOrder;
    77 
    7868private:
    79     float m_HeadingHeight;
    80     // Width of space avalible for columns
    81     float m_TotalAvalibleColumnWidth;
     69    // Width of space available for columns
     70    float m_TotalAvailableColumnWidth;
    8271};
    8372
    8473#endif // INCLUDED_COLIST