From 45fca2a87dac5a3dd1a4f3dd7d7834e1711aca8a Mon Sep 17 00:00:00 2001 From: blitzmann Date: Sun, 25 May 2014 14:48:40 -0400 Subject: [PATCH 1/5] All things that can affect attribute from current fit/ships is included in modifiedAttributeDict. The previous method was to only add those that change a value. This adds things can can affect it, and then pass a new `used` flag to the dict to show if it's used or not. --- eos/modifiedAttributeDict.py | 16 +++++----------- eos/saveddata/character.py | 4 +++- gui/itemStats.py | 6 ++++-- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/eos/modifiedAttributeDict.py b/eos/modifiedAttributeDict.py index 324d83b69..f067d27ff 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): """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..eaa1fc47c 100755 --- a/eos/saveddata/character.py +++ b/eos/saveddata/character.py @@ -275,7 +275,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/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()] From df046769ffffaede7d2948687d4a8c7f4706cc76 Mon Sep 17 00:00:00 2001 From: blitzmann Date: Tue, 27 May 2014 16:26:14 -0400 Subject: [PATCH 2/5] Add GUI support for changing affected skills --- gui/builtinContextMenus/__init__.py | 2 +- .../changeAffectingSkills.py | 100 ++++++++++++++++++ service/character.py | 12 +-- 3 files changed, 107 insertions(+), 7 deletions(-) create mode 100644 gui/builtinContextMenus/changeAffectingSkills.py 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..b0b9c9b96 --- /dev/null +++ b/gui/builtinContextMenus/changeAffectingSkills.py @@ -0,0 +1,100 @@ +# -*- 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 Affecting Skills" + + 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) + 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) + bitmap = bitmapLoader.getBitmap("level%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) + 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/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: From 1c84e9dc4b6a1b51e0ce21f3f794d5b2d4577dc6 Mon Sep 17 00:00:00 2001 From: blitzmann Date: Tue, 27 May 2014 16:29:22 -0400 Subject: [PATCH 3/5] Added default value for `used` parameter --- eos/modifiedAttributeDict.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eos/modifiedAttributeDict.py b/eos/modifiedAttributeDict.py index f067d27ff..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, used): + 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: From 0d1c7b93beab33bae9a598d1f3f33f88e0f7133b Mon Sep 17 00:00:00 2001 From: blitzmann Date: Wed, 28 May 2014 22:32:23 -0400 Subject: [PATCH 4/5] Add icons to skill context menu --- gui/builtinContextMenus/changeAffectingSkills.py | 7 ++++--- icons/lvl0.png | Bin 0 -> 196 bytes icons/lvl1.png | Bin 0 -> 212 bytes icons/lvl2.png | Bin 0 -> 200 bytes icons/lvl3.png | Bin 0 -> 197 bytes icons/lvl4.png | Bin 0 -> 199 bytes icons/lvl5.png | Bin 0 -> 194 bytes 7 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 icons/lvl0.png create mode 100644 icons/lvl1.png create mode 100644 icons/lvl2.png create mode 100644 icons/lvl3.png create mode 100644 icons/lvl4.png create mode 100644 icons/lvl5.png diff --git a/gui/builtinContextMenus/changeAffectingSkills.py b/gui/builtinContextMenus/changeAffectingSkills.py index b0b9c9b96..b82ce70c1 100644 --- a/gui/builtinContextMenus/changeAffectingSkills.py +++ b/gui/builtinContextMenus/changeAffectingSkills.py @@ -77,9 +77,10 @@ class ChangeAffectingSkills(ContextMenu): skillItem = wx.MenuItem(m, wx.NewId(), skill.item.name) sub = wx.Menu() skillItem.SetSubMenu(sub) - bitmap = bitmapLoader.getBitmap("level%s" % skill.level, "icons") - if bitmap is not None: - skillItem.SetBitmap(bitmap) + 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) diff --git a/icons/lvl0.png b/icons/lvl0.png new file mode 100644 index 0000000000000000000000000000000000000000..7c60aa2e3ddc526a783190a0bd1f8978f1d3b571 GIT binary patch literal 196 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkEa k>Xgg>GPwET+XZWxV^=GGPuOg!4>X*?)78&qol`;+03fJ7HUIzs literal 0 HcmV?d00001 diff --git a/icons/lvl1.png b/icons/lvl1.png new file mode 100644 index 0000000000000000000000000000000000000000..046a88dfa946655483b34fd8dce3801ab1243f94 GIT binary patch literal 212 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE)4%caKYZ?lYt_f1s;*b z3=G`DAk4@xYmNj^kiEpy*OmPqs| CQb(@< literal 0 HcmV?d00001 diff --git a/icons/lvl2.png b/icons/lvl2.png new file mode 100644 index 0000000000000000000000000000000000000000..90c566ea6375ec11970c8abcae08f6e2dd39842e GIT binary patch literal 200 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE)4%caKYZ?lYt_f1s;*b z3=G`DAk4@xYmNj^kiEpy*OmPqs|-VU@nB+Tao);fWU4OnYTH5Sucs5{$!(FCz;g0! pQ^AU(52oCzTe6yUadmT<*pf-|*}7fda)A~wc)I$ztaD0e0sxe$KKK9t literal 0 HcmV?d00001 diff --git a/icons/lvl3.png b/icons/lvl3.png new file mode 100644 index 0000000000000000000000000000000000000000..281f1be9f6da32eebae74f0acbd9c0bfa2d75bfd GIT binary patch literal 197 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE)4%caKYZ?lYt_f1s;*b z3=G`DAk4@xYmNj^kiEpy*OmPqs|%n=lFBZpe#&one$W@Plkqq71JD-J!^5^Yo@?CDb>;9%B2TwRZ?rt mDf_nHs#~(0b#Zlbnc0=UvWBlS+xdW|GkCiCxvXG~72#RDb<|YpRL|6NA%2FSe;s!dzc(B)Hy{eDc;gcHud;o0^lf juar%kC%54p|1C+yMv1*%57a&ajb`w4^>bP0l+XkKVd*^v literal 0 HcmV?d00001 From de9ae5c78cbeaef9549a3a06a701f217549f4fbc Mon Sep 17 00:00:00 2001 From: blitzmann Date: Thu, 29 May 2014 00:31:59 -0400 Subject: [PATCH 5/5] Ensure that we load all skills for a character and some minor tweaks. --- eos/saveddata/character.py | 7 +------ eos/saveddata/fit.py | 5 ++++- gui/builtinContextMenus/changeAffectingSkills.py | 5 +++-- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/eos/saveddata/character.py b/eos/saveddata/character.py index eaa1fc47c..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) diff --git a/eos/saveddata/fit.py b/eos/saveddata/fit.py index 8bb7a4ac1..eef8ea8b3 100755 --- a/eos/saveddata/fit.py +++ b/eos/saveddata/fit.py @@ -1246,8 +1246,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/changeAffectingSkills.py b/gui/builtinContextMenus/changeAffectingSkills.py index b82ce70c1..4d1f5fdd4 100644 --- a/gui/builtinContextMenus/changeAffectingSkills.py +++ b/gui/builtinContextMenus/changeAffectingSkills.py @@ -50,7 +50,7 @@ class ChangeAffectingSkills(ContextMenu): return len(self.skills) > 0 def getText(self, itmContext, selection): - return "Change Affecting Skills" + return "Change %s Skills" % itmContext def activate(self, fullContext, selection, i): pass @@ -63,7 +63,7 @@ class ChangeAffectingSkills(ContextMenu): id = wx.NewId() self.skillIds[id] = (skill, i) - menuItem = wx.MenuItem(rootMenu, id, label) + menuItem = wx.MenuItem(rootMenu, id, label, kind=wx.ITEM_CHECK) rootMenu.Bind(wx.EVT_MENU, self.handleSkillChange, menuItem) return menuItem @@ -85,6 +85,7 @@ class ChangeAffectingSkills(ContextMenu): 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