From 7667dac8423ac275d8290014647fb27903865c6f Mon Sep 17 00:00:00 2001 From: Aki Date: Sat, 23 Mar 2024 22:50:14 +0100 Subject: You may no longer attempt to join server with mismatched version --- StarsEx/ListBox.cpp | 52 ++++++++++++++++++++++++++++++++---------------- StarsEx/ListBox.h | 4 ++-- StarsEx/NetClientDlg.cpp | 7 +++++-- 3 files changed, 42 insertions(+), 21 deletions(-) (limited to 'StarsEx') diff --git a/StarsEx/ListBox.cpp b/StarsEx/ListBox.cpp index 8d52cfe..1f6fbed 100644 --- a/StarsEx/ListBox.cpp +++ b/StarsEx/ListBox.cpp @@ -27,10 +27,12 @@ class ListBoxCell public: static const char* TYPENAME() { return "ListBoxCell"; } - ListBoxCell() : data(0), image(0) { } + ListBoxCell() : data(0), color(Color::White), use_color(false), image(0) { } Text text; DWORD data; + Color color; + bool use_color; Bitmap* image; }; @@ -330,7 +332,7 @@ ListBox::DrawContent(const Rect& ctrl_rect) item_rect.h = h - item_rect.y - 1; } - Color item_color = GetItemColor(index-1, 0); + Color item_color = GetItemColor(index-1); if (item->selected) { font->SetColor(selected_color); @@ -521,6 +523,23 @@ Color ListBox::GetItemColor(int index) return Color::White; } +Color ListBox::GetItemColor(int index, int column) +{ + if (column == 0) + return GetItemColor(index); + column--; + if (0 > index || index >= items.size()) + return Color::White; + const auto* item = items[index]; + if (0 > column || column >= item->subitems.size()) + return Color::White; + if (item->subitems[column]->use_color) + return item->subitems[column]->color; + if (columns[column]->use_color) + return columns[column]->color; + return item->color; +} + void ListBox::SetItemColor(int index, Color c) { if (index >= 0 && index < items.size()) { @@ -528,6 +547,20 @@ void ListBox::SetItemColor(int index, Color c) } } +void ListBox::SetItemColor(int index, int column, Color c) +{ + if (column == 0) + return SetItemColor(index, c); + column--; + if (0 < index || index >= items.size()) + return; + auto* item = items[index]; + if (0 < column || column >= item->subitems.size()) + return; + item->subitems[column]->color = c; + item->subitems[column]->use_color = true; +} + Text ListBox::GetItemText(int index, int column) { if (column == 0) { @@ -862,21 +895,6 @@ void ListBox::SetColumnColor(int index, Color c) } } -Color ListBox::GetItemColor(int index, int column) -{ - Color c = Color::White; - - if (index >= 0 && index < items.size()) - c = items[index]->color; - - if (column >= 0 && column < columns.size()) { - if (columns[column]->use_color) - c = columns[column]->color; - } - - return c; -} - int ListBox::GetMultiSelect() { return multiselect; diff --git a/StarsEx/ListBox.h b/StarsEx/ListBox.h index fb44177..063fc20 100644 --- a/StarsEx/ListBox.h +++ b/StarsEx/ListBox.h @@ -88,6 +88,8 @@ public: void SetItemData(int index, int column, DWORD data); Bitmap* GetItemImage(int index, int column); void SetItemImage(int index, int column, Bitmap* img); + Color GetItemColor(int index, int column); + void SetItemColor(int index, int column, Color c); int AddItem(const char* text); int AddImage(Bitmap* img); @@ -114,8 +116,6 @@ public: Color GetColumnColor(int index); void SetColumnColor(int index, Color c); - Color GetItemColor(int index, int column); - int GetMultiSelect(); void SetMultiSelect(int nNewValue); bool GetShowHeadings(); diff --git a/StarsEx/NetClientDlg.cpp b/StarsEx/NetClientDlg.cpp index 03077f7..fb14f5a 100644 --- a/StarsEx/NetClientDlg.cpp +++ b/StarsEx/NetClientDlg.cpp @@ -23,6 +23,7 @@ #include "NetClientConfig.h" #include "NetLobbyClient.h" #include "Slider.h" +#include "VersionInfo.h" // +--------------------------------------------------------------------+ // DECLARE MAPPING FUNCTIONS: @@ -132,8 +133,8 @@ NetClientDlg::ExecFrame() NetServerInfo* info = config->GetServerInfo(server_index); - const bool server_selected = info != 0; - const bool join_enabled = server_selected && info->status > NetServerInfo::OFFLINE; + const bool server_selected = info != nullptr; + const bool join_enabled = server_selected && info->status > NetServerInfo::OFFLINE && info->version == versionInfo; const bool host_enabled = join_enabled && info->hosted == 0; if (btn_host) @@ -199,6 +200,8 @@ NetClientDlg::UpdateServers() NetServerInfo* info = config->GetServerList().at(n); lst_servers->SetItemText(i, 0, info->name); lst_servers->SetItemText(i, 1, info->version); + if (!info->version.empty() && versionInfo != info->version) + lst_servers->SetItemColor(i, 1, Color::Orange); Text status = ContentBundle::GetInstance()->GetText("NetClientDlg.offline"); -- cgit v1.1