Debian Codegraph @

source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Cinema/Cinema.cpp

raw
1 /* Copyright (C) 2025 Wildfire Games.
2 * This file is part of 0 A.D.
3 *
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #include "precompiled.h"
19
20 #include "Cinema.h"
21
22 #include "tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.h"
23 #include "tools/atlas/AtlasUI/ScenarioEditor/Sections/Common/Sidebar.h"
24 #include "tools/atlas/AtlasUI/ScenarioEditor/Tools/Common/Tools.h"
25 #include "tools/atlas/GameInterface/Messages.h"
26 #include "tools/atlas/GameInterface/Shareable.h"
27 #include "tools/atlas/GameInterface/SharedTypes.h"
28
29 #include <cstddef>
30 #include <string>
31 #include <vector>
32 #include <wx/button.h>
33 #include <wx/chartype.h>
34 #include <wx/checkbox.h>
35 #include <wx/listbox.h>
36 #include <wx/scrolwin.h>
37 #include <wx/sizer.h>
38 #include <wx/statbox.h>
39 #include <wx/string.h>
40 #include <wx/textctrl.h>
41 #include <wx/toolbar.h>
42 #include <wx/translation.h>
43 #include <wx/window.h>
44
45 using AtlasMessage::Shareable;
46
47 enum {
48 ID_PathsDrawing,
49 ID_PathsList,
50 ID_AddPath,
51 ID_DeletePath
52 };
53
54 // Helper function for adding tooltips
55 static wxWindow* Tooltipped(wxWindow* window, const wxString& tip)
56 {
57 window->SetToolTip(tip);
58 return window;
59 }
60
61 CinemaSidebar::CinemaSidebar(ScenarioEditor& scenarioEditor, wxWindow* sidebarContainer, wxWindow* bottomBarContainer)
62 : Sidebar(scenarioEditor, sidebarContainer, bottomBarContainer)
63 {
64 wxSizer* scrollSizer = new wxBoxSizer(wxVERTICAL);
65 scrolledWindow = new wxScrolledWindow(this);
66 scrolledWindow->SetScrollRate(10, 10);
67 scrolledWindow->SetSizer(scrollSizer);
68 m_MainSizer->Add(scrolledWindow, wxSizerFlags().Proportion(1).Expand());
69
70 wxStaticBoxSizer* commonSizer = new wxStaticBoxSizer(wxVERTICAL, scrolledWindow, _T("Common settings"));
71 scrollSizer->Add(commonSizer, wxSizerFlags().Expand());
72
73 wxFlexGridSizer* gridSizer = new wxFlexGridSizer(2, 5, 5);
74 gridSizer->AddGrowableCol(1);
75
76 gridSizer->Add(Tooltipped(m_DrawPath = new wxCheckBox(commonSizer->GetStaticBox(), ID_PathsDrawing, _("Draw all paths")),
77 _("Display every cinematic path added to the map")));
78
79 commonSizer->Add(gridSizer, wxSizerFlags().Expand());
80
81 // Paths list panel
82 wxStaticBoxSizer* pathsSizer = new wxStaticBoxSizer(wxVERTICAL, commonSizer->GetStaticBox(), _T("Paths"));
83 commonSizer->Add(pathsSizer, wxSizerFlags().Proportion(1).Expand());
84
85 pathsSizer->Add(m_PathList = new wxListBox(pathsSizer->GetStaticBox(), ID_PathsList, wxDefaultPosition, wxDefaultSize, 0, NULL, wxLB_SINGLE | wxLB_SORT), wxSizerFlags().Proportion(1).Expand());
86 commonSizer->AddSpacer(3);
87 pathsSizer->Add(Tooltipped(new wxButton(pathsSizer->GetStaticBox(), ID_DeletePath, _("Delete")), _T("Delete selected path")), wxSizerFlags().Expand());
88
89 pathsSizer->Add(m_NewPathName = new wxTextCtrl(pathsSizer->GetStaticBox(), wxID_ANY), wxSizerFlags().Expand());
90 pathsSizer->Add(new wxButton(pathsSizer->GetStaticBox(), ID_AddPath, _("Add")), wxSizerFlags().Expand());
91 }
92
93 void CinemaSidebar::OnFirstDisplay()
94 {
95 m_DrawPath->SetValue(false);
96
97 ReloadPathList();
98 }
99
100 void CinemaSidebar::OnMapReload()
101 {
102 m_DrawPath->SetValue(false);
103
104 ReloadPathList();
105 }
106
107 void CinemaSidebar::OnTogglePathsDrawing(wxCommandEvent& evt)
108 {
109 POST_COMMAND(SetCinemaPathsDrawing, (evt.IsChecked()));
110 }
111
112 void CinemaSidebar::OnAddPath(wxCommandEvent&)
113 {
114 if (m_NewPathName->GetValue().empty())
115 return;
116
117 POST_COMMAND(AddCinemaPath, ((std::wstring)m_NewPathName->GetValue().wc_str()));
118 m_NewPathName->Clear();
119 ReloadPathList();
120 }
121
122 void CinemaSidebar::OnDeletePath(wxCommandEvent&)
123 {
124 int index = m_PathList->GetSelection();
125 if (index < 0)
126 return;
127
128 wxString pathName = m_PathList->GetString(index);
129 if (pathName.empty())
130 return;
131
132 POST_COMMAND(DeleteCinemaPath, ((std::wstring)pathName.wc_str()));
133 ReloadPathList();
134 }
135
136 void CinemaSidebar::ReloadPathList()
137 {
138 int index = m_PathList->GetSelection();
139 wxString pathName;
140 if (index >= 0)
141 pathName = m_PathList->GetString(index);
142
143 AtlasMessage::qGetCinemaPaths query_paths;
144 query_paths.Post();
145
146 m_PathList->Clear();
147 for (const AtlasMessage::sCinemaPath& path : *query_paths.paths)
148 m_PathList->Append(*path.name);
149 }
150
151 BEGIN_EVENT_TABLE(CinemaSidebar, Sidebar)
152 EVT_CHECKBOX(ID_PathsDrawing, CinemaSidebar::OnTogglePathsDrawing)
153 EVT_BUTTON(ID_AddPath, CinemaSidebar::OnAddPath)
154 EVT_BUTTON(ID_DeletePath, CinemaSidebar::OnDeletePath)
155 END_EVENT_TABLE();