37 #ifdef USE_WIN32_WINDOWS
43 QString C4ConsoleQtTranslator::translate(
const char * context,
const char * sourceText,
const char * disambiguation,
int n)
const
46 if (disambiguation && !strcmp(disambiguation,
"res"))
49 return QString(sourceText);
57 : QAction(
text, parent), client_id(client_id), op(op)
59 connect(
this, SIGNAL(triggered()),
this, SLOT(Execute()));
62 void C4ConsoleClientAction::Execute()
82 C4ConsoleRemovePlayerAction::C4ConsoleRemovePlayerAction(int32_t player_num,
const char *
text, QObject *parent)
83 : QAction(
text, parent), player_num(player_num)
85 connect(
this, SIGNAL(triggered()),
this, SLOT(Execute()));
88 void C4ConsoleRemovePlayerAction::Execute()
98 C4ConsoleOpenViewportAction::C4ConsoleOpenViewportAction(int32_t player_num,
const char *
text, QObject *parent)
99 : QAction(
text, parent), player_num(player_num)
101 connect(
this, SIGNAL(triggered()),
this, SLOT(Execute()));
104 void C4ConsoleOpenViewportAction::Execute()
122 int ExecRecursionCheck::counter = 0;
127 C4ConsoleQtMainWindow::C4ConsoleQtMainWindow(
C4AbstractApp *app, C4ConsoleGUIState *state)
128 : QMainWindow(nullptr), state(state)
132 void C4ConsoleQtMainWindow::keyPressEvent(QKeyEvent * event)
134 if (HandleEditorKeyDown(event))
event->setAccepted(
true);
135 QMainWindow::keyPressEvent(event);
138 void C4ConsoleQtMainWindow::keyReleaseEvent(QKeyEvent * event)
140 if (HandleEditorKeyUp(event))
event->setAccepted(
true);
141 QMainWindow::keyPressEvent(event);
156 void C4ConsoleQtMainWindow::closeEvent(QCloseEvent *event)
160 QByteArray geometry = saveGeometry(), window_state = saveState();
161 ws.
geometry.
Copy(geometry.constData(), geometry.size());
163 StdBuf ws_contents = DecompileToBuf<StdCompilerBinWrite>(ws);
166 QMainWindow::closeEvent(event);
170 void C4ConsoleQtMainWindow::LoadGeometry()
179 CompileFromBuf<StdCompilerBinRead>(ws, ws_contents);
182 restoreGeometry(geometry);
183 restoreState(window_state);
187 Log(
"Editor: Could not restore window settings");
193 void C4ConsoleQtMainWindow::PlayPressed(
bool down)
198 state->ui.actionPlay->setChecked(
true);
201 void C4ConsoleQtMainWindow::PausePressed(
bool down)
209 void C4ConsoleQtMainWindow::CursorGamePressed(
bool down)
218 state->ui.actionCursorGame->setChecked(
true);
222 void C4ConsoleQtMainWindow::CursorSelectPressed(
bool down)
228 state->ui.propertyDockWidget->raise();
233 state->ui.actionCursorSelect->setChecked(
true);
237 void C4ConsoleQtMainWindow::CursorCreateObjPressed(
bool down)
243 state->ui.creatorDockWidget->raise();
248 state->ui.actionCursorCreateObj->setChecked(
true);
252 void C4ConsoleQtMainWindow::CursorDrawPenPressed(
bool down)
260 state->ui.actionCursorDrawPen->setChecked(
true);
263 void C4ConsoleQtMainWindow::CursorDrawLinePressed(
bool down)
271 state->ui.actionCursorDrawLine->setChecked(
true);
274 void C4ConsoleQtMainWindow::CursorDrawRectPressed(
bool down)
282 state->ui.actionCursorDrawRect->setChecked(
true);
285 void C4ConsoleQtMainWindow::CursorFillPressed(
bool down)
293 state->ui.actionCursorFill->setChecked(
true);
297 void C4ConsoleQtMainWindow::CursorPickerPressed(
bool down)
305 state->ui.actionCursorPicker->setChecked(
true);
308 void C4ConsoleQtMainWindow::DynamicLandscapePressed(
bool down)
313 state->ui.actionDynamicLandscape->setChecked(
true);
316 void C4ConsoleQtMainWindow::StaticLandscapePressed(
bool down)
321 state->ui.actionStaticLandscape->setChecked(
true);
324 void C4ConsoleQtMainWindow::StaticFlatLandscapePressed(
bool down)
329 state->ui.actionStaticFlatLandscape->setChecked(
true);
332 void C4ConsoleQtMainWindow::ExactLandscapePressed(
bool down)
337 state->ui.actionExactLandscape->setChecked(
true);
340 void C4ConsoleQtMainWindow::DrawSizeChanged(
int newval)
345 void C4ConsoleQtMainWindow::OpenTranslationsOverview()
348 if (!state->translation_overview_dialogue)
350 state->translation_overview_dialogue.reset(
new C4ConsoleQtLocalizeOverviewDlg(
this));
352 state->translation_overview_dialogue->Refresh();
353 state->translation_overview_dialogue->show();
354 state->translation_overview_dialogue->resize(size() * 8/10);
355 int32_t margin = size().width() / 10;
356 QRect geom = geometry();
357 geom.adjust(margin, margin, -margin, -margin);
358 state->translation_overview_dialogue->setGeometry(geom);
359 state->translation_overview_dialogue->raise();
360 state->translation_overview_dialogue->activateWindow();
366 void C4ConsoleQtMainWindow::FileOpenInNetwork() {
::Console.
FileOpen(
nullptr,
true); }
376 void C4ConsoleQtMainWindow::FileReInitScenario()
388 void C4ConsoleQtMainWindow::HelpToggle(
bool enabled)
396 void C4ConsoleQtMainWindow::MainConsoleEditEnter()
398 QLineEdit *main_console_edit = state->ui.consoleInputBox->lineEdit();
403 void C4ConsoleQtMainWindow::PropertyConsoleEditEnter()
405 QLineEdit *property_console_edit = state->ui.propertyInputBox->lineEdit();
410 void C4ConsoleQtMainWindow::OnCreatorSelectionChanged(
const QItemSelection & selected,
const QItemSelection & deselected)
412 state->OnCreatorSelectionChanged(selected, deselected);
415 void C4ConsoleQtMainWindow::OnCreatorCurrentChanged(
const QModelIndex & current,
const QModelIndex & previous)
417 state->OnCreatorCurrentChanged(current, previous);
420 void C4ConsoleQtMainWindow::OnObjectListSelectionChanged(
const QItemSelection & selected,
const QItemSelection & deselected)
422 state->OnObjectListSelectionChanged(selected, deselected);
425 void C4ConsoleQtMainWindow::AscendPropertyPath()
427 state->property_model->AscendPath();
431 void C4ConsoleQtMainWindow::AddArrayElement()
433 if (state->property_model) state->property_model->AddArrayElement();
436 void C4ConsoleQtMainWindow::RemoveArrayElement()
438 if (state->property_model) state->property_model->RemoveArrayElement();
442 bool C4ConsoleQtMainWindow::HandleEditorKeyDown(QKeyEvent *event)
444 switch (event->key())
454 if (event->modifiers() & Qt::AltModifier) shift |= MK_ALT;
455 if (event->modifiers() & Qt::ControlModifier) shift |= MK_CONTROL;
456 if (event->modifiers() & Qt::ShiftModifier) shift |= MK_SHIFT;
462 bool C4ConsoleQtMainWindow::HandleEditorKeyUp(QKeyEvent *event)
465 if (event->modifiers() & Qt::AltModifier) shift |= MK_ALT;
466 if (event->modifiers() & Qt::ControlModifier) shift |= MK_CONTROL;
467 if (event->modifiers() & Qt::ShiftModifier) shift |= MK_SHIFT;
475 int sep = mat_tex.indexOf(
'-');
483 *mat = mat_tex.mid(0, sep);
484 *tex = mat_tex.mid(sep + 1);
488 void C4ConsoleQtMainWindow::ForegroundMaterialChanged(
const QString &new_selection)
496 void C4ConsoleQtMainWindow::BackgroundMaterialChanged(
const QString &new_selection)
504 void C4ConsoleQtMainWindow::WelcomeLinkActivated(
const QString &link)
507 if (link ==
"new") FileNew();
508 else if (link ==
"open") FileOpen();
509 else if (link ==
"exploreuserpath")
511 bool success =
false;
512 #ifdef USE_WIN32_WINDOWS
514 intptr_t iError = (intptr_t) ::ShellExecute(
nullptr, L
"open", path.GetWideChar(),
nullptr, path.GetWideChar(), SW_SHOW);
515 if (iError > 32) success =
true;
520 QMessageBox::critical(
this,
LoadResStr(
"IDS_MNU_EXPLOREUSERPATH"),
LoadResStr(
"IDS_ERR_EXPLOREUSERPATH"));
523 else if (link.startsWith(
"open:"))
525 QString open_file = link.mid(5);
530 void C4ConsoleQtMainWindow::SelectionDelete()
535 void C4ConsoleQtMainWindow::SelectionDuplicate()
540 void C4ConsoleQtMainWindow::SelectionEjectContents()
545 void C4ConsoleQtMainWindow::FocusGlobalScriptBox()
547 state->ui.logDockWidget->show();
548 state->ui.logDockWidget->raise();
549 state->ui.consoleInputBox->setFocus();
552 void C4ConsoleQtMainWindow::FocusObjectScriptBox()
554 state->ui.propertyDockWidget->show();
555 state->ui.propertyDockWidget->raise();
556 state->ui.propertyInputBox->setFocus();
559 void C4ConsoleQtMainWindow::OpenMaterialSelection()
561 if (state->ui.foregroundMatTexComboBox->isEnabled())
563 state->ui.foregroundMatTexComboBox->setFocus();
564 state->ui.foregroundMatTexComboBox->showPopup();
568 void C4ConsoleQtMainWindow::FocusNextViewport()
571 bool has_focus_vp =
false;
572 for (C4ConsoleQtViewportDockWidget *vp : state->viewports)
579 else if (vp->HasFocus())
585 if (state->viewports.size())
587 state->viewports.front()->SetFocus();
591 void C4ConsoleQtMainWindow::GradeUp()
593 if (state->ui.drawSizeSlider->isEnabled())
595 state->ui.drawSizeSlider->setValue(state->ui.drawSizeSlider->value() + state->ui.drawSizeSlider->singleStep());
599 void C4ConsoleQtMainWindow::GradeDown()
601 if (state->ui.drawSizeSlider->isEnabled())
603 state->ui.drawSizeSlider->setValue(state->ui.drawSizeSlider->value() - state->ui.drawSizeSlider->singleStep());
610 C4ConsoleGUIState::C4ConsoleGUIState(
C4ConsoleGUI *console) : viewport_area(nullptr),
611 enabled(false), recording(false), net_enabled(false), landscape_mode(
LandscapeMode::
Dynamic), flat_chunk_shapes(false),
612 editcursor_mode(
C4CNS_ModePlay), drawing_tool(
C4TLS_Brush), is_object_selection_updating(0), disable_shortcut_filter(new C4DisableShortcutFilter(nullptr))
616 C4ConsoleGUIState::~C4ConsoleGUIState() =
default;
618 void C4ConsoleGUIState::AddToolbarSpacer(
int space)
620 auto spacer =
new QWidget();
621 spacer->setFixedWidth(space);
622 ui.toolBar->addWidget(spacer);
625 bool C4ConsoleGUIState::CreateConsoleWindow(
C4AbstractApp *app)
631 QSurfaceFormat format;
632 format.setMajorVersion( 3);
633 format.setMinorVersion( 2);
634 format.setRedBufferSize(8);
635 format.setGreenBufferSize(8);
636 format.setBlueBufferSize(8);
637 format.setDepthBufferSize(8);
638 format.setProfile(QSurfaceFormat::CoreProfile);
639 format.setSwapInterval(0);
641 format.setOption(QSurfaceFormat::DebugContext);
642 QSurfaceFormat::setDefaultFormat(format);
643 QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
649 static int fake_argc = 1;
650 static const char *fake_argv[] = {
"openclonk" };
651 application = std::make_unique<QApplication>(fake_argc,
const_cast<char **
>(fake_argv));
653 window = std::make_unique<C4ConsoleQtMainWindow>(app,
this);
654 ui.setupUi(window.get());
658 status_cursor =
new QLabel(
"", window.get());
659 status_framecounter =
new QLabel(
"", window.get());
660 status_timefps =
new QLabel(
"", window.get());
661 ui.statusbar->addPermanentWidget(status_cursor, 3);
662 ui.statusbar->addPermanentWidget(status_framecounter, 1);
663 ui.statusbar->addPermanentWidget(status_timefps, 1);
665 ui.toolBar->addWidget(ui.foregroundMatTexComboBox);
666 ui.toolBar->addWidget(ui.backgroundMatTexComboBox);
668 ui.toolBar->addWidget(ui.drawSizeLabel);
670 ui.toolBar->addWidget(ui.drawSizeSlider);
674 ui.drawSizeSlider->setSingleStep(1);
676 QLineEdit *main_console_edit = ui.consoleInputBox->lineEdit();
677 main_console_edit->completer()->setCaseSensitivity(Qt::CaseSensitivity::CaseSensitive);
678 main_console_edit->connect(main_console_edit, SIGNAL(returnPressed()), window.get(), SLOT(MainConsoleEditEnter()));
679 QLineEdit *property_console_edit = ui.propertyInputBox->lineEdit();
680 property_console_edit->connect(property_console_edit, SIGNAL(returnPressed()), window.get(), SLOT(PropertyConsoleEditEnter()));
681 property_console_edit->completer()->setCaseSensitivity(Qt::CaseSensitivity::CaseSensitive);
683 window_menu_separator = ui.menuWindows->addSeparator();
684 QAction *dock_action = ui.creatorDockWidget->toggleViewAction();
685 dock_action->setShortcut(QKeySequence(Qt::ALT | Qt::Key_1));
686 ui.menuWindows->addAction(dock_action);
687 dock_action = ui.objectListDockWidget->toggleViewAction();
688 dock_action->setShortcut(QKeySequence(Qt::ALT | Qt::Key_2));
689 ui.menuWindows->addAction(dock_action);
690 dock_action = ui.propertyDockWidget->toggleViewAction();
691 dock_action->setShortcut(QKeySequence(Qt::ALT | Qt::Key_3));
692 ui.menuWindows->addAction(dock_action);
693 dock_action = ui.logDockWidget->toggleViewAction();
694 dock_action->setShortcut(QKeySequence(Qt::ALT | Qt::Key_4));
695 ui.menuWindows->addAction(dock_action);
697 viewport_area =
new QMainWindow();
698 viewport_area->setWindowFlags(Qt::Widget);
699 window->setCentralWidget(viewport_area);
700 window->setDockNestingEnabled(
true);
701 viewport_area->setDockNestingEnabled(
true);
702 QWidget *foo =
new QWidget(viewport_area);
703 viewport_area->setCentralWidget(foo);
712 property_delegate_factory = std::make_unique<C4PropertyDelegateFactory>();
713 ui.propertyTable->setItemDelegateForColumn(1, property_delegate_factory.get());
714 ui.propertyEditAscendPathButton->setMaximumWidth(ui.propertyEditAscendPathButton->fontMetrics().boundingRect(ui.propertyEditAscendPathButton->text()).width() + 10);
715 ui.propertyTable->setDropIndicatorShown(
true);
716 ui.propertyTable->setAcceptDrops(
true);
717 property_name_delegate = std::make_unique<C4PropertyNameDelegate>();
718 ui.propertyTable->setItemDelegateForColumn(0, property_name_delegate.get());
719 ui.propertyTable->setMouseTracking(
true);
722 property_model = std::make_unique<C4ConsoleQtPropListModel>(property_delegate_factory.get());
723 property_delegate_factory->SetPropertyModel(property_model.get());
724 property_name_delegate->SetPropertyModel(property_model.get());
725 QItemSelectionModel *m = ui.propertyTable->selectionModel();
726 ui.propertyTable->setModel(property_model.get());
728 property_model->SetSelectionModel(ui.propertyTable->selectionModel());
729 object_list_model = std::make_unique<C4ConsoleQtObjectListModel>();
730 m = ui.objectListView->selectionModel();
731 ui.objectListView->setModel(object_list_model.get());
733 window->connect(ui.objectListView->selectionModel(), &QItemSelectionModel::selectionChanged, window.get(), &C4ConsoleQtMainWindow::OnObjectListSelectionChanged);
734 definition_list_model = std::make_unique<C4ConsoleQtDefinitionListModel>();
735 property_delegate_factory->SetDefinitionListModel(definition_list_model.get());
736 m = ui.creatorTreeView->selectionModel();
737 ui.creatorTreeView->setModel(definition_list_model.get());
739 window->connect(ui.creatorTreeView->selectionModel(), &QItemSelectionModel::selectionChanged, window.get(), &C4ConsoleQtMainWindow::OnCreatorSelectionChanged);
740 window->connect(ui.creatorTreeView->selectionModel(), &QItemSelectionModel::currentChanged, window.get(), &C4ConsoleQtMainWindow::OnCreatorCurrentChanged);
741 window->connect(ui.propertyTable->selectionModel(), &QItemSelectionModel::currentChanged, window.get(), [
this]() {
742 this->ui.arrayRemoveButton->setDisabled(this->property_model->IsTargetReadonly() || this->ui.propertyTable->selectionModel()->selectedRows().empty());
746 window->connect(ui.objectListView, &QTreeView::doubleClicked, window.get(), [
this](
const QModelIndex &index) {
747 window->FocusObjectScriptBox();
751 window->tabifyDockWidget(ui.objectListDockWidget, ui.propertyDockWidget);
752 window->tabifyDockWidget(ui.objectListDockWidget, ui.creatorDockWidget);
753 ui.propertyDockWidget->raise();
761 PropertyDlgUpdate(sel,
true);
764 window->LoadGeometry();
769 void C4ConsoleGUIState::DeleteConsoleWindow()
773 is_object_selection_updating =
false;
782 window_menu_separator =
nullptr;
783 status_cursor = status_framecounter = status_timefps =
nullptr;
785 while (!viewports.empty())
787 auto vp = viewports.front();
788 viewports.erase(viewports.begin());
790 viewport_area->removeDockWidget(vp);
794 client_actions.clear();
795 player_actions.clear();
796 viewport_actions.clear();
797 viewport_area =
nullptr;
799 disable_shortcut_filter.reset(
nullptr);
800 definition_list_model.reset(
nullptr);
801 object_list_model.reset(
nullptr);
802 property_name_delegate.reset(
nullptr);
803 property_delegate_factory.reset(
nullptr);
804 property_model.reset(
nullptr);
805 window.reset(
nullptr);
806 application.reset(
nullptr);
809 void C4ConsoleGUIState::Execute(
bool redraw_only)
815 void C4ConsoleGUIState::UpdateActionStates()
820 bool is_drawing = has_draw_tools && editcursor_mode ==
C4CNS_ModeDraw;
822 ui.actionFileNew->setEnabled(!enabled);
823 ui.actionFileReInitScenario->setEnabled(enabled);
824 ui.actionPlay->setEnabled(enabled || is_lobby);
825 ui.actionPause->setEnabled(enabled);
826 ui.actionCursorGame->setEnabled(enabled);
827 ui.actionCursorSelect->setEnabled(enabled);
828 ui.actionCursorCreateObj->setEnabled(enabled);
829 ui.actionCursorDrawPen->setEnabled(has_draw_tools);
830 ui.actionCursorDrawLine->setEnabled(has_draw_tools);
831 ui.actionCursorDrawRect->setEnabled(has_draw_tools);
832 ui.actionCursorPicker->setEnabled(has_draw_tools);
833 ui.actionCursorFill->setEnabled(has_exact_draw_tools);
834 ui.actionDynamicLandscape->setEnabled(enabled);
835 ui.actionStaticLandscape->setEnabled(enabled);
836 ui.actionStaticFlatLandscape->setEnabled(enabled);
837 ui.actionExactLandscape->setEnabled(enabled);
838 ui.actionTranslations->setEnabled(enabled);
839 ui.foregroundMatTexComboBox->setEnabled(is_drawing);
840 ui.backgroundMatTexComboBox->setEnabled(is_drawing);
841 ui.drawSizeSlider->setEnabled(is_drawing);
842 ui.actionFileClose->setEnabled(enabled);
843 ui.actionFileRecord->setEnabled(enabled && !recording);
844 ui.actionFileSaveGameAs->setEnabled(enabled);
845 ui.actionFileSaveScenario->setEnabled(enabled);
846 ui.actionFileSaveScenarioAs->setEnabled(enabled);
847 ui.actionFileExportScenarioPacked->setEnabled(enabled);
848 ui.actionViewportNew->setEnabled(enabled);
849 ui.actionPlayerJoin->setEnabled(enabled);
850 ui.menuNet->setEnabled(net_enabled);
853 ui.actionCursorGame->setChecked(editcursor_mode ==
C4CNS_ModePlay);
854 ui.actionCursorSelect->setChecked(editcursor_mode ==
C4CNS_ModeEdit);
863 ui.actionStaticFlatLandscape->setChecked(landscape_mode ==
LandscapeMode::Static && flat_chunk_shapes);
865 ui.actionFileRecord->setChecked(recording);
869 static void SetComboItems(QComboBox *box, std::list<const char*> &items)
871 QString
text = box->lineEdit()->text();
873 for (
auto & item : items)
876 box->addItem(
"----------");
880 box->lineEdit()->setText(
text);
883 void C4ConsoleGUIState::UpdateMatTex()
887 if (material !=
C4TLS_MatSky) new_index = ui.foregroundMatTexComboBox->findText(QString(
FormatString(
"%s-%s", material.getData(), texture.getData()).
getData()));
888 if (new_index >= 0) ui.foregroundMatTexComboBox->setCurrentIndex(new_index);
891 void C4ConsoleGUIState::UpdateBackMatTex()
895 if (back_material !=
C4TLS_MatSky) new_index = ui.backgroundMatTexComboBox->findText(QString(
FormatString(
"%s-%s", back_material.getData(), back_texture.getData()).
getData()));
896 if (new_index >= 0) ui.backgroundMatTexComboBox->setCurrentIndex(new_index);
901 auto *kick_action =
new C4ConsoleClientAction(index,
text, ui.menuNet, op);
903 client_actions.emplace_back(kick_action);
904 ui.menuNet->addAction(kick_action);
907 void C4ConsoleGUIState::ClearNetMenu()
909 for (
auto &action : client_actions) ui.menuNet->removeAction(action.get());
910 client_actions.clear();
913 void C4ConsoleGUIState::AddKickPlayerMenuItem(int32_t plr,
const char *
text,
bool item_enabled)
915 auto *kick_action =
new C4ConsoleRemovePlayerAction(plr,
text, ui.menuPlayers);
916 kick_action->setEnabled(item_enabled);
917 player_actions.emplace_back(kick_action);
918 ui.menuPlayers->addAction(kick_action);
921 void C4ConsoleGUIState::ClearPlayerMenu()
923 for (
auto &action : player_actions) ui.menuPlayers->removeAction(action.get());
924 player_actions.clear();
927 void C4ConsoleGUIState::AddPlayerViewportMenuItem(int32_t plr,
const char *
text)
929 auto *action =
new C4ConsoleOpenViewportAction(plr,
text, ui.menuWindows);
930 viewport_actions.emplace_back(action);
931 ui.menuWindows->insertAction(window_menu_separator, action);
934 void C4ConsoleGUIState::ClearViewportMenu()
936 for (
auto &action : viewport_actions) ui.menuWindows->removeAction(action.get());
937 viewport_actions.clear();
942 if (!viewport_area)
return;
943 C4ConsoleQtViewportDockWidget *new_viewport =
new C4ConsoleQtViewportDockWidget(window.get(), viewport_area, cvp);
944 viewport_area->addDockWidget(Qt::BottomDockWidgetArea, new_viewport);
945 viewports.push_back(new_viewport);
946 new_viewport->SetFocus();
951 if (!viewport_area)
return;
953 for (
auto iter = viewports.begin(); iter != viewports.end(); )
956 if (vp->GetViewportWindow() == cvp)
958 viewport_area->removeDockWidget(vp);
959 iter = viewports.erase(iter);
976 void C4ConsoleGUIState::SetInputFunctions(std::list<const char*> &functions)
978 SetComboItems(ui.consoleInputBox, functions);
981 void C4ConsoleGUIState::PropertyDlgUpdate(
C4EditCursorSelection &rSelection,
bool force_function_update)
983 int sel_count = rSelection.size();
984 bool is_array =
false;
988 property_model->SetBasePropList(
nullptr);
989 ui.propertyTable->setEnabled(
false);
991 ui.propertyEditAscendPathButton->hide();
992 UpdateActionObject(
nullptr);
993 ui.selectionHelpLabel->hide();
998 C4PropList *prev_list = property_model->GetBasePropList(), *new_list = rSelection.front().getPropList();
999 if (prev_list != new_list)
1001 property_model->SetBasePropList(new_list);
1002 ui.propertyTable->setFirstColumnSpanned(0, QModelIndex(),
true);
1003 ui.propertyTable->setFirstColumnSpanned(1, QModelIndex(),
true);
1004 ui.propertyTable->expand(property_model->index(0, 0, QModelIndex()));
1005 UpdateActionObject(new_list->GetObject());
1009 property_model->UpdateValue(
false);
1011 ui.selectionInfoLabel->setText(property_model->GetTargetPathText());
1012 QString help_text = property_model->GetTargetPathHelp();
1015 const char *help_label = property_model->GetTargetPathName();
1016 if (!help_label) help_label =
LoadResStr(
"IDS_CNS_DESCRIPTION");
1017 ui.selectionHelpLabel->setText(QString(
"%1: %2").arg(help_label).arg(help_text));
1018 ui.selectionHelpLabel->show();
1022 ui.selectionHelpLabel->hide();
1024 ui.propertyEditAscendPathButton->setVisible(property_model->GetTargetPathStackSize() >= 1);
1025 is_array = property_model->IsArray();
1028 bool is_readonly = property_model->IsTargetReadonly();
1029 ui.arrayAddButton->setDisabled(is_readonly);
1030 ui.arrayRemoveButton->setDisabled(is_readonly || ui.propertyTable->selectionModel()->selectedRows().empty());
1032 ui.propertyTable->setEnabled(
true);
1035 ui.arrayAddButton->setVisible(is_array);
1036 ui.arrayRemoveButton->setVisible(is_array);
1038 if (force_function_update)
1041 SetComboItems(ui.propertyInputBox, suggestions);
1045 void C4ConsoleGUIState::ReInitDefinitions()
1047 if (definition_list_model) definition_list_model->ReInit();
1049 if (object_list_model) object_list_model->Invalidate();
1052 void C4ConsoleGUIState::OnCreatorSelectionChanged(
const QItemSelection & selected,
const QItemSelection & deselected)
1054 if (is_object_selection_updating || !definition_list_model)
return;
1057 auto deselected_indexes = deselected.indexes();
1058 for (
const QModelIndex &item : deselected_indexes)
1059 if ((def = definition_list_model->GetDefByModelIndex(item)))
1061 auto selected_indexes = selected.indexes();
1062 for (
const QModelIndex &item : selected_indexes)
1063 if ((def = definition_list_model->GetDefByModelIndex(item)))
1067 if (!selected.empty())
1069 ui.objectListView->selectionModel()->clearSelection();
1075 void C4ConsoleGUIState::OnObjectListSelectionChanged(
const QItemSelection & selected,
const QItemSelection & deselected)
1077 if (is_object_selection_updating)
return;
1080 for (
const QModelIndex &item : deselected.indexes())
1081 if ((p = object_list_model->GetItemByModelIndex(item)))
1083 for (
const QModelIndex &item : selected.indexes())
1084 if ((p = object_list_model->GetItemByModelIndex(item)))
1088 if (!selected.empty())
1090 ui.creatorTreeView->selectionModel()->clearSelection();
1098 if (!window.get())
return;
1102 ++is_object_selection_updating;
1103 ui.objectListView->selectionModel()->clearSelection();
1104 ui.creatorTreeView->selectionModel()->clearSelection();
1105 QModelIndex last_idx_obj, last_idx_def, creator_idx;
1114 QModelIndex idx = definition_list_model->GetModelIndexByItem(def);
1117 ui.creatorTreeView->selectionModel()->select(idx, QItemSelectionModel::Select);
1119 if (def == creator_def) creator_idx = idx;
1124 QModelIndex idx = object_list_model->GetModelIndexByItem(v.getPropList());
1127 ui.objectListView->selectionModel()->select(idx, QItemSelectionModel::Select);
1132 if (last_idx_obj.isValid()) ui.objectListView->scrollTo(last_idx_obj);
1133 if (last_idx_def.isValid()) ui.creatorTreeView->scrollTo(last_idx_def);
1140 if (creator_idx.isValid()) ui.creatorTreeView->selectionModel()->select(creator_idx, QItemSelectionModel::Current);
1141 --is_object_selection_updating;
1144 void C4ConsoleGUIState::OnCreatorCurrentChanged(
const QModelIndex & current,
const QModelIndex & previous)
1148 if (!definition_list_model)
return;
1149 C4Def *new_def = definition_list_model->GetDefByModelIndex(current);
1154 bool C4ConsoleGUIState::CreateNewScenario(
StdStrBuf *out_filename,
bool *out_host_as_network)
1157 std::unique_ptr<C4ConsoleQtNewScenarioDlg> dlg(
new C4ConsoleQtNewScenarioDlg(window.get()));
1158 if (!dlg->exec())
return false;
1160 out_filename->
Copy(dlg->GetFilename());
1161 *out_host_as_network = dlg->IsHostAsNetwork();
1165 void C4ConsoleGUIState::InitWelcomeScreen()
1168 ui.welcomeNewLabel->setText(QString(R
"(<a href="new">%1</a>)").arg(ui.welcomeNewLabel->text()));
1169 ui.welcomeOpenLabel->setText(QString(R"(<a href="open">%1</a>)").arg(ui.welcomeOpenLabel->text()));
1170 ui.welcomeExploreUserPathLabel->setText(QString(R"(<a href="exploreuserpath">%1</a>)").arg(ui.welcomeExploreUserPathLabel->text()));
1172 bool any_file =
false;
1173 int recent_idx = ui.welcomeScrollLayout->indexOf(ui.welcomeRecentLabel);
1182 basename.Copy(filename, strlen(filename) - basename.getLength());
1183 int32_t len = basename.getLength();
1185 basename.SetLength(--len);
1187 basename.Take(base_folder_name);
1190 QLabel *link =
new QLabel(ui.welcomeScrollAreaWidgetContents);
1191 ui.welcomeScrollLayout->insertWidget(++recent_idx, link);
1192 link->setIndent(ui.welcomeOpenLabel->indent());
1193 link->setTextInteractionFlags(ui.welcomeOpenLabel->textInteractionFlags());
1194 link->setText(QString(R
"(<a href="open:%1">%2</a>)").arg(filename).arg(basename.getData()));
1196 window->connect(link, SIGNAL(linkActivated(QString)), window.get(), SLOT(WelcomeLinkActivated(QString)));
1199 if (!any_file) ui.welcomeRecentLabel->hide();
1202 void C4ConsoleGUIState::ShowWelcomeScreen()
1204 viewport_area->addDockWidget(Qt::BottomDockWidgetArea, ui.welcomeDockWidget);
1207 void C4ConsoleGUIState::HideWelcomeScreen()
1209 ui.welcomeDockWidget->close();
1212 void C4ConsoleGUIState::ClearGamePointers()
1214 if (property_delegate_factory) property_delegate_factory->ClearDelegates();
1217 void C4ConsoleGUIState::UpdateActionObject(
C4Object *new_action_object)
1220 C4Object *prev_object = action_object.getObj();
1221 if (new_action_object && prev_object == new_action_object)
return;
1222 action_object =
C4VObj(new_action_object);
1224 int32_t i = ui.objectActionPanel->count();
1227 ui.objectActionPanel->itemAt(i)->widget()->deleteLater();
1231 if (!new_action_object)
return;
1233 if (!editor_actions_list)
return;
1235 int row = 0, column = 0;
1236 for (
C4String *action_def_id : new_properties)
1240 if (!editor_actions_list->
GetPropertyByS(action_def_id, &action_def_val))
1256 action_name = action_def_id;
1259 QString action_help;
1263 action_help = QString(action_help_s->
GetCStr()).replace(
'|',
'\n');
1267 int32_t object_number = new_action_object->
Number;
1269 QPushButton *btn =
new QPushButton(action_name->
GetCStr(), window.get());
1270 if (!action_help.isEmpty()) btn->setToolTip(action_help);
1274 btn->connect(btn, &QPushButton::pressed, btn, [script_command, object_number, select_returned_object]()
1279 int32_t local_player_number = local_player ? local_player->
Number :
NO_OWNER;
1280 script_command_cpy.Replace(
"%player%",
FormatString(
"%d", (
int)local_player_number).getData());
1284 ui.objectActionPanel->addWidget(btn, row, column);
#define C4CFN_EditorGeometry
#define C4CFN_ScenarioCore
const int C4CNS_ModeCreateObject
C4ConsoleQtTranslator qt_translator
void SplitMaterialTexture(const QString &mat_tex, QString *mat, QString *tex)
const char * LoadResStr(const char *id)
bool Log(const char *szMessage)
C4Value C4VObj(C4Object *pObj)
StdStrBuf FormatString(const char *szFmt,...)
char * GetFilename(char *szPath)
void RemoveExtension(char *szFilename)
bool ItemExists(const char *szItemName)
C4Client * getClientByID(int32_t iID) const
void CtrlRemove(const C4Client *pClient, const char *szReason)
char RecentlyEditedSzenarios[CFG_MaxEditorMRU][CFG_MaxString+1]
char UserDataPath[CFG_MaxString+1]
const char * AtUserDataPath(const char *filename)
C4ConfigDeveloper Developer
C4ConfigGraphics Graphics
bool In(const char *szText)
bool FileOpen(const char *filename=nullptr, bool host_in_network=false)
void RegisterRecentInput(const char *input, RecentScriptInputLists section)
std::list< const char * > GetScriptSuggestions(class C4PropList *target, RecentScriptInputLists section) const
bool FileSaveAs(bool fSaveGame, bool export_packed=false)
void Add(C4PacketType eType, C4ControlPacket *pCtrl)
static C4ControlPlayerAction * Eliminate(const C4Player *source)
bool SetMode(int32_t iMode)
bool KeyDown(C4KeyCode KeyCode, DWORD dwKeyState)
void AddToSelection(C4PropList *add_obj)
bool In(const char *szText)
bool RemoveFromSelection(C4PropList *remove_obj)
void EMControl(enum C4PacketType eCtrlType, class C4ControlPacket *pCtrl)
void OnSelectionChanged(bool by_objectlist=false)
void SetCreatorDef(C4Def *new_def)
bool IsSelectionInvalidated() const
bool KeyUp(C4KeyCode KeyCode, DWORD dwKeyState)
void InvalidateSelection()
StdStrBuf GetDataString() const
C4Object * GetObject(int32_t index=0) const
void DoInput(C4PacketType eCtrlType, C4ControlPacket *pPkt, C4ControlDeliveryType eDelivery)
bool isLobbyActive() const
C4Player * Get(int iPlayer) const
C4Player * GetLocalByIndex(int iIndex) const
int32_t GetPropertyBool(C4PropertyName n, bool default_val=false) const
virtual C4Object * GetObject()
virtual bool GetPropertyByS(const C4String *k, C4Value *pResult) const
C4PropList * GetPropertyPropList(C4PropertyName k) const
C4String * GetPropertyStr(C4PropertyName k) const
virtual C4Def const * GetDef() const
std::vector< C4String * > GetSortedProperties(const char *prefix, C4PropList *ignore_parent=nullptr) const
StdStrBuf GetData() const
const char * GetCStr() const
C4PropList * getPropList() const
bool CreateViewport(int32_t player_nr, bool silent=false)
bool SaveToFile(const char *szFile) const
const void * getData() const
bool LoadFromFile(const char *szFile)
void Value(const T &rStruct)
const char * getData() const
void CompileFunc(StdCompiler *comp)