Refactor
Some checks failed
Build Dusk / run-tests (push) Successful in 1m55s
Build Dusk / build-linux (push) Successful in 2m0s
Build Dusk / build-psp (push) Failing after 1m40s

This commit is contained in:
2026-01-25 21:23:09 -06:00
parent d788de8637
commit 07afc3813a
35 changed files with 51 additions and 61 deletions

57
tools/editor/__main__.py Executable file
View File

@@ -0,0 +1,57 @@
#!/usr/bin/env python3
import sys
from PyQt5.QtWidgets import (
QApplication, QVBoxLayout, QPushButton,
QDialog
)
from OpenGL.GL import *
from OpenGL.GLU import *
from tools.editor.maptool import MapWindow
from tools.editor.langtool import LangToolWindow
from tools.editor.cutscenetool import CutsceneToolWindow
DEFAULT_TOOL = None
DEFAULT_TOOL = "map"
# DEFAULT_TOOL = "cutscene"
TOOLS = [
("Map Editor", "map", MapWindow),
("Language Editor", "language", LangToolWindow),
("Cutscene Editor", "cutscene", CutsceneToolWindow),
]
class EditorChoiceDialog(QDialog):
def __init__(self):
super().__init__()
self.setWindowTitle("Choose Tool")
layout = QVBoxLayout(self)
self.selected = None
for label, key, win_cls in TOOLS:
btn = QPushButton(label)
btn.clicked.connect(lambda checked, w=win_cls: self.choose_tool(w))
layout.addWidget(btn)
def choose_tool(self, win_cls):
self.selected = win_cls
self.accept()
def get_choice(self):
return self.selected
def main():
app = QApplication(sys.argv)
tool_map = { key: win_cls for _, key, win_cls in TOOLS }
if DEFAULT_TOOL in tool_map:
win_cls = tool_map[DEFAULT_TOOL]
else:
choice_dialog = EditorChoiceDialog()
if choice_dialog.exec_() == QDialog.Accepted:
win_cls = choice_dialog.get_choice()
else:
sys.exit(0)
win = win_cls()
win.show()
sys.exit(app.exec_())
if __name__ == "__main__":
main()

View 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

View 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()

View 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()

View 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()

View File

@@ -0,0 +1,101 @@
from PyQt5.QtWidgets import QMainWindow, QApplication, QWidget, QVBoxLayout, QHBoxLayout, QLabel, QPushButton, QListWidget, QListWidgetItem, QMenuBar, QAction, QFileDialog, QMessageBox
from PyQt5.QtGui import QKeySequence
from tools.editor.cutscene.cutsceneitemeditor import CutsceneItemEditor
from tools.editor.cutscene.cutscenemenubar import CutsceneMenuBar
import sys
class CutsceneToolWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("Dusk Cutscene Editor")
self.setGeometry(100, 100, 800, 600)
self.nextItemNumber = 1 # Track next available number
self.currentFile = None
self.dirty = False # Track unsaved changes
# File menu (handled by CutsceneMenuBar)
menubar = CutsceneMenuBar(self)
self.setMenuBar(menubar)
# Main layout: horizontal split
central = QWidget()
mainLayout = QHBoxLayout(central)
self.setCentralWidget(central)
# Timeline
leftPanel = QWidget()
leftLayout = QVBoxLayout(leftPanel)
self.timelineList = QListWidget()
self.timelineList.setSelectionMode(QListWidget.SingleSelection)
leftLayout.addWidget(QLabel("Cutscene Timeline"))
leftLayout.addWidget(self.timelineList)
btnLayout = QHBoxLayout()
self.addBtn = QPushButton("Add")
self.removeBtn = QPushButton("Remove")
btnLayout.addWidget(self.addBtn)
btnLayout.addWidget(self.removeBtn)
leftLayout.addLayout(btnLayout)
mainLayout.addWidget(leftPanel, 2)
# Property editor
self.editorPanel = QWidget()
self.editorLayout = QVBoxLayout(self.editorPanel)
self.itemEditor = None # Only create when needed
mainLayout.addWidget(self.editorPanel, 3)
# Events
self.timelineList.currentItemChanged.connect(self.onItemSelected)
self.addBtn.clicked.connect(self.addCutsceneItem)
self.removeBtn.clicked.connect(self.removeCutsceneItem)
def addCutsceneItem(self):
name = f"Cutscene item {self.nextItemNumber}"
timelineItem = QListWidgetItem(name)
self.timelineList.addItem(timelineItem)
self.timelineList.setCurrentItem(timelineItem)
self.nextItemNumber += 1
self.dirty = True
def removeCutsceneItem(self):
row = self.timelineList.currentRow()
if row < 0:
return
self.timelineList.takeItem(row)
self.dirty = True
# Remove editor if nothing selected
if self.timelineList.currentItem() is None or self.itemEditor is None:
return
self.editorLayout.removeWidget(self.itemEditor)
self.itemEditor.deleteLater()
self.itemEditor = None
def clearCutscene(self):
self.timelineList.clear()
self.nextItemNumber = 1
self.currentFile = None
self.dirty = False
if self.itemEditor:
self.editorLayout.removeWidget(self.itemEditor)
def onItemSelected(self, current, previous):
if current:
if not self.itemEditor:
self.itemEditor = CutsceneItemEditor()
self.editorLayout.addWidget(self.itemEditor)
return
if not self.itemEditor:
return
self.editorLayout.removeWidget(self.itemEditor)
self.itemEditor.deleteLater()
self.itemEditor = None
if __name__ == "__main__":
app = QApplication(sys.argv)
window = CutsceneToolWindow()
window.show()
sys.exit(app.exec_())

202
tools/editor/langtool.py Normal file
View File

@@ -0,0 +1,202 @@
#!/usr/bin/env python3
from PyQt5.QtWidgets import QMainWindow, QApplication, QAction, QMenuBar, QMessageBox, QFileDialog, QWidget, QVBoxLayout, QHBoxLayout, QLabel, QLineEdit, QTableWidget, QTableWidgetItem, QHeaderView, QPushButton, QTabWidget, QFormLayout
from PyQt5.QtCore import Qt
import sys
import os
import polib
class LangToolWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("Dusk Language Editor")
self.setGeometry(100, 100, 800, 600)
self.current_file = None
self.dirty = False
self.init_menu()
self.init_ui()
def init_ui(self):
central = QWidget()
layout = QVBoxLayout(central)
tabs = QTabWidget()
# Header Tab
header_tab = QWidget()
header_layout = QFormLayout(header_tab)
self.language_edit = QLineEdit()
self.language_edit.setMaximumWidth(220)
header_layout.addRow(QLabel("Language:"), self.language_edit)
self.plural_edit = QLineEdit()
self.plural_edit.setMaximumWidth(320)
header_layout.addRow(QLabel("Plural-Forms:"), self.plural_edit)
self.content_type_edit = QLineEdit("text/plain; charset=UTF-8")
self.content_type_edit.setMaximumWidth(320)
header_layout.addRow(QLabel("Content-Type:"), self.content_type_edit)
tabs.addTab(header_tab, "Header")
# Strings Tab
strings_tab = QWidget()
strings_layout = QVBoxLayout(strings_tab)
self.po_table = QTableWidget()
self.po_table.setColumnCount(2)
self.po_table.setHorizontalHeaderLabels(["msgid", "msgstr"])
self.po_table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
self.po_table.verticalHeader().setMinimumWidth(22)
self.po_table.verticalHeader().setDefaultAlignment(Qt.AlignRight | Qt.AlignVCenter)
strings_layout.addWidget(self.po_table)
row_btn_layout = QHBoxLayout()
add_row_btn = QPushButton("Add Row")
remove_row_btn = QPushButton("Remove Row")
row_btn_layout.addWidget(add_row_btn)
row_btn_layout.addWidget(remove_row_btn)
strings_layout.addLayout(row_btn_layout)
tabs.addTab(strings_tab, "Strings")
layout.addWidget(tabs)
add_row_btn.clicked.connect(self.add_row)
remove_row_btn.clicked.connect(self.remove_row)
self.add_row_btn = add_row_btn
self.remove_row_btn = remove_row_btn
self.setCentralWidget(central)
# Connect edits to dirty flag
self.language_edit.textChanged.connect(self.set_dirty)
self.plural_edit.textChanged.connect(self.set_dirty)
self.content_type_edit.textChanged.connect(self.set_dirty)
self.po_table.itemChanged.connect(self.set_dirty)
def set_dirty(self):
self.dirty = True
self.update_save_action()
def init_menu(self):
menubar = self.menuBar()
file_menu = menubar.addMenu("File")
new_action = QAction("New", self)
open_action = QAction("Open", self)
save_action = QAction("Save", self)
save_as_action = QAction("Save As", self)
new_action.triggered.connect(lambda: self.handle_file_action("new"))
open_action.triggered.connect(lambda: self.handle_file_action("open"))
save_action.triggered.connect(self.handle_save)
save_as_action.triggered.connect(self.handle_save_as)
file_menu.addAction(new_action)
file_menu.addAction(open_action)
file_menu.addAction(save_action)
file_menu.addAction(save_as_action)
self.save_action = save_action # Store reference for enabling/disabling
self.update_save_action()
def update_save_action(self):
self.save_action.setEnabled(self.current_file is not None)
def handle_file_action(self, action):
if self.dirty:
reply = QMessageBox.question(self, "Save Changes?", "Do you want to save changes before proceeding?", QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel)
if reply == QMessageBox.Cancel:
return
elif reply == QMessageBox.Yes:
self.handle_save()
if action == "new":
self.new_file()
elif action == "open":
default_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../assets/locale"))
file_path, _ = QFileDialog.getOpenFileName(self, "Open Language File", default_dir, "PO Files (*.po)")
if file_path:
self.open_file(file_path)
def new_file(self):
self.current_file = None
self.dirty = False
self.language_edit.setText("")
self.plural_edit.setText("")
self.po_table.setRowCount(0)
self.update_save_action()
def open_file(self, file_path):
self.current_file = file_path
self.dirty = False
self.update_save_action()
self.load_po_file(file_path)
def load_po_file(self, file_path):
po = polib.pofile(file_path)
language = po.metadata.get('Language', '')
plural = po.metadata.get('Plural-Forms', '')
content_type = po.metadata.get('Content-Type', 'text/plain; charset=UTF-8')
self.language_edit.setText(language)
self.plural_edit.setText(plural)
self.content_type_edit.setText(content_type)
self.po_table.setRowCount(len(po))
for row, entry in enumerate(po):
self.po_table.setItem(row, 0, QTableWidgetItem(entry.msgid))
self.po_table.setItem(row, 1, QTableWidgetItem(entry.msgstr))
def save_file(self, file_path):
po = polib.POFile()
po.metadata = {
'Language': self.language_edit.text(),
'Content-Type': self.content_type_edit.text(),
'Plural-Forms': self.plural_edit.text(),
}
for row in range(self.po_table.rowCount()):
msgid_item = self.po_table.item(row, 0)
msgstr_item = self.po_table.item(row, 1)
msgid = msgid_item.text() if msgid_item else ''
msgstr = msgstr_item.text() if msgstr_item else ''
if msgid or msgstr:
entry = polib.POEntry(msgid=msgid, msgstr=msgstr)
po.append(entry)
po.save(file_path)
self.dirty = False
self.update_save_action()
def handle_save(self):
if self.current_file:
self.save_file(self.current_file)
else:
self.handle_save_as()
def handle_save_as(self):
default_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../assets/locale"))
file_path, _ = QFileDialog.getSaveFileName(self, "Save Language File As", default_dir, "PO Files (*.po)")
if file_path:
self.current_file = file_path
self.update_save_action()
self.save_file(file_path)
def add_row(self):
row = self.po_table.rowCount()
self.po_table.insertRow(row)
self.po_table.setItem(row, 0, QTableWidgetItem(""))
self.po_table.setItem(row, 1, QTableWidgetItem(""))
self.po_table.setCurrentCell(row, 0)
self.set_dirty()
def remove_row(self):
row = self.po_table.currentRow()
if row >= 0:
self.po_table.removeRow(row)
self.set_dirty()
def closeEvent(self, event):
if self.dirty:
reply = QMessageBox.question(self, "Save Changes?", "Do you want to save changes before exiting?", QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel)
if reply == QMessageBox.Cancel:
event.ignore()
return
elif reply == QMessageBox.Yes:
self.handle_save()
event.accept()
if __name__ == "__main__":
app = QApplication(sys.argv)
window = LangToolWindow()
window.show()
sys.exit(app.exec_())

