14 :
Panel(parent,
"MainPanel"), m_activeSceneIndex(-1), m_nextSceneNumber(1) {
16 SetPanelType(
"Scene");
17 SetBackgroundColour(wxColour(50, 50, 50));
26 wxBoxSizer *sizer =
new wxBoxSizer(wxVERTICAL);
34 wxAUI_NB_DEFAULT_STYLE | wxAUI_NB_CLOSE_ON_ACTIVE_TAB);
41 sizer->Add(
m_toolbar, 0, wxEXPAND | wxALL, 2);
53 new wxToolBar(
this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTB_HORIZONTAL | wxTB_FLAT | wxTB_NODIVIDER);
54 m_toolbar->SetBackgroundColour(wxColour(60, 60, 60));
58 "Create a new empty behavior tree scene");
71 if (maxScenes > 0 &&
static_cast<int>(
m_scenes.size()) >= maxScenes) {
73 wxString::Format(
"Maximum number of scenes (%d) reached.\nClose some scenes before creating new ones.",
75 "Scene Limit Reached", wxOK | wxICON_WARNING);
84 m_scenes.push_back(std::move(scene));
100 if (index < 0 || index >=
static_cast<int>(
m_scenes.size())) {
106 wxMessageDialog dialog(
107 this, wxString::Format(
"Scene '%s' has unsaved changes. Close anyway?",
m_scenes[index]->
GetTitle()),
108 "Unsaved Changes", wxYES_NO | wxICON_QUESTION);
109 if (dialog.ShowModal() != wxID_YES) {
115 std::unique_ptr<IScene> sceneToRemove = std::move(
m_scenes[index]);
119 sceneToRemove->OnDeactivated();
130 if (index >=
static_cast<int>(
m_scenes.size())) {
161 if (index >= 0 && index <
static_cast<int>(
m_scenes.size())) {
168 if (index < 0 || index >=
static_cast<int>(
m_scenes.size())) {
192 auto newScene = std::make_unique<BehaviorTreeScene>(
m_sceneNotebook, title);
195 int index =
AddScene(std::move(newScene));
199 wxLogMessage(
"Created new scene: %s", title);
207 bool titleExists =
false;
214 for (
const auto &scene :
m_scenes) {
215 if (scene->GetTitle() == title) {
224 }
while (titleExists);
231 for (
const auto &scene :
m_scenes) {
232 if (scene->GetTitle() == title) {
241 auto newScene = std::make_unique<BehaviorTreeScene>(
m_sceneNotebook, customTitle);
244 int index =
AddScene(std::move(newScene));
248 wxLogMessage(
"Created new scene: %s", customTitle);
261 if (behaviorTreeScene) {
262 behaviorTreeScene->SetTitle(newTitle);
268 wxLogMessage(
"Updated scene title to: %s", newTitle);
272 int newIndex =
event.GetSelection();
281 IScene *newScene =
nullptr;
297 wxTextEntryDialog dialog(
this,
"Enter a name for the new scene:",
"New Scene",
GenerateSceneTitle());
299 if (dialog.ShowModal() == wxID_OK) {
300 wxString sceneName = dialog.GetValue().Trim();
303 if (sceneName.IsEmpty()) {
304 wxMessageBox(
"Scene name cannot be empty!",
"Invalid Name", wxOK | wxICON_WARNING,
this);
311 wxString::Format(
"A scene named '%s' already exists!\nPlease choose a different name.", sceneName),
312 "Duplicate Name", wxOK | wxICON_WARNING,
this);
322 int index =
event.GetSelection();
325 if (index < 0 || index >=
static_cast<int>(
m_scenes.size())) {
326 wxLogError(
"Invalid tab close index: %d (have %zu scenes)", index,
m_scenes.size());
335 bool shouldAsk =
false;
341 message = wxString::Format(
"Scene '%s' has unsaved changes. Close anyway?",
m_scenes[index]->
GetTitle());
343 message = wxString::Format(
"Close scene '%s'?",
m_scenes[index]->
GetTitle());
348 message = wxString::Format(
"Scene '%s' has unsaved changes. Close anyway?",
m_scenes[index]->
GetTitle());
354 wxMessageDialog dialog(
this, message,
"Close Scene", wxYES_NO | wxICON_QUESTION);
355 if (dialog.ShowModal() != wxID_YES) {
363 std::unique_ptr<IScene> sceneToCleanup = std::move(
m_scenes[index]);
367 sceneToCleanup->OnDeactivated();
377 if (index >=
static_cast<int>(
m_scenes.size())) {
410 int nextSelection = (currentSelection + 1) %
m_sceneNotebook->GetPageCount();
420 int prevSelection = (currentSelection - 1 + pageCount) % pageCount;
BehaviorTreeProjectDialog::OnProjectNameChanged BehaviorTreeProjectDialog::OnRemoveFiles wxEND_EVENT_TABLE() BehaviorTreeProjectDialog
MainPanel::OnTabChanged EVT_TOOL(ID_NEW_SCENE_BUTTON, MainPanel::OnNewSceneButton) wxEND_EVENT_TABLE() MainPanel
wxBEGIN_EVENT_TABLE(MainPanel, Panel) EVT_AUINOTEBOOK_PAGE_CHANGED(ID_SCENE_NOTEBOOK
Scene implementation for behavior tree visualization.
void SetCanvasBackgroundColor(const wxColour &color)
Set the canvas background color.
AppPreferences & GetPreferences()
static AppPreferencesManager & GetInstance()
MainPanelSettings & GetMainPanelSettings()
Custom tab art provider that uses the application's accent color.
Abstract interface for different scene types in the MainPanel.
Central panel for managing and displaying behavior tree scenes.
bool SetActiveScene(int index)
Set the active scene by index.
void UpdateActiveSceneTitle(const wxString &newTitle)
Update the title of the active scene.
bool RemoveScene(int index)
Remove a scene by index.
std::vector< std::unique_ptr< IScene > > m_scenes
void OnNewSceneButton(wxCommandEvent &event)
wxAuiNotebook * m_sceneNotebook
SceneChangedCallback m_sceneChangedCallback
wxString GetTitle() const override
Get the display title for this panel.
int AddScene(std::unique_ptr< IScene > scene)
Add a new scene to the panel.
void SwitchToNextScene()
Switch to the next scene (cyclic)
MainPanel(wxWindow *parent)
void CreateLayout() override
Create the panel's UI layout Called during initialization.
void OnTabChanged(wxAuiNotebookEvent &event)
wxString GenerateSceneTitle() const
void OnTabClosed(wxAuiNotebookEvent &event)
IScene * GetActiveScene() const
Get the currently active scene.
bool SceneTitleExists(const wxString &title) const
void ApplyCanvasBackgroundColor(const wxColour &color)
Apply canvas background color to all scenes.
IScene * GetScene(int index) const
Get a scene by index.
void SwitchToPreviousScene()
Switch to the previous scene (cyclic)
int CreateNewScene()
Create a new empty behavior tree scene.
Base implementation of IPanel interface.
bool HasUnsavedChanges() const override
Check if this panel has unsaved changes.
CloseConfirmationMode closeConfirmation