Added primitive update window.

Added diagonal directions (todo: add different text direcitons, primarily for Space)
Cleaned up keyword game file a bit.


git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@600 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
coppro
2007-08-05 00:38:12 +00:00
parent 633621558d
commit 1ce4bd9c3d
11 changed files with 275 additions and 11 deletions
+187 -4
View File
@@ -15,10 +15,13 @@
#include <wx/dialup.h>
#include <wx/url.h>
#include <wx/html/htmlwin.h>
#include <wx/vlbox.h>
DECLARE_POINTER_TYPE(PackageVersionData);
DECLARE_POINTER_TYPE(VersionData);
DECLARE_TYPEOF_COLLECTION(PackageVersionDataP);
// ----------------------------------------------------------------------------- : Update data
/// Information on available packages
@@ -55,7 +58,7 @@ IMPLEMENT_REFLECTION(PackageVersionData) {
REFLECT(is_installer);
REFLECT(version);
REFLECT(app_version);
REFLECT(depends);
REFLECT_N("depends ons", depends);
}
IMPLEMENT_REFLECTION(VersionData) {
@@ -67,6 +70,8 @@ IMPLEMENT_REFLECTION(VersionData) {
// The information for the latest version
VersionDataP update_version_data;
// Have we shown the update dialog?
bool shown_dialog = false;
// Is update checking in progress?
volatile bool checking_updates = false;
@@ -75,6 +80,12 @@ bool update_available() { return update_version_data && update_version_data->ve
// ----------------------------------------------------------------------------- : Update checking
BEGIN_DECLARE_EVENT_TYPES()
DECLARE_EVENT_TYPE(UPDATE_CHECK_FINISHED_EVT, -1)
END_DECLARE_EVENT_TYPES()
DEFINE_EVENT_TYPE(UPDATE_CHECK_FINISHED_EVT)
// Thread to retrieve update information
// Checks if the current version is the latest version
// If not, displays a message
@@ -142,14 +153,14 @@ struct HtmlWindowToBrowser : public wxHtmlWindow {
HtmlWindowToBrowser(Window* parent, int id, const wxPoint& pos, const wxSize& size, long flags)
: wxHtmlWindow(parent, id, pos, size, flags)
{}
virtual void OnLinkClicked(const wxHtmlLinkInfo& info) {
wxLaunchDefaultBrowser( info.GetHref() );
}
};
void show_update_dialog(Window* parent) {
if (!update_available()) return; // we already have the latest version
if (!update_available() || shown_dialog) return; // we already have the latest version, or this has already been displayed.
// Show update dialog
wxDialog* dlg = new wxDialog(parent, wxID_ANY, _TITLE_("updates availible"), wxDefaultPosition);
// controls
@@ -165,5 +176,177 @@ void show_update_dialog(Window* parent) {
dlg->SetSize(400,400);
dlg->Show();
// And never show it again this run
update_version_data = VersionDataP();
shown_dialog = true;
}
// ----------------------------------------------------------------------------- : UpdateWindow
class PackageUpdateList: public wxVListBox {
public:
PackageUpdateList(UpdateWindow * parent)
: wxVListBox (parent, wxID_ANY, wxDefaultPosition, wxSize(480,210), wxNO_BORDER | wxVSCROLL)
, parent(parent)
{
if (!checking_updates && !update_version_data) {
check_updates_now(true);
}
SetItemCount(update_version_data ? update_version_data->packages.size() : 1);
}
virtual void OnDrawItem(wxDC& dc, const wxRect& rect, size_t n) const {
static wxBrush greyBrush(Color(224,224,224));
if (checking_updates) {
String text = _ERROR_("checking updates");
wxSize text_size = dc.GetTextExtent(text);
dc.SetPen(*wxTRANSPARENT_PEN);
dc.SetBrush(greyBrush);
dc.DrawRectangle(rect);
dc.DrawText(text, rect.GetLeft() + (rect.GetWidth() - text_size.GetWidth()) / 2, rect.GetTop() + (rect.GetHeight() - text_size.GetHeight()) / 2);
} else if (!update_version_data || update_version_data->packages.empty()) {
String text = _ERROR_("no packages");
wxSize text_size = dc.GetTextExtent(text);
dc.SetPen(*wxTRANSPARENT_PEN);
dc.SetBrush(greyBrush);
dc.DrawRectangle(rect);
dc.DrawText(text, rect.GetLeft() + (rect.GetWidth() - text_size.GetWidth()) / 2, rect.GetTop() + (rect.GetHeight() - text_size.GetHeight()) / 2);
} else {
static wxBrush darkBrush(Color(192,224,255));
static wxBrush selectBrush(Color(96,96,192));
PackageVersionDataP pack = update_version_data->packages[n];
UpdateWindow::PackageStatus status = parent->package_data[pack].first;
UpdateWindow::PackageAction action = parent->package_data[pack].second;
dc.SetPen(*wxTRANSPARENT_PEN);
dc.SetBrush(IsSelected(n) ? selectBrush : (n % 2 ? *wxWHITE_BRUSH : darkBrush));
dc.DrawRectangle(rect);
// These two arrays correspond to PackageStatus and PackageAction, respectively
static Color status_colors [] = {
Color(32,160,32)
,Color(32,32,255)
,Color(192,32,32)
};
static Color action_colors [] = {
Color(32,160,32)
,Color(192,32,32)
,Color(192,192,32)
,Color(32,32,255)
,Color(32,32,32)
};
// Ditto here (these are the locale names)
static String status_texts [] = {
_TYPE_("installed")
,_TYPE_("uninstalled")
,_TYPE_("upgradeable")
};
static String action_texts [] = {
_TYPE_("install")
,_TYPE_("uninstall")
,_TYPE_("upgrade")
,_TYPE_("do nothing")
,_TYPE_("new mse")
};
static Color textBack(0,0,0,wxALPHA_TRANSPARENT);
static Color packageFront(64,64,64);
#define SELECT_WHITE(color) (IsSelected(n) ? *wxWHITE : color)
dc.SetTextForeground(SELECT_WHITE(packageFront));
dc.SetTextBackground(textBack);
dc.DrawText(pack->name, rect.GetLeft() + 1, rect.GetTop());
dc.SetTextForeground(SELECT_WHITE(status_colors[status]));
dc.DrawText(status_texts[status], rect.GetLeft() + 240, rect.GetTop());
dc.SetTextForeground(SELECT_WHITE(action_colors[action]));
dc.DrawText(action_texts[action], rect.GetLeft() + 360, rect.GetTop());
#undef SELECT_INVERT
}
}
virtual wxCoord OnMeasureItem(size_t) const {
return (update_version_data && !update_version_data->packages.empty()) ? 15 : 210;
}
void onUpdateCheckingFinished(wxEvent& event) {
SetItemCount(update_version_data ? update_version_data->packages.size() : 1);
}
virtual wxCoord EstimateTotalHeight() const {
return (update_version_data && !update_version_data->packages.empty()) ? 15 * update_version_data->packages.size() : 210;
}
private:
DECLARE_EVENT_TABLE()
UpdateWindow * parent;
};
BEGIN_EVENT_TABLE(PackageUpdateList, wxVListBox)
EVT_CUSTOM(UPDATE_CHECK_FINISHED_EVT, -1, PackageUpdateList::onUpdateCheckingFinished)
END_EVENT_TABLE()
UpdateWindow::UpdateWindow()
: Frame(nullptr, wxID_ANY, _TITLE_("package list"), wxDefaultPosition, wxSize(480,375), wxDEFAULT_DIALOG_STYLE | wxCLIP_CHILDREN)
{
SetIcon(wxIcon());
wxBoxSizer *v = new wxBoxSizer(wxVERTICAL);
package_list = new PackageUpdateList(this);
description_window = new HtmlWindowToBrowser(this, wxID_ANY, wxDefaultPosition, wxSize(480,100), wxHW_SCROLLBAR_AUTO | wxSUNKEN_BORDER);
wxCommandEvent ev;
SetDefaultPackageStatus(ev);
package_title = new wxStaticText(this, wxID_ANY, _TITLE_("package name"), wxDefaultPosition, wxSize(120,15), wxALIGN_LEFT | wxST_NO_AUTORESIZE);
status_title = new wxStaticText(this, wxID_ANY, _TITLE_("package status"), wxDefaultPosition, wxSize(120,15), wxALIGN_LEFT | wxST_NO_AUTORESIZE);
new_title = new wxStaticText(this, wxID_ANY, _TITLE_("new status"), wxDefaultPosition, wxSize(120,15), wxALIGN_LEFT | wxST_NO_AUTORESIZE);
package_title->Move(1,0);
status_title->Move(240,0);
new_title->Move(360,0);
v->AddSpacer(15);
v->Add(package_list);
v->Add(description_window);
SetSizer(v);
}
void UpdateWindow::SetDefaultPackageStatus(wxCommandEvent&)
{
if (!update_version_data)
return;
FOR_EACH(p, update_version_data->packages) {
PackagedP pack;
try { pack = packages.openAny(p->name); }
catch (Error& e) { } // We couldn't open a package... wonder why?
if (!pack) {
if (p->app_version > file_version)
package_data[p] = PackageData(STATUS_NOT_INSTALLED, ACTION_NEW_MSE);
else
package_data[p] = PackageData(STATUS_NOT_INSTALLED, ACTION_NOTHING);
} else if (pack->version < p->version) {
if (p->app_version > file_version)
package_data[p] = PackageData(STATUS_UPGRADEABLE, ACTION_NEW_MSE);
else
package_data[p] = PackageData(STATUS_UPGRADEABLE, ACTION_UPGRADE);
} else
package_data[p] = PackageData(STATUS_INSTALLED, ACTION_NOTHING);
}
}
BEGIN_EVENT_TABLE(UpdateWindow, Frame)
EVT_COMMAND(-1, UPDATE_CHECK_FINISHED_EVT, UpdateWindow::SetDefaultPackageStatus)
END_EVENT_TABLE()