View File

@@ -0,0 +1,55 @@
import math
import time
from OpenGL.GL import *
from OpenGL.GLU import *
from tools.dusk.defs import TILE_WIDTH, TILE_HEIGHT, TILE_DEPTH, RPG_CAMERA_PIXELS_PER_UNIT, RPG_CAMERA_Z_OFFSET, RPG_CAMERA_FOV
class Camera:
def __init__(self, parent):
self.parent = parent
self.pixelsPerUnit = RPG_CAMERA_PIXELS_PER_UNIT
self.yOffset = RPG_CAMERA_Z_OFFSET
self.fov = RPG_CAMERA_FOV
self.scale = 8.0
self.lastTime = time.time()
self.lookAtTarget = [0.0, 0.0, 0.0]
def setup(self, vw, vh, duration=0.1):
now = time.time()
delta = now - self.lastTime
self.lastTime = now
# Calculate ease factor for exponential smoothing over 'duration' seconds
ease = 1 - math.exp(-delta / duration)
z = (vh / 2.0) / (
(self.pixelsPerUnit * self.scale) * math.tan(math.radians(self.fov / 2.0))
)
lookAt = [
self.parent.map.position[0] * TILE_WIDTH,
self.parent.map.position[1] * TILE_HEIGHT,
self.parent.map.position[2] * TILE_DEPTH,
]
aspectRatio = vw / vh
# Ease the lookAt target
for i in range(3):
self.lookAtTarget[i] += (lookAt[i] - self.lookAtTarget[i]) * ease
# Camera position is now based on the eased lookAtTarget
cameraPosition = (
self.lookAtTarget[0],
self.lookAtTarget[1] + self.yOffset,
self.lookAtTarget[2] + z
)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluPerspective(self.fov, aspectRatio, 0.1, 1000.0)
glScalef(1.0, -1.0, 1.0) # Flip the projection matrix upside down
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
gluLookAt(
cameraPosition[0], cameraPosition[1], cameraPosition[2],
self.lookAtTarget[0], self.lookAtTarget[1], self.lookAtTarget[2],
0.0, 1.0, 0.0
)

View File

@@ -0,0 +1,80 @@
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QGridLayout, QTreeWidget, QTreeWidgetItem, QComboBox
from tools.dusk.defs import CHUNK_WIDTH, CHUNK_HEIGHT, CHUNK_DEPTH, TILE_SHAPES
class ChunkPanel(QWidget):
def __init__(self, parent):
super().__init__(parent)
self.parent = parent
layout = QVBoxLayout(self)
# Tile shape dropdown
self.tileShapeDropdown = QComboBox()
self.tileShapeDropdown.addItems(TILE_SHAPES.keys())
self.tileShapeDropdown.setToolTip("Tile Shape")
layout.addWidget(self.tileShapeDropdown)
# Add expandable tree list
self.tree = QTreeWidget()
self.tree.setHeaderLabel("Chunks")
self.tree.expandAll() # Expand by default, remove if you want collapsed
layout.addWidget(self.tree) # Removed invalid stretch factor
# Add stretch so tree expands
layout.setStretchFactor(self.tree, 1)
# Event subscriptions
self.parent.map.onMapData.sub(self.onMapData)
self.parent.map.onPositionChange.sub(self.onPositionChange)
self.tileShapeDropdown.currentTextChanged.connect(self.onTileShapeChanged)
# For each chunk
for chunk in self.parent.map.chunks.values():
# Create tree element
item = QTreeWidgetItem(self.tree, ["Chunk ({}, {}, {})".format(chunk.x, chunk.y, chunk.z)])
chunk.chunkPanelTree = item
chunk.chunkPanelTree.setExpanded(True)
item.setData(0, 0, chunk) # Store chunk reference
chunk.onChunkData.sub(self.onChunkData)
def onMapData(self, data):
pass
def onPositionChange(self, pos):
self.updateChunkList()
tile = self.parent.map.getTileAtWorldPos(*self.parent.map.position)
if tile is None:
return
key = "TILE_SHAPE_NULL"
for k, v in TILE_SHAPES.items():
if v != tile.shape:
continue
key = k
break
self.tileShapeDropdown.setCurrentText(key)
def onTileShapeChanged(self, shape_key):
tile = self.parent.map.getTileAtWorldPos(*self.parent.map.position)
if tile is None or shape_key not in TILE_SHAPES:
return
tile.setShape(TILE_SHAPES[shape_key])
def updateChunkList(self):
# Clear existing items
currentChunk = self.parent.map.getChunkAtWorldPos(*self.parent.map.position)
# Example tree items
for chunk in self.parent.map.chunks.values():
title = "Chunk ({}, {}, {})".format(chunk.x, chunk.y, chunk.z)
if chunk == currentChunk:
title += " [C]"
if chunk.isDirty():
title += " *"
item = chunk.chunkPanelTree
item.setText(0, title)
def onChunkData(self, chunk):
self.updateChunkList()

View File

@@ -0,0 +1,154 @@
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QComboBox, QHBoxLayout, QPushButton, QLineEdit, QListWidget, QListWidgetItem
from PyQt5.QtCore import Qt
from tools.dusk.entity import Entity
from tools.dusk.defs import CHUNK_WIDTH, CHUNK_HEIGHT, CHUNK_DEPTH, ENTITY_TYPES, ENTITY_TYPE_NULL
class EntityPanel(QWidget):
def __init__(self, parent):
super().__init__(parent)
self.parent = parent
layout = QVBoxLayout(self)
self.setLayout(layout)
# Top panel placeholder
topWidget = QLabel("Entity Editor")
layout.addWidget(topWidget)
# Name input
nameLayout = QHBoxLayout()
nameLabel = QLabel("Name:")
self.nameInput = QLineEdit()
nameLayout.addWidget(nameLabel)
nameLayout.addWidget(self.nameInput)
layout.addLayout(nameLayout)
# Entity Type dropdown (single selection)
typeLayout = QHBoxLayout()
typeLabel = QLabel("Type:")
self.typeDropdown = QComboBox()
self.typeDropdown.addItems(ENTITY_TYPES)
typeLayout.addWidget(typeLabel)
typeLayout.addWidget(self.typeDropdown)
layout.addLayout(typeLayout)
# Entity list and buttons
self.entityList = QListWidget()
self.entityList.addItems([])
layout.addWidget(self.entityList, stretch=1)
btnLayout = QHBoxLayout()
self.btnAdd = QPushButton("Add")
self.btnRemove = QPushButton("Remove")
btnLayout.addWidget(self.btnAdd)
btnLayout.addWidget(self.btnRemove)
layout.addLayout(btnLayout)
# Events
self.btnAdd.clicked.connect(self.onAddEntity)
self.btnRemove.clicked.connect(self.onRemoveEntity)
self.parent.map.onEntityData.sub(self.onEntityData)
self.parent.map.onPositionChange.sub(self.onPositionChange)
self.entityList.itemClicked.connect(self.onEntityClicked)
self.entityList.itemDoubleClicked.connect(self.onEntityDoubleClicked)
self.typeDropdown.currentIndexChanged.connect(self.onTypeSelected)
self.nameInput.textChanged.connect(self.onNameChanged)
# Call once to populate
self.onEntityData()
self.onEntityUnselect()
def onEntityUnselect(self):
self.entityList.setCurrentItem(None)
self.nameInput.setText("")
self.typeDropdown.setCurrentIndex(ENTITY_TYPE_NULL)
def onEntitySelect(self, entity):
self.entityList.setCurrentItem(entity.item)
self.nameInput.setText(entity.name)
self.typeDropdown.setCurrentIndex(entity.type)
def onEntityDoubleClicked(self, item):
entity = item.data(Qt.UserRole)
chunk = entity.chunk
worldX = (chunk.x * CHUNK_WIDTH) + entity.localX
worldY = (chunk.y * CHUNK_HEIGHT) + entity.localY
worldZ = (chunk.z * CHUNK_DEPTH) + entity.localZ
self.parent.map.moveTo(worldX, worldY, worldZ)
def onEntityClicked(self, item):
pass
def onAddEntity(self):
chunk = self.parent.map.getChunkAtWorldPos(*self.parent.map.position)
if chunk is None:
return
localX = (self.parent.map.position[0] - (chunk.x * CHUNK_WIDTH)) % CHUNK_WIDTH
localY = (self.parent.map.position[1] - (chunk.y * CHUNK_HEIGHT)) % CHUNK_HEIGHT
localZ = (self.parent.map.position[2] - (chunk.z * CHUNK_DEPTH)) % CHUNK_DEPTH
# Make sure there's not already an entity here
for ent in chunk.entities.values():
if ent.localX == localX and ent.localY == localY and ent.localZ == localZ:
print("Entity already exists at this location")
return
ent = chunk.addEntity(localX, localY, localZ)
def onRemoveEntity(self):
item = self.entityList.currentItem()
if item is None:
return
entity = item.data(Qt.UserRole)
if entity:
chunk = entity.chunk
chunk.removeEntity(entity)
pass
def onEntityData(self):
self.onEntityUnselect()
self.entityList.clear()
for chunk in self.parent.map.chunks.values():
for id, entity in chunk.entities.items():
item = QListWidgetItem(entity.name)
item.setData(Qt.UserRole, entity) # Store the entity object
entity.item = item
self.entityList.addItem(item)
# Select if there is something at current position
self.onPositionChange(self.parent.map.position)
def onPositionChange(self, position):
self.onEntityUnselect()
# Get Entity at..
chunk = self.parent.map.getChunkAtWorldPos(*position)
if chunk is None:
return
localX = (position[0] - (chunk.x * CHUNK_WIDTH)) % CHUNK_WIDTH
localY = (position[1] - (chunk.y * CHUNK_HEIGHT)) % CHUNK_HEIGHT
localZ = (position[2] - (chunk.z * CHUNK_DEPTH)) % CHUNK_DEPTH
for ent in chunk.entities.values():
if ent.localX != localX or ent.localY != localY or ent.localZ != localZ:
continue
self.onEntitySelect(ent)
self.entityList.setCurrentItem(ent.item)
break
def onTypeSelected(self, index):
item = self.entityList.currentItem()
if item is None:
return
entity = item.data(Qt.UserRole)
if entity:
entity.setType(index)
def onNameChanged(self, text):
item = self.entityList.currentItem()
if item is None:
return
entity = item.data(Qt.UserRole)
if entity:
entity.setName(text)

