Qt Editor: Add "Welcome" dock widget

qteditor
Sven Eberhardt 2016-03-25 00:12:41 -04:00
parent 1613885f47
commit f2daa51fa7
13 changed files with 408 additions and 16 deletions

View File

@ -40,6 +40,7 @@ IDS_CNS_CREATESTATUS=Platzierung: %s
IDS_CNS_CREATOR=Objekte erstellen
IDS_CNS_DEFINITIONS=Definitionen
IDS_CNS_DROPNODEF=Ungültiges oder nicht geladenes Objekt: %s
IDS_CNS_EDITOR=OpenClonk Editor
IDS_CNS_EFFECTS=Effekte:
IDS_CNS_EXACTTOSTATIC=Beim Wechsel von einer exakten zur statischen Landschaft gehen sämtliche in der exakten Karte gemachten Änderungen verloren.
IDS_CNS_FILENAME=Dateiname
@ -77,6 +78,7 @@ IDS_CNS_TYPE=Typ: %s (%s)
IDS_CNS_VALUE=Wert
IDS_CNS_VIEWPORT=Sichtfenster
IDS_CNS_WARNDOUBLE=Um Verdoppelungen der abgespeicherten Objekte beim nächsten Start zu vermeiden, sollte die Initialize-Funktion des Scripts entsprechend angepasst werden.
IDS_CNS_WELCOME=Willkommen
IDS_CNS_WIDTH=Breite
IDS_COMM_ACQUIRE=Beschaffung
IDS_COMM_ACTIVATE=Aktivieren
@ -318,6 +320,7 @@ IDS_DLG_NETWORK=Netzwerk
IDS_DLG_NO=&Nein
IDS_DLG_NOPLAYERSSELECTED=keine ausgewählt
IDS_DLG_OK=&OK
IDS_DLG_OPEN=Datei öffnen...
IDS_DLG_OPTIONS=&Optionen
IDS_DLG_PASSWORD=Passwort
IDS_DLG_PASTE=Einfügen
@ -330,6 +333,7 @@ IDS_DLG_PROGRAM=Programm
IDS_DLG_PROPERTIES=Eigenschaften
IDS_DLG_READY=Bereit
IDS_DLG_RESOURCES=Ressourcen
IDS_DLG_SAVE=Datei speichern...
IDS_DLG_SCENARIO=Szenario
IDS_DLG_SCENARIOS=Szenarien
IDS_DLG_SCENARIOTITLE=Geladenes Szenario
@ -502,11 +506,13 @@ IDS_MNU_OPTIONSINFO=Einstellungen ändern.
IDS_MNU_PLAYER=Spieler
IDS_MNU_PLAYERNAMES=Spielernamen
IDS_MNU_QUIT=Beenden
IDS_MNU_RECENT=Zuletzt geöffnet
IDS_MNU_RECORD=Aufnahme
IDS_MNU_SAVEGAME=Spiel speichern
IDS_MNU_SAVEGAMEAS=Spiel speichern unter...
IDS_MNU_SAVESCENARIO=Szenario speichern
IDS_MNU_SAVESCENARIOAS=Szenario speichern unter...
IDS_MNU_START=Start
IDS_MNU_SWITCHRESOLUTION=Bildschirmauflösung ändern
IDS_MNU_SWITCHRESOLUTION_LIKEIT=Neue Auflösung gewählt. Zufrieden?
IDS_MNU_SWITCHRESOLUTION_UNDO=Alte Einstellung wird in %d Sekunden wiederhergestellt...

View File

@ -40,6 +40,7 @@ IDS_CNS_CREATESTATUS=Place new %s
IDS_CNS_CREATOR=Create objects
IDS_CNS_DEFINITIONS=Definitions
IDS_CNS_DROPNODEF=Object invalid or not loaded: %s
IDS_CNS_EDITOR=OpenClonk Editor
IDS_CNS_EFFECTS=Effects:
IDS_CNS_EXACTTOSTATIC=When switching from exact to dynamic mode all changes made in dynamic mode will be lost.
IDS_CNS_FILENAME=Filename
@ -77,6 +78,7 @@ IDS_CNS_TYPE=Type: %s (%s)
IDS_CNS_VALUE=Value
IDS_CNS_VIEWPORT=Viewport
IDS_CNS_WARNDOUBLE=In order to avoid double creation, the script's 'Initialize' function should be modified.
IDS_CNS_WELCOME=Welcome
IDS_CNS_WIDTH=Width
IDS_COMM_ACQUIRE=Acquisition
IDS_COMM_ACTIVATE=Activation
@ -318,6 +320,7 @@ IDS_DLG_NETWORK=Network
IDS_DLG_NO=&No
IDS_DLG_NOPLAYERSSELECTED=none selected
IDS_DLG_OK=&OK
IDS_DLG_OPEN=Open file...
IDS_DLG_OPTIONS=&Options
IDS_DLG_PASSWORD=Password
IDS_DLG_PASTE=Paste
@ -330,6 +333,7 @@ IDS_DLG_PROGRAM=Program
IDS_DLG_PROPERTIES=Properties
IDS_DLG_READY=Ready
IDS_DLG_RESOURCES=Resources
IDS_DLG_SAVE=Save file...
IDS_DLG_SCENARIO=Scenario
IDS_DLG_SCENARIOS=Scenarios
IDS_DLG_SCENARIOTITLE=Loaded scenario
@ -502,11 +506,13 @@ IDS_MNU_OPTIONSINFO=Change program options.
IDS_MNU_PLAYER=Player
IDS_MNU_PLAYERNAMES=Player names
IDS_MNU_QUIT=Quit
IDS_MNU_RECENT=Recent
IDS_MNU_RECORD=Record
IDS_MNU_SAVEGAME=Save game
IDS_MNU_SAVEGAMEAS=Save game as...
IDS_MNU_SAVESCENARIO=Save scenario
IDS_MNU_SAVESCENARIOAS=Save scenario as...
IDS_MNU_START=Start
IDS_MNU_SWITCHRESOLUTION=Switch resolution
IDS_MNU_SWITCHRESOLUTION_LIKEIT=This is your new resolution. Do you like it?
IDS_MNU_SWITCHRESOLUTION_UNDO=Original resolution will be restored in %d seconds...

View File

@ -86,6 +86,24 @@ void C4ConfigDeveloper::CompileFunc(StdCompiler *pComp)
pComp->Value(mkNamingAdapt(s(AltTodoFilename), "AltTodoFilename2", "{USERPATH}/TODO.txt", false, true));
pComp->Value(mkNamingAdapt(MaxScriptMRU, "MaxScriptMRU", 30 , false, false));
pComp->Value(mkNamingAdapt(DebugShapeTextures, "DebugShapeTextures", 0 , false, true));
for (int32_t i = 0; i < CFG_MaxEditorMRU; ++i)
pComp->Value(mkNamingAdapt(s(RecentlyEditedSzenarios[i]), FormatString("EditorMRU%02d", (int)i).getData(), "", false, false));
}
void C4ConfigDeveloper::AddRecentlyEditedScenario(const char *fn)
{
if (!fn || !*fn) return;
// Put given scenario first in list by moving all other scenarios down
// Check how many scenarios to move down the list. Stop moving down when the given scenario is in the list
int32_t move_down_num;
for (move_down_num = 0; move_down_num < CFG_MaxEditorMRU - 1; ++move_down_num)
if (!strncmp(fn, RecentlyEditedSzenarios[move_down_num], CFG_MaxString))
break;
// Move them down
for (int32_t i = move_down_num; i > 0; --i)
strcpy(RecentlyEditedSzenarios[i], RecentlyEditedSzenarios[i - 1]);
// Put current scenario in
strncpy(RecentlyEditedSzenarios[0], fn, CFG_MaxString);
}
void C4ConfigGraphics::CompileFunc(StdCompiler *pComp)

View File

@ -26,7 +26,7 @@
#include <list>
#define C4DEFAULT_FONT_NAME "Endeavour"
enum { CFG_MaxString = 1024 };
enum { CFG_MaxString = 1024, CFG_MaxEditorMRU = 8 };
class C4ConfigGeneral
{
@ -87,7 +87,9 @@ public:
char AltTodoFilename[CFG_MaxString + 1];
int32_t MaxScriptMRU; // maximum number of remembered elements in recently used scripts
int32_t DebugShapeTextures; // if nonzero, show messages about loaded shape textures
char RecentlyEditedSzenarios[CFG_MaxEditorMRU][CFG_MaxString + 1];
void CompileFunc(StdCompiler *pComp);
void AddRecentlyEditedScenario(const char *fn);
};
class C4ConfigGraphics

View File

