Merge pull request #1772 from tron1point0/issue/pyfa-org/1769

Try loading smaller variants if scaled icons are missing
This commit is contained in:
Ryan Holmes
2018-10-15 21:11:02 -04:00
committed by GitHub
3 changed files with 25 additions and 11 deletions

View File

@@ -84,16 +84,15 @@ class BitmapLoader(object):
if cls.scaling_factor is None:
import gui.mainFrame
cls.scaling_factor = int(gui.mainFrame.MainFrame.getInstance().GetContentScaleFactor())
scale = cls.scaling_factor
filenameScaled = "{0}@{1}x.png".format(name, scale)
img = cls.loadImage(filenameScaled, location)
filename, img = cls.loadScaledBitmap(name, location, scale)
if img is None:
# can't find the scaled image, fallback to no scaling
filename = "{0}.png".format(name)
img = cls.loadImage(filename, location)
scale = 1
while img is None and scale > 0:
# can't find the correctly scaled image, fallback to smaller scales
scale -= 1
filename, img = cls.loadScaledBitmap(name, location, scale)
if img is None:
print(("Missing icon file: {0}/{1}".format(location, filename)))
@@ -101,9 +100,26 @@ class BitmapLoader(object):
bmp: wx.Bitmap = img.ConvertToBitmap()
if scale > 1:
bmp.SetSize((int(bmp.GetWidth()/scale), int(bmp.GetHeight()/scale)))
bmp.SetSize((bmp.GetWidth() // scale, bmp.GetHeight() // scale))
return bmp
@classmethod
def loadScaledBitmap(cls, name, location, scale=0):
"""Attempts to load a scaled bitmap.
Args:
name (str): TypeID or basename of the image being requested.
location (str): Path to a location that may contain the image.
scale (int): Scale factor of the image variant to load. If ``0``, attempts to load the unscaled variant.
Returns:
(str, wx.Image): Tuple of the filename that may have been loaded and the image at that location. The
filename will always be present, but the image may be ``None``.
"""
filename = "{0}@{1}x.png".format(name, scale) if scale > 0 else "{0}.png".format(name)
img = cls.loadImage(filename, location)
return filename, img
@classmethod
def loadImage(cls, filename, location):
if cls.archive:

View File

@@ -48,7 +48,6 @@ class GuiMetaSwapCommand(wx.Command):
for x in selection:
self.data.append(((FitChangeDroneVariationCommand, fitID, fit.drones.index(x), itemID),),)
def Do(self):
for cmds in self.data:
for cmd in cmds:

View File

@@ -83,7 +83,6 @@ class EfsPort():
@staticmethod
def getPropData(fit, sFit):
fitID = fit.ID
propMods = filter(lambda mod: mod.item and mod.item.group.name == "Propulsion Module", fit.modules)
activePropWBloomFilter = lambda mod: mod.state > 0 and "signatureRadiusBonus" in mod.item.attributes
propWithBloom = next(filter(activePropWBloomFilter, propMods), None)
@@ -341,7 +340,7 @@ class EfsPort():
# This also covers non-bomb weapons with dps values and no hardpoints, most notably targeted doomsdays.
typeing = "SmartBomb"
# Targeted DDs are the only non drone/fighter weapon without an explict max range
if stats.item.group.name == 'Super Weapon' and stats.maxRange == None:
if stats.item.group.name == 'Super Weapon' and stats.maxRange is None:
maxRange = 300000
else:
maxRange = stats.maxRange