About to draw chunk
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
import sys
|
||||
import os
|
||||
import json
|
||||
from PyQt5.QtCore import Qt, QTimer
|
||||
from PyQt5.QtWidgets import (
|
||||
QApplication, QMainWindow, QWidget,
|
||||
QHBoxLayout, QVBoxLayout, QPushButton,
|
||||
QLabel, QSlider, QDialog, QRadioButton, QDialogButtonBox,
|
||||
QAction, QFileDialog, QLineEdit
|
||||
QAction, QFileDialog, QLineEdit, QMessageBox
|
||||
)
|
||||
from editortool.map.glwidget import GLWidget
|
||||
|
||||
@@ -36,6 +37,8 @@ class MapWindow(QMainWindow):
|
||||
action_save_as.triggered.connect(self.saveFileAs)
|
||||
|
||||
self.current_file = None
|
||||
self.dirty = False
|
||||
self.highlighted_pos = [0, 0, 0] # x, y, z
|
||||
|
||||
central = QWidget()
|
||||
self.setCentralWidget(central)
|
||||
@@ -46,6 +49,22 @@ class MapWindow(QMainWindow):
|
||||
left_panel = QVBoxLayout()
|
||||
chunk_info_label = QLabel("CHUNK INFO")
|
||||
left_panel.addWidget(chunk_info_label)
|
||||
|
||||
# Movement controls
|
||||
move_label = QLabel("Move Selection")
|
||||
left_panel.addWidget(move_label)
|
||||
btn_n = QPushButton("N")
|
||||
btn_s = QPushButton("S")
|
||||
btn_e = QPushButton("E")
|
||||
btn_w = QPushButton("W")
|
||||
btn_up = QPushButton("Up")
|
||||
btn_down = QPushButton("Down")
|
||||
left_panel.addWidget(btn_n)
|
||||
left_panel.addWidget(btn_s)
|
||||
left_panel.addWidget(btn_e)
|
||||
left_panel.addWidget(btn_w)
|
||||
left_panel.addWidget(btn_up)
|
||||
left_panel.addWidget(btn_down)
|
||||
left_panel.addStretch()
|
||||
|
||||
# Right panel
|
||||
@@ -53,9 +72,9 @@ class MapWindow(QMainWindow):
|
||||
map_info_label = QLabel("Map Information")
|
||||
right_panel.addWidget(map_info_label)
|
||||
map_title_label = QLabel("Map Title")
|
||||
map_title_input = QLineEdit()
|
||||
self.map_title_input = QLineEdit()
|
||||
right_panel.addWidget(map_title_label)
|
||||
right_panel.addWidget(map_title_input)
|
||||
right_panel.addWidget(self.map_title_input)
|
||||
right_panel.addStretch()
|
||||
|
||||
# Add panels to main layout
|
||||
@@ -73,9 +92,23 @@ class MapWindow(QMainWindow):
|
||||
right_widget.setFixedWidth(250)
|
||||
main_layout.addWidget(right_widget)
|
||||
|
||||
self.map_title_input.textChanged.connect(self._on_map_title_changed)
|
||||
|
||||
# Connect movement buttons
|
||||
btn_n.clicked.connect(lambda: self.move_highlight(0, 1, 0))
|
||||
btn_s.clicked.connect(lambda: self.move_highlight(0, -1, 0))
|
||||
btn_e.clicked.connect(lambda: self.move_highlight(1, 0, 0))
|
||||
btn_w.clicked.connect(lambda: self.move_highlight(-1, 0, 0))
|
||||
btn_up.clicked.connect(lambda: self.move_highlight(0, 0, 1))
|
||||
btn_down.clicked.connect(lambda: self.move_highlight(0, 0, -1))
|
||||
|
||||
def _on_map_title_changed(self):
|
||||
self.dirty = True
|
||||
|
||||
def newFile(self):
|
||||
# Implement new file logic here
|
||||
self.current_file = None
|
||||
self.map_title_input.setText("")
|
||||
self.dirty = False
|
||||
# ...clear relevant data...
|
||||
|
||||
def openFile(self):
|
||||
@@ -83,12 +116,18 @@ class MapWindow(QMainWindow):
|
||||
fname, _ = QFileDialog.getOpenFileName(self, "Open JSON File", default_dir, "JSON Files (*.json)")
|
||||
if fname:
|
||||
self.current_file = fname
|
||||
# ...load file logic...
|
||||
try:
|
||||
with open(fname, "r", encoding="utf-8") as f:
|
||||
data = json.load(f)
|
||||
self.map_title_input.setText(data.get("mapName", ""))
|
||||
self.dirty = False
|
||||
except Exception as e:
|
||||
self.map_title_input.setText("")
|
||||
# Optionally show error dialog
|
||||
|
||||
def saveFile(self):
|
||||
if self.current_file:
|
||||
# ...save logic...
|
||||
pass
|
||||
self._save_to_file(self.current_file)
|
||||
else:
|
||||
self.saveFileAs()
|
||||
|
||||
@@ -97,4 +136,43 @@ class MapWindow(QMainWindow):
|
||||
fname, _ = QFileDialog.getSaveFileName(self, "Save JSON File As", default_dir, "JSON Files (*.json)")
|
||||
if fname:
|
||||
self.current_file = fname
|
||||
# ...save logic...
|
||||
self._save_to_file(fname)
|
||||
|
||||
def _save_to_file(self, fname):
|
||||
data = {
|
||||
"mapName": self.map_title_input.text()
|
||||
}
|
||||
try:
|
||||
with open(fname, "w", encoding="utf-8") as f:
|
||||
json.dump(data, f, indent=2)
|
||||
self.dirty = False
|
||||
except Exception as e:
|
||||
# Optionally show error dialog
|
||||
pass
|
||||
|
||||
def move_highlight(self, dx, dy, dz):
|
||||
self.highlighted_pos[0] += dx
|
||||
self.highlighted_pos[1] += dy
|
||||
self.highlighted_pos[2] += dz
|
||||
self.gl_widget.set_highlighted_pos(self.highlighted_pos)
|
||||
self.dirty = True
|
||||
|
||||
def closeEvent(self, event):
|
||||
if self.dirty:
|
||||
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.saveFile()
|
||||
if self.dirty:
|
||||
event.ignore()
|
||||
return
|
||||
elif reply == QMessageBox.Cancel:
|
||||
event.ignore()
|
||||
return
|
||||
# Discard: continue closing
|
||||
event.accept()
|
||||
Reference in New Issue
Block a user