Files
dusk/tools/editortool/map/chunkpanel.py
Dominic Masters 6f33522c1c
Some checks failed
Build Dusk / build-linux (push) Failing after 56s
Build Dusk / build-psp (push) Failing after 1m8s
Begin adding entities to editor
2025-11-22 10:38:16 -06:00

80 lines
2.5 KiB
Python

from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QGridLayout, QTreeWidget, QTreeWidgetItem, QComboBox
from 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()