Browse Source

added proper zooming. mouse focussed region will be centered if possible.

master
Christian Voigt 1 year ago
parent
commit
51b7bfe9f9
  1. 7
      README.md
  2. 6
      sdtd_world/region_label.py
  3. 12
      sdtd_world/region_label_collection.py
  4. 33
      sdtd_world/world_regions_widget.py

7
README.md

@ -11,6 +11,7 @@ the whole project needs to be defined
That's about it for now
#### Core Functions
Loading of 7dtd RAW map files (dtm.raw)
Zooming in and out of a loaded map file
Visually marking regions of a loaded 7dtd map file
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)

6
sdtd_world/region_label.py

@ -14,12 +14,13 @@ class RegionLabel(QLabel):
image = QImage
def __init__(self, x=None, y=None):
def __init__(self, collection, x=None, y=None):
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_region = False
self.parent_collection = collection
self.region_string = "r.{}.{}.7rg".format(
int(x - 16),
@ -57,3 +58,6 @@ class RegionLabel(QLabel):
self.setGraphicsEffect(None)
super().mousePressEvent(event)
def wheelEvent(self, event):
self.parent_collection.set_currently_hovered_label(self)

12
sdtd_world/region_label_collection.py

@ -1,6 +1,7 @@
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPixmap, QColor, QPainter
from PyQt5.QtWidgets import (
QGridLayout
QGridLayout, QApplication
)
from .region_label import RegionLabel
@ -8,13 +9,18 @@ from .region_label import RegionLabel
class RegionLabelCollection(QGridLayout):
label_collection = dict
currently_hovered_label = object
def __init__(self, size):
def __init__(self, world_regions, size):
super().__init__()
self.label_collection = {}
self.world_regions = world_regions
self.create_label_collection(size)
def set_currently_hovered_label(self, label):
self.world_regions.set_currently_hovered_region(label)
def create_label_collection(self, label_size):
for y in range(0, 32):
for x in range(0, 32):
@ -22,7 +28,7 @@ class RegionLabelCollection(QGridLayout):
self.create_label(x, y, label_size, grid_slot)
def create_label(self, x, y, size, index):
label = RegionLabel(x, y)
label = RegionLabel(self, x, y)
label.setFixedSize(size, size)
self.addWidget(label, y, x)
self.label_collection.update({index: label})

33
sdtd_world/world_regions_widget.py

@ -32,6 +32,8 @@ class WorldRegionsWidget(QScrollArea):
world_regions_image = QImage
world_regions_image_raw_data = np.array
currently_hovered_region = object
def __init__(self, zoom_factor=1.0, min_zoom_factor=1.0, max_zoom_factor=48.0, region_size=24):
super().__init__()
self.min_zoom_factor = min_zoom_factor
@ -44,7 +46,7 @@ class WorldRegionsWidget(QScrollArea):
self.drag_start = QPoint(0, 0)
self.region_label_collection = RegionLabelCollection(
self.get_zoom_adjusted_label_size()
self, self.get_zoom_adjusted_label_size()
)
self.region_label_collection.setSpacing(0)
@ -68,6 +70,9 @@ class WorldRegionsWidget(QScrollArea):
self.action_open_world_file = open_world_file
self.addAction(self.action_open_world_file)
def set_currently_hovered_region(self, label):
self.currently_hovered_region = label
def get_zoom_adjusted_label_size(self):
return self.world_label_zoom_factor * self.world_label_region_size
@ -80,6 +85,8 @@ class WorldRegionsWidget(QScrollArea):
self.region_label_collection.change_label_size(
self.get_zoom_adjusted_label_size()
)
self.adjust_scrollbar_positions()
self.adjust_mouse_position()
def action_zoom_out(self):
self.world_label_zoom_factor -= self.min_zoom_factor
@ -90,6 +97,30 @@ class WorldRegionsWidget(QScrollArea):
self.region_label_collection.change_label_size(
self.get_zoom_adjusted_label_size()
)
self.adjust_scrollbar_positions()
self.adjust_mouse_position()
def adjust_scrollbar_positions(self):
size = (self.currently_hovered_region.width())
widget_index_x = int(self.currently_hovered_region.region_string.split(".")[1]) + 17
widget_index_y = int((int(self.currently_hovered_region.region_string.split(".")[2]) * -1)) + 16
widget_position_x = int(widget_index_x * size)
widget_position_y = int(widget_index_y * size)
self.horizontalScrollBar().setValue(
int(widget_position_x - size / 2 - self.width() / 2)
)
self.verticalScrollBar().setValue(
int(widget_position_y - size / 2 - self.height() / 2)
)
def adjust_mouse_position(self):
QCursor.setPos(self.currently_hovered_region.mapToGlobal(QPoint(
int(self.currently_hovered_region.width() / 2),
int(self.currently_hovered_region.height() / 2)
)))
""" altering class functions """
def mousePressEvent(self, event):

Loading…
Cancel
Save