Refactor
This commit is contained in:
58
tools/editor/cutscene/cutsceneitemeditor.py
Normal file
58
tools/editor/cutscene/cutsceneitemeditor.py
Normal file
@@ -0,0 +1,58 @@
|
||||
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLineEdit, QLabel, QSizePolicy, QComboBox, QHBoxLayout, QSpacerItem
|
||||
from PyQt5.QtCore import Qt, pyqtSignal
|
||||
from .cutscenewait import CutsceneWaitEditor
|
||||
from .cutscenetext import CutsceneTextEditor
|
||||
|
||||
EDITOR_MAP = (
|
||||
( "wait", "Wait", CutsceneWaitEditor ),
|
||||
( "text", "Text", CutsceneTextEditor )
|
||||
)
|
||||
|
||||
class CutsceneItemEditor(QWidget):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self.layout = QVBoxLayout(self)
|
||||
self.layout.setAlignment(Qt.AlignTop | Qt.AlignLeft)
|
||||
self.layout.addWidget(QLabel("Item Properties:"))
|
||||
|
||||
rowLayout = QHBoxLayout()
|
||||
rowLayout.setSpacing(8)
|
||||
|
||||
rowLayout.addWidget(QLabel("Name:"))
|
||||
self.nameInput = QLineEdit()
|
||||
rowLayout.addWidget(self.nameInput)
|
||||
|
||||
rowLayout.addWidget(QLabel("Type:"))
|
||||
self.typeDropdown = QComboBox()
|
||||
self.typeDropdown.addItems([typeName for typeKey, typeName, editorClass in EDITOR_MAP])
|
||||
rowLayout.addWidget(self.typeDropdown)
|
||||
self.layout.addLayout(rowLayout)
|
||||
|
||||
self.activeEditor = None
|
||||
|
||||
# Events
|
||||
self.nameInput.textChanged.connect(self.onNameChanged)
|
||||
self.typeDropdown.currentTextChanged.connect(self.onTypeChanged)
|
||||
|
||||
# First load
|
||||
self.onNameChanged(self.nameInput.text())
|
||||
self.onTypeChanged(self.typeDropdown.currentText())
|
||||
|
||||
def onNameChanged(self, nameText):
|
||||
pass
|
||||
|
||||
def onTypeChanged(self, typeText):
|
||||
typeKey = typeText.lower()
|
||||
|
||||
# Remove existing editor
|
||||
if self.activeEditor:
|
||||
self.layout.removeWidget(self.activeEditor)
|
||||
self.activeEditor.deleteLater()
|
||||
self.activeEditor = None
|
||||
|
||||
# Create new editor
|
||||
for key, name, editorClass in EDITOR_MAP:
|
||||
if key == typeKey:
|
||||
self.activeEditor = editorClass()
|
||||
self.layout.addWidget(self.activeEditor)
|
||||
break
|
||||
54
tools/editor/cutscene/cutscenemenubar.py
Normal file
54
tools/editor/cutscene/cutscenemenubar.py
Normal file
@@ -0,0 +1,54 @@
|
||||
from PyQt5.QtWidgets import QMenuBar, QAction, QFileDialog, QMessageBox
|
||||
from PyQt5.QtGui import QKeySequence
|
||||
|
||||
class CutsceneMenuBar(QMenuBar):
|
||||
def __init__(self, parent):
|
||||
super().__init__(parent)
|
||||
self.parent = parent
|
||||
fileMenu = self.addMenu("File")
|
||||
|
||||
self.newAction = QAction("New", self)
|
||||
self.newAction.setShortcut(QKeySequence.New)
|
||||
self.newAction.triggered.connect(self.newFile)
|
||||
fileMenu.addAction(self.newAction)
|
||||
|
||||
self.openAction = QAction("Open", self)
|
||||
self.openAction.setShortcut(QKeySequence.Open)
|
||||
self.openAction.triggered.connect(self.openFile)
|
||||
fileMenu.addAction(self.openAction)
|
||||
|
||||
self.saveAction = QAction("Save", self)
|
||||
self.saveAction.setShortcut(QKeySequence.Save)
|
||||
self.saveAction.triggered.connect(self.saveFile)
|
||||
fileMenu.addAction(self.saveAction)
|
||||
|
||||
self.saveAsAction = QAction("Save As", self)
|
||||
self.saveAsAction.setShortcut(QKeySequence.SaveAs)
|
||||
self.saveAsAction.triggered.connect(self.saveFileAs)
|
||||
fileMenu.addAction(self.saveAsAction)
|
||||
|
||||
def newFile(self):
|
||||
self.parent.clearCutscene()
|
||||
|
||||
def openFile(self):
|
||||
path, _ = QFileDialog.getOpenFileName(self.parent, "Open Cutscene File", "", "JSON Files (*.json);;All Files (*)")
|
||||
if not path:
|
||||
return
|
||||
|
||||
# TODO: Load file contents into timeline
|
||||
self.parent.currentFile = path
|
||||
pass
|
||||
|
||||
def saveFile(self):
|
||||
if not self.parent.currentFile:
|
||||
self.saveFileAs()
|
||||
return
|
||||
|
||||
# TODO: Save timeline to self.parent.currentFile
|
||||
pass
|
||||
|
||||
def saveFileAs(self):
|
||||
path, _ = QFileDialog.getSaveFileName(self.parent, "Save Cutscene File As", "", "JSON Files (*.json);;All Files (*)")
|
||||
if path:
|
||||
self.parent.currentFile = path
|
||||
self.saveFile()
|
||||
21
tools/editor/cutscene/cutscenetext.py
Normal file
21
tools/editor/cutscene/cutscenetext.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QTextEdit
|
||||
from PyQt5.QtCore import Qt
|
||||
|
||||
class CutsceneTextEditor(QWidget):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
layout = QVBoxLayout(self)
|
||||
layout.setContentsMargins(0, 0, 0, 0)
|
||||
layout.setSpacing(0)
|
||||
label = QLabel("Text:")
|
||||
label.setSizePolicy(label.sizePolicy().Expanding, label.sizePolicy().Fixed)
|
||||
layout.addWidget(label)
|
||||
self.textInput = QTextEdit()
|
||||
self.textInput.setSizePolicy(self.textInput.sizePolicy().Expanding, self.textInput.sizePolicy().Expanding)
|
||||
layout.addWidget(self.textInput, stretch=1)
|
||||
|
||||
def setText(self, text):
|
||||
self.textInput.setPlainText(text)
|
||||
|
||||
def getText(self):
|
||||
return self.textInput.toPlainText()
|
||||
20
tools/editor/cutscene/cutscenewait.py
Normal file
20
tools/editor/cutscene/cutscenewait.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from PyQt5.QtWidgets import QWidget, QFormLayout, QDoubleSpinBox, QLabel
|
||||
|
||||
class CutsceneWaitEditor(QWidget):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
layout = QFormLayout(self)
|
||||
layout.setContentsMargins(0, 0, 0, 0)
|
||||
layout.setSpacing(0)
|
||||
self.waitTimeInput = QDoubleSpinBox()
|
||||
self.waitTimeInput.setMinimum(0.0)
|
||||
self.waitTimeInput.setMaximum(9999.0)
|
||||
self.waitTimeInput.setDecimals(2)
|
||||
self.waitTimeInput.setSingleStep(0.1)
|
||||
layout.addRow(QLabel("Wait Time (seconds):"), self.waitTimeInput)
|
||||
|
||||
def setWaitTime(self, value):
|
||||
self.waitTimeInput.setValue(value)
|
||||
|
||||
def getWaitTime(self):
|
||||
return self.waitTimeInput.value()
|
||||
Reference in New Issue
Block a user