Compare commits
2 commits
8c95f3b9fb
...
f80e9c4cc3
Author | SHA1 | Date | |
---|---|---|---|
f80e9c4cc3 | |||
c2135b2f8c |
5 changed files with 32 additions and 9 deletions
|
@ -93,6 +93,10 @@ void processInput(GLFWwindow* window) {
|
|||
camera.processMovement(DIRECTION_LEFT, deltaTime);
|
||||
if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS)
|
||||
camera.processMovement(DIRECTION_RIGHT, deltaTime);
|
||||
if (glfwGetKey(window, GLFW_KEY_E) == GLFW_PRESS)
|
||||
camera.processMovement(DIRECTION_UP, deltaTime);
|
||||
if (glfwGetKey(window, GLFW_KEY_Q) == GLFW_PRESS)
|
||||
camera.processMovement(DIRECTION_DOWN, deltaTime);
|
||||
if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS)
|
||||
camera.processMovement(DIRECTION_UP, deltaTime);
|
||||
if (glfwGetKey(window, GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS)
|
||||
|
|
|
@ -496,6 +496,7 @@ void MainGLWidget::buildContextMenu() {
|
|||
|
||||
static int moveZ = 0;
|
||||
static int moveX = 0;
|
||||
static int moveYw = 0; // World Y
|
||||
|
||||
static std::chrono::time_point lastTime = std::chrono::steady_clock::now();
|
||||
void MainGLWidget::updateCycle() {
|
||||
|
@ -506,6 +507,8 @@ void MainGLWidget::updateCycle() {
|
|||
camera.processMovement(moveZ == 1 ? DIRECTION_FORWARD : DIRECTION_BACKWARDS, deltaTime);
|
||||
if (moveX)
|
||||
camera.processMovement(moveX == 1 ? DIRECTION_LEFT : DIRECTION_RIGHT, deltaTime);
|
||||
if (moveYw)
|
||||
camera.processMovement(moveYw == 1 ? DIRECTION_UP : DIRECTION_DOWN, deltaTime);
|
||||
|
||||
}
|
||||
|
||||
|
@ -517,6 +520,9 @@ void MainGLWidget::keyPressEvent(QKeyEvent* evt) {
|
|||
if (evt->key() == Qt::Key_A) moveX = 1;
|
||||
else if (evt->key() == Qt::Key_D) moveX = -1;
|
||||
|
||||
if (evt->key() == Qt::Key_E) moveYw = 1;
|
||||
else if (evt->key() == Qt::Key_Q) moveYw = -1;
|
||||
|
||||
if (evt->key() == Qt::Key_F) {
|
||||
gWorkspace()->AddChild(lastPart = Part::New({
|
||||
.position = camera.cameraPos + camera.cameraFront * glm::vec3(3),
|
||||
|
@ -539,6 +545,7 @@ void MainGLWidget::keyPressEvent(QKeyEvent* evt) {
|
|||
void MainGLWidget::keyReleaseEvent(QKeyEvent* evt) {
|
||||
if (evt->key() == Qt::Key_W || evt->key() == Qt::Key_S) moveZ = 0;
|
||||
else if (evt->key() == Qt::Key_A || evt->key() == Qt::Key_D) moveX = 0;
|
||||
else if (evt->key() == Qt::Key_E || evt->key() == Qt::Key_Q) moveYw = 0;
|
||||
}
|
||||
|
||||
MainWindow* MainGLWidget::mainWindow() {
|
||||
|
|
|
@ -572,15 +572,26 @@ std::optional<std::string> MainWindow::openFileDialog(QString filter, QString de
|
|||
return dialog.selectedFiles().front().toStdString();
|
||||
}
|
||||
|
||||
ScriptDocument* MainWindow::findScriptWindow(std::shared_ptr<Script> script) {
|
||||
for (QMdiSubWindow* window : ui->mdiArea->subWindowList()) {
|
||||
ScriptDocument* doc = dynamic_cast<ScriptDocument*>(window);
|
||||
if (doc == nullptr) continue;
|
||||
|
||||
if (doc->getScript() == script)
|
||||
return doc;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void MainWindow::openScriptDocument(std::shared_ptr<Script> script) {
|
||||
// Document already exists, don't open it
|
||||
if (scriptDocuments.count(script) > 0) {
|
||||
ui->mdiArea->setActiveSubWindow(scriptDocuments[script]);
|
||||
ScriptDocument* doc = findScriptWindow(script);
|
||||
if (doc != nullptr) {
|
||||
ui->mdiArea->setActiveSubWindow(doc);
|
||||
return;
|
||||
}
|
||||
|
||||
ScriptDocument* doc = new ScriptDocument(script);
|
||||
scriptDocuments[script] = doc;
|
||||
doc = new ScriptDocument(script);
|
||||
doc->setAttribute(Qt::WA_DeleteOnClose, true);
|
||||
ui->mdiArea->addSubWindow(doc);
|
||||
ui->mdiArea->setActiveSubWindow(doc);
|
||||
|
@ -588,12 +599,10 @@ void MainWindow::openScriptDocument(std::shared_ptr<Script> script) {
|
|||
}
|
||||
|
||||
void MainWindow::closeScriptDocument(std::shared_ptr<Script> script) {
|
||||
if (scriptDocuments.count(script) == 0) return;
|
||||
|
||||
ScriptDocument* doc = scriptDocuments[script];
|
||||
ScriptDocument* doc = findScriptWindow(script);
|
||||
if (doc == nullptr) return; // Script is not open
|
||||
ui->mdiArea->removeSubWindow(doc);
|
||||
ui->mdiArea->activeSubWindow()->showMaximized();
|
||||
scriptDocuments.erase(script);
|
||||
doc->deleteLater();
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include <map>
|
||||
#include <memory>
|
||||
#include <qfiledialog.h>
|
||||
#include <qmdisubwindow.h>
|
||||
|
||||
enum SelectedTool {
|
||||
TOOL_SELECT,
|
||||
|
@ -67,10 +68,10 @@ public:
|
|||
friend PlaceDocument;
|
||||
private:
|
||||
PlaceDocument* placeDocument;
|
||||
std::map<std::shared_ptr<Script>, ScriptDocument*> scriptDocuments;
|
||||
|
||||
void updateToolbars();
|
||||
void closeEvent(QCloseEvent* evt) override;
|
||||
ScriptDocument* findScriptWindow(std::shared_ptr<Script>);
|
||||
|
||||
void connectActionHandlers();
|
||||
|
||||
|
|
|
@ -15,4 +15,6 @@ class ScriptDocument : public QMdiSubWindow {
|
|||
public:
|
||||
ScriptDocument(std::shared_ptr<Script> script, QWidget* parent = nullptr);
|
||||
~ScriptDocument() override;
|
||||
|
||||
inline std::shared_ptr<Script> getScript() { return script; }
|
||||
};
|
Loading…
Add table
Reference in a new issue