@ -235,6 +235,7 @@ bool C4Console::FileSaveAs(bool fSaveGame)
OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY,
true)) return false;
DefaultExtension(&filename,"ocs");
::Config.Developer.AddRecentlyEditedScenario(filename.getData());
if (fSaveGame)
// Save game
return SaveGame(filename.getData());
@ -254,6 +255,7 @@ bool C4Console::FileNew()
#ifdef WITH_QT_EDITOR
if (!C4ConsoleGUI::CreateNewScenario(&filename)) return false;
Application.ClearCommandLine();
::Config.Developer.AddRecentlyEditedScenario(filename.getData());
Application.OpenGame(filename.getData());
return true;
#endif
@ -262,17 +264,22 @@ bool C4Console::FileNew()
}
bool C4Console::FileOpen()
bool C4Console::FileOpen(const char *filename)
{
// Get scenario file name
StdCopyStrBuf c4sfile("");
if (!FileSelect(&c4sfile,
FILE_SELECT_FILTER_FOR_C4S,
OFN_HIDEREADONLY | OFN_FILEMUSTEXIST))
return false;
if (!filename)
{
if (!FileSelect(&c4sfile,
FILE_SELECT_FILTER_FOR_C4S,
OFN_HIDEREADONLY | OFN_FILEMUSTEXIST))
return false;
filename = c4sfile.getData();
}
Application.ClearCommandLine();
::Config.Developer.AddRecentlyEditedScenario(filename);
// Open game
Application.OpenGame(c4sfile.getData());
Application.OpenGame(filename);
return true;
}
@ -309,6 +316,7 @@ bool C4Console::FileOpenWPlrs()
{
SAddModule(Game.PlayerFilenames, c4pfile.getData());
}
::Config.Developer.AddRecentlyEditedScenario(c4sfile.getData());
// Open game
Application.OpenGame(c4sfile.getData());
return true;

View File

@ -77,7 +77,7 @@ public:
bool FileSaveAs(bool fSaveGame);
bool FileSave();
bool FileNew();
bool FileOpen();
bool FileOpen(const char *filename=NULL);
bool FileOpenWPlrs();
bool FileCommand();
bool FileClose();

View File

@ -84,6 +84,7 @@ public:
void AddViewport(C4ViewportWindow *cvp);
void OnObjectSelectionChanged(class C4EditCursorSelection &selection); // selection changed (through other means than creator or object list view)
bool CreateNewScenario(StdStrBuf *out_filename);
void OnStartGame();
friend class C4ConsoleQtMainWindow;
friend class C4ToolsDlg;
@ -91,6 +92,7 @@ public:
void Execute() { }
void AddViewport(C4ViewportWindow *cvp) { }
void OnObjectSelectionChanged(class C4EditCursorSelection &selection) { }
void OnStartGame() { }
#endif
void SetCursor(Cursor cursor);

View File

