Add support for toggling implants on and off
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
__all__ = ["moduleState", "moduleNameOrSlot", "attributeDisplay", "maxRange",
|
||||
"name", "droneDps", "droneNameAmount", "droneCheckbox", "moduleAmmo",
|
||||
"capacitorUse"]
|
||||
"capacitorUse", "implantCheckbox"]
|
||||
|
||||
47
gui/builtinViewColumns/implantCheckbox.py
Normal file
47
gui/builtinViewColumns/implantCheckbox.py
Normal file
@@ -0,0 +1,47 @@
|
||||
#===============================================================================
|
||||
# Copyright (C) 2010 Diego Duclos
|
||||
#
|
||||
# This file is part of pyfa.
|
||||
#
|
||||
# pyfa is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# pyfa is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with pyfa. If not, see <http://www.gnu.org/licenses/>.
|
||||
#===============================================================================
|
||||
|
||||
from gui import builtinViewColumns
|
||||
from gui.viewColumn import ViewColumn
|
||||
import gui.mainFrame
|
||||
import wx
|
||||
|
||||
class ImplantCheckbox(ViewColumn):
|
||||
name = "Implant Checkbox"
|
||||
def __init__(self, fittingView, params):
|
||||
ViewColumn.__init__(self, fittingView)
|
||||
self.resizable = False
|
||||
self.size = 24
|
||||
for name, state in (("checked", wx.CONTROL_CHECKED), ("unchecked", 0)):
|
||||
bitmap = wx.EmptyBitmap(16, 16)
|
||||
dc = wx.MemoryDC()
|
||||
dc.SelectObject(bitmap)
|
||||
dc.SetBackground(wx.TheBrushList.FindOrCreateBrush(fittingView.GetBackgroundColour(), wx.SOLID))
|
||||
dc.Clear()
|
||||
wx.RendererNative.Get().DrawCheckBox(fittingView, dc, wx.Rect(0, 0, 16, 16), state)
|
||||
dc.Destroy()
|
||||
setattr(self, "%sId" % name, fittingView.imageList.Add(bitmap))
|
||||
|
||||
def getText(self, mod):
|
||||
return ""
|
||||
|
||||
def getImageId(self, implant):
|
||||
return self.checkedId if implant.active else self.uncheckedId
|
||||
|
||||
ImplantCheckbox.register()
|
||||
@@ -22,9 +22,11 @@ import service
|
||||
import gui.display as d
|
||||
import gui.fittingView as fv
|
||||
import gui.marketBrowser as mb
|
||||
from gui.builtinViewColumns.implantCheckbox import ImplantCheckbox
|
||||
|
||||
class ImplantView(d.Display):
|
||||
DEFAULT_COLS = ["Name",
|
||||
DEFAULT_COLS = ["Implant Checkbox",
|
||||
"Name",
|
||||
"attr:implantness"]
|
||||
|
||||
def __init__(self, parent):
|
||||
@@ -33,6 +35,7 @@ class ImplantView(d.Display):
|
||||
self.mainFrame.Bind(mb.ITEM_SELECTED, self.addItem)
|
||||
self.Bind(wx.EVT_LEFT_DCLICK, self.removeItem)
|
||||
self.Bind(wx.EVT_KEY_UP, self.kbEvent)
|
||||
self.Bind(wx.EVT_LEFT_DOWN, self.click)
|
||||
|
||||
def kbEvent(self,event):
|
||||
keycode = event.GetKeyCode()
|
||||
@@ -44,6 +47,7 @@ class ImplantView(d.Display):
|
||||
cFit.removeImplant(fitID, self.GetItemData(row))
|
||||
row = self.GetNextSelected(row)
|
||||
wx.PostEvent(self.mainFrame, fv.FitChanged(fitID=fitID))
|
||||
|
||||
def fitChanged(self, event):
|
||||
cFit = service.Fit.getInstance()
|
||||
fit = cFit.getFit(event.fitID)
|
||||
@@ -68,4 +72,14 @@ class ImplantView(d.Display):
|
||||
fitID = self.mainFrame.getActiveFit()
|
||||
cFit = service.Fit.getInstance()
|
||||
cFit.removeImplant(fitID, self.GetItemData(row))
|
||||
wx.PostEvent(self.mainFrame, fv.FitChanged(fitID=fitID))
|
||||
wx.PostEvent(self.mainFrame, fv.FitChanged(fitID=fitID))
|
||||
|
||||
def click(self, event):
|
||||
row, _ = self.HitTest(event.Position)
|
||||
if row != -1:
|
||||
col = self.getColumn(event.Position)
|
||||
if col == self.getColIndex(ImplantCheckbox):
|
||||
fitID = self.mainFrame.getActiveFit()
|
||||
cFit = service.Fit.getInstance()
|
||||
cFit.toggleImplant(fitID, row)
|
||||
wx.PostEvent(self.mainFrame, fv.FitChanged(fitID=fitID))
|
||||
|
||||
@@ -234,6 +234,16 @@ class Fit(object):
|
||||
fit.calculateModifiedAttributes()
|
||||
return True
|
||||
|
||||
def toggleImplant(self, fitID, i):
|
||||
fit = eos.db.getFit(fitID)
|
||||
implant = fit.implants[i]
|
||||
implant.active = not implant.active
|
||||
|
||||
eos.db.commit()
|
||||
fit.clear()
|
||||
fit.calculateModifiedAttributes()
|
||||
return True
|
||||
|
||||
def changeChar(self, fitID, charID):
|
||||
if fitID is None or charID is None:
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user