Ticket #3905: 3905_COList_refresh_v4.patch
File 3905_COList_refresh_v4.patch, 29.5 KB (added by , 8 years ago) |
---|
-
binaries/data/mods/mod/gui/common/modern/styles.xml
39 39 <style name = "ModernList" 40 40 buffer_zone = "5" 41 41 font = "sans-bold-stroke-14" 42 heading_height="25" 42 43 scrollbar = "true" 43 44 scrollbar_style = "ModernScrollBar" 44 45 sprite = "ModernDarkBoxGoldNoTop" -
binaries/data/mods/mod/gui/gui.rnc
52 52 attribute button_width { xsd:decimal }?& 53 53 attribute checked { bool }?& 54 54 attribute clip { bool }?& 55 attribute default_column { text }?&56 attribute default_column_order { text }?&57 55 attribute dropdown_size { xsd:decimal }?& 58 56 attribute dropdown_buffer { xsd:decimal }?& 59 57 attribute enabled { bool }?& 60 58 attribute font { text }?& 61 59 attribute fov_wedge_color { ccolor }?& 60 attribute heading_height { text }?& 62 61 attribute hotkey { text }?& 63 62 attribute cell_id { xsd:integer }?& 64 63 attribute independent { bool }?& … … 72 71 attribute scrollbar { bool }?& 73 72 attribute scrollbar_style { text }?& 74 73 attribute scroll_bottom { bool }?& 74 attribute selected_column { text }?& 75 attribute selected_column_order { text }?& 75 76 attribute sortable { bool }?& 76 77 attribute sound_closed { text }?& 77 78 attribute sound_disabled { text }?& … … 122 123 ((object 123 124 | action 124 125 | \attribute 125 | def126 | column 126 127 | \include 127 128 | item 128 129 | repeat … … 143 144 (keep | translate)*, 144 145 attribute id { text } 145 146 } 146 def=147 element def{147 column = 148 element column { 148 149 translatableAttribute?, 149 150 ( 150 151 attribute id { text }& -
binaries/data/mods/mod/gui/gui.rng
200 200 </attribute> 201 201 </optional> 202 202 <optional> 203 <attribute name="default_column"/>204 </optional>205 <optional>206 <attribute name="default_column_order"/>207 </optional>208 <optional>209 203 <attribute name="dropdown_size"> 210 204 <data type="decimal"/> 211 205 </attribute> … … 229 223 </attribute> 230 224 </optional> 231 225 <optional> 226 <attribute name="heading_height"/> 227 </optional> 228 <optional> 232 229 <attribute name="hotkey"/> 233 230 </optional> 234 231 <optional> … … 293 290 </attribute> 294 291 </optional> 295 292 <optional> 293 <attribute name="selected_column"/> 294 </optional> 295 <optional> 296 <attribute name="selected_column_order"/> 297 </optional> 298 <optional> 296 299 <attribute name="sortable"/> 297 300 </optional> 298 301 <optional> … … 446 449 <ref name="object"/> 447 450 <ref name="action"/> 448 451 <ref name="attribute"/> 449 <ref name=" def"/>452 <ref name="column"/> 450 453 <ref name="include"/> 451 454 <ref name="item"/> 452 455 <ref name="repeat"/> … … 480 483 <attribute name="id"/> 481 484 </element> 482 485 </define> 483 <define name=" def">484 <element name=" def">486 <define name="column"> 487 <element name="column"> 485 488 <optional> 486 489 <ref name="translatableAttribute"/> 487 490 </optional> -
binaries/data/mods/mod/gui/modmod/modmod.xml
86 86 <translatableAttribute id="caption">Available Mods</translatableAttribute> 87 87 </object> 88 88 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 > 90 95 <action on="SelectionChange">showModDescription(this.name);</action> 91 96 <!-- List headers --> 92 < defid="name" color="100 100 200" width="10%">97 <column id="name" color="100 100 200" width="10%"> 93 98 <translatableAttribute id="heading">Name</translatableAttribute> 94 </ def>95 < defid="modVersion" color="128 128 128" width="7%">99 </column> 100 <column id="modVersion" color="128 128 128" width="7%"> 96 101 <translatableAttribute id="heading">Version</translatableAttribute> 97 </ def>98 < defid="modFolderName" color="100 100 200" width="13%">102 </column> 103 <column id="modFolderName" color="100 100 200" width="13%"> 99 104 <translatableAttribute id="heading">(Folder)</translatableAttribute> 100 </ def>101 < defid="modLabel" color="0 60 0" width="18%">105 </column> 106 <column id="modLabel" color="0 60 0" width="18%"> 102 107 <translatableAttribute id="heading">Mod Label</translatableAttribute> 103 </ def>104 < defid="modType" color="0 128 128" width="12%">108 </column> 109 <column id="modType" color="0 128 128" width="12%"> 105 110 <translatableAttribute id="heading">Mod Type</translatableAttribute> 106 </ def>107 < defid="modDependencies" color="128 128 128" width="20%">111 </column> 112 <column id="modDependencies" color="128 128 128" width="20%"> 108 113 <translatableAttribute id="heading">Dependencies</translatableAttribute> 109 </ def>110 < defid="modURL" color="128 128 128" width="24%">114 </column> 115 <column id="modURL" color="128 128 128" width="24%"> 111 116 <translatableAttribute id="heading">Website</translatableAttribute> 112 </ def>117 </column> 113 118 </object> 114 119 <object name="globalModDescription" type="text" style="ModmodScrollbar" size="0 100%-28 100%-16 100%"> 115 120 <attribute id="caption"><keep>[color="100 100 100"]</keep><translate>Description</translate><keep>[/color]</keep></attribute> … … 127 132 <translatableAttribute id="caption">Enabled Mods</translatableAttribute> 128 133 </object> 129 134 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 > 131 142 <action on="SelectionChange">showModDescription(this.name);</action> 132 143 <!-- List headers --> 133 < defid="name" color="100 100 200" width="10%">144 <column id="name" color="100 100 200" width="10%"> 134 145 <translatableAttribute id="heading">Name</translatableAttribute> 135 </ def>136 < defid="modVersion" color="128 128 128" width="7%">146 </column> 147 <column id="modVersion" color="128 128 128" width="7%"> 137 148 <translatableAttribute id="heading">Version</translatableAttribute> 138 </ def>139 < defid="modFolderName" color="100 100 200" width="13%">149 </column> 150 <column id="modFolderName" color="100 100 200" width="13%"> 140 151 <translatableAttribute id="heading">(Folder)</translatableAttribute> 141 </ def>142 < defid="modLabel" color="0 60 0" width="18%">152 </column> 153 <column id="modLabel" color="0 60 0" width="18%"> 143 154 <translatableAttribute id="heading">Mod Label</translatableAttribute> 144 </ def>145 < defid="modType" color="0 128 128" width="12%">155 </column> 156 <column id="modType" color="0 128 128" width="12%"> 146 157 <translatableAttribute id="heading">Mod Type</translatableAttribute> 147 </ def>148 < defid="modDependencies" color="128 128 128" width="20%">158 </column> 159 <column id="modDependencies" color="128 128 128" width="20%"> 149 160 <translatableAttribute id="heading">Dependencies</translatableAttribute> 150 </ def>151 < defid="modURL" color="128 128 128" width="20%">161 </column> 162 <column id="modURL" color="128 128 128" width="20%"> 152 163 <translatableAttribute id="heading">Website</translatableAttribute> 153 </ def>164 </column> 154 165 </object> 155 166 156 167 <object type="button" style="ModernButtonRed" size="96% 23 100% 40%+12"> -
binaries/data/mods/public/gui/lobby/lobby.xml
23 23 24 24 <!-- Left panel: Player list. --> 25 25 <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%"> 28 39 <translatableAttribute id="heading">Status</translatableAttribute> 29 </ def>30 < defid="name" width="48%">40 </column> 41 <column id="name" width="48%"> 31 42 <translatableAttribute id="heading">Name</translatableAttribute> 32 </ def>33 < defid="rating" width="26%">43 </column> 44 <column id="rating" width="26%"> 34 45 <translatableAttribute id="heading">Rating</translatableAttribute> 35 </ def>46 </column> 36 47 <action on="SelectionChange"> 37 48 displayProfile("lobbylist"); 38 49 </action> … … 172 183 173 184 <!-- Middle panel: Filters, game list, chat box. --> 174 185 <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 > 176 198 <action on="SelectionChange">updateGameSelection();</action> 177 199 <action on="SelectionColumnChange">applyFilters();</action> 178 200 <action on="mouseleftdoubleclickitem">joinButton();</action> 179 < defid="name" color="0 60 0" width="27%">201 <column id="name" color="0 60 0" width="27%"> 180 202 <translatableAttribute id="heading">Name</translatableAttribute> 181 </ def>182 <!--< defid="ip" heading="IP" color="0 128 128" width="170"/>-->183 < defid="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%"> 184 206 <translatableAttribute id="heading">Map Name</translatableAttribute> 185 </ def>186 < defid="mapSize" color="128 128 128" width="16%">207 </column> 208 <column id="mapSize" color="128 128 128" width="16%"> 187 209 <translatableAttribute id="heading" context="map">Size</translatableAttribute> 188 </ def>189 < defid="mapType" color="0 128 128" width="16%">210 </column> 211 <column id="mapType" color="0 128 128" width="16%"> 190 212 <translatableAttribute id="heading" context="map">Type</translatableAttribute> 191 </ def>192 < defid="nPlayers" color="0 128 128" width="16%">213 </column> 214 <column id="nPlayers" color="0 128 128" width="16%"> 193 215 <translatableAttribute id="heading">Players</translatableAttribute> 194 </ def>216 </column> 195 217 </object> 196 218 197 219 <object name="filterPanel" size="0 0 100% 24"> … … 254 276 style="ModernList" 255 277 type="olist" 256 278 size="19 19 100%-19 100%-62"> 257 < defid="rank" color="255 255 255" width="15%">279 <column id="rank" color="255 255 255" width="15%"> 258 280 <translatableAttribute id="heading">Rank</translatableAttribute> 259 </ def>260 < defid="name" color="255 255 255" width="55%">281 </column> 282 <column id="name" color="255 255 255" width="55%"> 261 283 <translatableAttribute id="heading">Name</translatableAttribute> 262 </ def>263 < defid="rating" color="255 255 255" width="30%">284 </column> 285 <column id="rating" color="255 255 255" width="30%"> 264 286 <translatableAttribute id="heading">Rating</translatableAttribute> 265 </ def>287 </column> 266 288 <action on="SelectionChange"> 267 289 displayProfile("leaderboard"); 268 290 </action> -
binaries/data/mods/public/gui/replaymenu/replay_filters.js
188 188 let cmpA, cmpB; 189 189 switch (sortKey) 190 190 { 191 case ' name':191 case 'months': 192 192 cmpA = +a.timestamp; 193 193 cmpB = +b.timestamp; 194 194 break; -
binaries/data/mods/public/gui/replaymenu/replay_menu.js
218 218 219 219 // Push to GUI 220 220 replaySelection.selected = -1; 221 replaySelection.list_ name= list.months || [];221 replaySelection.list_months = list.months || []; 222 222 replaySelection.list_players = list.playerNames || []; 223 223 replaySelection.list_mapName = list.mapNames || []; 224 224 replaySelection.list_mapSize = list.mapSizes || []; -
binaries/data/mods/public/gui/replaymenu/replay_menu.xml
63 63 </object> 64 64 65 65 <!-- 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 > 67 78 68 79 <action on="SelectionChange">displayReplayDetails();</action> 69 80 <action on="SelectionColumnChange">displayReplayList();</action> … … 70 81 <action on="mouseleftdoubleclickitem">startReplay();</action> 71 82 72 83 <!-- 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%"> 75 85 <translatableAttribute id="heading" context="replay">Date / Time</translatableAttribute> 76 </ def>86 </column> 77 87 78 < defid="players" color="192 192 192" width="44%">88 <column id="players" color="192 192 192" width="44%"> 79 89 <translatableAttribute id="heading" context="replay">Players</translatableAttribute> 80 </ def>90 </column> 81 91 82 < defid="mapName" color="192 192 192" width="14%">92 <column id="mapName" color="192 192 192" width="14%"> 83 93 <translatableAttribute id="heading" context="replay">Map Name</translatableAttribute> 84 </ def>94 </column> 85 95 86 < defid="mapSize" color="192 192 192" width="10%">96 <column id="mapSize" color="192 192 192" width="10%"> 87 97 <translatableAttribute id="heading" context="replay">Size</translatableAttribute> 88 </ def>98 </column> 89 99 90 < defid="popCapacity" color="192 192 192" width="10%">100 <column id="popCapacity" color="192 192 192" width="10%"> 91 101 <translatableAttribute id="heading" context="replay">Population</translatableAttribute> 92 </ def>102 </column> 93 103 94 < defid="duration" color="192 192 192" width="10%">104 <column id="duration" color="192 192 192" width="10%"> 95 105 <translatableAttribute id="heading" context="replay">Duration</translatableAttribute> 96 </ def>106 </column> 97 107 98 108 </object> 99 109 -
source/gui/COList.cpp
23 23 #include "ps/CLogger.h" 24 24 #include "soundmanager/ISoundManager.h" 25 25 26 COList::COList() 27 : CList(), m_HeadingHeight(30.f), m_SelectedDef(-1), m_SelectedColumnOrder(0) 26 COList::COList() : CList() 28 27 { 29 28 AddSetting(GUIST_CGUISpriteInstance, "sprite_heading"); 29 AddSetting(GUIST_float, "heading_height"); 30 30 AddSetting(GUIST_bool, "sortable"); // The actual sorting is done in JS for more versatility 31 31 AddSetting(GUIST_CStr, "selected_column"); 32 32 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");36 33 AddSetting(GUIST_CGUISpriteInstance, "sprite_asc"); // Show the order of sorting 37 34 AddSetting(GUIST_CGUISpriteInstance, "sprite_desc"); 38 35 AddSetting(GUIST_CGUISpriteInstance, "sprite_not_sorted"); 39 36 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); 43 38 } 44 39 45 40 void COList::SetupText() … … 48 43 return; 49 44 50 45 CGUIList* pList; 51 GUI<CGUIList>::GetSettingPointer(this, "list _name", pList);46 GUI<CGUIList>::GetSettingPointer(this, "list", pList); 52 47 53 48 m_ItemsYPositions.resize(pList->m_Items.size() + 1); 54 49 … … 73 68 if (scrollbar && GetScrollBar(0).GetStyle()) 74 69 width -= GetScrollBar(0).GetStyle()->m_Width; 75 70 76 m_TotalAva libleColumnWidth = width;71 m_TotalAvailableColumnWidth = width; 77 72 78 73 float buffer_zone = 0.f; 79 74 GUI<float>::GetSetting(this, "buffer_zone", buffer_zone); 80 75 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) 86 77 { 87 78 SGUIText* text = new SGUIText(); 88 79 CGUIString gui_string; 89 gui_string.SetValue( m_ObjectsDefs[c].m_Heading);80 gui_string.SetValue(column.m_Heading); 90 81 *text = GetGUI()->GenerateText(gui_string, font, width, buffer_zone, this); 91 82 AddText(text); 92 93 if (m_SelectedDef == (size_t)-1 && defaultColumn == m_ObjectsDefs[c].m_Id)94 m_SelectedDef = c;95 83 } 96 84 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 106 85 // Generate texts 107 86 float buffered_y = 0.f; 108 87 … … 109 88 for (size_t i = 0; i < pList->m_Items.size(); ++i) 110 89 { 111 90 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) 113 92 { 114 93 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); 116 95 SGUIText* text = new SGUIText(); 117 96 *text = GetGUI()->GenerateText(pList_c->m_Items[i], font, width, buffer_zone, this); 118 97 if (c == 0) … … 125 104 126 105 if (scrollbar) 127 106 { 107 CRect rect = GetListRect(); 128 108 GetScrollBar(0).SetScrollRange(m_ItemsYPositions.back()); 129 GetScrollBar(0).SetScrollSpace( GetListRect().GetHeight());109 GetScrollBar(0).SetScrollSpace(rect.GetHeight()); 130 110 131 CRect rect = GetListRect();132 111 GetScrollBar(0).SetX(rect.right); 133 112 GetScrollBar(0).SetY(rect.top); 134 113 GetScrollBar(0).SetZ(GetBufferedZ()); … … 138 117 139 118 CRect COList::GetListRect() const 140 119 { 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); 142 123 } 143 124 144 125 void COList::HandleMessage(SGUIMessage& Message) … … 159 140 if (!m_CachedActualSize.PointInside(mouse)) 160 141 return; 161 142 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 162 150 float xpos = 0; 163 for ( size_t def = 0; def < m_ObjectsDefs.size(); ++def)151 for (COListColumn column : m_Columns) 164 152 { 165 float width = m_ObjectsDefs[def].m_Width;153 float width = column.m_Width; 166 154 // 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_TotalAva libleColumnWidth;155 if (column.m_Width < 1 && column.m_Width > 0) 156 width *= m_TotalAvailableColumnWidth; 169 157 CPos leftTopCorner = m_CachedActualSize.TopLeft() + CPos(xpos, 0); 170 158 if (mouse.x >= leftTopCorner.x && 171 159 mouse.x < leftTopCorner.x + width && 172 mouse.y < leftTopCorner.y + m_HeadingHeight)160 mouse.y < leftTopCorner.y + headingHeight) 173 161 { 174 if ( def != m_SelectedDef)162 if (column.m_Id != selectedColumn) 175 163 { 176 m_SelectedColumnOrder = 1;177 m_SelectedDef = def;164 selectedColumnOrder = 1; 165 selectedColumn = column.m_Id; 178 166 } 179 167 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); 184 171 ScriptEvent("selectioncolumnchange"); 185 172 186 173 CStrW soundPath; … … 203 190 #define ELMT(x) int elmt_##x = pFile->GetElementID(#x) 204 191 #define ATTR(x) int attr_##x = pFile->GetAttributeID(#x) 205 192 ELMT(item); 206 ELMT( def);193 ELMT(column); 207 194 ELMT(translatableAttribute); 208 195 ATTR(id); 209 196 ATTR(context); … … 213 200 AddItem(child.GetText().FromUTF8(), child.GetText().FromUTF8()); 214 201 return true; 215 202 } 216 else if (child.GetNodeName() == elmt_ def)203 else if (child.GetNodeName() == elmt_column) 217 204 { 218 ObjectDef oDef;205 COListColumn column; 219 206 220 207 for (XMBAttribute attr : child.GetAttributes()) 221 208 { … … 227 214 CColor color; 228 215 if (!GUI<CColor>::ParseString(attr_value.FromUTF8(), color)) 229 216 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; 231 218 } 232 219 else if (attr_name == "id") 233 220 { 234 oDef.m_Id = "list_"+attr_value;221 column.m_Id = attr_value; 235 222 } 236 223 else if (attr_name == "width") 237 224 { … … 243 230 // Check if it's a relative value, and save as decimal if so. 244 231 if (attr_value.find("%") != std::string::npos) 245 232 width = width / 100.f; 246 oDef.m_Width = width;233 column.m_Width = width; 247 234 } 248 235 } 249 236 else if (attr_name == "heading") 250 237 { 251 oDef.m_Heading = attr_value.FromUTF8();238 column.m_Heading = attr_value.FromUTF8(); 252 239 } 253 240 } 254 241 … … 258 245 continue; 259 246 260 247 CStr attributeName(grandchild.GetAttributes().GetNamedItem(attr_id)); 261 // only the heading is translatable for list defs248 // only the heading is translatable for list column 262 249 if (attributeName.empty() || attributeName != "heading") 263 250 { 264 LOGERROR("GUI: translatable attribute in olist defthat 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()); 265 252 continue; 266 253 } 267 254 … … 273 260 if (!context.empty()) 274 261 { 275 262 CStr translatedValue(g_L10n.TranslateWithContext(context, value)); 276 oDef.m_Heading = translatedValue.FromUTF8();263 column.m_Heading = translatedValue.FromUTF8(); 277 264 } 278 265 else 279 266 { 280 267 CStr translatedValue(g_L10n.Translate(value)); 281 oDef.m_Heading = translatedValue.FromUTF8();268 column.m_Heading = translatedValue.FromUTF8(); 282 269 } 283 270 } 284 271 285 m_ ObjectsDefs.push_back(oDef);272 m_Columns.push_back(column); 286 273 287 AddSetting(GUIST_CGUIList, oDef.m_Id);274 AddSetting(GUIST_CGUIList, "list_" + column.m_Id); 288 275 SetupText(); 289 276 290 277 return true; … … 318 305 GUI<int>::GetSetting(this, "cell_id", cell_id); 319 306 320 307 CGUIList* pList; 321 GUI<CGUIList>::GetSettingPointer(this, "list _name", pList);308 GUI<CGUIList>::GetSettingPointer(this, "list", pList); 322 309 323 310 GetGUI()->DrawSprite(*sprite, cell_id, bz, rect); 324 311 … … 360 347 } 361 348 } 362 349 363 CColor color;364 GUI< CColor>::GetSetting(this, _textcolor, color);350 float headingHeight; 351 GUI<float>::GetSetting(this, "heading_height", headingHeight); 365 352 366 353 // Draw line above column header 367 354 CGUISpriteInstance* sprite_heading = NULL; 368 355 GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_heading", sprite_heading); 369 356 CRect rect_head(m_CachedActualSize.left, m_CachedActualSize.top, m_CachedActualSize.right, 370 m_CachedActualSize.top + m_HeadingHeight);357 m_CachedActualSize.top + headingHeight); 371 358 GetGUI()->DrawSprite(*sprite_heading, cell_id, bz, rect_head); 372 359 360 int selectedColumnOrder; 361 GUI<int>::GetSetting(this, "selected_column_order", selectedColumnOrder); 362 373 363 CGUISpriteInstance* sprite_order; 374 364 CGUISpriteInstance* sprite_not_sorted; 375 if ( m_SelectedColumnOrder != -1)365 if (selectedColumnOrder != -1) 376 366 GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_asc", sprite_order); 377 367 else 378 368 GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_desc", sprite_order); 379 369 GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_not_sorted", sprite_not_sorted); 380 370 371 CStr selectedColumn; 372 GUI<CStr>::GetSetting(this, "selected_column", selectedColumn); 373 374 CColor color; 375 GUI<CColor>::GetSetting(this, _textcolor, color); 381 376 // Draw column headers 382 377 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) 384 379 { 385 380 // 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_TotalAva libleColumnWidth;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; 389 384 390 385 CPos leftTopCorner = m_CachedActualSize.TopLeft() + CPos(xpos, 0); 391 386 392 387 CGUISpriteInstance* sprite; 393 388 // If the list sorted by current column 394 if ( m_SelectedDef == def)389 if (selectedColumn == m_Columns[col].m_Id) 395 390 sprite = sprite_order; 396 391 else 397 392 sprite = sprite_not_sorted; … … 400 395 GetGUI()->DrawSprite(*sprite, cell_id, bz + 0.1f, CRect(leftTopCorner + CPos(width - 16, 0), leftTopCorner + CPos(width, 16))); 401 396 402 397 // 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); 404 399 xpos += width; 405 400 } 406 401 407 402 // Draw list items for each column 408 const size_t objectsCount = m_ ObjectsDefs.size();403 const size_t objectsCount = m_Columns.size(); 409 404 for (size_t i = 0; i < pList->m_Items.size(); ++i) 410 405 { 411 406 if (m_ItemsYPositions[i+1] - scroll < 0 || … … 430 425 431 426 // Draw all items for that column 432 427 xpos = 0; 433 for (size_t def = 0; def < objectsCount; ++def)428 for (size_t col = 0; col < objectsCount; ++col) 434 429 { 435 430 // Determine text position and width 436 431 const CPos textPos = rect.TopLeft() + CPos(xpos, -scroll + m_ItemsYPositions[i]); 437 432 438 float width = m_ ObjectsDefs[def].m_Width;;433 float width = m_Columns[col].m_Width; 439 434 // 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_TotalAva libleColumnWidth;435 if (m_Columns[col].m_Width < 1 && m_Columns[col].m_Width > 0) 436 width *= m_TotalAvailableColumnWidth; 442 437 443 438 // Clip text to the column (to prevent drawing text into the neighboring column) 444 439 CRect cliparea2 = cliparea; … … 446 441 cliparea2.bottom = std::min(cliparea2.bottom, textPos.y + rowHeight); 447 442 448 443 // 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); 450 445 xpos += width; 451 446 } 452 447 } -
source/gui/COList.h
23 23 /** 24 24 * Represents a column. 25 25 */ 26 struct ObjectDef26 struct COListColumn 27 27 { 28 28 CColor m_TextColor; 29 29 CStr m_Id; … … 63 63 /** 64 64 * Available columns. 65 65 */ 66 std::vector< ObjectDef> m_ObjectsDefs;66 std::vector<COListColumn> m_Columns; 67 67 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 78 68 private: 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; 82 71 }; 83 72 84 73 #endif // INCLUDED_COLIST