@ -39,6 +39,12 @@
// * crash when viewport closes on player elimination
// -----------------------------------------------
void C4ConsoleGUI::OnStartGame()
{
// Welcome screen made invisible on first game load
state->HideWelcomeScreen();
}
void C4ConsoleGUI::Execute() { state->Execute(); }
void C4ConsoleGUI::SetCursor(C4ConsoleGUI::Cursor cursor)
@ -171,7 +177,7 @@ bool C4ConsoleGUI::FileSelect(StdStrBuf *sFilename, const char * szFilter, DWORD
if (fSave)
filename = QFileDialog::getSaveFileName(state->window.get(), LoadResStr("IDS_DLG_SAVE"), QString(), filter, &selected_filter);
else if (!has_multi)
filename = QFileDialog::getOpenFileName(state->window.get(), LoadResStr("IDS_DLG_OPEN"), QString(), filter, &selected_filter);
filename = QFileDialog::getExistingDirectory(state->window.get(), LoadResStr("IDS_DLG_OPEN"), QString(), 0);
else
filenames = QFileDialog::getOpenFileNames(state->window.get(), LoadResStr("IDS_DLG_OPEN"), QString(), filter, &selected_filter);
#ifdef USE_WIN32_WINDOWS

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>955</width>
<height>578</height>
<height>625</height>
</rect>
</property>
<property name="windowTitle">
@ -85,6 +85,256 @@
<string comment="res">IDS_CTL_SIZE</string>
</property>
</widget>
<widget class="QDockWidget" name="welcomeDockWidget">
<property name="geometry">
<rect>
<x>30</x>
<y>60</y>
<width>311</width>
<height>211</height>
</rect>
</property>
<property name="windowTitle">
<string comment="res">IDS_CNS_WELCOME</string>
</property>
<widget class="QWidget" name="welcomeDockWidgetContents">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QScrollArea" name="welcomeScrollArea">
<property name="palette">
<palette>
<active>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
</brush>
</colorrole>
<colorrole role="Window">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>251</green>
<blue>241</blue>
</color>
</brush>
</colorrole>
</active>
<inactive>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
</brush>
</colorrole>
<colorrole role="Window">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>251</green>
<blue>241</blue>
</color>
</brush>
</colorrole>
</inactive>
<disabled>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>251</green>
<blue>241</blue>
</color>
</brush>
</colorrole>
<colorrole role="Window">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>251</green>
<blue>241</blue>
</color>
</brush>
</colorrole>
</disabled>
</palette>
</property>
<property name="autoFillBackground">
<bool>true</bool>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="welcomeScrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>311</width>
<height>191</height>
</rect>
</property>
<layout class="QVBoxLayout" name="welcomeScrollLayout">
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Maximum</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>10</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="welcomeTitleLabel">
<property name="font">
<font>
<pointsize>16</pointsize>
</font>
</property>
<property name="text">
<string comment="res">IDS_CNS_EDITOR</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Maximum</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>10</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="welcomeStartLabel">
<property name="font">
<font>
<pointsize>9</pointsize>
</font>
</property>
<property name="text">
<string comment="res">IDS_MNU_START</string>
</property>
<property name="indent">
<number>15</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="welcomeNewLabel">
<property name="text">
<string comment="res">IDS_MNU_NEW</string>
</property>
<property name="indent">
<number>25</number>
</property>
<property name="textInteractionFlags">
<set>Qt::TextBrowserInteraction</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="welcomeOpenLabel">
<property name="text">
<string comment="res">IDS_MNU_OPEN</string>
</property>
<property name="indent">
<number>25</number>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Maximum</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>10</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="welcomeRecentLabel">
<property name="font">
<font>
<pointsize>9</pointsize>
</font>
</property>
<property name="text">
<string comment="res">IDS_MNU_RECENT</string>
</property>
<property name="indent">
<number>15</number>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
@ -276,12 +526,7 @@
</attribute>
</widget>
</item>
<item>
<widget class="QComboBox" name="creatorModeComboBox"/>
</item>
</layout>
<zorder>creatorModeComboBox</zorder>
<zorder>creatorTreeView</zorder>
</widget>
</widget>
<widget class="QToolBar" name="toolBar">
@ -1073,6 +1318,38 @@
</hint>
</hints>
</connection>
<connection>
<sender>welcomeNewLabel</sender>
<signal>linkActivated(QString)</signal>
<receiver>MainWindow</receiver>
<slot>WelcomeLinkActivated(QString)</slot>
<hints>
<hint type="sourcelabel">
<x>445</x>
<y>218</y>
</hint>
<hint type="destinationlabel">
<x>477</x>
<y>312</y>
</hint>
</hints>
</connection>
<connection>
<sender>welcomeOpenLabel</sender>
<signal>linkActivated(QString)</signal>
<receiver>MainWindow</receiver>
<slot>WelcomeLinkActivated(QString)</slot>
<hints>
<hint type="sourcelabel">
<x>445</x>
<y>237</y>
</hint>
<hint type="destinationlabel">
<x>477</x>
<y>312</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>PlayPressed(bool)</slot>
@ -1104,5 +1381,6 @@
<slot>ForegroundMaterialChanged(QString)</slot>
<slot>BackgroundMaterialChanged(QString)</slot>
<slot>FileNew()</slot>
<slot>WelcomeLinkActivated(QString)</slot>
</slots>
</ui>

View File

@ -362,6 +362,18 @@ void C4ConsoleQtMainWindow::BackgroundMaterialChanged(const QString &new_selecti
if (tex.size() > 0) ::Console.ToolsDlg.SelectBackTexture(tex.toUtf8(), true);
}
void C4ConsoleQtMainWindow::WelcomeLinkActivated(const QString &link)
{
// Default links
if (link == "new") FileNew();
else if (link == "open") FileOpen();
// Open recent link
else if (link.startsWith("open:"))
{
QString open_file = link.mid(5);
::Console.FileOpen(open_file.toUtf8());
}
}
@ -444,6 +456,13 @@ bool C4ConsoleGUIState::CreateConsoleWindow(C4AbstractApp *app)
ui.creatorTreeView->setModel(definition_list_model.get());
window->connect(ui.creatorTreeView->selectionModel(), &QItemSelectionModel::selectionChanged, window.get(), &C4ConsoleQtMainWindow::OnCreatorSelectionChanged);
window->connect(ui.creatorTreeView->selectionModel(), &QItemSelectionModel::currentChanged, window.get(), &C4ConsoleQtMainWindow::OnCreatorCurrentChanged);
// Welcome page
InitWelcomeScreen();
ShowWelcomeScreen();
// Initial empty property page
PropertyDlgUpdate(C4EditCursorSelection(), false);
window->showNormal();
#ifdef USE_WIN32_WINDOWS
@ -770,3 +789,39 @@ bool C4ConsoleGUIState::CreateNewScenario(StdStrBuf *out_filename)
out_filename->Copy(dlg->GetFilename());
return true;
}
void C4ConsoleGUIState::InitWelcomeScreen()
{
// Init links
ui.welcomeNewLabel->setText(QString("<a href=\"new\">%1</a>").arg(ui.welcomeNewLabel->text()));
ui.welcomeOpenLabel->setText(QString("<a href=\"open\">%1</a>").arg(ui.welcomeOpenLabel->text()));
// Recently opened scenarios
bool any_file = false;
int recent_idx = ui.welcomeScrollLayout->indexOf(ui.welcomeRecentLabel);
for (int32_t i = 0; i < CFG_MaxEditorMRU; ++i)
{
const char *filename = ::Config.Developer.RecentlyEditedSzenarios[i];
if (*filename && ::ItemExists(filename))
{
const char *basename = GetFilenameOnly(filename);
QLabel *link = new QLabel(ui.welcomeScrollAreaWidgetContents);
ui.welcomeScrollLayout->insertWidget(++recent_idx, link);
link->setIndent(ui.welcomeOpenLabel->indent());
link->setTextInteractionFlags(ui.welcomeOpenLabel->textInteractionFlags());
link->setText(QString("<a href=\"open:%1\">%2</a>").arg(filename).arg(basename)); // let's hope file names never contain "
any_file = true;
window->connect(link, SIGNAL(linkActivated(QString)), window.get(), SLOT(WelcomeLinkActivated(QString)));
}
}
if (!any_file) ui.welcomeRecentLabel->hide();
}
void C4ConsoleGUIState::ShowWelcomeScreen()
{
viewport_area->addDockWidget(Qt::BottomDockWidgetArea, ui.welcomeDockWidget);
}
void C4ConsoleGUIState::HideWelcomeScreen()
{
ui.welcomeDockWidget->close();
}

