Merge pull request #110 from blitzmann/issue-101

Add "Change affecting skill" context menu, resolves #101
This commit is contained in:
Anton Vorobyov
2014-06-01 19:06:19 +04:00
13 changed files with 126 additions and 28 deletions

View File

@@ -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"""

View File

@@ -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

View File

@@ -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:

View File

@@ -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"]

View File

@@ -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()

View File

@@ -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()]

BIN
icons/lvl0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 196 B

BIN
icons/lvl1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 212 B

BIN
icons/lvl2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 200 B

BIN
icons/lvl3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 197 B

BIN
icons/lvl4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 199 B

BIN
icons/lvl5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 194 B

View File

@@ -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: