NovaBryan/EVE_Dump
Log | Files | 📦 下载最新源码 (.zip) | Refs | README

eveEdit.py (10751B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\control\eveEdit.py
      2 import utillib
      3 from carbon.common.script.util import commonutils
      4 from carbonui import uiconst
      5 from carbonui.control.edit import EditCore
      6 from carbonui.uicore import uicore
      7 from eve.client.script.ui.util import searchOld, uix
      8 import evetypes
      9 import localization
     10 import log
     11 from eve.client.script.ui.control.eveEdit_Parser import ParserBase
     12 from player_messaging.client.ui_message import prompt_player_fsd_dialog
     13 
     14 class Edit(EditCore):
     15     __guid__ = 'uicontrols.Edit'
     16     default_align = uiconst.TOALL
     17     default_left = 0
     18     default_top = 0
     19     default_width = 0
     20     default_height = 0
     21 
     22     def UpdateUIScaling(self, value, oldValue):
     23         super(Edit, self).UpdateUIScaling(value, oldValue)
     24         if not self.destroyed:
     25             self.DoContentResize()
     26 
     27     def OnDropDataDelegate(self, node, nodes):
     28         EditCore.OnDropDataDelegate(self, node, nodes)
     29         if self.readonly:
     30             return
     31         log.LogException('Nowadays, this old edit field is only be used for read only, but is being used to edit text?')
     32 
     33     def ApplyGameSelection(self, what, data, changeObjs):
     34         if what == 6 and len(changeObjs):
     35             key = {}
     36             if data:
     37                 key['link'] = data['link']
     38                 t = self.DoSearch(key['link'], data['text'])
     39                 if not t:
     40                     return
     41             else:
     42                 format = [{'type': 'checkbox',
     43                   'label': '_hide',
     44                   'text': 'http://',
     45                   'key': 'http://',
     46                   'required': 1,
     47                   'setvalue': 1,
     48                   'group': 'link',
     49                   'onchange': self.OnLinkTypeChange},
     50                  {'type': 'checkbox',
     51                   'label': '_hide',
     52                   'text': localization.GetByLabel('UI/Common/Character'),
     53                   'key': 'char',
     54                   'required': 1,
     55                   'setvalue': 0,
     56                   'group': 'link',
     57                   'onchange': self.OnLinkTypeChange},
     58                  {'type': 'checkbox',
     59                   'label': '_hide',
     60                   'text': localization.GetByLabel('UI/Common/Corporation'),
     61                   'key': 'corp',
     62                   'required': 1,
     63                   'setvalue': 0,
     64                   'group': 'link',
     65                   'onchange': self.OnLinkTypeChange},
     66                  {'type': 'checkbox',
     67                   'label': '_hide',
     68                   'text': localization.GetByLabel('UI/Common/ItemType'),
     69                   'key': 'type',
     70                   'required': 1,
     71                   'setvalue': 0,
     72                   'group': 'link',
     73                   'onchange': self.OnLinkTypeChange},
     74                  {'type': 'checkbox',
     75                   'label': '_hide',
     76                   'text': localization.GetByLabel('UI/Common/SolarSystem'),
     77                   'key': 'solarsystem',
     78                   'required': 1,
     79                   'setvalue': 0,
     80                   'group': 'link',
     81                   'onchange': self.OnLinkTypeChange},
     82                  {'type': 'checkbox',
     83                   'label': '_hide',
     84                   'text': localization.GetByLabel('UI/Common/Station'),
     85                   'key': 'station',
     86                   'required': 1,
     87                   'setvalue': 0,
     88                   'group': 'link',
     89                   'onchange': self.OnLinkTypeChange},
     90                  {'type': 'push'},
     91                  {'type': 'edit',
     92                   'label': localization.GetByLabel('UI/Common/HtmlLink'),
     93                   'text': 'http://',
     94                   'labelwidth': 100,
     95                   'required': 1,
     96                   'key': 'txt'},
     97                  {'type': 'push'}]
     98                 key = self.AskLink(localization.GetByLabel('UI/Common/EnterLink'), format, width=400)
     99             anchor = -1
    100             if key:
    101                 link = key['link']
    102                 if link == None:
    103                     return
    104                 if link in ('char', 'corp', 'alliance', 'solarsystem', 'station', 'type'):
    105                     if not self.typeID:
    106                         t = self.DoSearch(link, key['txt'])
    107                         if not t:
    108                             return
    109                     anchor = 'showinfo:' + str(self.typeID)
    110                     if self.itemID:
    111                         anchor += '//' + str(self.itemID)
    112                 elif link == 'fleet':
    113                     anchor = 'fleet:' + str(self.itemID)
    114                 elif link == 'http://':
    115                     if key['txt'].startswith(key['link']) or key['txt'].startswith('https://'):
    116                         anchor = ''
    117                     else:
    118                         anchor = key['link']
    119                     anchor += key['txt']
    120                 else:
    121                     anchor = key['link'] + key['txt']
    122             return anchor
    123         return -1
    124 
    125     def OnLinkTypeChange(self, chkbox, *args):
    126         if chkbox.GetValue():
    127             self.itemID = self.typeID = 0
    128             self.key = chkbox.data['key']
    129             text = chkbox.GetChild('text')
    130             wnd = chkbox.FindParentByName(localization.GetByLabel('UI/Common/GenerateLink'))
    131             if not wnd:
    132                 return
    133             editParent = wnd.FindChild('editField')
    134             if editParent is not None:
    135                 label = editParent.FindChild('label')
    136                 label.text = text.text
    137                 edit = editParent.FindChild('edit_txt')
    138                 edit.SetValue('')
    139                 self.sr.searchbutt = editParent.FindChild('button')
    140                 if self.key in ('char', 'corp', 'type', 'solarsystem', 'station'):
    141                     if self.sr.searchbutt == None:
    142                         from carbonui.control.button import Button
    143                         self.sr.searchbutt = Button(parent=editParent, label=localization.GetByLabel('UI/Common/SearchForItemType'), func=self.OnSearch, btn_default=0, align=uiconst.TOPRIGHT)
    144                     else:
    145                         self.sr.searchbutt.state = uiconst.UI_NORMAL
    146                     edit.width = 55
    147                 elif self.sr.searchbutt != None:
    148                     self.sr.searchbutt.state = uiconst.UI_HIDDEN
    149                     edit.width = 0
    150 
    151     def OnSearch(self, *args):
    152         wnd = self.sr.searchbutt.FindParentByName(localization.GetByLabel('UI/Common/GenerateLink'))
    153         if not wnd:
    154             return
    155         editParent = wnd.FindChild('editField')
    156         edit = editParent.FindChild('edit_txt')
    157         val = edit.GetValue().strip().lower()
    158         name = self.DoSearch(self.key, val)
    159         if name is not None:
    160             edit.SetValue(name)
    161 
    162     def DoSearch(self, key, val):
    163         self.itemID = None
    164         self.typeID = None
    165         id = None
    166         name = ''
    167         if key == 'type':
    168             if getattr(self, 'markettypes', None) == None:
    169                 from eve.client.script.util.contractutils import GetMarketTypes
    170                 self.markettypes = GetMarketTypes()
    171             itemTypes = []
    172             for t in self.markettypes:
    173                 if t.typeName.lower().find(val.lower()) >= 0:
    174                     itemTypes.append((evetypes.GetName(t.typeID), None, t.typeID))
    175 
    176             if not itemTypes:
    177                 prompt_player_fsd_dialog('NoItemTypesFound')
    178                 return
    179             id = uix.ListWnd(itemTypes, 'item', localization.GetByLabel('UI/Common/SelectItemType'), None, 1)
    180         else:
    181             group = None
    182             hideNPC = 0
    183             if key == 'solarsystem':
    184                 group = const.groupSolarSystem
    185             elif key == 'station':
    186                 group = const.groupStation
    187             elif key == 'char':
    188                 group = const.groupCharacter
    189             elif key == 'corp':
    190                 group = const.groupCorporationOwner
    191             elif key == 'alliance':
    192                 group = const.groupAlliance
    193             id = searchOld.Search(val, group, hideNPC=hideNPC, listType='Generic')
    194         name = ''
    195         if id:
    196             self.itemID = id
    197             self.typeID = 0
    198             if key in ('char', 'corp', 'alliance'):
    199                 o = cfg.eveowners.Get(id)
    200                 self.typeID = o.typeID
    201                 name = o.name
    202             elif key == 'solarsystem':
    203                 l = cfg.evelocations.Get(id)
    204                 self.typeID = l.typeID
    205                 name = l.name
    206             elif key == 'station':
    207                 self.typeID = sm.GetService('ui').GetStationStaticInfo(id).stationTypeID
    208                 l = cfg.evelocations.Get(id)
    209                 name = l.name
    210             elif key == 'type':
    211                 self.typeID = id[2]
    212                 self.itemID = None
    213                 name = id[0]
    214         return name
    215 
    216     def AskLink(self, label = '', lines = [], width = 280):
    217         icon = uiconst.QUESTION
    218         format = [{'type': 'text',
    219           'text': label}] + lines
    220         retval = uix.HybridWnd(format, caption=localization.GetByLabel('UI/Common/GenerateLink'), windowID='askLink', modal=1, buttons=uiconst.OKCANCEL, minW=width, minH=110, icon=icon)
    221         if retval:
    222             return retval
    223         else:
    224             return None
    225 
    226     def AddLink(self, text, link = None):
    227         self.SetSelectionRange(None, None)
    228         text = commonutils.StripTags(text, stripOnly=['localized'])
    229         shiftCursor = len(text)
    230         node, obj, npos = self.GetNodeAndTextObjectFromGlobalCursor()
    231         if obj.letters:
    232             orgString = obj.letters
    233             orgIndex = node.stack.index(obj)
    234             obj.letters = orgString[:npos]
    235             firstSpaceObj = self.GetTextObject(' ')
    236             firstSpaceObj.a = None
    237             node.stack.insert(orgIndex + 1, firstSpaceObj)
    238             newObject = self.GetTextObject(' ')
    239             newObject.a = None
    240             node.stack.insert(orgIndex + 2, newObject)
    241             restObj = obj.Copy()
    242             restObj.letters = orgString[npos:]
    243             if restObj.letters:
    244                 node.stack.insert(orgIndex + 3, restObj)
    245         else:
    246             newObject = obj
    247             newObject.a = None
    248         newObject.letters = text
    249         if link is not None:
    250             anchor = link
    251             attr = utillib.KeyVal()
    252             attr.href = anchor
    253             attr.alt = anchor
    254             newObject.a = attr
    255         endSpaceObj = newObject.Copy()
    256         endSpaceObj.letters = ' '
    257         endSpaceObj.a = None
    258         node.stack.insert(node.stack.index(newObject) + 1, endSpaceObj)
    259         self._OnResize(0)
    260         self.SetCursorPosAtObjectEnd(newObject)
    261         uicore.registry.SetFocus(self)
    262 
    263 
    264 from carbonui.control.edit import EditCoreOverride
    265 EditCoreOverride.__bases__ = (Edit,)