2023-04-27 19:20:23 +00:00
|
|
|
/*
|
|
|
|
speciesgen
|
|
|
|
Copyright (C) 2022-2023 prisixia
|
|
|
|
|
|
|
|
This file is part of speciesgen.
|
|
|
|
|
|
|
|
speciesgen 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.
|
|
|
|
|
|
|
|
speciesgen 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 speciesgen. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gui/main_panel.h"
|
|
|
|
|
|
|
|
namespace SpeciesGen {
|
|
|
|
|
|
|
|
wxBEGIN_EVENT_TABLE(MainPanel, wxPanel)
|
|
|
|
#if wxUSE_DIRDLG
|
|
|
|
EVT_BUTTON(DIR_CHOOSE, MainPanel::DoChooseDir)
|
|
|
|
#endif // wxUSE_DIRDLG
|
|
|
|
wxEND_EVENT_TABLE()
|
|
|
|
|
2023-05-06 13:33:40 +00:00
|
|
|
// NOLINTBEGIN(cppcoreguidelines-owning-memory): wxWidgets already manages its
|
|
|
|
// memory more or less so that there's no need for owning the memory
|
2023-04-27 19:20:23 +00:00
|
|
|
MainPanel::MainPanel(wxWindow *window, int x, int y, int w, int h,
|
2023-05-05 12:10:52 +00:00
|
|
|
const std::string &handlerName)
|
2023-04-27 19:20:23 +00:00
|
|
|
: wxPanel(window, wxID_ANY, wxPoint(x, y), wxSize(w, h)),
|
|
|
|
ErrorHandler(handlerName) {
|
|
|
|
wxBoxSizer *column1 = new wxBoxSizer(wxVERTICAL);
|
|
|
|
wxBoxSizer *column2 = new wxBoxSizer(wxVERTICAL);
|
|
|
|
wxBoxSizer *row = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL);
|
|
|
|
|
|
|
|
m_authorText = new wxStaticText(this, wxID_ANY, "Author");
|
|
|
|
m_nameText = new wxStaticText(this, wxID_ANY, "Species (Internal)");
|
|
|
|
m_friendlyNameText = new wxStaticText(this, wxID_ANY, "Species (In-Game)");
|
|
|
|
m_modDestinationText = new wxStaticText(this, wxID_ANY, "Output directory");
|
|
|
|
|
|
|
|
m_author = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition,
|
|
|
|
wxSize(150, wxDefaultSize.GetHeight()));
|
|
|
|
m_author->SetHint("Author's name");
|
|
|
|
m_author->SetMaxLength(128);
|
|
|
|
#ifdef _WIN32
|
|
|
|
m_author->SetValue(wxGetUserName());
|
|
|
|
#else
|
|
|
|
m_author->SetValue(getenv("USER"));
|
|
|
|
#endif // _WIN32
|
|
|
|
|
|
|
|
m_name = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition,
|
|
|
|
wxSize(150, wxDefaultSize.GetHeight()));
|
|
|
|
m_name->SetHint("Internal species name");
|
|
|
|
m_name->SetMaxLength(128);
|
|
|
|
|
|
|
|
m_friendlyName =
|
|
|
|
new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition,
|
|
|
|
wxSize(150, wxDefaultSize.GetHeight()));
|
|
|
|
m_friendlyName->SetHint("In-Game species name");
|
|
|
|
m_friendlyName->SetMaxLength(128);
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
m_modDestination = new wxTextCtrl(
|
|
|
|
this, wxID_ANY,
|
|
|
|
"C:\\Program Files (x86)\\Steam\\steamapps\\common\\Starbound\\mods",
|
|
|
|
wxDefaultPosition, wxSize(400, wxDefaultSize.GetHeight()));
|
|
|
|
#else
|
|
|
|
m_modDestination = new wxTextCtrl(
|
|
|
|
this, wxID_ANY,
|
|
|
|
wxString::Format("%s/.steam/steam/steamapps/common/Starbound/mods",
|
|
|
|
wxGetUserHome(wxGetUserName())));
|
|
|
|
#endif // _WIN32
|
|
|
|
|
|
|
|
m_generate = new wxButton(this, MOD_GENERATE, "Generate mod",
|
|
|
|
wxDefaultPosition, wxSize(280, 80));
|
|
|
|
|
|
|
|
column1->Add(m_authorText, 0, wxEXPAND | wxLEFT | wxUP, 10);
|
|
|
|
column1->Add(m_author, 0, wxEXPAND | wxALL, 10);
|
|
|
|
column1->Add(m_nameText, 0, wxEXPAND | wxLEFT | wxUP, 10);
|
|
|
|
column1->Add(m_name, 0, wxEXPAND | wxALL, 10);
|
|
|
|
column1->Add(m_friendlyNameText, 0, wxEXPAND | wxLEFT | wxUP, 10);
|
|
|
|
column1->Add(m_friendlyName, 0, wxEXPAND | wxALL, 10);
|
|
|
|
column2->Add(m_modDestinationText, 0, wxEXPAND | wxLEFT | wxUP, 10);
|
|
|
|
column2->Add(m_modDestination, 0, wxEXPAND | wxLEFT | wxUP, 10);
|
|
|
|
|
|
|
|
#if wxUSE_DIRDLG
|
|
|
|
m_browse = new wxButton(this, DIR_CHOOSE, "Browse...");
|
|
|
|
column2->Add(m_browse, 0, wxALL, 10);
|
|
|
|
#endif // wxUSE_DIRDLG
|
|
|
|
|
|
|
|
column2->AddSpacer(20);
|
|
|
|
column2->Add(m_generate, 0, wxALIGN_CENTER, 0);
|
|
|
|
row->Add(column1, 0, wxALL | wxALIGN_CENTER, 10);
|
|
|
|
row->Add(column2, 0, wxALL | wxALIGN_CENTER, 10);
|
|
|
|
topSizer->Add(row, 0, wxALL | wxALIGN_CENTER, 10);
|
|
|
|
|
|
|
|
SetSizer(topSizer);
|
|
|
|
}
|
2023-05-06 13:33:40 +00:00
|
|
|
// NOLINTEND(cppcoreguidelines-owning-memory)
|
2023-04-27 19:20:23 +00:00
|
|
|
|
|
|
|
#if wxUSE_CLIPBOARD
|
|
|
|
/*
|
|
|
|
wxTextCtrl *MainPanel::GetFocusedText() const
|
|
|
|
{
|
|
|
|
wxWindow *win = FindFocus();
|
|
|
|
|
|
|
|
wxTextCtrl *text = win ? wxDynamicCast(win, wxTextCtrl) : NULL;
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MainPanel::HasSelection() const
|
|
|
|
{
|
|
|
|
long from;
|
|
|
|
long to;
|
|
|
|
GetFocusedText()->GetSelection(&from, &to);
|
|
|
|
return from != to;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainPanel::DoPasteFromClipboard()
|
|
|
|
{
|
|
|
|
// On X11, we want to get the data from the primary selection instead
|
|
|
|
// of the normal clipboard (which isn't normal under X11 at all). This
|
|
|
|
// call has no effect under MSW.
|
|
|
|
wxTheClipboard->UsePrimarySelection();
|
|
|
|
|
|
|
|
if (!wxTheClipboard->Open())
|
|
|
|
return;
|
|
|
|
|
|
|
|
wxTextDataObject data;
|
|
|
|
|
|
|
|
if (wxTheClipboard->IsSupported(data.GetFormat())) {
|
|
|
|
if (wxTheClipboard->GetData(data))
|
|
|
|
GetFocusedText()->AppendText(data.GetText());
|
|
|
|
}
|
|
|
|
|
|
|
|
wxTheClipboard->Close();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainPanel::DoCopyToClipboard()
|
|
|
|
{
|
|
|
|
// On X11, we want to get the data from the primary selection instead
|
|
|
|
// of the normal clipboard (which isn't normal under X11 at all). This
|
|
|
|
// call has no effect under MSW.
|
|
|
|
wxTheClipboard->UsePrimarySelection();
|
|
|
|
|
|
|
|
wxString text(GetFocusedText()->GetStringSelection());
|
|
|
|
|
|
|
|
if (text.IsEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!wxTheClipboard->Open())
|
|
|
|
return;
|
|
|
|
|
|
|
|
wxTextDataObject *data = new wxTextDataObject(text);
|
|
|
|
wxTheClipboard->SetData(data);
|
|
|
|
wxTheClipboard->Close();
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
#endif // wxUSE_CLIPBOARD
|
|
|
|
|
|
|
|
#if wxUSE_DIRDLG
|
|
|
|
void MainPanel::DoChooseDir(wxCommandEvent &WXUNUSED(event)) {
|
|
|
|
wxString dirHome =
|
|
|
|
wxStandardPaths::Get().GetUserDir(wxStandardPaths::Dir_Desktop);
|
|
|
|
wxDirDialog dialog(this, "Select a directory", dirHome,
|
|
|
|
wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST);
|
2023-05-06 11:08:18 +00:00
|
|
|
if (dialog.ShowModal() == wxID_OK) {
|
2023-04-27 19:20:23 +00:00
|
|
|
m_modDestination->SetValue(dialog.GetPath());
|
2023-05-06 11:08:18 +00:00
|
|
|
}
|
2023-04-27 19:20:23 +00:00
|
|
|
}
|
|
|
|
#endif // wxUSE_DIRDLG
|
|
|
|
|
|
|
|
size_t MainPanel::CheckForErrors() {
|
2023-05-04 17:29:13 +00:00
|
|
|
m_errorLog.clear();
|
|
|
|
|
2023-04-27 19:20:23 +00:00
|
|
|
size_t errorCount = 0;
|
|
|
|
|
|
|
|
if (m_author->IsEmpty()) {
|
|
|
|
m_errorLog.push_back("Empty author field, please fill it out.");
|
|
|
|
errorCount++;
|
|
|
|
}
|
|
|
|
if (m_name->IsEmpty()) {
|
|
|
|
m_errorLog.push_back("Empty internal name field, please fill it out.");
|
|
|
|
errorCount++;
|
|
|
|
}
|
|
|
|
if (m_friendlyName->IsEmpty()) {
|
|
|
|
m_errorLog.push_back("Empty in-game name field, please fill it out.");
|
|
|
|
errorCount++;
|
|
|
|
}
|
|
|
|
if (m_modDestination->IsEmpty()) {
|
|
|
|
m_errorLog.push_back("Empty path field, please fill it out.");
|
|
|
|
errorCount++;
|
|
|
|
}
|
|
|
|
if (!wxDir::Exists(m_modDestination->GetValue())) {
|
|
|
|
m_errorLog.push_back(
|
|
|
|
"Invalid directory, please check your entered path.");
|
|
|
|
errorCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return errorCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace SpeciesGen
|