OlliN 13 Posted June 5, 2015 I'm trying to remove the build it string of cname/gname from gui\shared\utils\gui_items.pyc Original code: def formatPrice(price, reverse = False): outPrice = [] credits, gold = price[:2] if credits != 0 or gold == 0: cname = makeString('#menu:price/credits') + ': ' cformatted = BigWorld.wg_getIntegralFormat(credits) outPrice.extend([cformatted, ' ', cname] if reverse else [cname, ' ', cformatted]) if gold != 0: outPrice.append(', ') if gold != 0: gname = makeString('#menu:price/gold') + ': ' gformatted = BigWorld.wg_getGoldFormat(gold) outPrice.extend([gformatted, ' ', gname] if reverse else [gname, ' ', gformatted]) return ''.join(outPrice) Is it enough to import cname/gname or do I have to replace the whole function? Both doesn't seem to work. What could be wrong? from gui.shared.utils.gui_items import formatPrice cname = '' gname = '' from gui.shared.utils.gui_items import formatPrice def newformatPrice(price, reverse = False): outPrice = [] credits, gold = price[:2] if credits != 0 or gold == 0: cname = '' cformatted = BigWorld.wg_getIntegralFormat(credits) outPrice.extend([cformatted, ' ', cname] if reverse else [cname, ' ', cformatted]) if gold != 0: outPrice.append(' und ') if gold != 0: gname = '' gformatted = BigWorld.wg_getGoldFormat(gold) outPrice.extend([gformatted, ' ', gname] if reverse else [gname, ' ', gformatted]) print gname return ''.join(outPrice) formatPrice = newformatPrice Quote Share this post Link to post Short link Share on other sites
Helkar 385 #276606 Posted June 5, 2015 import from gui.shared.utils.gui_items as gui_items ... gui_items.formatPrice = newformatPrice Quote Share this post Link to post Short link Share on other sites
OlliN 13 #276615 Posted June 5, 2015 (edited) import from gui.shared.utils.gui_items as gui_items invalid syntax Should be from gui.shared.utils import gui_items as gui_items right? Edited June 5, 2015 by OlliN Quote Share this post Link to post Short link Share on other sites
Helkar 385 #276617 Posted June 5, 2015 invalid syntax Should be from gui.shared.utils import gui_items as gui_items right? sorry remove "from" from what i wrote: import gui.shared.utils.gui_items as gui_items ... gui_items.formatPrice = newformatPrice 1 Quote Share this post Link to post Short link Share on other sites
OlliN 13 #276622 Posted June 5, 2015 Hm, the function isn't executed. It's still showing the default cname string. If I make the changes to the vanilla file it's working. Quote Share this post Link to post Short link Share on other sites
Helkar 385 #276627 Posted June 5, 2015 Hm, the function isn't executed. It's still showing the default cname string. If I make the changes to the vanilla file it's working. if you add print 'foo' before return it does not print? Quote Share this post Link to post Short link Share on other sites
OlliN 13 #276629 Posted June 5, 2015 (edited) Correct. EDIT: corresponding pyc is listed in the python.log Edited June 5, 2015 by OlliN Quote Share this post Link to post Short link Share on other sites
Helkar 385 #276630 Posted June 5, 2015 maybe you have error in some other place in script? could you attach the whole file? Quote Share this post Link to post Short link Share on other sites
OlliN 13 #276633 Posted June 5, 2015 (edited) Sure. ColonRemover.zip Edited June 5, 2015 by OlliN Quote Share this post Link to post Short link Share on other sites
Helkar 385 #276635 Posted June 5, 2015 from first look, you should add "import BigWorld" Quote Share this post Link to post Short link Share on other sites
OlliN 13 #276636 Posted June 5, 2015 Had it in before, no change. Quote Share this post Link to post Short link Share on other sites
Helkar 385 #276638 Posted June 5, 2015 (edited) i'm not sure what you expect to achieve, but the code works (with added 'import BigWorld'), it changes the function you wanted to change. you can try: run the function from other script and see the change: from gui.shared.utils.gui_items import formatPriceprint formatPrice([1, 2, 3]) output: 1 und 2 Edited June 5, 2015 by Helkar Quote Share this post Link to post Short link Share on other sites
OlliN 13 #276644 Posted June 5, 2015 (edited) The vanilla function adds "credits: " to the money string of system messages, but I don't want it and it's still there with the function above. "Shells %(name)s successfully purchased (%(count)s item(s)). Spent %(money)s." will become "Shells M53 successfully purchased (1 item(s)). Spent credits: 100." I hope, I do not have to replace every occurrences of formatPrice in other functions? Edited June 5, 2015 by OlliN Quote Share this post Link to post Short link Share on other sites
Helkar 385 #276730 Posted June 5, 2015 (edited) i can confirm that overloading this function has no effect on results (though the function IS overloaded as you wanted). i could not manage to get it work in the way you wanted, only can suggest workaround: overload such methods: from gui.shared.gui_items.processors.vehicle import VehicleLayoutProcessor VehicleLayoutProcessor._successHandler(...) need to manually edit the result they return and change the strings the result is namedtuple of 4 elements, can get them this way: arg1, arg2, arg3, arg4 = result edit as needed and return as namedtuple. Edited June 5, 2015 by Helkar 1 Quote Share this post Link to post Short link Share on other sites
OlliN 13 #276762 Posted June 6, 2015 Too bad. I'll stick with editing the vanilla file. Thx a lot for your time and support. Quote Share this post Link to post Short link Share on other sites
OlliN 13 #278944 Posted June 20, 2015 Ok, another issue. I want to remove the flag in the barracks of XVM's tankman info. The True/False switch for XVM_Installed is working, but xvm_hangar_python_BarracksMeta_as_setTankmenS isn't executed. Looks like I'm missing something. import BigWorld try: import xvm_main XVM_Installed = True except: XVM_Installed = False if XVM_Installed: import xvm_hangar.python xvm_hangar.python.BarracksMeta_as_setTankmenS = xvm_hangar_python_BarracksMeta_as_setTankmenS def xvm_hangar_python_BarracksMeta_as_setTankmenS(base, self, tankmenCount, placesCount, tankmenInBarracks, tankmanArr): print 'Test' try: import nations from gui.shared import g_itemsCache imgPath = 'img://../mods/shared_resources/xvm/res/icons/barracks' for tankman in tankmanArr: if 'role' not in tankman: continue tankman['rank'] = tankman['role'] tankman_full_info = g_itemsCache.items.getTankman(tankman['tankmanID']) skills_str = '' for skill in tankman_full_info.skills: skills_str += "<img src='%s/skills/%s' vspace='-3'>" % (imgPath, skill.icon) if len(tankman_full_info.skills): skills_str += '%s%%' % tankman_full_info.descriptor.lastSkillLevel if tankman_full_info.hasNewSkill: skills_str += "<img src='%s/skills/new_skill.png' vspace='-3'>x%s" % (imgPath, tankman_full_info.newSkillCount[0]) if not skills_str: skills_str = l10n('noSkills') tankman['role'] += ' ' + skills_str except Exception as ex: err(traceback.format_exc()) return base(self, tankmenCount, placesCount, tankmenInBarracks, tankmanArr) Quote Share this post Link to post Short link Share on other sites
Helkar 385 #278948 Posted June 20, 2015 (edited) Ok, another issue. I want to remove the flag in the barracks of XVM's tankman info. The True/False switch for XVM_Installed is working, but xvm_hangar_python_BarracksMeta_as_setTankmenS isn't executed. Looks like I'm missing something. import BigWorld try: import xvm_main XVM_Installed = True except: XVM_Installed = False if XVM_Installed: import xvm_hangar.python xvm_hangar.python.BarracksMeta_as_setTankmenS = xvm_hangar_python_BarracksMeta_as_setTankmenS def xvm_hangar_python_BarracksMeta_as_setTankmenS(base, self, tankmenCount, placesCount, tankmenInBarracks, tankmanArr): print 'Test' try: import nations from gui.shared import g_itemsCache imgPath = 'img://../mods/shared_resources/xvm/res/icons/barracks' for tankman in tankmanArr: if 'role' not in tankman: continue tankman['rank'] = tankman['role'] tankman_full_info = g_itemsCache.items.getTankman(tankman['tankmanID']) skills_str = '' for skill in tankman_full_info.skills: skills_str += "<img src='%s/skills/%s' vspace='-3'>" % (imgPath, skill.icon) if len(tankman_full_info.skills): skills_str += '%s%%' % tankman_full_info.descriptor.lastSkillLevel if tankman_full_info.hasNewSkill: skills_str += "<img src='%s/skills/new_skill.png' vspace='-3'>x%s" % (imgPath, tankman_full_info.newSkillCount[0]) if not skills_str: skills_str = l10n('noSkills') tankman['role'] += ' ' + skills_str except Exception as ex: err(traceback.format_exc()) return base(self, tankmenCount, placesCount, tankmenInBarracks, tankmanArr) you need to overload the original function, not the XVM's overload. Edited June 20, 2015 by Helkar Quote Share this post Link to post Short link Share on other sites
OlliN 13 #278962 Posted June 21, 2015 But then XVM will overload the original function again and the output remains at it is. Or not? Below example is from SpawnPoint mod and is working fine. try: import xvm_battleloading.python import xvm_main.python.config as xvmcfg def xvm_battleloading_python_BattleLoading_as_setTipTitleS(base, self, title): stateInfo = xvmcfg.get('__stateInfo') if 'error' in stateInfo: title = '<font color="#FF4040">{}</font>'.format(title) elif 'warning' in stateInfo: title = '<font color="#FFD040">{}</font>'.format(title) title = '<p align="left"><font size="16">{}</font></p>'.format(title) return base(self, title) xvm_battleloading.python.BattleLoading_as_setTipTitleS = xvm_battleloading_python_BattleLoading_as_setTipTitleS except: pass Quote Share this post Link to post Short link Share on other sites
Helkar 385 #278989 Posted June 21, 2015 (edited) But then XVM will overload the original function again and the output remains at it is. Or not? you are right, XVM runs before other mods, but the overloads are with delay, and occur after other overloads. anyway, in your script there is an error: you need to make the overload after declaration of function: def foo(): pass boo = foo not: boo = foo def foo(): pass Edited June 21, 2015 by Helkar Quote Share this post Link to post Short link Share on other sites
OlliN 13 #279017 Posted June 21, 2015 (edited) Ok, script adapted, but still no luck. XVMInstalled is true and working print commands are T1 & T2. T3, T4 & T5 don't work. Looks like overloading of this function has no effect either. import BigWorld try: import xvm_hangar.python print 'T1' XVM_Installed = True except: XVM_Installed = False def xvm_hangar_python_BarracksMeta_as_setTankmenS(base, self, tankmenCount, placesCount, tankmenInBarracks, tankmanArr): print 'T3' try: print 'T4' import nations from gui.shared import g_itemsCache imgPath = 'img://../mods/shared_resources/xvm/res/icons/barracks' for tankman in tankmanArr: if 'role' not in tankman: continue tankman['rank'] = tankman['role'] tankman_full_info = g_itemsCache.items.getTankman(tankman['tankmanID']) skills_str = '' for skill in tankman_full_info.skills: skills_str += "<img src='%s/skills/%s' vspace='-3'>" % (imgPath, skill.icon) if len(tankman_full_info.skills): skills_str += '%s%%' % tankman_full_info.descriptor.lastSkillLevel if tankman_full_info.hasNewSkill: skills_str += "<img src='%s/skills/new_skill.png' vspace='-3'>x%s" % (imgPath, tankman_full_info.newSkillCount[0]) if not skills_str: skills_str = l10n('noSkills') tankman['role'] += ' ' + skills_str except Exception as ex: print 'T5' err(traceback.format_exc()) return base(self, tankmenCount, placesCount, tankmenInBarracks, tankmanArr) if XVM_Installed: print 'T2' xvm_hangar.python.BarracksMeta_as_setTankmenS = xvm_hangar_python_BarracksMeta_as_setTankmenS Edited June 21, 2015 by OlliN Quote Share this post Link to post Short link Share on other sites