Ticket #3905: 3905_COList_refresh_v3.patch
File 3905_COList_refresh_v3.patch, 21.3 KB (added by , 8 years ago) |
---|
-
binaries/data/mods/mod/gui/gui.rnc
122 122 ((object 123 123 | action 124 124 | \attribute 125 | def125 | column 126 126 | \include 127 127 | item 128 128 | repeat … … 143 143 (keep | translate)*, 144 144 attribute id { text } 145 145 } 146 def=147 element def{146 column = 147 element column { 148 148 translatableAttribute?, 149 149 ( 150 150 attribute id { text }& -
binaries/data/mods/mod/gui/gui.rng
446 446 <ref name="object"/> 447 447 <ref name="action"/> 448 448 <ref name="attribute"/> 449 <ref name=" def"/>449 <ref name="column"/> 450 450 <ref name="include"/> 451 451 <ref name="item"/> 452 452 <ref name="repeat"/> … … 480 480 <attribute name="id"/> 481 481 </element> 482 482 </define> 483 <define name=" def">484 <element name=" def">483 <define name="column"> 484 <element name="column"> 485 485 <optional> 486 486 <ref name="translatableAttribute"/> 487 487 </optional> -
binaries/data/mods/mod/gui/modmod/modmod.xml
89 89 <object name="modsAvailableList" style="ModernList" type="olist" size="0 25 100%-2 100%" font="sans-stroke-13"> 90 90 <action on="SelectionChange">showModDescription(this.name);</action> 91 91 <!-- List headers --> 92 < defid="name" color="100 100 200" width="10%">92 <column id="name" color="100 100 200" width="10%"> 93 93 <translatableAttribute id="heading">Name</translatableAttribute> 94 </ def>95 < defid="modVersion" color="128 128 128" width="7%">94 </column> 95 <column id="modVersion" color="128 128 128" width="7%"> 96 96 <translatableAttribute id="heading">Version</translatableAttribute> 97 </ def>98 < defid="modFolderName" color="100 100 200" width="13%">97 </column> 98 <column id="modFolderName" color="100 100 200" width="13%"> 99 99 <translatableAttribute id="heading">(Folder)</translatableAttribute> 100 </ def>101 < defid="modLabel" color="0 60 0" width="18%">100 </column> 101 <column id="modLabel" color="0 60 0" width="18%"> 102 102 <translatableAttribute id="heading">Mod Label</translatableAttribute> 103 </ def>104 < defid="modType" color="0 128 128" width="12%">103 </column> 104 <column id="modType" color="0 128 128" width="12%"> 105 105 <translatableAttribute id="heading">Mod Type</translatableAttribute> 106 </ def>107 < defid="modDependencies" color="128 128 128" width="20%">106 </column> 107 <column id="modDependencies" color="128 128 128" width="20%"> 108 108 <translatableAttribute id="heading">Dependencies</translatableAttribute> 109 </ def>110 < defid="modURL" color="128 128 128" width="24%">109 </column> 110 <column id="modURL" color="128 128 128" width="24%"> 111 111 <translatableAttribute id="heading">Website</translatableAttribute> 112 </ def>112 </column> 113 113 </object> 114 114 <object name="globalModDescription" type="text" style="ModmodScrollbar" size="0 100%-28 100%-16 100%"> 115 115 <attribute id="caption"><keep>[color="100 100 100"]</keep><translate>Description</translate><keep>[/color]</keep></attribute> … … 130 130 <object name="modsEnabledList" style="ModernList" type="olist" size="0 25 96%-5 100%" font="sans-stroke-13" tooltip_style="pgToolTip"> 131 131 <action on="SelectionChange">showModDescription(this.name);</action> 132 132 <!-- List headers --> 133 < defid="name" color="100 100 200" width="10%">133 <column id="name" color="100 100 200" width="10%"> 134 134 <translatableAttribute id="heading">Name</translatableAttribute> 135 </ def>136 < defid="modVersion" color="128 128 128" width="7%">135 </column> 136 <column id="modVersion" color="128 128 128" width="7%"> 137 137 <translatableAttribute id="heading">Version</translatableAttribute> 138 </ def>139 < defid="modFolderName" color="100 100 200" width="13%">138 </column> 139 <column id="modFolderName" color="100 100 200" width="13%"> 140 140 <translatableAttribute id="heading">(Folder)</translatableAttribute> 141 </ def>142 < defid="modLabel" color="0 60 0" width="18%">141 </column> 142 <column id="modLabel" color="0 60 0" width="18%"> 143 143 <translatableAttribute id="heading">Mod Label</translatableAttribute> 144 </ def>145 < defid="modType" color="0 128 128" width="12%">144 </column> 145 <column id="modType" color="0 128 128" width="12%"> 146 146 <translatableAttribute id="heading">Mod Type</translatableAttribute> 147 </ def>148 < defid="modDependencies" color="128 128 128" width="20%">147 </column> 148 <column id="modDependencies" color="128 128 128" width="20%"> 149 149 <translatableAttribute id="heading">Dependencies</translatableAttribute> 150 </ def>151 < defid="modURL" color="128 128 128" width="20%">150 </column> 151 <column id="modURL" color="128 128 128" width="20%"> 152 152 <translatableAttribute id="heading">Website</translatableAttribute> 153 </ def>153 </column> 154 154 </object> 155 155 156 156 <object type="button" style="ModernButtonRed" size="96% 23 100% 40%+12"> -
binaries/data/mods/public/gui/lobby/lobby.xml
24 24 <!-- Left panel: Player list. --> 25 25 <object name="leftPanel" size="20 30 20% 100%-280"> 26 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 < defid="status" width="26%">27 <column id="status" width="26%"> 28 28 <translatableAttribute id="heading">Status</translatableAttribute> 29 </ def>30 < defid="name" width="48%">29 </column> 30 <column id="name" width="48%"> 31 31 <translatableAttribute id="heading">Name</translatableAttribute> 32 </ def>33 < defid="rating" width="26%">32 </column> 33 <column id="rating" width="26%"> 34 34 <translatableAttribute id="heading">Rating</translatableAttribute> 35 </ def>35 </column> 36 36 <action on="SelectionChange"> 37 37 displayProfile("lobbylist"); 38 38 </action> … … 176 176 <action on="SelectionChange">updateGameSelection();</action> 177 177 <action on="SelectionColumnChange">applyFilters();</action> 178 178 <action on="mouseleftdoubleclickitem">joinButton();</action> 179 < defid="name" color="0 60 0" width="27%">179 <column id="name" color="0 60 0" width="27%"> 180 180 <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%">181 </column> 182 <!--<column id="ip" heading="IP" color="0 128 128" width="170"/>--> 183 <column id="mapName" color="128 128 128" width="25%"> 184 184 <translatableAttribute id="heading">Map Name</translatableAttribute> 185 </ def>186 < defid="mapSize" color="128 128 128" width="16%">185 </column> 186 <column id="mapSize" color="128 128 128" width="16%"> 187 187 <translatableAttribute id="heading" context="map">Size</translatableAttribute> 188 </ def>189 < defid="mapType" color="0 128 128" width="16%">188 </column> 189 <column id="mapType" color="0 128 128" width="16%"> 190 190 <translatableAttribute id="heading" context="map">Type</translatableAttribute> 191 </ def>192 < defid="nPlayers" color="0 128 128" width="16%">191 </column> 192 <column id="nPlayers" color="0 128 128" width="16%"> 193 193 <translatableAttribute id="heading">Players</translatableAttribute> 194 </ def>194 </column> 195 195 </object> 196 196 197 197 <object name="filterPanel" size="0 0 100% 24"> … … 254 254 style="ModernList" 255 255 type="olist" 256 256 size="19 19 100%-19 100%-62"> 257 < defid="rank" color="255 255 255" width="15%">257 <column id="rank" color="255 255 255" width="15%"> 258 258 <translatableAttribute id="heading">Rank</translatableAttribute> 259 </ def>260 < defid="name" color="255 255 255" width="55%">259 </column> 260 <column id="name" color="255 255 255" width="55%"> 261 261 <translatableAttribute id="heading">Name</translatableAttribute> 262 </ def>263 < defid="rating" color="255 255 255" width="30%">262 </column> 263 <column id="rating" color="255 255 255" width="30%"> 264 264 <translatableAttribute id="heading">Rating</translatableAttribute> 265 </ def>265 </column> 266 266 <action on="SelectionChange"> 267 267 displayProfile("leaderboard"); 268 268 </action> -
binaries/data/mods/public/gui/replaymenu/replay_menu.xml
71 71 72 72 <!-- Columns --> 73 73 <!-- We have to call one "name" as the GUI expects one. --> 74 < defid="name" color="172 172 212" width="12%">74 <column id="name" color="172 172 212" width="12%"> 75 75 <translatableAttribute id="heading" context="replay">Date / Time</translatableAttribute> 76 </ def>76 </column> 77 77 78 < defid="players" color="192 192 192" width="44%">78 <column id="players" color="192 192 192" width="44%"> 79 79 <translatableAttribute id="heading" context="replay">Players</translatableAttribute> 80 </ def>80 </column> 81 81 82 < defid="mapName" color="192 192 192" width="14%">82 <column id="mapName" color="192 192 192" width="14%"> 83 83 <translatableAttribute id="heading" context="replay">Map Name</translatableAttribute> 84 </ def>84 </column> 85 85 86 < defid="mapSize" color="192 192 192" width="10%">86 <column id="mapSize" color="192 192 192" width="10%"> 87 87 <translatableAttribute id="heading" context="replay">Size</translatableAttribute> 88 </ def>88 </column> 89 89 90 < defid="popCapacity" color="192 192 192" width="10%">90 <column id="popCapacity" color="192 192 192" width="10%"> 91 91 <translatableAttribute id="heading" context="replay">Population</translatableAttribute> 92 </ def>92 </column> 93 93 94 < defid="duration" color="192 192 192" width="10%">94 <column id="duration" color="192 192 192" width="10%"> 95 95 <translatableAttribute id="heading" context="replay">Duration</translatableAttribute> 96 </ def>96 </column> 97 97 98 98 </object> 99 99 -
source/gui/COList.cpp
24 24 #include "soundmanager/ISoundManager.h" 25 25 26 26 COList::COList() 27 : CList(), m_HeadingHeight(30.f), m_Selected Def(-1), m_SelectedColumnOrder(0)27 : CList(), m_HeadingHeight(30.f), m_SelectedColumn(""), m_SelectedColumnOrder(0) 28 28 { 29 29 AddSetting(GUIST_CGUISpriteInstance, "sprite_heading"); 30 30 AddSetting(GUIST_bool, "sortable"); // The actual sorting is done in JS for more versatility … … 32 32 AddSetting(GUIST_int, "selected_column_order"); 33 33 AddSetting(GUIST_CStr, "default_column"); 34 34 AddSetting(GUIST_int, "default_column_order"); 35 AddSetting(GUIST_int, "selected_def");36 35 AddSetting(GUIST_CGUISpriteInstance, "sprite_asc"); // Show the order of sorting 37 36 AddSetting(GUIST_CGUISpriteInstance, "sprite_desc"); 38 37 AddSetting(GUIST_CGUISpriteInstance, "sprite_not_sorted"); … … 39 38 40 39 GUI<CStr>::SetSetting(this, "selected_column", ""); 41 40 GUI<int>::SetSetting(this, "selected_column_order", 0); 42 GUI<int>::SetSetting(this, "selected_def", -1);43 41 } 44 42 45 43 void COList::SetupText() … … 73 71 if (scrollbar && GetScrollBar(0).GetStyle()) 74 72 width -= GetScrollBar(0).GetStyle()->m_Width; 75 73 76 m_TotalAva libleColumnWidth = width;74 m_TotalAvailbleColumnWidth = width; 77 75 78 76 float buffer_zone = 0.f; 79 77 GUI<float>::GetSetting(this, "buffer_zone", buffer_zone); 80 78 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) 79 for (COListColumn column : m_Columns) 86 80 { 87 81 SGUIText* text = new SGUIText(); 88 82 CGUIString gui_string; 89 gui_string.SetValue( m_ObjectsDefs[c].m_Heading);83 gui_string.SetValue(column.m_Heading); 90 84 *text = GetGUI()->GenerateText(gui_string, font, width, buffer_zone, this); 91 85 AddText(text); 92 93 if (m_SelectedDef == (size_t)-1 && defaultColumn == m_ObjectsDefs[c].m_Id)94 m_SelectedDef = c;95 86 } 96 87 97 if (m_Selected Def != (size_t)-1)98 GUI<CStr>:: SetSetting(this, "selected_column", m_ObjectsDefs[m_SelectedDef].m_Id.substr(5));88 if (m_SelectedColumn == "") 89 GUI<CStr>::GetSetting(this, "default_column", m_SelectedColumn); 99 90 91 if (m_SelectedColumn != "") 92 GUI<CStr>::SetSetting(this, "selected_column", m_SelectedColumn); 93 100 94 if (m_SelectedColumnOrder == 0) 101 95 { 102 96 GUI<int>::GetSetting(this, "default_column_order", m_SelectedColumnOrder); … … 109 103 for (size_t i = 0; i < pList->m_Items.size(); ++i) 110 104 { 111 105 m_ItemsYPositions[i] = buffered_y; 112 for (size_t c = 0; c < m_ ObjectsDefs.size(); ++c)106 for (size_t c = 0; c < m_Columns.size(); ++c) 113 107 { 114 108 CGUIList* pList_c; 115 GUI<CGUIList>::GetSettingPointer(this, m_ObjectsDefs[c].m_Id, pList_c);109 GUI<CGUIList>::GetSettingPointer(this, "list_" + m_Columns[c].m_Id, pList_c); 116 110 SGUIText* text = new SGUIText(); 117 111 *text = GetGUI()->GenerateText(pList_c->m_Items[i], font, width, buffer_zone, this); 118 112 if (c == 0) … … 147 141 148 142 switch (Message.type) 149 143 { 144 case GUIM_SETTINGS_UPDATED: 145 { 146 if (Message.value == "selected_column_order") 147 GUI<int>::GetSetting(this, "selected_column_order", m_SelectedColumnOrder); 148 else if (Message.value == "selected_column") 149 GUI<CStr>::GetSetting(this, "selected_column", m_SelectedColumn); 150 return; 151 } 150 152 // If somebody clicks on the column heading 151 153 case GUIM_MOUSE_PRESS_LEFT: 152 154 { … … 160 162 return; 161 163 162 164 float xpos = 0; 163 for ( size_t def = 0; def < m_ObjectsDefs.size(); ++def)165 for (COListColumn column : m_Columns) 164 166 { 165 float width = m_ObjectsDefs[def].m_Width;167 float width = column.m_Width; 166 168 // 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;169 if (column.m_Width < 1 && column.m_Width > 0) 170 width *= m_TotalAvailbleColumnWidth; 169 171 CPos leftTopCorner = m_CachedActualSize.TopLeft() + CPos(xpos, 0); 170 172 if (mouse.x >= leftTopCorner.x && 171 173 mouse.x < leftTopCorner.x + width && 172 174 mouse.y < leftTopCorner.y + m_HeadingHeight) 173 175 { 174 if ( def != m_SelectedDef)176 if (column.m_Id != m_SelectedColumn) 175 177 { 176 178 m_SelectedColumnOrder = 1; 177 m_Selected Def = def;179 m_SelectedColumn = column.m_Id; 178 180 } 179 181 else 180 182 m_SelectedColumnOrder = -m_SelectedColumnOrder; 181 GUI<CStr>::SetSetting(this, "selected_column", m_ObjectsDefs[def].m_Id.substr(5));183 GUI<CStr>::SetSetting(this, "selected_column", column.m_Id); 182 184 GUI<int>::SetSetting(this, "selected_column_order", m_SelectedColumnOrder); 183 GUI<int>::SetSetting(this, "selected_def", def);184 185 ScriptEvent("selectioncolumnchange"); 185 186 186 187 CStrW soundPath; … … 203 204 #define ELMT(x) int elmt_##x = pFile->GetElementID(#x) 204 205 #define ATTR(x) int attr_##x = pFile->GetAttributeID(#x) 205 206 ELMT(item); 206 ELMT( def);207 ELMT(column); 207 208 ELMT(translatableAttribute); 208 209 ATTR(id); 209 210 ATTR(context); … … 213 214 AddItem(child.GetText().FromUTF8(), child.GetText().FromUTF8()); 214 215 return true; 215 216 } 216 else if (child.GetNodeName() == elmt_ def)217 else if (child.GetNodeName() == elmt_column) 217 218 { 218 ObjectDef oDef;219 COListColumn column; 219 220 220 221 for (XMBAttribute attr : child.GetAttributes()) 221 222 { … … 227 228 CColor color; 228 229 if (!GUI<CColor>::ParseString(attr_value.FromUTF8(), color)) 229 230 LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name.c_str(), attr_value.c_str()); 230 else oDef.m_TextColor = color;231 else column.m_TextColor = color; 231 232 } 232 233 else if (attr_name == "id") 233 234 { 234 oDef.m_Id = "list_"+attr_value;235 column.m_Id = attr_value; 235 236 } 236 237 else if (attr_name == "width") 237 238 { … … 243 244 // Check if it's a relative value, and save as decimal if so. 244 245 if (attr_value.find("%") != std::string::npos) 245 246 width = width / 100.f; 246 oDef.m_Width = width;247 column.m_Width = width; 247 248 } 248 249 } 249 250 else if (attr_name == "heading") 250 251 { 251 oDef.m_Heading = attr_value.FromUTF8();252 column.m_Heading = attr_value.FromUTF8(); 252 253 } 253 254 } 254 255 … … 258 259 continue; 259 260 260 261 CStr attributeName(grandchild.GetAttributes().GetNamedItem(attr_id)); 261 // only the heading is translatable for list defs262 // only the heading is translatable for list column 262 263 if (attributeName.empty() || attributeName != "heading") 263 264 { 264 LOGERROR("GUI: translatable attribute in olist defthat isn't a heading. (object: %s)", this->GetPresentableName().c_str());265 LOGERROR("GUI: translatable attribute in olist column that isn't a heading. (object: %s)", this->GetPresentableName().c_str()); 265 266 continue; 266 267 } 267 268 … … 273 274 if (!context.empty()) 274 275 { 275 276 CStr translatedValue(g_L10n.TranslateWithContext(context, value)); 276 oDef.m_Heading = translatedValue.FromUTF8();277 column.m_Heading = translatedValue.FromUTF8(); 277 278 } 278 279 else 279 280 { 280 281 CStr translatedValue(g_L10n.Translate(value)); 281 oDef.m_Heading = translatedValue.FromUTF8();282 column.m_Heading = translatedValue.FromUTF8(); 282 283 } 283 284 } 284 285 285 m_ ObjectsDefs.push_back(oDef);286 m_Columns.push_back(column); 286 287 287 AddSetting(GUIST_CGUIList, oDef.m_Id);288 AddSetting(GUIST_CGUIList, "list_" + column.m_Id); 288 289 SetupText(); 289 290 290 291 return true; … … 380 381 381 382 // Draw column headers 382 383 float xpos = 0; 383 for (size_t def = 0; def < m_ObjectsDefs.size(); ++def)384 for (size_t col = 0; col < m_Columns.size(); ++col) 384 385 { 385 386 // 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;387 float width = m_Columns[col].m_Width; 388 if (m_Columns[col].m_Width < 1 && m_Columns[col].m_Width > 0) 389 width *= m_TotalAvailbleColumnWidth; 389 390 390 391 CPos leftTopCorner = m_CachedActualSize.TopLeft() + CPos(xpos, 0); 391 392 392 393 CGUISpriteInstance* sprite; 393 394 // If the list sorted by current column 394 if (m_Selected Def == def)395 if (m_SelectedColumn == m_Columns[col].m_Id) 395 396 sprite = sprite_order; 396 397 else 397 398 sprite = sprite_not_sorted; … … 400 401 GetGUI()->DrawSprite(*sprite, cell_id, bz + 0.1f, CRect(leftTopCorner + CPos(width - 16, 0), leftTopCorner + CPos(width, 16))); 401 402 402 403 // Draw column header text 403 DrawText( def, color, leftTopCorner + CPos(0, 4), bz + 0.1f, rect_head);404 DrawText(col, color, leftTopCorner + CPos(0, 4), bz + 0.1f, rect_head); 404 405 xpos += width; 405 406 } 406 407 407 408 // Draw list items for each column 408 const size_t objectsCount = m_ ObjectsDefs.size();409 const size_t objectsCount = m_Columns.size(); 409 410 for (size_t i = 0; i < pList->m_Items.size(); ++i) 410 411 { 411 412 if (m_ItemsYPositions[i+1] - scroll < 0 || … … 430 431 431 432 // Draw all items for that column 432 433 xpos = 0; 433 for (size_t def = 0; def < objectsCount; ++def)434 for (size_t col = 0; col < objectsCount; ++col) 434 435 { 435 436 // Determine text position and width 436 437 const CPos textPos = rect.TopLeft() + CPos(xpos, -scroll + m_ItemsYPositions[i]); 437 438 438 float width = m_ ObjectsDefs[def].m_Width;;439 float width = m_Columns[col].m_Width;; 439 440 // 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;441 if (m_Columns[col].m_Width < 1 && m_Columns[col].m_Width > 0) 442 width *= m_TotalAvailbleColumnWidth; 442 443 443 444 // Clip text to the column (to prevent drawing text into the neighboring column) 444 445 CRect cliparea2 = cliparea; … … 446 447 cliparea2.bottom = std::min(cliparea2.bottom, textPos.y + rowHeight); 447 448 448 449 // Draw list item 449 DrawText(objectsCount * (i +/*Heading*/1) + def, m_ObjectsDefs[def].m_TextColor, textPos, bz+0.1f, cliparea2);450 DrawText(objectsCount * (i +/*Heading*/1) + col, m_Columns[col].m_TextColor, textPos, bz + 0.1f, cliparea2); 450 451 xpos += width; 451 452 } 452 453 } -
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 68 /** 69 69 * Index of the selected column. 70 70 */ 71 size_t m_SelectedDef;71 CStr m_SelectedColumn; 72 72 73 73 /** 74 74 * +1 for ascending, -1 for descending sort order. … … 77 77 78 78 private: 79 79 float m_HeadingHeight; 80 // Width of space ava lible for columns81 float m_TotalAva libleColumnWidth;80 // Width of space availble for columns 81 float m_TotalAvailbleColumnWidth; 82 82 }; 83 83 84 84 #endif // INCLUDED_COLIST