Merge branch 'master' into attrGroup

# Conflicts:
#	eve.db
#	gui/bitmap_loader.py
This commit is contained in:
blitzmann
2018-10-27 15:13:54 -04:00
17 changed files with 79 additions and 14 deletions

View File

@@ -85,14 +85,12 @@ class BitmapLoader(object):
cls.scaling_factor = int(wx.GetApp().GetTopWindow().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)))
@@ -100,9 +98,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

@@ -0,0 +1,39 @@
import wx
from logbook import Logger
import eos.db
pyfalog = Logger(__name__)
class FitChangeDroneVariationCommand(wx.Command):
""""
Fitting command that changes an existing drone into another variation.
"""
def __init__(self, fitID, position, itemID):
wx.Command.__init__(self, True, "Change Module")
self.fitID = fitID
self.itemID = itemID
self.position = position
self.old_drone = None
def Do(self):
return self.change_drone(self.fitID, self.position, self.itemID)
def Undo(self):
self.change_drone(self.fitID, self.position, self.old_drone)
return True
def change_drone(self, fitID, position, itemID):
fit = eos.db.getFit(self.fitID)
drone = fit.drones[self.position]
if itemID == drone.itemID:
return False
self.old_drone = drone.itemID
drone.changeType(itemID)
eos.db.commit()
# todo: ensure that, whatever type we send in, is actually a variation of the original drone. If not, return False
return True

View File

@@ -12,6 +12,7 @@ from .calc.fitAddCargo import FitAddCargoCommand
from .calc.fitReplaceModule import FitReplaceModuleCommand
from .calc.fitAddFighter import FitAddFighterCommand
from .calc.fitRemoveFighter import FitRemoveFighterCommand
from .calc.fitChangeDroneVariation import FitChangeDroneVariationCommand
class GuiMetaSwapCommand(wx.Command):
@@ -44,7 +45,8 @@ class GuiMetaSwapCommand(wx.Command):
for x in selection:
self.data.append(((FitRemoveFighterCommand, fitID, fit.fighters.index(x)), (FitAddFighterCommand, fitID, itemID)))
elif context == 'droneItem':
raise NotImplementedError()
for x in selection:
self.data.append(((FitChangeDroneVariationCommand, fitID, fit.drones.index(x), itemID),),)
def Do(self):
for cmds in self.data: