Cleanups in map object UI.

* Fix the context menu
* Remove unnecessary overrides
* Clean up formatting/naming
* Factor out base class for shared behavior
This commit is contained in:
Dan Albert
2020-09-13 22:51:41 -07:00
parent dcaa8d4e96
commit 80f2b7a1db
3 changed files with 107 additions and 106 deletions

View File

@@ -0,0 +1,28 @@
"""Common base for objects drawn on the game map."""
from PySide2.QtCore import Qt
from PySide2.QtWidgets import (
QGraphicsRectItem,
QGraphicsSceneHoverEvent,
QGraphicsSceneMouseEvent,
)
class QMapObject(QGraphicsRectItem):
"""Base class for objects drawn on the game map.
Game map objects have an on_click behavior that triggers on left click, and
change the mouse cursor on hover.
"""
def __init__(self, x: float, y: float, w: float, h: float):
super().__init__(x, y, w, h)
self.setAcceptHoverEvents(True)
def hoverEnterEvent(self, event: QGraphicsSceneHoverEvent):
self.setCursor(Qt.PointingHandCursor)
def mousePressEvent(self, event: QGraphicsSceneMouseEvent):
if event.button() == Qt.LeftButton:
self.on_click()
def on_click(self) -> None:
raise NotImplementedError