Add fallback terrain icons in campaign selector (#80)

This commit is contained in:
MetalStormGhost 2023-01-14 16:33:05 +02:00 committed by GitHub
parent cccc6e5a44
commit 3313535b27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 15 additions and 0 deletions

View File

@ -32,6 +32,7 @@ DEFAULT_BUDGET = 2000
class Campaign:
name: str
menu_thumbnail_dcs_relative_path: Path
fallback_icon_path: Path
authors: str
description: str
@ -90,6 +91,7 @@ class Campaign:
return cls(
data["name"],
TheaterLoader(data["theater"].lower()).menu_thumbnail_dcs_relative_path,
TheaterLoader(data["theater"].lower()).icon_path,
data.get("authors", "???"),
data.get("description", ""),
(version.major, version.minor),

View File

@ -90,6 +90,10 @@ class TheaterLoader:
def landmap_path(self) -> Path:
return self.descriptor_path.with_name("landmap.p")
@property
def icon_path(self) -> Path:
return self.descriptor_path.with_name("icon.gif")
@property
def menu_thumbnail_dcs_relative_path(self) -> Path:
with self.descriptor_path.open() as descriptor_file:

View File

@ -15,8 +15,17 @@ class QCampaignItem(QStandardItem):
def __init__(self, campaign: Campaign) -> None:
super(QCampaignItem, self).__init__()
self.setData(campaign, QCampaignList.CampaignRole)
# Define terrain icon path from the DCS installation directory by default
dcs_path = get_dcs_install_directory()
icon_path = dcs_path / campaign.menu_thumbnail_dcs_relative_path
# If the path does not exist (user does not have the terrain installed),
# use the old icons as fallback to avoid an ugly campaign list with missing icons
if not icon_path.exists():
print(f"Icon path: {campaign.fallback_icon_path}")
icon_path = campaign.fallback_icon_path
self.setIcon(QtGui.QIcon(QPixmap(str(icon_path))))
self.setEditable(False)
if campaign.is_compatible:

Binary file not shown.

After

Width:  |  Height:  |  Size: 852 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB