Load map icons directly from DCS.

If the user's DCS directory is not configured correctly this will
degrade by not showing an icon. Otherwise (and typically) we get nicer
looking icons for each theater, and we don't have to make these for each
new map.
This commit is contained in:
Dan Albert 2022-09-27 19:09:19 -07:00 committed by Raffson
parent 868c38b782
commit 7e8f734309
No known key found for this signature in database
GPG Key ID: B0402B2C9B764D99
11 changed files with 14 additions and 15 deletions

View File

@ -31,7 +31,7 @@ DEFAULT_BUDGET = 2000
@dataclass(frozen=True) @dataclass(frozen=True)
class Campaign: class Campaign:
name: str name: str
icon_name: str menu_thumbnail_dcs_relative_path: Path
authors: str authors: str
description: str description: str
@ -89,7 +89,7 @@ class Campaign:
return cls( return cls(
data["name"], data["name"],
f"Terrain_{sanitized_theater}", TheaterLoader(data["theater"].lower()).menu_thumbnail_dcs_relative_path,
data.get("authors", "???"), data.get("authors", "???"),
data.get("description", ""), data.get("description", ""),
(version.major, version.minor), (version.major, version.minor),

View File

@ -73,6 +73,13 @@ class TheaterLoader:
def landmap_path(self) -> Path: def landmap_path(self) -> Path:
return self.descriptor_path.with_name("landmap.p") return self.descriptor_path.with_name("landmap.p")
@property
def menu_thumbnail_dcs_relative_path(self) -> Path:
with self.descriptor_path.open() as descriptor_file:
data = yaml.safe_load(descriptor_file)
name = data.get("pydcs_name", data["name"])
return Path("Mods/terrains") / name / "Theme/icon.png"
def load(self) -> ConflictTheater: def load(self) -> ConflictTheater:
with self.descriptor_path.open() as descriptor_file: with self.descriptor_path.open() as descriptor_file:
data = yaml.safe_load(descriptor_file) data = yaml.safe_load(descriptor_file)

View File

@ -63,16 +63,6 @@ def load_icons():
ICONS["Hangar"] = QPixmap("./resources/ui/misc/hangar.png") ICONS["Hangar"] = QPixmap("./resources/ui/misc/hangar.png")
ICONS["Terrain_Caucasus"] = QPixmap("./resources/ui/terrain_caucasus.gif")
ICONS["Terrain_PersianGulf"] = 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_TheChannel"] = QPixmap("./resources/ui/terrain_channel.gif")
ICONS["Terrain_Syria"] = QPixmap("./resources/ui/terrain_syria.gif")
ICONS["Terrain_MarianaIslands"] = QPixmap("./resources/ui/terrain_marianas.gif")
# TODO
ICONS["Terrain_Falklands"] = QPixmap("./resources/ui/terrain_marianas.gif")
ICONS["Dawn"] = QPixmap("./resources/ui/conditions/timeofday/dawn.png") ICONS["Dawn"] = QPixmap("./resources/ui/conditions/timeofday/dawn.png")
ICONS["Day"] = QPixmap("./resources/ui/conditions/timeofday/day.png") ICONS["Day"] = QPixmap("./resources/ui/conditions/timeofday/day.png")
ICONS["Dusk"] = QPixmap("./resources/ui/conditions/timeofday/dusk.png") ICONS["Dusk"] = QPixmap("./resources/ui/conditions/timeofday/dusk.png")

View File

@ -4,18 +4,20 @@ from typing import Optional
from PySide2 import QtGui from PySide2 import QtGui
from PySide2.QtCore import QItemSelectionModel, QModelIndex, Qt from PySide2.QtCore import QItemSelectionModel, QModelIndex, Qt
from PySide2.QtGui import QStandardItem, QStandardItemModel from PySide2.QtGui import QPixmap, QStandardItem, QStandardItemModel
from PySide2.QtWidgets import QAbstractItemView, QListView from PySide2.QtWidgets import QAbstractItemView, QListView
import qt_ui.uiconstants as CONST
from game.campaignloader.campaign import Campaign from game.campaignloader.campaign import Campaign
from qt_ui.liberation_install import get_dcs_install_directory
class QCampaignItem(QStandardItem): class QCampaignItem(QStandardItem):
def __init__(self, campaign: Campaign) -> None: def __init__(self, campaign: Campaign) -> None:
super(QCampaignItem, self).__init__() super(QCampaignItem, self).__init__()
self.setData(campaign, QCampaignList.CampaignRole) self.setData(campaign, QCampaignList.CampaignRole)
self.setIcon(QtGui.QIcon(CONST.ICONS[campaign.icon_name])) dcs_path = get_dcs_install_directory()
icon_path = dcs_path / campaign.menu_thumbnail_dcs_relative_path
self.setIcon(QtGui.QIcon(QPixmap(str(icon_path))))
self.setEditable(False) self.setEditable(False)
if campaign.is_compatible: if campaign.is_compatible:
name = campaign.name name = campaign.name

Binary file not shown.

Before

Width:  |  Height:  |  Size: 852 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 260 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB