forked from 0ad/0ad
Major ordered list GUI cleanup. Patch by Imarok, fixes #3905.
Remove m_SelectedDef, m_SelectedColumnOrder and m_HeadingHeight. Use GetSetting and SetSetting instead. Thus implement selecting a column / column order sprite from JS correctly. Since the actual list sorting is done in JS, only the column header sprites were inaccurate. Remove "selected_def" since that is redundant with "selected_column". Merge "selected_column" with "default_column" (and "selected_column_order" with "default_column_order") since all properties provided in XML pages are defaults and to remove the copying on init. Rename "def" to "column" and "ObjectDef" to "COListColumn". Replace 30px header height hardcoded in the C++ with an option set by the style. Remove the unneeded requirement to specify a "list_name". Thus rename "list_name" to "list_month" in the replay menu. Remove unneeded "list_" prefix and substr(5) in column checks. Use ranged loops. Fix typo "Avalible". Add an error message if the GUI style doesn't specify the selected column order. This was SVN commit r18652.
This commit is contained in:
parent
a4a99bc129
commit
8f1b37b216
@ -39,6 +39,7 @@
|
||||
<style name = "ModernList"
|
||||
buffer_zone = "5"
|
||||
font = "sans-bold-stroke-14"
|
||||
heading_height="25"
|
||||
scrollbar = "true"
|
||||
scrollbar_style = "ModernScrollBar"
|
||||
sprite = "ModernDarkBoxGoldNoTop"
|
||||
|
@ -52,13 +52,12 @@ ex_settings =
|
||||
attribute button_width { xsd:decimal }?&
|
||||
attribute checked { bool }?&
|
||||
attribute clip { bool }?&
|
||||
attribute default_column { text }?&
|
||||
attribute default_column_order { text }?&
|
||||
attribute dropdown_size { xsd:decimal }?&
|
||||
attribute dropdown_buffer { xsd:decimal }?&
|
||||
attribute enabled { bool }?&
|
||||
attribute font { text }?&
|
||||
attribute fov_wedge_color { ccolor }?&
|
||||
attribute heading_height { text }?&
|
||||
attribute hotkey { text }?&
|
||||
attribute cell_id { xsd:integer }?&
|
||||
attribute independent { bool }?&
|
||||
@ -72,6 +71,8 @@ ex_settings =
|
||||
attribute scrollbar { bool }?&
|
||||
attribute scrollbar_style { text }?&
|
||||
attribute scroll_bottom { bool }?&
|
||||
attribute selected_column { text }?&
|
||||
attribute selected_column_order { text }?&
|
||||
attribute sortable { bool }?&
|
||||
attribute sound_closed { text }?&
|
||||
attribute sound_disabled { text }?&
|
||||
@ -122,7 +123,7 @@ object =
|
||||
((object
|
||||
| action
|
||||
| \attribute
|
||||
| def
|
||||
| column
|
||||
| \include
|
||||
| item
|
||||
| repeat
|
||||
@ -143,8 +144,8 @@ action =
|
||||
(keep | translate)*,
|
||||
attribute id { text }
|
||||
}
|
||||
def =
|
||||
element def {
|
||||
column =
|
||||
element column {
|
||||
translatableAttribute?,
|
||||
(
|
||||
attribute id { text }&
|
||||
|
@ -199,12 +199,6 @@
|
||||
<ref name="bool"/>
|
||||
</attribute>
|
||||
</optional>
|
||||
<optional>
|
||||
<attribute name="default_column"/>
|
||||
</optional>
|
||||
<optional>
|
||||
<attribute name="default_column_order"/>
|
||||
</optional>
|
||||
<optional>
|
||||
<attribute name="dropdown_size">
|
||||
<data type="decimal"/>
|
||||
@ -228,6 +222,9 @@
|
||||
<ref name="ccolor"/>
|
||||
</attribute>
|
||||
</optional>
|
||||
<optional>
|
||||
<attribute name="heading_height"/>
|
||||
</optional>
|
||||
<optional>
|
||||
<attribute name="hotkey"/>
|
||||
</optional>
|
||||
@ -292,6 +289,12 @@
|
||||
<ref name="bool"/>
|
||||
</attribute>
|
||||
</optional>
|
||||
<optional>
|
||||
<attribute name="selected_column"/>
|
||||
</optional>
|
||||
<optional>
|
||||
<attribute name="selected_column_order"/>
|
||||
</optional>
|
||||
<optional>
|
||||
<attribute name="sortable"/>
|
||||
</optional>
|
||||
@ -446,7 +449,7 @@
|
||||
<ref name="object"/>
|
||||
<ref name="action"/>
|
||||
<ref name="attribute"/>
|
||||
<ref name="def"/>
|
||||
<ref name="column"/>
|
||||
<ref name="include"/>
|
||||
<ref name="item"/>
|
||||
<ref name="repeat"/>
|
||||
@ -480,8 +483,8 @@
|
||||
<attribute name="id"/>
|
||||
</element>
|
||||
</define>
|
||||
<define name="def">
|
||||
<element name="def">
|
||||
<define name="column">
|
||||
<element name="column">
|
||||
<optional>
|
||||
<ref name="translatableAttribute"/>
|
||||
</optional>
|
||||
|
@ -86,30 +86,35 @@
|
||||
<translatableAttribute id="caption">Available Mods</translatableAttribute>
|
||||
</object>
|
||||
|
||||
<object name="modsAvailableList" style="ModernList" type="olist" size="0 25 100%-2 100%" font="sans-stroke-13">
|
||||
<object name="modsAvailableList"
|
||||
style="ModernList"
|
||||
type="olist"
|
||||
size="0 25 100%-2 100%"
|
||||
font="sans-stroke-13"
|
||||
>
|
||||
<action on="SelectionChange">showModDescription(this.name);</action>
|
||||
<!-- List headers -->
|
||||
<def id="name" color="100 100 200" width="10%">
|
||||
<column id="name" color="100 100 200" width="10%">
|
||||
<translatableAttribute id="heading">Name</translatableAttribute>
|
||||
</def>
|
||||
<def id="modVersion" color="128 128 128" width="7%">
|
||||
</column>
|
||||
<column id="modVersion" color="128 128 128" width="7%">
|
||||
<translatableAttribute id="heading">Version</translatableAttribute>
|
||||
</def>
|
||||
<def id="modFolderName" color="100 100 200" width="13%">
|
||||
</column>
|
||||
<column id="modFolderName" color="100 100 200" width="13%">
|
||||
<translatableAttribute id="heading">(Folder)</translatableAttribute>
|
||||
</def>
|
||||
<def id="modLabel" color="0 60 0" width="18%">
|
||||
</column>
|
||||
<column id="modLabel" color="0 60 0" width="18%">
|
||||
<translatableAttribute id="heading">Mod Label</translatableAttribute>
|
||||
</def>
|
||||
<def id="modType" color="0 128 128" width="12%">
|
||||
</column>
|
||||
<column id="modType" color="0 128 128" width="12%">
|
||||
<translatableAttribute id="heading">Mod Type</translatableAttribute>
|
||||
</def>
|
||||
<def id="modDependencies" color="128 128 128" width="20%">
|
||||
</column>
|
||||
<column id="modDependencies" color="128 128 128" width="20%">
|
||||
<translatableAttribute id="heading">Dependencies</translatableAttribute>
|
||||
</def>
|
||||
<def id="modURL" color="128 128 128" width="24%">
|
||||
</column>
|
||||
<column id="modURL" color="128 128 128" width="24%">
|
||||
<translatableAttribute id="heading">Website</translatableAttribute>
|
||||
</def>
|
||||
</column>
|
||||
</object>
|
||||
<object name="globalModDescription" type="text" style="ModmodScrollbar" size="0 100%-28 100%-16 100%">
|
||||
<attribute id="caption"><keep>[color="100 100 100"]</keep><translate>Description</translate><keep>[/color]</keep></attribute>
|
||||
@ -127,30 +132,36 @@
|
||||
<translatableAttribute id="caption">Enabled Mods</translatableAttribute>
|
||||
</object>
|
||||
|
||||
<object name="modsEnabledList" style="ModernList" type="olist" size="0 25 96%-5 100%" font="sans-stroke-13" tooltip_style="pgToolTip">
|
||||
<object name="modsEnabledList"
|
||||
style="ModernList"
|
||||
type="olist"
|
||||
size="0 25 96%-5 100%"
|
||||
font="sans-stroke-13"
|
||||
tooltip_style="pgToolTip"
|
||||
>
|
||||
<action on="SelectionChange">showModDescription(this.name);</action>
|
||||
<!-- List headers -->
|
||||
<def id="name" color="100 100 200" width="10%">
|
||||
<column id="name" color="100 100 200" width="10%">
|
||||
<translatableAttribute id="heading">Name</translatableAttribute>
|
||||
</def>
|
||||
<def id="modVersion" color="128 128 128" width="7%">
|
||||
</column>
|
||||
<column id="modVersion" color="128 128 128" width="7%">
|
||||
<translatableAttribute id="heading">Version</translatableAttribute>
|
||||
</def>
|
||||
<def id="modFolderName" color="100 100 200" width="13%">
|
||||
</column>
|
||||
<column id="modFolderName" color="100 100 200" width="13%">
|
||||
<translatableAttribute id="heading">(Folder)</translatableAttribute>
|
||||
</def>
|
||||
<def id="modLabel" color="0 60 0" width="18%">
|
||||
</column>
|
||||
<column id="modLabel" color="0 60 0" width="18%">
|
||||
<translatableAttribute id="heading">Mod Label</translatableAttribute>
|
||||
</def>
|
||||
<def id="modType" color="0 128 128" width="12%">
|
||||
</column>
|
||||
<column id="modType" color="0 128 128" width="12%">
|
||||
<translatableAttribute id="heading">Mod Type</translatableAttribute>
|
||||
</def>
|
||||
<def id="modDependencies" color="128 128 128" width="20%">
|
||||
</column>
|
||||
<column id="modDependencies" color="128 128 128" width="20%">
|
||||
<translatableAttribute id="heading">Dependencies</translatableAttribute>
|
||||
</def>
|
||||
<def id="modURL" color="128 128 128" width="20%">
|
||||
</column>
|
||||
<column id="modURL" color="128 128 128" width="20%">
|
||||
<translatableAttribute id="heading">Website</translatableAttribute>
|
||||
</def>
|
||||
</column>
|
||||
</object>
|
||||
|
||||
<object type="button" style="ModernButtonRed" size="96% 23 100% 40%+12">
|
||||
|
@ -23,16 +23,27 @@
|
||||
|
||||
<!-- Left panel: Player list. -->
|
||||
<object name="leftPanel" size="20 30 20% 100%-280">
|
||||
<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">
|
||||
<def id="status" width="26%">
|
||||
<object name="playersBox"
|
||||
style="ModernList"
|
||||
sprite_asc="ModernArrowDown"
|
||||
selected_column="name"
|
||||
selected_column_order="1"
|
||||
sprite_desc="ModernArrowUp"
|
||||
sprite_not_sorted="ModernNotSorted"
|
||||
type="olist"
|
||||
sortable="true"
|
||||
size="0 0 100% 100%"
|
||||
font="sans-bold-stroke-13"
|
||||
>
|
||||
<column id="status" width="26%">
|
||||
<translatableAttribute id="heading">Status</translatableAttribute>
|
||||
</def>
|
||||
<def id="name" width="48%">
|
||||
</column>
|
||||
<column id="name" width="48%">
|
||||
<translatableAttribute id="heading">Name</translatableAttribute>
|
||||
</def>
|
||||
<def id="rating" width="26%">
|
||||
</column>
|
||||
<column id="rating" width="26%">
|
||||
<translatableAttribute id="heading">Rating</translatableAttribute>
|
||||
</def>
|
||||
</column>
|
||||
<action on="SelectionChange">
|
||||
displayProfile("lobbylist");
|
||||
</action>
|
||||
@ -172,26 +183,36 @@
|
||||
|
||||
<!-- Middle panel: Filters, game list, chat box. -->
|
||||
<object name="middlePanel" size="20%+5 5% 100%-255 97.2%">
|
||||
<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">
|
||||
<object name="gamesBox"
|
||||
style="ModernList"
|
||||
sprite_asc="ModernArrowDown"
|
||||
selected_column="status"
|
||||
selected_column_order="1"
|
||||
sprite_desc="ModernArrowUp"
|
||||
sprite_not_sorted="ModernNotSorted"
|
||||
type="olist"
|
||||
sortable="true"
|
||||
size="0 25 100% 48%"
|
||||
font="sans-stroke-13"
|
||||
>
|
||||
<action on="SelectionChange">updateGameSelection();</action>
|
||||
<action on="SelectionColumnChange">applyFilters();</action>
|
||||
<action on="mouseleftdoubleclickitem">joinButton();</action>
|
||||
<def id="name" color="0 60 0" width="27%">
|
||||
<column id="name" color="0 60 0" width="27%">
|
||||
<translatableAttribute id="heading">Name</translatableAttribute>
|
||||
</def>
|
||||
<!--<def id="ip" heading="IP" color="0 128 128" width="170"/>-->
|
||||
<def id="mapName" color="128 128 128" width="25%">
|
||||
</column>
|
||||
<column id="mapName" color="128 128 128" width="25%">
|
||||
<translatableAttribute id="heading">Map Name</translatableAttribute>
|
||||
</def>
|
||||
<def id="mapSize" color="128 128 128" width="16%">
|
||||
</column>
|
||||
<column id="mapSize" color="128 128 128" width="16%">
|
||||
<translatableAttribute id="heading" context="map">Size</translatableAttribute>
|
||||
</def>
|
||||
<def id="mapType" color="0 128 128" width="16%">
|
||||
</column>
|
||||
<column id="mapType" color="0 128 128" width="16%">
|
||||
<translatableAttribute id="heading" context="map">Type</translatableAttribute>
|
||||
</def>
|
||||
<def id="nPlayers" color="0 128 128" width="16%">
|
||||
</column>
|
||||
<column id="nPlayers" color="0 128 128" width="16%">
|
||||
<translatableAttribute id="heading">Players</translatableAttribute>
|
||||
</def>
|
||||
</column>
|
||||
</object>
|
||||
|
||||
<object name="filterPanel" size="0 0 100% 24">
|
||||
@ -254,15 +275,15 @@
|
||||
style="ModernList"
|
||||
type="olist"
|
||||
size="19 19 100%-19 100%-62">
|
||||
<def id="rank" color="255 255 255" width="15%">
|
||||
<column id="rank" color="255 255 255" width="15%">
|
||||
<translatableAttribute id="heading">Rank</translatableAttribute>
|
||||
</def>
|
||||
<def id="name" color="255 255 255" width="55%">
|
||||
</column>
|
||||
<column id="name" color="255 255 255" width="55%">
|
||||
<translatableAttribute id="heading">Name</translatableAttribute>
|
||||
</def>
|
||||
<def id="rating" color="255 255 255" width="30%">
|
||||
</column>
|
||||
<column id="rating" color="255 255 255" width="30%">
|
||||
<translatableAttribute id="heading">Rating</translatableAttribute>
|
||||
</def>
|
||||
</column>
|
||||
<action on="SelectionChange">
|
||||
displayProfile("leaderboard");
|
||||
</action>
|
||||
|
@ -188,7 +188,7 @@ function filterReplays()
|
||||
let cmpA, cmpB;
|
||||
switch (sortKey)
|
||||
{
|
||||
case 'name':
|
||||
case 'months':
|
||||
cmpA = +a.timestamp;
|
||||
cmpB = +b.timestamp;
|
||||
break;
|
||||
|
@ -218,7 +218,7 @@ function displayReplayList()
|
||||
|
||||
// Push to GUI
|
||||
replaySelection.selected = -1;
|
||||
replaySelection.list_name = list.months || [];
|
||||
replaySelection.list_months = list.months || [];
|
||||
replaySelection.list_players = list.playerNames || [];
|
||||
replaySelection.list_mapName = list.mapNames || [];
|
||||
replaySelection.list_mapSize = list.mapSizes || [];
|
||||
|
@ -63,37 +63,47 @@
|
||||
</object>
|
||||
|
||||
<!-- Replay List in that left panel -->
|
||||
<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">
|
||||
<object name="replaySelection"
|
||||
size="0 35 100% 100%"
|
||||
style="ModernList"
|
||||
type="olist"
|
||||
sortable="true"
|
||||
selected_column="months"
|
||||
selected_column_order="-1"
|
||||
sprite_asc="ModernArrowDown"
|
||||
sprite_desc="ModernArrowUp"
|
||||
sprite_not_sorted="ModernNotSorted"
|
||||
font="sans-stroke-13"
|
||||
>
|
||||
|
||||
<action on="SelectionChange">displayReplayDetails();</action>
|
||||
<action on="SelectionColumnChange">displayReplayList();</action>
|
||||
<action on="mouseleftdoubleclickitem">startReplay();</action>
|
||||
|
||||
<!-- Columns -->
|
||||
<!-- We have to call one "name" as the GUI expects one. -->
|
||||
<def id="name" color="172 172 212" width="12%">
|
||||
<column id="months" color="172 172 212" width="12%">
|
||||
<translatableAttribute id="heading" context="replay">Date / Time</translatableAttribute>
|
||||
</def>
|
||||
</column>
|
||||
|
||||
<def id="players" color="192 192 192" width="44%">
|
||||
<column id="players" color="192 192 192" width="44%">
|
||||
<translatableAttribute id="heading" context="replay">Players</translatableAttribute>
|
||||
</def>
|
||||
</column>
|
||||
|
||||
<def id="mapName" color="192 192 192" width="14%">
|
||||
<column id="mapName" color="192 192 192" width="14%">
|
||||
<translatableAttribute id="heading" context="replay">Map Name</translatableAttribute>
|
||||
</def>
|
||||
</column>
|
||||
|
||||
<def id="mapSize" color="192 192 192" width="10%">
|
||||
<column id="mapSize" color="192 192 192" width="10%">
|
||||
<translatableAttribute id="heading" context="replay">Size</translatableAttribute>
|
||||
</def>
|
||||
</column>
|
||||
|
||||
<def id="popCapacity" color="192 192 192" width="10%">
|
||||
<column id="popCapacity" color="192 192 192" width="10%">
|
||||
<translatableAttribute id="heading" context="replay">Population</translatableAttribute>
|
||||
</def>
|
||||
</column>
|
||||
|
||||
<def id="duration" color="192 192 192" width="10%">
|
||||
<column id="duration" color="192 192 192" width="10%">
|
||||
<translatableAttribute id="heading" context="replay">Duration</translatableAttribute>
|
||||
</def>
|
||||
</column>
|
||||
|
||||
</object>
|
||||
|
||||
|
@ -23,23 +23,16 @@
|
||||
#include "ps/CLogger.h"
|
||||
#include "soundmanager/ISoundManager.h"
|
||||
|
||||
COList::COList()
|
||||
: CList(), m_HeadingHeight(30.f), m_SelectedDef(-1), m_SelectedColumnOrder(0)
|
||||
COList::COList() : CList()
|
||||
{
|
||||
AddSetting(GUIST_CGUISpriteInstance, "sprite_heading");
|
||||
AddSetting(GUIST_float, "heading_height");
|
||||
AddSetting(GUIST_bool, "sortable"); // The actual sorting is done in JS for more versatility
|
||||
AddSetting(GUIST_CStr, "selected_column");
|
||||
AddSetting(GUIST_int, "selected_column_order");
|
||||
AddSetting(GUIST_CStr, "default_column");
|
||||
AddSetting(GUIST_int, "default_column_order");
|
||||
AddSetting(GUIST_int, "selected_def");
|
||||
AddSetting(GUIST_CGUISpriteInstance, "sprite_asc"); // Show the order of sorting
|
||||
AddSetting(GUIST_CGUISpriteInstance, "sprite_desc");
|
||||
AddSetting(GUIST_CGUISpriteInstance, "sprite_not_sorted");
|
||||
|
||||
GUI<CStr>::SetSetting(this, "selected_column", "");
|
||||
GUI<int>::SetSetting(this, "selected_column_order", 0);
|
||||
GUI<int>::SetSetting(this, "selected_def", -1);
|
||||
}
|
||||
|
||||
void COList::SetupText()
|
||||
@ -48,7 +41,7 @@ void COList::SetupText()
|
||||
return;
|
||||
|
||||
CGUIList* pList;
|
||||
GUI<CGUIList>::GetSettingPointer(this, "list_name", pList);
|
||||
GUI<CGUIList>::GetSettingPointer(this, "list", pList);
|
||||
|
||||
m_ItemsYPositions.resize(pList->m_Items.size() + 1);
|
||||
|
||||
@ -73,34 +66,18 @@ void COList::SetupText()
|
||||
if (scrollbar && GetScrollBar(0).GetStyle())
|
||||
width -= GetScrollBar(0).GetStyle()->m_Width;
|
||||
|
||||
m_TotalAvalibleColumnWidth = width;
|
||||
m_TotalAvailableColumnWidth = width;
|
||||
|
||||
float buffer_zone = 0.f;
|
||||
GUI<float>::GetSetting(this, "buffer_zone", buffer_zone);
|
||||
|
||||
CStr defaultColumn;
|
||||
GUI<CStr>::GetSetting(this, "default_column", defaultColumn);
|
||||
defaultColumn = "list_" + defaultColumn;
|
||||
|
||||
for (size_t c = 0; c < m_ObjectsDefs.size(); ++c)
|
||||
for (COListColumn column : m_Columns)
|
||||
{
|
||||
SGUIText* text = new SGUIText();
|
||||
CGUIString gui_string;
|
||||
gui_string.SetValue(m_ObjectsDefs[c].m_Heading);
|
||||
gui_string.SetValue(column.m_Heading);
|
||||
*text = GetGUI()->GenerateText(gui_string, font, width, buffer_zone, this);
|
||||
AddText(text);
|
||||
|
||||
if (m_SelectedDef == (size_t)-1 && defaultColumn == m_ObjectsDefs[c].m_Id)
|
||||
m_SelectedDef = c;
|
||||
}
|
||||
|
||||
if (m_SelectedDef != (size_t)-1)
|
||||
GUI<CStr>::SetSetting(this, "selected_column", m_ObjectsDefs[m_SelectedDef].m_Id.substr(5));
|
||||
|
||||
if (m_SelectedColumnOrder == 0)
|
||||
{
|
||||
GUI<int>::GetSetting(this, "default_column_order", m_SelectedColumnOrder);
|
||||
GUI<int>::SetSetting(this, "selected_column_order", m_SelectedColumnOrder);
|
||||
}
|
||||
|
||||
// Generate texts
|
||||
@ -109,10 +86,10 @@ void COList::SetupText()
|
||||
for (size_t i = 0; i < pList->m_Items.size(); ++i)
|
||||
{
|
||||
m_ItemsYPositions[i] = buffered_y;
|
||||
for (size_t c = 0; c < m_ObjectsDefs.size(); ++c)
|
||||
for (size_t c = 0; c < m_Columns.size(); ++c)
|
||||
{
|
||||
CGUIList* pList_c;
|
||||
GUI<CGUIList>::GetSettingPointer(this, m_ObjectsDefs[c].m_Id, pList_c);
|
||||
GUI<CGUIList>::GetSettingPointer(this, "list_" + m_Columns[c].m_Id, pList_c);
|
||||
SGUIText* text = new SGUIText();
|
||||
*text = GetGUI()->GenerateText(pList_c->m_Items[i], font, width, buffer_zone, this);
|
||||
if (c == 0)
|
||||
@ -125,10 +102,10 @@ void COList::SetupText()
|
||||
|
||||
if (scrollbar)
|
||||
{
|
||||
GetScrollBar(0).SetScrollRange(m_ItemsYPositions.back());
|
||||
GetScrollBar(0).SetScrollSpace(GetListRect().GetHeight());
|
||||
|
||||
CRect rect = GetListRect();
|
||||
GetScrollBar(0).SetScrollRange(m_ItemsYPositions.back());
|
||||
GetScrollBar(0).SetScrollSpace(rect.GetHeight());
|
||||
|
||||
GetScrollBar(0).SetX(rect.right);
|
||||
GetScrollBar(0).SetY(rect.top);
|
||||
GetScrollBar(0).SetZ(GetBufferedZ());
|
||||
@ -138,7 +115,9 @@ void COList::SetupText()
|
||||
|
||||
CRect COList::GetListRect() const
|
||||
{
|
||||
return m_CachedActualSize + CRect(0, m_HeadingHeight, 0, 0);
|
||||
float headingHeight;
|
||||
GUI<float>::GetSetting(this, "heading_height", headingHeight);
|
||||
return m_CachedActualSize + CRect(0, headingHeight, 0, 0);
|
||||
}
|
||||
|
||||
void COList::HandleMessage(SGUIMessage& Message)
|
||||
@ -159,28 +138,34 @@ void COList::HandleMessage(SGUIMessage& Message)
|
||||
if (!m_CachedActualSize.PointInside(mouse))
|
||||
return;
|
||||
|
||||
CStr selectedColumn;
|
||||
GUI<CStr>::GetSetting(this, "selected_column", selectedColumn);
|
||||
int selectedColumnOrder;
|
||||
GUI<int>::GetSetting(this, "selected_column_order", selectedColumnOrder);
|
||||
float headingHeight;
|
||||
GUI<float>::GetSetting(this, "heading_height", headingHeight);
|
||||
|
||||
float xpos = 0;
|
||||
for (size_t def = 0; def < m_ObjectsDefs.size(); ++def)
|
||||
for (COListColumn column : m_Columns)
|
||||
{
|
||||
float width = m_ObjectsDefs[def].m_Width;
|
||||
float width = column.m_Width;
|
||||
// Check if it's a decimal value, and if so, assume relative positioning.
|
||||
if (m_ObjectsDefs[def].m_Width < 1 && m_ObjectsDefs[def].m_Width > 0)
|
||||
width *= m_TotalAvalibleColumnWidth;
|
||||
if (column.m_Width < 1 && column.m_Width > 0)
|
||||
width *= m_TotalAvailableColumnWidth;
|
||||
CPos leftTopCorner = m_CachedActualSize.TopLeft() + CPos(xpos, 0);
|
||||
if (mouse.x >= leftTopCorner.x &&
|
||||
mouse.x < leftTopCorner.x + width &&
|
||||
mouse.y < leftTopCorner.y + m_HeadingHeight)
|
||||
mouse.y < leftTopCorner.y + headingHeight)
|
||||
{
|
||||
if (def != m_SelectedDef)
|
||||
if (column.m_Id != selectedColumn)
|
||||
{
|
||||
m_SelectedColumnOrder = 1;
|
||||
m_SelectedDef = def;
|
||||
selectedColumnOrder = 1;
|
||||
selectedColumn = column.m_Id;
|
||||
}
|
||||
else
|
||||
m_SelectedColumnOrder = -m_SelectedColumnOrder;
|
||||
GUI<CStr>::SetSetting(this, "selected_column", m_ObjectsDefs[def].m_Id.substr(5));
|
||||
GUI<int>::SetSetting(this, "selected_column_order", m_SelectedColumnOrder);
|
||||
GUI<int>::SetSetting(this, "selected_def", def);
|
||||
selectedColumnOrder = -selectedColumnOrder;
|
||||
GUI<CStr>::SetSetting(this, "selected_column", column.m_Id);
|
||||
GUI<int>::SetSetting(this, "selected_column_order", selectedColumnOrder);
|
||||
ScriptEvent("selectioncolumnchange");
|
||||
|
||||
CStrW soundPath;
|
||||
@ -203,7 +188,7 @@ bool COList::HandleAdditionalChildren(const XMBElement& child, CXeromyces* pFile
|
||||
#define ELMT(x) int elmt_##x = pFile->GetElementID(#x)
|
||||
#define ATTR(x) int attr_##x = pFile->GetAttributeID(#x)
|
||||
ELMT(item);
|
||||
ELMT(def);
|
||||
ELMT(column);
|
||||
ELMT(translatableAttribute);
|
||||
ATTR(id);
|
||||
ATTR(context);
|
||||
@ -213,9 +198,9 @@ bool COList::HandleAdditionalChildren(const XMBElement& child, CXeromyces* pFile
|
||||
AddItem(child.GetText().FromUTF8(), child.GetText().FromUTF8());
|
||||
return true;
|
||||
}
|
||||
else if (child.GetNodeName() == elmt_def)
|
||||
else if (child.GetNodeName() == elmt_column)
|
||||
{
|
||||
ObjectDef oDef;
|
||||
COListColumn column;
|
||||
|
||||
for (XMBAttribute attr : child.GetAttributes())
|
||||
{
|
||||
@ -227,11 +212,12 @@ bool COList::HandleAdditionalChildren(const XMBElement& child, CXeromyces* pFile
|
||||
CColor color;
|
||||
if (!GUI<CColor>::ParseString(attr_value.FromUTF8(), color))
|
||||
LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name.c_str(), attr_value.c_str());
|
||||
else oDef.m_TextColor = color;
|
||||
else
|
||||
column.m_TextColor = color;
|
||||
}
|
||||
else if (attr_name == "id")
|
||||
{
|
||||
oDef.m_Id = "list_"+attr_value;
|
||||
column.m_Id = attr_value;
|
||||
}
|
||||
else if (attr_name == "width")
|
||||
{
|
||||
@ -243,12 +229,12 @@ bool COList::HandleAdditionalChildren(const XMBElement& child, CXeromyces* pFile
|
||||
// Check if it's a relative value, and save as decimal if so.
|
||||
if (attr_value.find("%") != std::string::npos)
|
||||
width = width / 100.f;
|
||||
oDef.m_Width = width;
|
||||
column.m_Width = width;
|
||||
}
|
||||
}
|
||||
else if (attr_name == "heading")
|
||||
{
|
||||
oDef.m_Heading = attr_value.FromUTF8();
|
||||
column.m_Heading = attr_value.FromUTF8();
|
||||
}
|
||||
}
|
||||
|
||||
@ -258,10 +244,10 @@ bool COList::HandleAdditionalChildren(const XMBElement& child, CXeromyces* pFile
|
||||
continue;
|
||||
|
||||
CStr attributeName(grandchild.GetAttributes().GetNamedItem(attr_id));
|
||||
// only the heading is translatable for list defs
|
||||
// only the heading is translatable for list column
|
||||
if (attributeName.empty() || attributeName != "heading")
|
||||
{
|
||||
LOGERROR("GUI: translatable attribute in olist def that isn't a heading. (object: %s)", this->GetPresentableName().c_str());
|
||||
LOGERROR("GUI: translatable attribute in olist column that isn't a heading. (object: %s)", this->GetPresentableName().c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -273,18 +259,18 @@ bool COList::HandleAdditionalChildren(const XMBElement& child, CXeromyces* pFile
|
||||
if (!context.empty())
|
||||
{
|
||||
CStr translatedValue(g_L10n.TranslateWithContext(context, value));
|
||||
oDef.m_Heading = translatedValue.FromUTF8();
|
||||
column.m_Heading = translatedValue.FromUTF8();
|
||||
}
|
||||
else
|
||||
{
|
||||
CStr translatedValue(g_L10n.Translate(value));
|
||||
oDef.m_Heading = translatedValue.FromUTF8();
|
||||
column.m_Heading = translatedValue.FromUTF8();
|
||||
}
|
||||
}
|
||||
|
||||
m_ObjectsDefs.push_back(oDef);
|
||||
m_Columns.push_back(column);
|
||||
|
||||
AddSetting(GUIST_CGUIList, oDef.m_Id);
|
||||
AddSetting(GUIST_CGUIList, "list_" + column.m_Id);
|
||||
SetupText();
|
||||
|
||||
return true;
|
||||
@ -318,7 +304,7 @@ void COList::DrawList(const int& selected, const CStr& _sprite, const CStr& _spr
|
||||
GUI<int>::GetSetting(this, "cell_id", cell_id);
|
||||
|
||||
CGUIList* pList;
|
||||
GUI<CGUIList>::GetSettingPointer(this, "list_name", pList);
|
||||
GUI<CGUIList>::GetSettingPointer(this, "list", pList);
|
||||
|
||||
GetGUI()->DrawSprite(*sprite, cell_id, bz, rect);
|
||||
|
||||
@ -360,38 +346,48 @@ void COList::DrawList(const int& selected, const CStr& _sprite, const CStr& _spr
|
||||
}
|
||||
}
|
||||
|
||||
CColor color;
|
||||
GUI<CColor>::GetSetting(this, _textcolor, color);
|
||||
float headingHeight;
|
||||
GUI<float>::GetSetting(this, "heading_height", headingHeight);
|
||||
|
||||
// Draw line above column header
|
||||
CGUISpriteInstance* sprite_heading = NULL;
|
||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_heading", sprite_heading);
|
||||
CRect rect_head(m_CachedActualSize.left, m_CachedActualSize.top, m_CachedActualSize.right,
|
||||
m_CachedActualSize.top + m_HeadingHeight);
|
||||
m_CachedActualSize.top + headingHeight);
|
||||
GetGUI()->DrawSprite(*sprite_heading, cell_id, bz, rect_head);
|
||||
|
||||
int selectedColumnOrder;
|
||||
GUI<int>::GetSetting(this, "selected_column_order", selectedColumnOrder);
|
||||
|
||||
CGUISpriteInstance* sprite_order;
|
||||
CGUISpriteInstance* sprite_not_sorted;
|
||||
if (m_SelectedColumnOrder != -1)
|
||||
if (selectedColumnOrder == 0)
|
||||
LOGERROR("selected_column_order must not be 0");
|
||||
else if (selectedColumnOrder != -1)
|
||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_asc", sprite_order);
|
||||
else
|
||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_desc", sprite_order);
|
||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_not_sorted", sprite_not_sorted);
|
||||
|
||||
CStr selectedColumn;
|
||||
GUI<CStr>::GetSetting(this, "selected_column", selectedColumn);
|
||||
|
||||
// Draw column headers
|
||||
CColor color;
|
||||
GUI<CColor>::GetSetting(this, _textcolor, color);
|
||||
float xpos = 0;
|
||||
for (size_t def = 0; def < m_ObjectsDefs.size(); ++def)
|
||||
for (size_t col = 0; col < m_Columns.size(); ++col)
|
||||
{
|
||||
// Check if it's a decimal value, and if so, assume relative positioning.
|
||||
float width = m_ObjectsDefs[def].m_Width;
|
||||
if (m_ObjectsDefs[def].m_Width < 1 && m_ObjectsDefs[def].m_Width > 0)
|
||||
width *= m_TotalAvalibleColumnWidth;
|
||||
float width = m_Columns[col].m_Width;
|
||||
if (m_Columns[col].m_Width < 1 && m_Columns[col].m_Width > 0)
|
||||
width *= m_TotalAvailableColumnWidth;
|
||||
|
||||
CPos leftTopCorner = m_CachedActualSize.TopLeft() + CPos(xpos, 0);
|
||||
|
||||
CGUISpriteInstance* sprite;
|
||||
// If the list sorted by current column
|
||||
if (m_SelectedDef == def)
|
||||
if (selectedColumn == m_Columns[col].m_Id)
|
||||
sprite = sprite_order;
|
||||
else
|
||||
sprite = sprite_not_sorted;
|
||||
@ -400,12 +396,12 @@ void COList::DrawList(const int& selected, const CStr& _sprite, const CStr& _spr
|
||||
GetGUI()->DrawSprite(*sprite, cell_id, bz + 0.1f, CRect(leftTopCorner + CPos(width - 16, 0), leftTopCorner + CPos(width, 16)));
|
||||
|
||||
// Draw column header text
|
||||
DrawText(def, color, leftTopCorner + CPos(0, 4), bz + 0.1f, rect_head);
|
||||
DrawText(col, color, leftTopCorner + CPos(0, 4), bz + 0.1f, rect_head);
|
||||
xpos += width;
|
||||
}
|
||||
|
||||
// Draw list items for each column
|
||||
const size_t objectsCount = m_ObjectsDefs.size();
|
||||
const size_t objectsCount = m_Columns.size();
|
||||
for (size_t i = 0; i < pList->m_Items.size(); ++i)
|
||||
{
|
||||
if (m_ItemsYPositions[i+1] - scroll < 0 ||
|
||||
@ -430,15 +426,15 @@ void COList::DrawList(const int& selected, const CStr& _sprite, const CStr& _spr
|
||||
|
||||
// Draw all items for that column
|
||||
xpos = 0;
|
||||
for (size_t def = 0; def < objectsCount; ++def)
|
||||
for (size_t col = 0; col < objectsCount; ++col)
|
||||
{
|
||||
// Determine text position and width
|
||||
const CPos textPos = rect.TopLeft() + CPos(xpos, -scroll + m_ItemsYPositions[i]);
|
||||
|
||||
float width = m_ObjectsDefs[def].m_Width;;
|
||||
float width = m_Columns[col].m_Width;
|
||||
// Check if it's a decimal value, and if so, assume relative positioning.
|
||||
if (m_ObjectsDefs[def].m_Width < 1 && m_ObjectsDefs[def].m_Width > 0)
|
||||
width *= m_TotalAvalibleColumnWidth;
|
||||
if (m_Columns[col].m_Width < 1 && m_Columns[col].m_Width > 0)
|
||||
width *= m_TotalAvailableColumnWidth;
|
||||
|
||||
// Clip text to the column (to prevent drawing text into the neighboring column)
|
||||
CRect cliparea2 = cliparea;
|
||||
@ -446,7 +442,7 @@ void COList::DrawList(const int& selected, const CStr& _sprite, const CStr& _spr
|
||||
cliparea2.bottom = std::min(cliparea2.bottom, textPos.y + rowHeight);
|
||||
|
||||
// Draw list item
|
||||
DrawText(objectsCount * (i+/*Heading*/1) + def, m_ObjectsDefs[def].m_TextColor, textPos, bz+0.1f, cliparea2);
|
||||
DrawText(objectsCount * (i +/*Heading*/1) + col, m_Columns[col].m_TextColor, textPos, bz + 0.1f, cliparea2);
|
||||
xpos += width;
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@
|
||||
/**
|
||||
* Represents a column.
|
||||
*/
|
||||
struct ObjectDef
|
||||
struct COListColumn
|
||||
{
|
||||
CColor m_TextColor;
|
||||
CStr m_Id;
|
||||
@ -63,22 +63,11 @@ protected:
|
||||
/**
|
||||
* Available columns.
|
||||
*/
|
||||
std::vector<ObjectDef> m_ObjectsDefs;
|
||||
|
||||
/**
|
||||
* Index of the selected column.
|
||||
*/
|
||||
size_t m_SelectedDef;
|
||||
|
||||
/**
|
||||
* +1 for ascending, -1 for descending sort order.
|
||||
*/
|
||||
int m_SelectedColumnOrder;
|
||||
std::vector<COListColumn> m_Columns;
|
||||
|
||||
private:
|
||||
float m_HeadingHeight;
|
||||
// Width of space avalible for columns
|
||||
float m_TotalAvalibleColumnWidth;
|
||||
// Width of space available for columns
|
||||
float m_TotalAvailableColumnWidth;
|
||||
};
|
||||
|
||||
#endif // INCLUDED_COLIST
|
||||
|
Loading…
Reference in New Issue
Block a user