View File

@ -134,6 +134,8 @@ public slots:
// Material changed in landscape drawing mode
void ForegroundMaterialChanged(const QString &new_selection);
void BackgroundMaterialChanged(const QString &new_selection);
// Links on welcome page
void WelcomeLinkActivated(const QString &link);
};
@ -210,6 +212,10 @@ public:
#ifdef USE_WIN32_WINDOWS
bool HandleWin32KeyboardMessage(MSG *msg);
#endif
void InitWelcomeScreen();
void ShowWelcomeScreen();
void HideWelcomeScreen();
};
class C4ConsoleGUI::State : public C4ConsoleGUIState

View File

@ -55,7 +55,8 @@ bool C4ConsoleQtViewportView::IsPlayViewport() const
void C4ConsoleQtViewportView::resizeEvent(QResizeEvent *resize_event)
{
QWidget::resizeEvent(resize_event);
if (cvp) dock->cvp->cvp->UpdateOutputSize(resize_event->size().width(), resize_event->size().height());
if (cvp && dock->cvp->cvp)
dock->cvp->cvp->UpdateOutputSize(resize_event->size().width(), resize_event->size().height());
}
bool C4ConsoleQtViewportView::nativeEvent(const QByteArray &eventType, void *message, long *result)

View File

@ -685,6 +685,10 @@ void C4Application::GameTick()
// immediate progress to next state; OpenGame will enter HandleMessage-loops in startup and lobby!
C4Startup::CloseStartup();
AppState = C4AS_Game;
#ifdef WITH_QT_EDITOR
// Notify console
::Console.OnStartGame();
#endif
// first-time game initialization
if (!Game.Init())
{