81 lines
2.8 KiB
Python
81 lines
2.8 KiB
Python
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QLineEdit, QPushButton, QHBoxLayout, QMessageBox
|
|
from editortool.map.map import map
|
|
from dusk.defs import defs
|
|
|
|
chunkWidth = int(defs.get('CHUNK_WIDTH'))
|
|
chunkHeight = int(defs.get('CHUNK_HEIGHT'))
|
|
chunkDepth = int(defs.get('CHUNK_DEPTH'))
|
|
|
|
class MapInfoPanel(QWidget):
|
|
def __init__(self, parent=None):
|
|
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("Chunk Position: 0, 0, 0")
|
|
layout.addWidget(self.chunkPosLabel)
|
|
self.chunkLabel = QLabel("Chunk: 0, 0, 0")
|
|
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)
|
|
map.positionEvent.sub(self.updatePositionLabels)
|
|
parent.mapData.onMapData.sub(self.onMapData)
|
|
|
|
self.mapTitleInput.textChanged.connect(self.onMapNameChange)
|
|
|
|
# Initial label setting
|
|
self.updatePositionLabels(map.position)
|
|
|
|
def goToPosition(self):
|
|
try:
|
|
x = int(self.tileXInput.text())
|
|
y = int(self.tileYInput.text())
|
|
z = int(self.tileZInput.text())
|
|
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]))
|
|
self.chunkPosLabel.setText(f"Chunk Position: {pos[0] % chunkWidth}, {pos[1] % chunkHeight}, {pos[2] % chunkDepth}")
|
|
self.chunkLabel.setText(f"Chunk: {pos[0] // chunkWidth}, {pos[1] // chunkHeight}, {pos[2] // chunkDepth}")
|
|
|
|
def onMapData(self, data):
|
|
self.updatePositionLabels(map.position)
|
|
self.mapTitleInput.setText(data.get("mapName", ""))
|
|
|
|
def onMapNameChange(self, text):
|
|
self.parent.mapData.data['mapName'] = text |