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
parent 037ff85396
commit 4b4738c58f
11 changed files with 14 additions and 15 deletions

View File

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

View File

@ -73,6 +73,13 @@ class TheaterLoader:
def landmap_path(self) -> Path:
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:
with self.descriptor_path.open() as descriptor_file:
data = yaml.safe_load(descriptor_file)

View File

@ -62,16 +62,6 @@ def load_icons():
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["Day"] = QPixmap("./resources/ui/conditions/timeofday/day.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.QtCore import QItemSelectionModel, QModelIndex, Qt
from PySide2.QtGui import QStandardItem, QStandardItemModel
from PySide2.QtGui import QPixmap, QStandardItem, QStandardItemModel
from PySide2.QtWidgets import QAbstractItemView, QListView
import qt_ui.uiconstants as CONST
from game.campaignloader.campaign import Campaign
from qt_ui.liberation_install import get_dcs_install_directory
class QCampaignItem(QStandardItem):
def __init__(self, campaign: Campaign) -> None:
super(QCampaignItem, self).__init__()
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)
if campaign.is_compatible:
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