Channel map support.

This commit is contained in:
Khopa
2020-06-12 19:10:58 +02:00
parent c708abafc8
commit 601375d06f
16 changed files with 304 additions and 79 deletions

View File

@@ -54,6 +54,7 @@ def load_icons():
ICONS["Terrain_Persian_Gulf"] = QPixmap("./resources/ui/terrain_pg.gif")
ICONS["Terrain_Nevada"] = QPixmap("./resources/ui/terrain_nevada.gif")
ICONS["Terrain_Normandy"] = QPixmap("./resources/ui/terrain_normandy.gif")
ICONS["Terrain_Channel"] = QPixmap("./resources/ui/terrain_channel.gif")
ICONS["Dawn"] = QPixmap("./resources/ui/daytime/dawn.png")
ICONS["Day"] = QPixmap("./resources/ui/daytime/day.png")

View File

@@ -1,6 +1,7 @@
import typing
from typing import Dict
from PySide2 import QtCore
from PySide2.QtCore import Qt, QRect, QPointF
from PySide2.QtGui import QPixmap, QBrush, QColor, QWheelEvent, QPen, QFont
from PySide2.QtWidgets import QGraphicsView, QFrame, QGraphicsOpacityEffect
@@ -64,12 +65,60 @@ class QLiberationMap(QGraphicsView):
if self.game is not None:
self.reload_scene()
"""
Uncomment to set up theather reference points
def keyPressEvent(self, event):
#super(QLiberationMap, self).keyPressEvent(event)
numpad_mod = int(event.modifiers()) & QtCore.Qt.KeypadModifier
i = 0
for k,v in self.game.theater.reference_points.items():
if i == 0:
point_0 = k
else:
point_1 = k
i = i + 1
if event.key() == QtCore.Qt.Key_Down:
self.game.theater.reference_points[point_0] = self.game.theater.reference_points[point_0][0] + 100, self.game.theater.reference_points[point_0][1]
if event.key() == QtCore.Qt.Key_Up:
self.game.theater.reference_points[point_0] = self.game.theater.reference_points[point_0][0] - 100, self.game.theater.reference_points[point_0][1]
if event.key() == QtCore.Qt.Key_Left:
self.game.theater.reference_points[point_0] = self.game.theater.reference_points[point_0][0], self.game.theater.reference_points[point_0][1] + 100
if event.key() == QtCore.Qt.Key_Right:
self.game.theater.reference_points[point_0] = self.game.theater.reference_points[point_0][0], self.game.theater.reference_points[point_0][1] - 100
if event.key() == QtCore.Qt.Key_2 and numpad_mod:
self.game.theater.reference_points[point_1] = self.game.theater.reference_points[point_1][0] + 100, self.game.theater.reference_points[point_1][1]
if event.key() == QtCore.Qt.Key_8 and numpad_mod:
self.game.theater.reference_points[point_1] = self.game.theater.reference_points[point_1][0] - 100, self.game.theater.reference_points[point_1][1]
if event.key() == QtCore.Qt.Key_4 and numpad_mod:
self.game.theater.reference_points[point_1] = self.game.theater.reference_points[point_1][0], self.game.theater.reference_points[point_1][1] + 100
if event.key() == QtCore.Qt.Key_6 and numpad_mod:
self.game.theater.reference_points[point_1] = self.game.theater.reference_points[point_1][0], self.game.theater.reference_points[point_1][1] - 100
print(self.game.theater.reference_points)
self.reload_scene()
"""
def reload_scene(self):
scene = self.scene()
scene.clear()
self.addBackground()
#self.add_game_events()
# Uncomment below to help set up theater reference points
#for i, r in enumerate(self.game.theater.reference_points.items()):
# text = scene.addText(str(r), font=QFont("Trebuchet MS", 10, weight=5, italic=False))
# text.setPos(0, i * 24)
for cp in self.game.theater.controlpoints:
@@ -252,56 +301,6 @@ class QLiberationMap(QGraphicsView):
return X > treshold and X or treshold, Y > treshold and Y or treshold
def add_game_events(self):
occupied_rects = []
for cp in self.game.theater.controlpoints:
point = self._transform_point(cp.position)
occupied_rects.append(QRect(point[0] - 16, point[1] - 16, 32, 48))
def _location_to_rect(location: Point) -> QRect:
nonlocal occupied_rects
point = self._transform_point(location)
rect = QRect(point[0] - 16, point[1] - 16, 32, 32)
i = 0
while True:
result = True
for occupied_rect in occupied_rects:
if rect.intersects(occupied_rect):
i += 1
if i % 2:
rect.setY(rect.y() + occupied_rect.height())
else:
rect.setX(rect.x() + occupied_rect.width())
result = False
break
if result:
break
occupied_rects.append(rect)
return rect
def _events_priority_key(event: Event) -> int:
priority_list = [InfantryTransportEvent, StrikeEvent, BaseAttackEvent, UnitsDeliveryEvent]
if type(event) not in priority_list:
return 0
else:
return priority_list.index(type(event)) + 1
scene = self.scene()
events = self.game.events
events.sort(key=_events_priority_key, reverse=True)
for event in events:
location = event.location
if type(event) in [FrontlineAttackEvent, FrontlinePatrolEvent, ConvoyStrikeEvent]:
location = self._frontline_center(event.from_cp, event.to_cp)
rect = _location_to_rect(location)
scene.addItem(QMapEvent(self, rect.x(), rect.y(), 32, 32, event))
def addBackground(self):
scene = self.scene()

View File

@@ -8,7 +8,7 @@ from dcs.task import CAP, CAS
import qt_ui.uiconstants as CONST
from game import db, Game
from gen import namegen
from theater import start_generator, persiangulf, nevada, caucasus, ConflictTheater, normandy
from theater import start_generator, persiangulf, nevada, caucasus, ConflictTheater, normandy, thechannel
from userdata.logging import version_string
@@ -41,6 +41,8 @@ class NewGameWizard(QtWidgets.QWizard):
isTerrainCaucasusNorth= self.field("isTerrainCaucasusNorth")
isIranianCampaignTheater = self.field("isIranianCampaignTheater")
isTerrainNormandy = self.field("isTerrainNormandy")
isTerrainNormandySmall = self.field("isTerrainNormandySmall")
isTerrainChannel = self.field("isTerrainChannel")
isTerrainEmirates = self.field("isTerrainEmirates")
timePeriod = db.TIME_PERIODS[list(db.TIME_PERIODS.keys())[self.field("timePeriod")]]
midGame = self.field("midGame")
@@ -65,6 +67,10 @@ class NewGameWizard(QtWidgets.QWizard):
conflicttheater = persiangulf.Emirates()
elif isTerrainNormandy:
conflicttheater = normandy.NormandyTheater()
elif isTerrainNormandySmall:
conflicttheater = normandy.NormandySmall()
elif isTerrainChannel:
conflicttheater = thechannel.ChannelTheater()
else:
conflicttheater = caucasus.CaucasusTheater()
@@ -238,8 +244,12 @@ class TheaterConfiguration(QtWidgets.QWizardPage):
terrainEmirates.setIcon(QtGui.QIcon(CONST.ICONS["Terrain_Persian_Gulf"]))
terrainNttr = QtWidgets.QRadioButton("Nevada - North Nevada [RECOMMENDED]")
terrainNttr.setIcon(QtGui.QIcon(CONST.ICONS["Terrain_Nevada"]))
terrainNormandy = QtWidgets.QRadioButton("Normandy [Alpha]")
terrainNormandy = QtWidgets.QRadioButton("Normandy")
terrainNormandy.setIcon(QtGui.QIcon(CONST.ICONS["Terrain_Normandy"]))
terrainNormandySmall = QtWidgets.QRadioButton("Normandy Small")
terrainNormandySmall.setIcon(QtGui.QIcon(CONST.ICONS["Terrain_Normandy"]))
terrainChannel = QtWidgets.QRadioButton("Channel")
terrainChannel.setIcon(QtGui.QIcon(CONST.ICONS["Terrain_Channel"]))
terrainCaucasusSmall.setChecked(True)
# Time Period
@@ -261,6 +271,8 @@ class TheaterConfiguration(QtWidgets.QWizardPage):
self.registerField('isTerrainEmirates', terrainEmirates)
self.registerField('isTerrainNttr', terrainNttr)
self.registerField('isTerrainNormandy', terrainNormandy)
self.registerField('isTerrainNormandySmall', terrainNormandySmall)
self.registerField('isTerrainChannel', terrainChannel)
self.registerField('timePeriod', timePeriodSelect)
# Build layout
@@ -274,6 +286,8 @@ class TheaterConfiguration(QtWidgets.QWizardPage):
terrainGroupLayout.addWidget(terrainPg)
terrainGroupLayout.addWidget(terrainNttr)
terrainGroupLayout.addWidget(terrainNormandy)
terrainGroupLayout.addWidget(terrainNormandySmall)
terrainGroupLayout.addWidget(terrainChannel)
terrainGroup.setLayout(terrainGroupLayout)
timeGroupLayout = QtWidgets.QGridLayout()

View File

@@ -124,10 +124,14 @@ class QMissionPlanning(QDialog):
def on_start(self):
# TODO : refactor this nonsense
self.gameEvent = None
for event in self.game.events:
if isinstance(event, FrontlineAttackEvent) and event.is_player_attacking:
self.gameEvent = event
if self.gameEvent is None:
self.gameEvent = FrontlineAttackEvent(self.game, self.game.theater.controlpoints[0], self.game.theater.controlpoints[0],
self.game.theater.controlpoints[0].position, self.game.player_name, self.game.enemy_name)
#if self.awacs_checkbox.isChecked() == 1:
# self.gameEvent.is_awacs_enabled = True
# self.game.awacs_expense_commit()