diff --git a/eos/modifiedAttributeDict.py b/eos/modifiedAttributeDict.py index 324d83b69..62811b614 100755 --- a/eos/modifiedAttributeDict.py +++ b/eos/modifiedAttributeDict.py @@ -184,7 +184,7 @@ class ModifiedAttributeDict(collections.MutableMapping): def iterAfflictions(self): return self.__affectedBy.__iter__() - def __afflict(self, attributeName, operation, bonus): + def __afflict(self, attributeName, operation, bonus, used=True): """Add modifier to list of things affecting current item""" # Do nothing if no fit is assigned if self.fit is None: @@ -201,15 +201,13 @@ class ModifiedAttributeDict(collections.MutableMapping): # Get modifier which helps to compose 'Affected by' map modifier = self.fit.getModifier() # Add current affliction to set - affs.add((modifier, operation, bonus)) + affs.add((modifier, operation, bonus, used)) def preAssign(self, attributeName, value): """Overwrites original value of the entity with given one, allowing further modification""" self.__preAssigns[attributeName] = value self.__placehold(attributeName) - # Add to afflictions only if preassigned value differs from original - if value != self.getOriginal(attributeName): - self.__afflict(attributeName, "=", value) + self.__afflict(attributeName, "=", value, value != self.getOriginal(attributeName)) def increase(self, attributeName, increase, position="pre"): """Increase value of given attribute by given number""" @@ -225,9 +223,7 @@ class ModifiedAttributeDict(collections.MutableMapping): tbl[attributeName] = 0 tbl[attributeName] += increase self.__placehold(attributeName) - # Add to list of afflictions only if we actually modify value - if increase != 0: - self.__afflict(attributeName, "+", increase) + self.__afflict(attributeName, "+", increase, increase != 0) def multiply(self, attributeName, multiplier, stackingPenalties=False, penaltyGroup="default"): """Multiply value of given attribute by given factor""" @@ -246,9 +242,7 @@ class ModifiedAttributeDict(collections.MutableMapping): self.__multipliers[attributeName] = 1 self.__multipliers[attributeName] *= multiplier self.__placehold(attributeName) - # Add to list of afflictions only if we actually modify value - if multiplier != 1: - self.__afflict(attributeName, "%s*" % ("s" if stackingPenalties else ""), multiplier) + self.__afflict(attributeName, "%s*" % ("s" if stackingPenalties else ""), multiplier, multiplier != 1) def boost(self, attributeName, boostFactor, *args, **kwargs): """Boost value by some percentage""" diff --git a/eos/saveddata/character.py b/eos/saveddata/character.py index 8695ddba2..281f27dbe 100755 --- a/eos/saveddata/character.py +++ b/eos/saveddata/character.py @@ -87,6 +87,7 @@ class Character(object): all0 = eos.db.getCharacter("All 0") if all0 is None: all0 = Character("All 0") + all0.defaultLevel = None eos.db.add(all0) cls.__all0 = all0 @@ -173,12 +174,6 @@ class Character(object): return self.__implants def iterSkills(self): - if self.defaultLevel is not None: - return self.iterDefaultLevel() - else: - return self.__skills.__iter__() - - def iterDefaultLevel(self): for item in self.getSkillList(): yield self.getSkill(item) @@ -275,7 +270,9 @@ class Skill(HandledItem): return self.item.attributes[key].value def calculateModifiedAttributes(self, fit, runTime): - if self.__suppressed or not self.learned: return + if self.__suppressed: # or not self.learned - removed for GH issue 101 + return + item = self.item if item is None: return diff --git a/eos/saveddata/fit.py b/eos/saveddata/fit.py index f207d6717..fda71788c 100755 --- a/eos/saveddata/fit.py +++ b/eos/saveddata/fit.py @@ -588,8 +588,11 @@ class Fit(object): for attr in ("shieldRepair", "armorRepair", "hullRepair"): sustainable[attr] = self.extraAttributes[attr] dict = self.extraAttributes.getAfflictions(attr) + print dict if self in dict: - for mod, _, amount in dict[self]: + for mod, _, amount, used in dict[self]: + if not used: + continue if mod.projected is False: usesCap = True try: diff --git a/gui/builtinContextMenus/__init__.py b/gui/builtinContextMenus/__init__.py index edec6a9fc..1dccad065 100644 --- a/gui/builtinContextMenus/__init__.py +++ b/gui/builtinContextMenus/__init__.py @@ -1,2 +1,2 @@ -__all__ = ["moduleAmmoPicker", "itemStats", "damagePattern", "marketJump", "droneSplit", "itemRemove", +__all__ = ["moduleAmmoPicker", "changeAffectingSkills", "itemStats", "damagePattern", "marketJump", "droneSplit", "itemRemove", "droneRemoveStack", "ammoPattern", "project", "factorReload", "whProjector", "cargo"] diff --git a/gui/builtinContextMenus/changeAffectingSkills.py b/gui/builtinContextMenus/changeAffectingSkills.py new file mode 100644 index 000000000..4d1f5fdd4 --- /dev/null +++ b/gui/builtinContextMenus/changeAffectingSkills.py @@ -0,0 +1,102 @@ +# -*- coding: utf-8 -*- +from gui.contextMenu import ContextMenu +import gui.mainFrame +import service +import wx +from gui import bitmapLoader +from eos.types import Skill +import gui.globalEvents as GE + +class ChangeAffectingSkills(ContextMenu): + def __init__(self): + self.mainFrame = gui.mainFrame.MainFrame.getInstance() + self.sChar = service.Character.getInstance() + + self.sFit = service.Fit.getInstance() + fit = self.sFit.getFit(self.mainFrame.getActiveFit()) + + self.charID = fit.character.ID + + def display(self, srcContext, selection): + if self.mainFrame.getActiveFit() is None or srcContext not in ("fittingModule", "fittingShip"): + return False + + if self.sChar.getCharName(self.charID) in ("All 0", "All 5"): + return False + + if srcContext == "fittingShip": + fitID = self.mainFrame.getActiveFit() + sFit = service.Fit.getInstance() + self.stuff = sFit.getFit(fitID).ship + else: + self.stuff = selection[0] + + cont = self.stuff.itemModifiedAttributes + self.skills = [] + + for attrName in cont.iterAfflictions(): + if cont[attrName] == 0: + continue + + for fit, afflictors in cont.getAfflictions(attrName).iteritems(): + for afflictor, modifier, amount, used in afflictors: + # only add Skills + if not isinstance(afflictor, Skill): + continue + + self.skills.append(afflictor) + self.skills.sort(key=lambda x: x.item.name) + + return len(self.skills) > 0 + + def getText(self, itmContext, selection): + return "Change %s Skills" % itmContext + + def activate(self, fullContext, selection, i): + pass + + def addSkill(self, rootMenu, skill, i): + if i < 0: + label = "Not Learned" + else: + label = "Level %s" % i + + id = wx.NewId() + self.skillIds[id] = (skill, i) + menuItem = wx.MenuItem(rootMenu, id, label, kind=wx.ITEM_CHECK) + rootMenu.Bind(wx.EVT_MENU, self.handleSkillChange, menuItem) + return menuItem + + def getSubMenu(self, context, selection, menu, i): + self.context = context + self.skillIds = {} + + m = wx.Menu() + + for skill in self.skills: + skillItem = wx.MenuItem(m, wx.NewId(), skill.item.name) + sub = wx.Menu() + skillItem.SetSubMenu(sub) + if skill.learned: + bitmap = bitmapLoader.getBitmap("lvl%s" % skill.level, "icons") + if bitmap is not None: + skillItem.SetBitmap(bitmap) + + for i in xrange(-1, 6): + levelItem = self.addSkill(menu, skill, i) + sub.AppendItem(levelItem) + #@ todo: add check to current level. Need to fix #109 first + m.AppendItem(skillItem) + + return m + + def handleSkillChange(self, event): + skill, level = self.skillIds[event.Id] + + self.sChar.changeLevel(self.charID, skill.item.ID, level) + fitID = self.mainFrame.getActiveFit() + self.sFit.changeChar(fitID, self.charID) + + wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fitID)) + +ChangeAffectingSkills.register() diff --git a/gui/itemStats.py b/gui/itemStats.py index 6f4d1c6fa..8a20b28b9 100644 --- a/gui/itemStats.py +++ b/gui/itemStats.py @@ -615,13 +615,15 @@ class ItemAffectedBy (wx.Panel): cont = self.stuff.itemModifiedAttributes if self.item == self.stuff.item else self.stuff.chargeModifiedAttributes things = {} + for attrName in cont.iterAfflictions(): + # if value is 0 or there has been no change from original to modified, return if cont[attrName] == (cont.getOriginal(attrName) or 0): continue for fit, afflictors in cont.getAfflictions(attrName).iteritems(): - for afflictor, modifier, amount in afflictors: - if afflictor.item is None: + for afflictor, modifier, amount, used in afflictors: + if not used or afflictor.item is None: continue if afflictor.item.name not in things: things[afflictor.item.name] = [type(afflictor), set(), set()] diff --git a/icons/lvl0.png b/icons/lvl0.png new file mode 100644 index 000000000..7c60aa2e3 Binary files /dev/null and b/icons/lvl0.png differ diff --git a/icons/lvl1.png b/icons/lvl1.png new file mode 100644 index 000000000..046a88dfa Binary files /dev/null and b/icons/lvl1.png differ diff --git a/icons/lvl2.png b/icons/lvl2.png new file mode 100644 index 000000000..90c566ea6 Binary files /dev/null and b/icons/lvl2.png differ diff --git a/icons/lvl3.png b/icons/lvl3.png new file mode 100644 index 000000000..281f1be9f Binary files /dev/null and b/icons/lvl3.png differ diff --git a/icons/lvl4.png b/icons/lvl4.png new file mode 100644 index 000000000..215e7cd3d Binary files /dev/null and b/icons/lvl4.png differ diff --git a/icons/lvl5.png b/icons/lvl5.png new file mode 100644 index 000000000..7c38c0d37 Binary files /dev/null and b/icons/lvl5.png differ diff --git a/service/character.py b/service/character.py index 60633cbd4..7a8a6cbc6 100644 --- a/service/character.py +++ b/service/character.py @@ -72,7 +72,7 @@ class SkillBackupThread(threading.Thread): backupData = sCharacter.exportXml() else: backupData = sCharacter.exportText() - + if self.saveFmt == "emp": with gzip.open(path, mode='wb') as backupFile: backupFile.write(backupData) @@ -112,12 +112,12 @@ class Character(object): root = ElementTree.Element("plan") root.attrib["name"] = "Pyfa exported plan for "+self.skillReqsDict['charname'] root.attrib["revision"] = config.evemonMinVersion - + sorts = ElementTree.SubElement(root, "sorting") sorts.attrib["criteria"] = "None" sorts.attrib["order"] = "None" sorts.attrib["groupByPriority"] = "false" - + skillsSeen = set() for s in self.skillReqsDict['skills']: @@ -134,7 +134,7 @@ class Character(object): entry.attrib["type"] = "Prerequisite" notes = ElementTree.SubElement(entry, "notes") notes.text = entry.attrib["skill"] - + tree = ElementTree.ElementTree(root) data = ElementTree.tostring(root, 'utf-8') prettydata = minidom.parseString(data).toprettyxml(indent=" ") @@ -237,7 +237,7 @@ class Character(object): def apiEnabled(self, charID): id, key, default, _ = self.getApiDetails(charID) return id is not "" and key is not "" and default is not "" - + def charList(self, charID, userID, apiKey): char = eos.db.getCharacter(charID) try: @@ -263,7 +263,7 @@ class Character(object): def changeLevel(self, charID, skillID, level): char = eos.db.getCharacter(charID) skill = char.getSkill(skillID) - if isinstance(level, basestring): + if isinstance(level, basestring) or level > 5 or level < 0: skill.learned = False skill.level = None else: