tibia-rme/source/extension_window.cpp

136 lines
3.8 KiB
C++
Raw Permalink Normal View History

//////////////////////////////////////////////////////////////////////
// This file is part of Remere's Map Editor
//////////////////////////////////////////////////////////////////////
2020-07-30 11:42:28 -03:00
// Remere's Map Editor is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Remere's Map Editor is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//////////////////////////////////////////////////////////////////////
#include "main.h"
#include "extension_window.h"
#include "gui.h"
#include "materials.h"
extern Materials g_materials;
BEGIN_EVENT_TABLE(ExtensionsDialog, wxDialog)
2023-10-09 19:12:16 -07:00
EVT_HTML_LINK_CLICKED(wxID_ANY, ExtensionsDialog::OnClickLink)
EVT_BUTTON(wxID_OK, ExtensionsDialog::OnClickOK)
EVT_BUTTON(EXTENSIONS_OPEN_FOLDER_BUTTON, ExtensionsDialog::OnClickOpenFolder)
END_EVENT_TABLE()
ExtensionsDialog::ExtensionsDialog(wxWindow* parent) :
2023-10-09 19:12:16 -07:00
wxDialog(parent, wxID_ANY, "Extensions", wxDefaultPosition, wxSize(600, 500), wxRESIZE_BORDER | wxCAPTION) {
wxBoxSizer* topSizer = new wxBoxSizer(wxVERTICAL);
wxHtmlWindow* htmlWindow = new wxHtmlWindow(this, wxID_ANY, wxDefaultPosition, wxSize(550, 400));
htmlWindow->SetPage(HTML());
topSizer->Add(htmlWindow, wxSizerFlags(1).DoubleBorder().Expand());
wxSizer* buttonSizer = newd wxBoxSizer(wxHORIZONTAL);
2016-11-05 15:28:14 +01:00
buttonSizer->Add(newd wxButton(this, wxID_OK, "OK"), wxSizerFlags(1).Center());
buttonSizer->Add(newd wxButton(this, EXTENSIONS_OPEN_FOLDER_BUTTON, "Open Extensions Folder"), wxSizerFlags(1).Center());
topSizer->Add(buttonSizer, 0, wxCENTER | wxLEFT | wxRIGHT | wxBOTTOM, 20);
SetSizerAndFit(topSizer);
2016-02-29 21:47:54 -03:00
Centre(wxBOTH);
}
2023-10-09 19:12:16 -07:00
ExtensionsDialog::~ExtensionsDialog() {
2015-12-06 11:42:37 -03:00
////
}
2023-10-09 19:12:16 -07:00
void ExtensionsDialog::OnClickLink(wxHtmlLinkEvent &evt) {
::wxLaunchDefaultBrowser(evt.GetLinkInfo().GetHref(), wxBROWSER_NEW_WINDOW);
}
2023-10-09 19:12:16 -07:00
void ExtensionsDialog::OnClickOK(wxCommandEvent &evt) {
EndModal(0);
}
2023-10-09 19:12:16 -07:00
void ExtensionsDialog::OnClickOpenFolder(wxCommandEvent &evt) {
wxString cmd, extensionsDir = g_gui.GetExtensionsDirectory();
#if defined __WINDOWS__
cmd << "explorer";
#elif defined __APPLE__
cmd << "open";
2023-10-09 19:12:16 -07:00
extensionsDir.Replace(" ", "\\ "); // Escape spaces
#elif defined __linux
cmd << "xdg-open";
#else
2023-10-09 19:12:16 -07:00
#error "NOT IMPLEMENTED"
#endif
cmd << " " << extensionsDir;
wxExecute(cmd);
}
2023-10-09 19:12:16 -07:00
wxString ExtensionsDialog::HTML() const {
wxString markup;
2023-10-09 19:12:16 -07:00
for (MaterialsExtensionList::const_iterator me = g_materials.getExtensions().begin(); me != g_materials.getExtensions().end(); ++me) {
markup << HTMLForExtension(*me);
markup << "<hr>";
}
return markup;
}
2023-10-09 19:12:16 -07:00
wxString ExtensionsDialog::HTMLForExtension(MaterialsExtension* me) const {
wxString markup;
markup
<< "<table>"
<< "< background='#ff0000'>"
<< "<td width='100px'><b>Extension</b></td>"
<< "<td>";
2016-09-29 19:24:45 -03:00
2023-10-09 19:12:16 -07:00
if (me->url.empty()) {
markup << me->name;
2023-10-09 19:12:16 -07:00
} else {
markup << "<a href='" << me->url << "'>" << me->name << "</a>";
2023-10-09 19:12:16 -07:00
}
2016-09-29 19:24:45 -03:00
markup
<< "</td>"
<< "</tr>"
<< "<tr>"
<< "<td width='100px'><b>Author</b></td>"
<< "<td>";
2023-10-09 19:12:16 -07:00
if (me->author_url.empty()) {
markup << me->author;
2023-10-09 19:12:16 -07:00
} else {
markup << "<a href='" << me->author_url << "'>" << me->author << "</a>";
2023-10-09 19:12:16 -07:00
}
markup
<< "</td>"
<< "</tr>"
<< "<tr>"
<< "<td width='100px'><b>Description</b></td>"
<< "<td>" << me->description << "</td>"
<< "</tr>"
<< "<tr>"
<< "<td width='100px'><b>Clients</b></td>"
<< "<td>" << me->getVersionString() << "</td>"
<< "</tr>"
2023-10-09 19:12:16 -07:00
<< "</table>";
return markup;
}