View File

@@ -0,0 +1,41 @@
from PyQt5.QtCore import QTimer
from PyQt5.QtWidgets import QOpenGLWidget
from OpenGL.GL import *
from OpenGL.GLU import *
class GLWidget(QOpenGLWidget):
def __init__(self, parent):
super().__init__(parent)
self.parent = parent
self.timer = QTimer(self)
self.timer.timeout.connect(self.update)
self.timer.start(16) # ~60 FPS
def initializeGL(self):
glClearColor(0.392, 0.584, 0.929, 1.0)
glEnable(GL_DEPTH_TEST)
glEnable(GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
glEnable(GL_POLYGON_OFFSET_FILL)
glPolygonOffset(1.0, 1.0)
glDisable(GL_POLYGON_OFFSET_FILL)
def resizeGL(self, w, h):
pass
def paintGL(self):
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glLoadIdentity()
w = self.width()
h = self.height()
if h <= 0:
h = 1
if w <= 0:
w = 1
glViewport(0, 0, w, h)
self.parent.camera.setup(w, h)
self.parent.grid.draw()
self.parent.map.draw()
self.parent.selectBox.draw()

46
tools/editor/map/grid.py Normal file
View File

@@ -0,0 +1,46 @@
from OpenGL.GL import *
from tools.dusk.defs import TILE_WIDTH, TILE_HEIGHT, TILE_DEPTH
class Grid:
def __init__(self, lines=1000):
self.cellWidth = TILE_WIDTH
self.cellHeight = TILE_HEIGHT
self.lines = lines
self.enabled = True
def draw(self):
if not self.enabled:
return
center = [0.01,0.01,0.01]
halfWidth = self.cellWidth * self.lines // 2
halfHeight = self.cellHeight * self.lines // 2
# Draw origin axes
glBegin(GL_LINES)
# X axis - RED
glColor3f(1.0, 0.0, 0.0)
glVertex3f(center[0] - halfWidth, center[1], center[2])
glVertex3f(center[0] + halfWidth, center[1], center[2])
# Y axis - GREEN
glColor3f(0.0, 1.0, 0.0)
glVertex3f(center[0], center[1] - halfHeight, center[2])
glVertex3f(center[0], center[1] + halfHeight, center[2])
# Z axis - BLUE
glColor3f(0.0, 0.0, 1.0)
glVertex3f(center[0], center[1], center[2] - halfWidth)
glVertex3f(center[0], center[1], center[2] + halfWidth)
glEnd()
# Draw grid
glColor3f(0.8, 0.8, 0.8)
glBegin(GL_LINES)
for i in range(-self.lines // 2, self.lines // 2 + 1):
# Vertical lines
glVertex3f(center[0] + i * self.cellWidth, center[1] - halfHeight, center[2])
glVertex3f(center[0] + i * self.cellWidth, center[1] + halfHeight, center[2])
# Horizontal lines
glVertex3f(center[0] - halfWidth, center[1] + i * self.cellHeight, center[2])
glVertex3f(center[0] + halfWidth, center[1] + i * self.cellHeight, center[2])
glEnd()

View File

@@ -0,0 +1,83 @@
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QLineEdit, QPushButton, QHBoxLayout, QMessageBox
from tools.dusk.defs import CHUNK_WIDTH, CHUNK_HEIGHT, CHUNK_DEPTH
class MapInfoPanel(QWidget):
def __init__(self, parent):
super().__init__(parent)
self.parent = parent
# Components
layout = QVBoxLayout()
mapTitleLabel = QLabel("Map Title")
self.mapTitleInput = QLineEdit()
layout.addWidget(mapTitleLabel)
layout.addWidget(self.mapTitleInput)
tilePositionLabel = QLabel("Tile Position")
layout.addWidget(tilePositionLabel)
tilePositionRow = QHBoxLayout()
self.tileXInput = QLineEdit()
self.tileXInput.setPlaceholderText("X")
tilePositionRow.addWidget(self.tileXInput)
self.tileYInput = QLineEdit()
self.tileYInput.setPlaceholderText("Y")
tilePositionRow.addWidget(self.tileYInput)
self.tileZInput = QLineEdit()
self.tileZInput.setPlaceholderText("Z")
tilePositionRow.addWidget(self.tileZInput)
self.tileGo = QPushButton("Go")
tilePositionRow.addWidget(self.tileGo)
layout.addLayout(tilePositionRow)
self.chunkPosLabel = QLabel()
layout.addWidget(self.chunkPosLabel)
self.chunkLabel = QLabel()
layout.addWidget(self.chunkLabel)
layout.addStretch()
self.setLayout(layout)
# Events
self.tileGo.clicked.connect(self.goToPosition)
self.tileXInput.returnPressed.connect(self.goToPosition)
self.tileYInput.returnPressed.connect(self.goToPosition)
self.tileZInput.returnPressed.connect(self.goToPosition)
self.parent.map.onPositionChange.sub(self.updatePositionLabels)
self.parent.map.onMapData.sub(self.onMapData)
self.mapTitleInput.textChanged.connect(self.onMapNameChange)
# Initial label setting
self.updatePositionLabels(self.parent.map.position)
def goToPosition(self):
try:
x = int(self.tileXInput.text())
y = int(self.tileYInput.text())
z = int(self.tileZInput.text())
self.parent.map.moveTo(x, y, z)
except ValueError:
QMessageBox.warning(self, "Invalid Input", "Please enter valid integer coordinates.")
def updatePositionLabels(self, pos):
self.tileXInput.setText(str(pos[0]))
self.tileYInput.setText(str(pos[1]))
self.tileZInput.setText(str(pos[2]))
chunkTileX = pos[0] % CHUNK_WIDTH
chunkTileY = pos[1] % CHUNK_HEIGHT
chunkTileZ = pos[2] % CHUNK_DEPTH
chunkTileIndex = chunkTileX + chunkTileY * CHUNK_WIDTH + chunkTileZ * CHUNK_WIDTH * CHUNK_HEIGHT
self.chunkPosLabel.setText(f"Chunk Position: {chunkTileX}, {chunkTileY}, {chunkTileZ} ({chunkTileIndex})")
chunkX = pos[0] // CHUNK_WIDTH
chunkY = pos[1] // CHUNK_HEIGHT
chunkZ = pos[2] // CHUNK_DEPTH
self.chunkLabel.setText(f"Chunk: {chunkX}, {chunkY}, {chunkZ}")
def onMapData(self, data):
self.updatePositionLabels(self.parent.map.position)
self.mapTitleInput.setText(data.get("mapName", ""))
def onMapNameChange(self, text):
self.parent.map.data['mapName'] = text

View File

@@ -0,0 +1,51 @@
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QGridLayout, QPushButton, QTabWidget, QLabel
from tools.editor.map.chunkpanel import ChunkPanel
from tools.editor.map.entitypanel import EntityPanel
from tools.editor.map.regionpanel import RegionPanel
class MapLeftPanel(QWidget):
def __init__(self, parent):
super().__init__(parent)
self.parent = parent
layout = QVBoxLayout(self)
self.setLayout(layout)
# Nav buttons
self.chunkInfoLabel = QLabel("Tile Information")
layout.addWidget(self.chunkInfoLabel)
grid = QGridLayout()
self.btnUp = QPushButton("U")
self.btnN = QPushButton("N")
self.btnDown = QPushButton("D")
self.btnW = QPushButton("W")
self.btnS = QPushButton("S")
self.btnE = QPushButton("E")
grid.addWidget(self.btnUp, 0, 0)
grid.addWidget(self.btnN, 0, 1)
grid.addWidget(self.btnDown, 0, 2)
grid.addWidget(self.btnW, 1, 0)
grid.addWidget(self.btnS, 1, 1)
grid.addWidget(self.btnE, 1, 2)
layout.addLayout(grid)
# Panels
self.chunkPanel = ChunkPanel(self.parent)
self.entityPanel = EntityPanel(self.parent)
self.regionPanel = RegionPanel(self.parent)
# Tabs
self.tabs = QTabWidget()
self.tabs.addTab(self.chunkPanel, "Tiles")
self.tabs.addTab(self.entityPanel, "Entities")
self.tabs.addTab(self.regionPanel, "Regions")
self.tabs.addTab(None, "Triggers")
layout.addWidget(self.tabs)
# Event subscriptions
self.btnN.clicked.connect(lambda: self.parent.map.moveRelative(0, -1, 0))
self.btnS.clicked.connect(lambda: self.parent.map.moveRelative(0, 1, 0))
self.btnE.clicked.connect(lambda: self.parent.map.moveRelative(1, 0, 0))
self.btnW.clicked.connect(lambda: self.parent.map.moveRelative(-1, 0, 0))
self.btnUp.clicked.connect(lambda: self.parent.map.moveRelative(0, 0, 1))
self.btnDown.clicked.connect(lambda: self.parent.map.moveRelative(0, 0, -1))

View File

@@ -0,0 +1,46 @@
import os
from PyQt5.QtWidgets import QAction, QMenuBar, QFileDialog
from PyQt5.QtGui import QKeySequence
from tools.dusk.map import MAP_DEFAULT_PATH
class MapMenubar:
def __init__(self, parent):
self.parent = parent
self.menubar = QMenuBar(parent)
parent.setMenuBar(self.menubar)
self.fileMenu = self.menubar.addMenu("File")
self.actionNew = QAction("New", parent)
self.actionOpen = QAction("Open", parent)
self.actionSave = QAction("Save", parent)
self.actionSaveAs = QAction("Save As", parent)
self.actionNew.setShortcut(QKeySequence("Ctrl+N"))
self.actionOpen.setShortcut(QKeySequence("Ctrl+O"))
self.actionSave.setShortcut(QKeySequence("Ctrl+S"))
self.actionSaveAs.setShortcut(QKeySequence("Ctrl+Shift+S"))
self.actionNew.triggered.connect(self.newFile)
self.actionOpen.triggered.connect(self.openFile)
self.actionSave.triggered.connect(self.saveFile)
self.actionSaveAs.triggered.connect(self.saveAsFile)
self.fileMenu.addAction(self.actionNew)
self.fileMenu.addAction(self.actionOpen)
self.fileMenu.addAction(self.actionSave)
self.fileMenu.addAction(self.actionSaveAs)
def newFile(self):
self.parent.map.newFile()
def openFile(self):
filePath, _ = QFileDialog.getOpenFileName(self.menubar, "Open Map File", MAP_DEFAULT_PATH, "Map Files (*.json)")
if filePath:
self.parent.map.load(filePath)
def saveFile(self):
self.parent.map.save()
def saveAsFile(self):
filePath, _ = QFileDialog.getSaveFileName(self.menubar, "Save Map File As", MAP_DEFAULT_PATH, "Map Files (*.json)")
if filePath:
self.parent.map.save(filePath)

View File

@@ -0,0 +1,15 @@
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QComboBox, QHBoxLayout, QPushButton, QLineEdit, QListWidget, QListWidgetItem
from PyQt5.QtCore import Qt
from tools.dusk.entity import Entity
from tools.dusk.defs import CHUNK_WIDTH, CHUNK_HEIGHT, CHUNK_DEPTH, ENTITY_TYPES, ENTITY_TYPE_NULL
class RegionPanel(QWidget):
def __init__(self, parent):
super().__init__(parent)
self.parent = parent
layout = QVBoxLayout(self)
self.setLayout(layout)
# Top panel placeholder
topWidget = QLabel("Region Editor")
layout.addWidget(topWidget)

View File

@@ -0,0 +1,44 @@
import OpenGL.GL as gl
from tools.dusk.defs import defs
import colorsys
from tools.dusk.defs import TILE_WIDTH, TILE_HEIGHT, TILE_DEPTH
class SelectBox:
def __init__(self, parent):
self.parent = parent
self.hue = 0.0
def draw(self):
position = [
self.parent.map.position[0] * TILE_WIDTH - (TILE_WIDTH / 2.0),
self.parent.map.position[1] * TILE_HEIGHT - (TILE_HEIGHT / 2.0),
self.parent.map.position[2] * TILE_DEPTH - (TILE_DEPTH / 2.0)
]
vertices = [
(position[0], position[1], position[2]),
(position[0]+TILE_WIDTH, position[1], position[2]),
(position[0]+TILE_WIDTH, position[1]+TILE_HEIGHT, position[2]),
(position[0], position[1]+TILE_HEIGHT, position[2]),
(position[0], position[1], position[2]+TILE_DEPTH),
(position[0]+TILE_WIDTH, position[1], position[2]+TILE_DEPTH),
(position[0]+TILE_WIDTH, position[1]+TILE_HEIGHT, position[2]+TILE_DEPTH),
(position[0], position[1]+TILE_HEIGHT, position[2]+TILE_DEPTH)
]
edges = [
(0, 1), (1, 2), (2, 3), (3, 0), # bottom face
(4, 5), (5, 6), (6, 7), (7, 4), # top face
(4, 5), (5, 6), (6, 7), (7, 4), # top face
(0, 4), (1, 5), (2, 6), (3, 7) # vertical edges
]
# Cycle hue
self.hue = (self.hue + 0.01) % 1.0
r, g, b = colorsys.hsv_to_rgb(self.hue, 1.0, 1.0)
gl.glColor3f(r, g, b)
gl.glLineWidth(2.0)
gl.glBegin(gl.GL_LINES)
for edge in edges:
for vertex in edge:
gl.glVertex3f(*vertices[vertex])
gl.glEnd()

View File

@@ -0,0 +1,18 @@
from PyQt5.QtWidgets import QStatusBar, QLabel
class StatusBar(QStatusBar):
def __init__(self, parent=None):
super().__init__(parent)
self.parent = parent
self.leftLabel = QLabel("")
self.rightLabel = QLabel("")
self.addWidget(self.leftLabel, 1)
self.addPermanentWidget(self.rightLabel)
parent.map.onMapData.sub(self.onMapData)
def setStatus(self, message):
self.leftLabel.setText(message)
def onMapData(self, data):
self.rightLabel.setText(self.parent.map.mapFileName if self.parent.map.mapFileName else "Untitled.json")

View File

@@ -0,0 +1,80 @@
from OpenGL.GL import *
import array
class VertexBuffer:
def __init__(self, componentsPerVertex=3):
self.componentsPerVertex = componentsPerVertex
self.vertices = []
self.colors = []
self.uvs = []
self.data = None
self.colorData = None
self.uvData = None
def buildData(self):
hasColors = len(self.colors) > 0
hasUvs = len(self.uvs) > 0
vertexCount = len(self.vertices) // self.componentsPerVertex
dataList = []
colorList = []
uvList = []
for i in range(vertexCount):
vStart = i * self.componentsPerVertex
dataList.extend(self.vertices[vStart:vStart+self.componentsPerVertex])
if hasColors:
cStart = i * 4 # Assuming RGBA
colorList.extend(self.colors[cStart:cStart+4])
if hasUvs:
uStart = i * 2 # Assuming UV
uvList.extend(self.uvs[uStart:uStart+2])
self.data = array.array('f', dataList)
if hasColors:
self.colorData = array.array('f', colorList)
else:
self.colorData = None
if hasUvs:
self.uvData = array.array('f', uvList)
else:
self.uvData = None
def draw(self, mode=GL_TRIANGLES, count=-1):
if count == -1:
count = len(self.data) // self.componentsPerVertex
if count == 0:
return
glEnableClientState(GL_VERTEX_ARRAY)
glVertexPointer(self.componentsPerVertex, GL_FLOAT, 0, self.data.tobytes())
if self.colorData:
glEnableClientState(GL_COLOR_ARRAY)
glColorPointer(4, GL_FLOAT, 0, self.colorData.tobytes())
if self.uvData:
glEnableClientState(GL_TEXTURE_COORD_ARRAY)
glTexCoordPointer(2, GL_FLOAT, 0, self.uvData.tobytes())
glDrawArrays(mode, 0, count)
glDisableClientState(GL_VERTEX_ARRAY)
if self.colorData:
glDisableClientState(GL_COLOR_ARRAY)
if self.uvData:
glDisableClientState(GL_TEXTURE_COORD_ARRAY)
def clear(self):
self.vertices = []
self.colors = []
self.uvs = []
self.data = array.array('f')
self.colorData = None
self.uvData = None

143
tools/editor/maptool.py Normal file
View File

@@ -0,0 +1,143 @@
import os
from PyQt5.QtWidgets import QMainWindow, QWidget, QHBoxLayout, QMessageBox
from PyQt5.QtCore import Qt
from tools.editor.map.glwidget import GLWidget
from tools.editor.map.mapleftpanel import MapLeftPanel
from tools.editor.map.mapinfopanel import MapInfoPanel
from tools.editor.map.menubar import MapMenubar
from tools.editor.map.statusbar import StatusBar
from tools.dusk.map import Map
from tools.dusk.defs import CHUNK_WIDTH, CHUNK_HEIGHT, CHUNK_DEPTH, TILE_SHAPE_NULL, TILE_SHAPE_FLOOR
from tools.editor.map.selectbox import SelectBox
from tools.editor.map.camera import Camera
from tools.editor.map.grid import Grid
class MapWindow(QMainWindow):
def __init__(self):
super().__init__()
self.insertPressed = False
self.deletePressed = False
# Subclasses
self.map = Map(self)
self.camera = Camera(self)
self.grid = Grid()
self.selectBox = SelectBox(self)
# Window setup
self.setWindowTitle("Dusk Map Editor")
self.resize(1600, 900)
# Menubar (TESTING)
self.menubar = MapMenubar(self)
central = QWidget()
self.setCentralWidget(central)
mainLayout = QHBoxLayout(central)
# Left panel (tabs + nav buttons)
self.leftPanel = MapLeftPanel(self)
self.leftPanel.setFixedWidth(350)
mainLayout.addWidget(self.leftPanel)
# Center panel (GLWidget + controls)
self.glWidget = GLWidget(self)
mainLayout.addWidget(self.glWidget, stretch=3)
# Right panel (MapInfoPanel)
self.mapInfoPanel = MapInfoPanel(self)
rightWidget = self.mapInfoPanel
rightWidget.setFixedWidth(250)
mainLayout.addWidget(rightWidget)
# Status bar
self.statusBar = StatusBar(self)
self.setStatusBar(self.statusBar)
self.installEventFilter(self)
self.installEventFilterRecursively(self)
def installEventFilterRecursively(self, widget):
for child in widget.findChildren(QWidget):
child.installEventFilter(self)
self.installEventFilterRecursively(child)
def closeEvent(self, event):
if not self.map.isDirty():
event.accept()
return
reply = QMessageBox.question(
self,
"Unsaved Changes",
"You have unsaved changes. Do you want to save before closing?",
QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel,
QMessageBox.Save
)
if reply == QMessageBox.Save:
self.map.save()
elif reply == QMessageBox.Cancel:
event.ignore()
return
event.accept()
def eventFilter(self, obj, event):
if event.type() == event.KeyPress:
amtX, amtY, amtZ = 0, 0, 0
key = event.key()
if key == Qt.Key_Left:
amtX = -1
elif key == Qt.Key_Right:
amtX = 1
elif key == Qt.Key_Up:
amtY = -1
elif key == Qt.Key_Down:
amtY = 1
elif key == Qt.Key_PageUp:
amtZ = 1
elif key == Qt.Key_PageDown:
amtZ = -1
if event.modifiers() & Qt.ShiftModifier:
amtX *= CHUNK_WIDTH
amtY *= CHUNK_HEIGHT
amtZ *= CHUNK_DEPTH
if amtX != 0 or amtY != 0 or amtZ != 0:
self.map.moveRelative(amtX, amtY, amtZ)
if self.insertPressed:
tile = self.map.getTileAtWorldPos(*self.map.position)
if tile is not None and tile.shape == TILE_SHAPE_NULL:
tile.setShape(TILE_SHAPE_FLOOR)
if self.deletePressed:
tile = self.map.getTileAtWorldPos(*self.map.position)
if tile is not None:
tile.setShape(TILE_SHAPE_NULL)
event.accept()
return True
if key == Qt.Key_Delete:
tile = self.map.getTileAtWorldPos(*self.map.position)
self.deletePressed = True
if tile is not None:
tile.setShape(TILE_SHAPE_NULL)
event.accept()
return True
if key == Qt.Key_Insert:
tile = self.map.getTileAtWorldPos(*self.map.position)
self.insertPressed = True
if tile is not None and tile.shape == TILE_SHAPE_NULL:
tile.setShape(TILE_SHAPE_FLOOR)
event.accept()
elif event.type() == event.KeyRelease:
key = event.key()
if key == Qt.Key_Delete:
self.deletePressed = False
event.accept()
return True
if key == Qt.Key_Insert:
self.insertPressed = False
event.accept()
return super().eventFilter(obj, event)