tibia-rme/source/result_window.cpp

90 lines
3.3 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.
//
2020-07-30 11:42:28 -03:00
// Remere's Map Editor is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
2020-07-30 11:42:28 -03:00
// 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
2020-07-30 11:42:28 -03:00
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//////////////////////////////////////////////////////////////////////
#include "main.h"
#include "result_window.h"
#include "gui.h"
#include "position.h"
BEGIN_EVENT_TABLE(SearchResultWindow, wxPanel)
2023-10-09 19:12:16 -07:00
EVT_LISTBOX(wxID_ANY, SearchResultWindow::OnClickResult)
EVT_BUTTON(wxID_FILE, SearchResultWindow::OnClickExport)
EVT_BUTTON(wxID_CLEAR, SearchResultWindow::OnClickClear)
END_EVENT_TABLE()
SearchResultWindow::SearchResultWindow(wxWindow* parent) :
2023-10-09 19:12:16 -07:00
wxPanel(parent, wxID_ANY) {
wxSizer* sizer = newd wxBoxSizer(wxVERTICAL);
2020-05-18 14:06:00 -03:00
result_list = newd wxListBox(this, wxID_ANY, wxDefaultPosition, wxSize(200, 330), 0, nullptr, wxLB_SINGLE | wxLB_ALWAYS_SB);
sizer->Add(result_list, wxSizerFlags(1).Expand());
2020-07-30 11:42:28 -03:00
wxSizer* buttonsSizer = newd wxBoxSizer(wxHORIZONTAL);
2016-11-05 15:28:14 +01:00
buttonsSizer->Add(newd wxButton(this, wxID_FILE, "Export"), wxSizerFlags(0).Center());
buttonsSizer->Add(newd wxButton(this, wxID_CLEAR, "Clear"), wxSizerFlags(0).Center());
sizer->Add(buttonsSizer, wxSizerFlags(0).Center().DoubleBorder());
SetSizerAndFit(sizer);
}
2023-10-09 19:12:16 -07:00
SearchResultWindow::~SearchResultWindow() {
Clear();
}
2023-10-09 19:12:16 -07:00
void SearchResultWindow::Clear() {
for (uint32_t n = 0; n < result_list->GetCount(); ++n) {
delete reinterpret_cast<Position*>(result_list->GetClientData(n));
}
result_list->Clear();
}
2023-10-09 19:12:16 -07:00
void SearchResultWindow::AddPosition(wxString description, Position pos) {
2016-11-05 15:28:14 +01:00
result_list->Append(description << " (" << pos.x << "," << pos.y << "," << pos.z << ")", newd Position(pos));
}
2023-10-09 19:12:16 -07:00
void SearchResultWindow::OnClickResult(wxCommandEvent &event) {
Position* pos = reinterpret_cast<Position*>(event.GetClientData());
2023-10-09 19:12:16 -07:00
if (pos) {
g_gui.SetScreenCenterPosition(*pos);
}
}
2023-10-09 19:12:16 -07:00
void SearchResultWindow::OnClickExport(wxCommandEvent &WXUNUSED(event)) {
wxFileDialog dialog(this, "Save file...", "", "", "Text Documents (*.txt) | *.txt", wxFD_SAVE);
2023-10-09 19:12:16 -07:00
if (dialog.ShowModal() == wxID_OK) {
wxFile file(dialog.GetPath(), wxFile::write);
2023-10-09 19:12:16 -07:00
if (file.IsOpened()) {
2016-11-05 15:28:14 +01:00
g_gui.CreateLoadBar("Exporting search result...");
2016-11-05 19:10:21 -03:00
file.Write("Generated by Remere's Map Editor " + __RME_VERSION__);
2016-11-05 15:28:14 +01:00
file.Write("\n=============================================\n\n");
wxArrayString lines = result_list->GetStrings();
size_t count = lines.Count();
2023-10-09 19:12:16 -07:00
for (size_t i = 0; i < count; ++i) {
2016-11-05 15:28:14 +01:00
file.Write(lines[i] + "\n");
g_gui.SetLoadScale((int32_t)i, (int32_t)count);
}
file.Close();
g_gui.DestroyLoadBar();
}
}
}
2023-10-09 19:12:16 -07:00
void SearchResultWindow::OnClickClear(wxCommandEvent &WXUNUSED(event)) {
Clear();
}