Ticket #3905: 3905_COList_refresh_v4.1.patch
File 3905_COList_refresh_v4.1.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 selected_column="name" 30 selected_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 selected_column="status" 190 selected_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 <!--<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="mapName" color="128 128 128" width="25%"> 184 205 <translatableAttribute id="heading">Map Name</translatableAttribute> 185 </ def>186 < defid="mapSize" color="128 128 128" width="16%">206 </column> 207 <column id="mapSize" color="128 128 128" width="16%"> 187 208 <translatableAttribute id="heading" context="map">Size</translatableAttribute> 188 </ def>189 < defid="mapType" color="0 128 128" width="16%">209 </column> 210 <column id="mapType" color="0 128 128" width="16%"> 190 211 <translatableAttribute id="heading" context="map">Type</translatableAttribute> 191 </ def>192 < defid="nPlayers" color="0 128 128" width="16%">212 </column> 213 <column id="nPlayers" color="0 128 128" width="16%"> 193 214 <translatableAttribute id="heading">Players</translatableAttribute> 194 </ def>215 </column> 195 216 </object> 196 217 197 218 <object name="filterPanel" size="0 0 100% 24"> … … 254 275 style="ModernList" 255 276 type="olist" 256 277 size="19 19 100%-19 100%-62"> 257 < defid="rank" color="255 255 255" width="15%">278 <column id="rank" color="255 255 255" width="15%"> 258 279 <translatableAttribute id="heading">Rank</translatableAttribute> 259 </ def>260 < defid="name" color="255 255 255" width="55%">280 </column> 281 <column id="name" color="255 255 255" width="55%"> 261 282 <translatableAttribute id="heading">Name</translatableAttribute> 262 </ def>263 < defid="rating" color="255 255 255" width="30%">283 </column> 284 <column id="rating" color="255 255 255" width="30%"> 264 285 <translatableAttribute id="heading">Rating</translatableAttribute> 265 </ def>286 </column> 266 287 <action on="SelectionChange"> 267 288 displayProfile("leaderboard"); 268 289 </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 40 GUI<CStr>::SetSetting(this, "selected_column", "");41 GUI<int>::SetSetting(this, "selected_column_order", 0);42 GUI<int>::SetSetting(this, "selected_def", -1);43 36 } 44 37 45 38 void COList::SetupText() … … 48 41 return; 49 42 50 43 CGUIList* pList; 51 GUI<CGUIList>::GetSettingPointer(this, "list _name", pList);44 GUI<CGUIList>::GetSettingPointer(this, "list", pList); 52 45 53 46 m_ItemsYPositions.resize(pList->m_Items.size() + 1); 54 47 … … 73 66 if (scrollbar && GetScrollBar(0).GetStyle()) 74 67 width -= GetScrollBar(0).GetStyle()->m_Width; 75 68 76 m_TotalAva libleColumnWidth = width;69 m_TotalAvailableColumnWidth = width; 77 70 78 71 float buffer_zone = 0.f; 79 72 GUI<float>::GetSetting(this, "buffer_zone", buffer_zone); 80 73 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) 74 for (COListColumn column : m_Columns) 86 75 { 87 76 SGUIText* text = new SGUIText(); 88 77 CGUIString gui_string; 89 gui_string.SetValue( m_ObjectsDefs[c].m_Heading);78 gui_string.SetValue(column.m_Heading); 90 79 *text = GetGUI()->GenerateText(gui_string, font, width, buffer_zone, this); 91 80 AddText(text); 92 93 if (m_SelectedDef == (size_t)-1 && defaultColumn == m_ObjectsDefs[c].m_Id)94 m_SelectedDef = c;95 81 } 96 82 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 83 // Generate texts 107 84 float buffered_y = 0.f; 108 85 … … 109 86 for (size_t i = 0; i < pList->m_Items.size(); ++i) 110 87 { 111 88 m_ItemsYPositions[i] = buffered_y; 112 for (size_t c = 0; c < m_ ObjectsDefs.size(); ++c)89 for (size_t c = 0; c < m_Columns.size(); ++c) 113 90 { 114 91 CGUIList* pList_c; 115 GUI<CGUIList>::GetSettingPointer(this, m_ObjectsDefs[c].m_Id, pList_c);92 GUI<CGUIList>::GetSettingPointer(this, "list_" + m_Columns[c].m_Id, pList_c); 116 93 SGUIText* text = new SGUIText(); 117 94 *text = GetGUI()->GenerateText(pList_c->m_Items[i], font, width, buffer_zone, this); 118 95 if (c == 0) … … 125 102 126 103 if (scrollbar) 127 104 { 105 CRect rect = GetListRect(); 128 106 GetScrollBar(0).SetScrollRange(m_ItemsYPositions.back()); 129 GetScrollBar(0).SetScrollSpace( GetListRect().GetHeight());107 GetScrollBar(0).SetScrollSpace(rect.GetHeight()); 130 108 131 CRect rect = GetListRect();132 109 GetScrollBar(0).SetX(rect.right); 133 110 GetScrollBar(0).SetY(rect.top); 134 111 GetScrollBar(0).SetZ(GetBufferedZ()); … … 138 115 139 116 CRect COList::GetListRect() const 140 117 { 141 return m_CachedActualSize + CRect(0, m_HeadingHeight, 0, 0); 118 float headingHeight; 119 GUI<float>::GetSetting(this, "heading_height", headingHeight); 120 return m_CachedActualSize + CRect(0, headingHeight, 0, 0); 142 121 } 143 122 144 123 void COList::HandleMessage(SGUIMessage& Message) … … 159 138 if (!m_CachedActualSize.PointInside(mouse)) 160 139 return; 161 140 141 CStr selectedColumn; 142 GUI<CStr>::GetSetting(this, "selected_column", selectedColumn); 143 int selectedColumnOrder; 144 GUI<int>::GetSetting(this, "selected_column_order", selectedColumnOrder); 145 float headingHeight; 146 GUI<float>::GetSetting(this, "heading_height", headingHeight); 147 162 148 float xpos = 0; 163 for ( size_t def = 0; def < m_ObjectsDefs.size(); ++def)149 for (COListColumn column : m_Columns) 164 150 { 165 float width = m_ObjectsDefs[def].m_Width;151 float width = column.m_Width; 166 152 // 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;153 if (column.m_Width < 1 && column.m_Width > 0) 154 width *= m_TotalAvailableColumnWidth; 169 155 CPos leftTopCorner = m_CachedActualSize.TopLeft() + CPos(xpos, 0); 170 156 if (mouse.x >= leftTopCorner.x && 171 157 mouse.x < leftTopCorner.x + width && 172 mouse.y < leftTopCorner.y + m_HeadingHeight)158 mouse.y < leftTopCorner.y + headingHeight) 173 159 { 174 if ( def != m_SelectedDef)160 if (column.m_Id != selectedColumn) 175 161 { 176 m_SelectedColumnOrder = 1;177 m_SelectedDef = def;162 selectedColumnOrder = 1; 163 selectedColumn = column.m_Id; 178 164 } 179 165 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); 166 selectedColumnOrder = -selectedColumnOrder; 167 GUI<CStr>::SetSetting(this, "selected_column", column.m_Id); 168 GUI<int>::SetSetting(this, "selected_column_order", selectedColumnOrder); 184 169 ScriptEvent("selectioncolumnchange"); 185 170 186 171 CStrW soundPath; … … 203 188 #define ELMT(x) int elmt_##x = pFile->GetElementID(#x) 204 189 #define ATTR(x) int attr_##x = pFile->GetAttributeID(#x) 205 190 ELMT(item); 206 ELMT( def);191 ELMT(column); 207 192 ELMT(translatableAttribute); 208 193 ATTR(id); 209 194 ATTR(context); … … 213 198 AddItem(child.GetText().FromUTF8(), child.GetText().FromUTF8()); 214 199 return true; 215 200 } 216 else if (child.GetNodeName() == elmt_ def)201 else if (child.GetNodeName() == elmt_column) 217 202 { 218 ObjectDef oDef;203 COListColumn column; 219 204 220 205 for (XMBAttribute attr : child.GetAttributes()) 221 206 { … … 227 212 CColor color; 228 213 if (!GUI<CColor>::ParseString(attr_value.FromUTF8(), color)) 229 214 LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name.c_str(), attr_value.c_str()); 230 else oDef.m_TextColor = color;215 else column.m_TextColor = color; 231 216 } 232 217 else if (attr_name == "id") 233 218 { 234 oDef.m_Id = "list_"+attr_value;219 column.m_Id = attr_value; 235 220 } 236 221 else if (attr_name == "width") 237 222 { … … 243 228 // Check if it's a relative value, and save as decimal if so. 244 229 if (attr_value.find("%") != std::string::npos) 245 230 width = width / 100.f; 246 oDef.m_Width = width;231 column.m_Width = width; 247 232 } 248 233 } 249 234 else if (attr_name == "heading") 250 235 { 251 oDef.m_Heading = attr_value.FromUTF8();236 column.m_Heading = attr_value.FromUTF8(); 252 237 } 253 238 } 254 239 … … 258 243 continue; 259 244 260 245 CStr attributeName(grandchild.GetAttributes().GetNamedItem(attr_id)); 261 // only the heading is translatable for list defs246 // only the heading is translatable for list column 262 247 if (attributeName.empty() || attributeName != "heading") 263 248 { 264 LOGERROR("GUI: translatable attribute in olist defthat isn't a heading. (object: %s)", this->GetPresentableName().c_str());249 LOGERROR("GUI: translatable attribute in olist column that isn't a heading. (object: %s)", this->GetPresentableName().c_str()); 265 250 continue; 266 251 } 267 252 … … 273 258 if (!context.empty()) 274 259 { 275 260 CStr translatedValue(g_L10n.TranslateWithContext(context, value)); 276 oDef.m_Heading = translatedValue.FromUTF8();261 column.m_Heading = translatedValue.FromUTF8(); 277 262 } 278 263 else 279 264 { 280 265 CStr translatedValue(g_L10n.Translate(value)); 281 oDef.m_Heading = translatedValue.FromUTF8();266 column.m_Heading = translatedValue.FromUTF8(); 282 267 } 283 268 } 284 269 285 m_ ObjectsDefs.push_back(oDef);270 m_Columns.push_back(column); 286 271 287 AddSetting(GUIST_CGUIList, oDef.m_Id);272 AddSetting(GUIST_CGUIList, "list_" + column.m_Id); 288 273 SetupText(); 289 274 290 275 return true; … … 318 303 GUI<int>::GetSetting(this, "cell_id", cell_id); 319 304 320 305 CGUIList* pList; 321 GUI<CGUIList>::GetSettingPointer(this, "list _name", pList);306 GUI<CGUIList>::GetSettingPointer(this, "list", pList); 322 307 323 308 GetGUI()->DrawSprite(*sprite, cell_id, bz, rect); 324 309 … … 360 345 } 361 346 } 362 347 363 CColor color;364 GUI< CColor>::GetSetting(this, _textcolor, color);348 float headingHeight; 349 GUI<float>::GetSetting(this, "heading_height", headingHeight); 365 350 366 351 // Draw line above column header 367 352 CGUISpriteInstance* sprite_heading = NULL; 368 353 GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_heading", sprite_heading); 369 354 CRect rect_head(m_CachedActualSize.left, m_CachedActualSize.top, m_CachedActualSize.right, 370 m_CachedActualSize.top + m_HeadingHeight);355 m_CachedActualSize.top + headingHeight); 371 356 GetGUI()->DrawSprite(*sprite_heading, cell_id, bz, rect_head); 372 357 358 int selectedColumnOrder; 359 GUI<int>::GetSetting(this, "selected_column_order", selectedColumnOrder); 360 373 361 CGUISpriteInstance* sprite_order; 374 362 CGUISpriteInstance* sprite_not_sorted; 375 if (m_SelectedColumnOrder != -1) 363 if (selectedColumnOrder == 0) 364 LOGERROR("selected_column_order must not be 0"); 365 else 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