def __init__(self, game): super(MapManager, self).__init__() self.game = game self.map_data = self.game.scenario.setup_map() self.map_model = MapTileModel(self.map_data) self.model = QMLInterfaceModel(self.map_model) self.game.main_window.ui.mapView.rootContext().setContextProperty("map_model", self.model) self.game.main_window.ui.mapView.setSource(QtCore.QUrl("./manitae/maps/Map.qml")) self.qml_root = self.game.main_window.ui.mapView.rootObject() self.qml_root.resize(self.model.model.columnCount(), self.model.model.rowCount()) self.qml_root.mapClicked.connect(self.update_current_tile) self.game.main_window.ui.goToTabPushButton.clicked.connect(self.go_to_tab)
class MapManager(QtCore.QObject): def __init__(self, game): super(MapManager, self).__init__() self.game = game self.map_data = self.game.scenario.setup_map() self.map_model = MapTileModel(self.map_data) self.model = QMLInterfaceModel(self.map_model) self.game.main_window.ui.mapView.rootContext().setContextProperty("map_model", self.model) self.game.main_window.ui.mapView.setSource(QtCore.QUrl("./manitae/maps/Map.qml")) self.qml_root = self.game.main_window.ui.mapView.rootObject() self.qml_root.resize(self.model.model.columnCount(), self.model.model.rowCount()) self.qml_root.mapClicked.connect(self.update_current_tile) self.game.main_window.ui.goToTabPushButton.clicked.connect(self.go_to_tab) def __del__(self): self.game.main_window.ui.positionLineEdit.setText("") self.game.main_window.ui.tileOccupantLineEdit.setText("") self.game.main_window.ui.goToTabPushButton.setEnabled(False) def update_current_tile(self, tile_index): self.current_tile_coords = self.model.index_to_coords(tile_index) self.current_tile = self.map_data[self.current_tile_coords[1]][self.current_tile_coords[0]] self.update_data(self.current_tile_coords, self.current_tile) def update_data(self, coords, tile): self.game.main_window.ui.buildPushButton.setEnabled(tile.buildable) self.game.main_window.ui.positionLineEdit.setText(str(coords)) if tile.unit: self.game.main_window.ui.tileOccupantLineEdit.setText(str(tile.unit)) self.game.main_window.ui.goToTabPushButton.setEnabled(True) else: self.game.main_window.ui.tileOccupantLineEdit.setText("") self.game.main_window.ui.goToTabPushButton.setEnabled(False) def go_to_tab(self): tab = self.current_tile.unit.widget self.game.main_window.ui.tabWidget.setCurrentWidget(tab)