diff --git a/gui/characterEditor.py b/gui/characterEditor.py index 76e0b296a..af8453710 100644 --- a/gui/characterEditor.py +++ b/gui/characterEditor.py @@ -30,7 +30,7 @@ from gui.bitmap_loader import BitmapLoader from gui.contextMenu import ContextMenu import gui.globalEvents as GE from gui.builtinViews.implantEditor import BaseImplantEditorView -from gui.builtinViews.entityEditor import EntityEditor, BaseValidator +from gui.builtinViews.entityEditor import EntityEditor, BaseValidator, TextEntryValidatedDialog from service.fit import Fit from service.character import Character from service.network import AuthenticationError, TimeoutError @@ -65,14 +65,14 @@ class CharacterTextValidor(BaseValidator): return CharacterTextValidor() def Validate(self, win): - entityEditor = win.parent textCtrl = self.GetWindow() text = textCtrl.GetValue().strip() + sChar = Character.getInstance() try: if len(text) == 0: raise ValueError("You must supply a name for the Character!") - elif text in [x.name for x in entityEditor.choices]: + elif text in [x.name for x in sChar.getCharacterList()]: raise ValueError("Character name already in use, please choose another.") return True @@ -242,8 +242,8 @@ class CharacterEditor(wx.Frame): def saveCharAs(self, event): char = self.entityEditor.getActiveEntity() - dlg = SaveCharacterAs(self, char.ID) - dlg.ShowModal() + self.SaveCharacterAs(self, char.ID) + wx.PostEvent(self, GE.CharListUpdated()) def revertChar(self, event): sChr = Character.getInstance() @@ -285,6 +285,22 @@ class CharacterEditor(wx.Frame): wx.Frame.Destroy(self) + @staticmethod + def SaveCharacterAs(parent, charID): + sChar = Character.getInstance() + name = sChar.getCharName(charID) + + dlg = TextEntryValidatedDialog(parent, CharacterTextValidor, + "Enter a name for your new Character:", + "Save Character As...") + dlg.SetValue("{} Copy".format(name)) + dlg.txtctrl.SetInsertionPointEnd() + dlg.CenterOnParent() + + if dlg.ShowModal() == wx.ID_OK: + sChar = Character.getInstance() + return sChar.saveCharacterAs(charID, dlg.txtctrl.GetValue().strip()) + class SkillTreeView(wx.Panel): def __init__(self, parent): @@ -881,36 +897,6 @@ class APIView(wx.Panel): self.stStatus.SetLabel("Unable to retrieve {}\'s skills. Error message:\n{}".format(charName, exc_obj)) -class SaveCharacterAs(wx.Dialog): - def __init__(self, parent, charID): - wx.Dialog.__init__(self, parent, title="Save Character As...", size=wx.Size(300, 60)) - self.charID = charID - self.parent = parent - sChar = Character.getInstance() - name = sChar.getCharName(charID) - bSizer1 = wx.BoxSizer(wx.HORIZONTAL) - - self.input = wx.TextCtrl(self, wx.ID_ANY, name, style=wx.TE_PROCESS_ENTER) - - bSizer1.Add(self.input, 1, wx.ALL, 5) - self.input.Bind(wx.EVT_TEXT_ENTER, self.change) - self.button = wx.Button(self, wx.ID_OK, "Save") - bSizer1.Add(self.button, 0, wx.ALL, 5) - - self.SetSizer(bSizer1) - self.Layout() - self.Centre(wx.BOTH) - self.button.Bind(wx.EVT_BUTTON, self.change) - - def change(self, event): - sChar = Character.getInstance() - sChar.saveCharacterAs(self.charID, self.input.GetLineText(0)) - wx.PostEvent(self.parent, GE.CharListUpdated()) - - event.Skip() - self.Close() - - class SecStatusDialog(wx.Dialog): def __init__(self, parent, sec): diff --git a/gui/mainFrame.py b/gui/mainFrame.py index 8fbb2e78a..5d2e568e4 100644 --- a/gui/mainFrame.py +++ b/gui/mainFrame.py @@ -49,7 +49,7 @@ from gui.multiSwitch import MultiSwitch from gui.statsPane import StatsPane from gui.shipBrowser import ShipBrowser from gui.builtinShipBrowser.events import FitSelected, ImportSelected, Stage3Selected -from gui.characterEditor import CharacterEditor, SaveCharacterAs +from gui.characterEditor import CharacterEditor from gui.characterSelection import CharacterSelection from gui.patternEditor import DmgPatternEditorDlg from gui.resistsEditor import ResistsEditorDlg @@ -692,8 +692,8 @@ class MainFrame(wx.Frame): def saveCharAs(self, event): charID = self.charSelection.getActiveCharacter() - dlg = SaveCharacterAs(self, charID) - dlg.ShowModal() + CharacterEditor.SaveCharacterAs(self, charID) + wx.PostEvent(self, GE.CharListUpdated()) def revertChar(self, event): sChr = Character.getInstance() diff --git a/service/character.py b/service/character.py index 5e712f3d8..958d99f4b 100644 --- a/service/character.py +++ b/service/character.py @@ -253,6 +253,7 @@ class Character(object): # revert old char char.revertLevels() + return newChar.ID @staticmethod def revertCharacter(charID):