Jump to content
Korean Random
OlliN

Script issue, help needed

Recommended Posts

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

Share this post


Link to post

Short link
Share on other sites

import from gui.shared.utils.gui_items as gui_items

...

gui_items.formatPrice = newformatPrice

Share this post


Link to post

Short link
Share on other sites

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 by OlliN

Share this post


Link to post

Short link
Share on other sites

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

  • Upvote 1

Share this post


Link to post

Short link
Share on other sites

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.

Share this post


Link to post

Short link
Share on other sites

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?

Share this post


Link to post

Short link
Share on other sites

Correct.

 

EDIT: corresponding pyc is listed in the python.log

Edited by OlliN

Share this post


Link to post

Short link
Share on other sites

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 formatPrice
print formatPrice([1, 2, 3])

 

output: 1 und 2

Edited by Helkar

Share this post


Link to post

Short link
Share on other sites

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 by OlliN

Share this post


Link to post

Short link
Share on other sites

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 by Helkar
  • Upvote 1

Share this post


Link to post

Short link
Share on other sites

Too bad. I'll stick with editing the vanilla file.

 

Thx a lot for your time and support.

Share this post


Link to post

Short link
Share on other sites

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)


Share this post


Link to post

Short link
Share on other sites

 

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 by Helkar

Share this post


Link to post

Short link
Share on other sites

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

 

Share this post


Link to post

Short link
Share on other sites
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 by Helkar

Share this post


Link to post

Short link
Share on other sites

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 by OlliN

Share this post


Link to post

Short link
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...