Browse Source

tinkered with the selection stuff, not sure if it's elegant. but it does the job fine.

you can select or mark regions.
moving and selecting now works without CTRL key, CTRL key is used to add regions to the marked list
master
Christian Voigt 1 year ago
parent
commit
5e1e7de7ec
  1. 9
      README.md
  2. 47
      sdtd_world/region_label.py
  3. 15
      sdtd_world/region_label_collection.py
  4. 20
      sdtd_world/world_regions_widget.py

9
README.md

@ -11,7 +11,8 @@ the whole project needs to be defined
That's about it for now
#### Core Functions
Loading of 7dtd RAW map files (dtm.raw)(CTRL+O)
*proper* Zooming in and out of a loaded map file (CTRL+Wheel)
Visually marking regions of a loaded 7dtd map file (CTRL+rightMouse)
Identifying region strings (Statusbar on Hover)
Loading of 7dtd RAW map files (dtm.raw, any RAW 16bit grayscale that's stored in order) (CTRL+O)
*proper* Zooming in and out and navigate in a loaded map (Wheel, leftMouseDrag)
Visually selecting a region of a loaded map file (leftMouse)
Visually marking regions of a loaded 7dtd map file (CTRL+leftMouse)
Identifying region strings (Statusbar on Hover)

47
sdtd_world/region_label.py

@ -3,14 +3,18 @@ from PyQt5.QtGui import (
QPixmap, QColor, QImage
)
from PyQt5.QtWidgets import (
QLabel, QGraphicsColorizeEffect
QLabel, QGraphicsColorizeEffect, QApplication
)
class RegionLabel(QLabel):
region_string = str
is_selected = bool
is_marked = bool
is_region = bool
is_selected = bool
parent_collection = object
image = QImage
@ -18,8 +22,10 @@ class RegionLabel(QLabel):
super(RegionLabel, self).__init__()
pixmap = QPixmap(512, 512)
fill_color = QColor(x, y, int(x * 2.5) + int(y * 0.5))
self.is_selected = False
self.is_marked = False
self.is_region = False
self.is_selected = False
self.parent_collection = collection
self.region_string = "r.{}.{}.7rg".format(
@ -46,16 +52,33 @@ class RegionLabel(QLabel):
def mark_as_region(self):
self.is_region = True
def update_graphics_effect(self):
effect = QGraphicsColorizeEffect()
effect_required = False
if self.is_marked:
effect_required = True
effect.setColor(QColor(0, 200, 0))
if self.is_selected:
effect_required = True
effect.setColor(QColor(200, 0, 0))
if self.is_selected and self.is_marked:
effect_required = True
effect.setColor(QColor(0, 0, 200))
if effect_required:
self.setGraphicsEffect(effect)
else:
self.setGraphicsEffect(None)
def mousePressEvent(self, event):
if event.buttons() == Qt.RightButton:
self.is_selected = not self.is_selected
if self.is_selected:
effect = QGraphicsColorizeEffect()
effect.setColor(QColor(200, 0, 0))
self.setGraphicsEffect(effect)
else:
self.setGraphicsEffect(None)
modifiers = QApplication.keyboardModifiers()
if modifiers == Qt.ControlModifier:
if event.buttons() == Qt.LeftButton:
self.parent_collection.set_selected(self)
self.parent_collection.toggle_marked(self)
else:
if event.buttons() == Qt.LeftButton:
self.parent_collection.set_selected(self)
super().mousePressEvent(event)

15
sdtd_world/region_label_collection.py

@ -1,7 +1,7 @@
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPixmap, QColor, QPainter
from PyQt5.QtWidgets import (
QGridLayout, QApplication
QGridLayout, QApplication, QGraphicsColorizeEffect
)
from .region_label import RegionLabel
@ -21,6 +21,19 @@ class RegionLabelCollection(QGridLayout):
def set_currently_hovered_label(self, label):
self.world_regions.set_currently_hovered_region(label)
def set_selected(self, region_label=None):
for index, label in self.label_collection.items():
label.is_selected = False
label.update_graphics_effect()
if region_label is not None:
region_label.is_selected = True
region_label.update_graphics_effect()
def toggle_marked(self, region_label=None):
region_label.is_marked = not region_label.is_marked
region_label.update_graphics_effect()
def create_label_collection(self, label_size):
for y in range(0, 32):
for x in range(0, 32):

20
sdtd_world/world_regions_widget.py

@ -124,11 +124,9 @@ class WorldRegionsWidget(QScrollArea):
""" altering class functions """
def mousePressEvent(self, event):
modifiers = QApplication.keyboardModifiers()
if modifiers == Qt.ControlModifier and event.button() == Qt.LeftButton:
self.drag_in_progress = True
self.drag_start.setX(event.x())
self.drag_start.setY(event.y())
self.drag_in_progress = True
self.drag_start.setX(event.x())
self.drag_start.setY(event.y())
super().mousePressEvent(event)
@ -153,12 +151,10 @@ class WorldRegionsWidget(QScrollArea):
super().mouseMoveEvent(event)
def wheelEvent(self, event):
modifiers = QApplication.keyboardModifiers()
if modifiers == Qt.ControlModifier:
if event.angleDelta().y() > 0:
self.action_zoom_in()
else:
self.action_zoom_out()
if event.angleDelta().y() > 0:
self.action_zoom_in()
else:
self.action_zoom_out()
""" We do NOT weant to call the super() here,
we do not want to scroll with the wheel, this is not a list """
@ -166,7 +162,7 @@ class WorldRegionsWidget(QScrollArea):
def keyPressEvent(self, event):
if event.key() in (16777249, 16777250):
self.setCursor(QCursor(Qt.SizeAllCursor))
self.setCursor(QCursor(Qt.CrossCursor))
super().keyPressEvent(event)

Loading…
Cancel
Save