Author Topic: BC accessibility question  (Read 895 times)

Offline erion

  • Posts: 4
  • Cookies: 0
BC accessibility question
« on: June 12, 2011, 05:41:38 AM »
Hello,

I'd like to create a basic modification of BC, where parts of the game text are sent to either MS Sapi or a dedicated screen reader.
BC has excellent keyboard support and feedback from the crew, the crew can be accessed via f1 through f5, menu items via the numpad, etc. However parts of the game, if you do not have vision is just guesswork. A good example of this is the course menu.
Thus what I would like to do is either hook into the menu move up or down events (if they exist), get the title of the menu item and process it.
The same goes for friendly and enemy targetting, names of nav points, etc, as soon as the user switches (via t, i, n, etc)
I looked through the api documentation but I does not seem to be able to find these events, nor to get the text of a current menu item.

Could anyone advice me please?

Erion

Offline Mario

  • Senior Software Developer
  • Administrator
  • Posts: 2187
  • Cookies: 1706
  • Life is life
Re: BC accessibility question
« Reply #1 on: June 12, 2011, 12:33:41 PM »
To be honest API documentation sucks and is not pretty much detailed -- someone in Totally Games was too lazy. There is no exactly native support for what you're asking for (to my knowledge), but in theory it can be achieved. I can try and point you on your way, also currently I don't have BC installation with me so from the top of my head to hook into the menu move up and down or item clicked events it could be something like this (this is untested obviously).

Code: [Select]
def BindEvents():               
    pEngineer = GetBridgeMenu("Engineer")
    pEngineer.AddPythonFuncHandlerForInstance(App.ET_ST_BUTTON_CLICKED, __name__ + ".buttonclicked")
    pEngineer.AddPythonFuncHandlerForInstance(App.ET_KEYBOARD, __name__ + ".menumove")

def GetBridgeMenu(menuName):
    pTactCtrlWindow = App.TacticalControlWindow_GetTacticalControlWindow()
    pDatabase = App.g_kLocalizationManager.Load("data/TGL/Bridge Menus.tgl")
    if(pDatabase is None):
        return
    return pTactCtrlWindow.FindMenu(pDatabase.GetString(menuName))   

def buttonclicked(pObject, pEvent):
    print "clicked"

def menumove(pObj, pEvent):
    if pEvent != None:
        pChar = pEvent.GetUnicode()
        # Move up and down through menus in theory
        if pChar == App.g_kKeyboardBinding.FindKey(App.ET_INPUT_SELECT_OPTION, App.KeyboardBinding.GET_INT_EVENT, 1.0):
            print 'got it'
        if pChar == App.g_kKeyboardBinding.FindKey(App.ET_INPUT_SELECT_OPTION, App.KeyboardBinding.GET_INT_EVENT, -1.0):
            print 'got it'                   
        pObj.CallNextHandler(pEvent)

To get the menu text, for that I shall need the BC and my old libraries which currently aren't with me.
Acta, non verba.
aka USS Sovereign

Offline Defiant

  • Posts: 398
  • Cookies: 1105
    • BC: Kobayashi Maru
Re: BC accessibility question
« Reply #2 on: June 13, 2011, 02:22:50 AM »
If you do know some python, look at http://bckobayashimaru.de/svn/trunk/scripts/Custom/QBautostart/Orbit.py, Function GetButton().

It iterates through the Helm menu until a button with a specific name is found.

Offline erion

  • Posts: 4
  • Cookies: 0
Re: BC accessibility question
« Reply #3 on: June 13, 2011, 05:39:14 AM »
Hello,

Thank you very much, I really appreciate your extra code.
Now the question is, how do I run a script? As far as I know you have to enable custom scripts in 'options', however that might cause a problem when the game is installed for the first time, since VI users will have no speech feedback to do so.
Is there a way to quickly enable a script, either from the console, or by modifying a configuration parameter, registry value, etc? I assume, since the game saves the state of custom scripts, in theory there should be. After that the posted events should fire and there should be no problem.
I'll definitely test this and post if there's anything new.
Once again, thank you very much for your help. This is a way too great game :-)

Erion

Offline Defiant

  • Posts: 398
  • Cookies: 1105
    • BC: Kobayashi Maru
Re: BC accessibility question
« Reply #4 on: June 13, 2011, 08:17:48 AM »
Thats not a problem, e.g. when KM is started the first time it enables all Mutators - or you can just copy the configuration file, for Foundation Mutators it is  scripts/Custom/FoundationConfig.py
I would suggest writing the script first and worrying about the enable part later.

May I ask: What is your programming background?

Offline erion

  • Posts: 4
  • Cookies: 0
Re: BC accessibility question
« Reply #5 on: June 13, 2011, 08:56:31 AM »
Hi,

Well, it is a jack of all trades really. Basically if a language does not handle what I am trying to accomplish I learn a new capable one.
As for Python, I did not program that much in it, but most things are familiar, vars, functions, loops, iteration, classes, etc. I don't think Python knowledge would be an issue.
My main problem is that I have absolutely no knowledge of the BC api, besides what the sdk presents, which is sadly not much.

Erion

Offline Defiant

  • Posts: 398
  • Cookies: 1105
    • BC: Kobayashi Maru
Re: BC accessibility question
« Reply #6 on: June 13, 2011, 11:27:44 AM »
ok good. I would suggest you start with my GetButton() Function because it has all API calls needed to iterate/read a menu. It just needs a small rewrite for your purpose. For the communication with the rest of the world...I think a shared file under scripts/Custom/ is the only option here.

Offline erion

  • Posts: 4
  • Cookies: 0
Re: BC accessibility question
« Reply #7 on: June 13, 2011, 12:02:23 PM »
Hello,

Thanks. So, if my script is in scripts/custom/accessibility.py, the game should be able to run it and detect events automagically, am I right?
Also, is there a way to add 3rd party python packages, for instance PyTTS, or CTypes?
If yes, I could probably mess with sys.path, but I assume there's a more elegant way to specify an import path.

Erion

Offline Defiant

  • Posts: 398
  • Cookies: 1105
    • BC: Kobayashi Maru
Re: BC accessibility question
« Reply #8 on: June 13, 2011, 01:17:43 PM »
Sorry, we only have limited Python 1.5 support and as far as I can tell we can not load additional librarys, so no support for ctypes. Havn't tested TTS but my guess would be no.

To make your script run best thing is to put it under scripts/Custom/Autoload (Foundaion required) or scripts/Custom/QBautostart (QBautostart required).

Offline Mario

  • Senior Software Developer
  • Administrator
  • Posts: 2187
  • Cookies: 1706
  • Life is life
Re: BC accessibility question
« Reply #9 on: June 13, 2011, 01:38:06 PM »
Quote
Thanks. So, if my script is in scripts/custom/accessibility.py, the game should be able to run it and detect events automagically, am I right?

Well not exactly, you need to use Foundation to plugin the script. QBAutostart by Defiant works on the same principle and also requires the Foundation. Of course you could do it without Foundation but for your own purposes I'd recommend the Foundation way.

All you need to do is to place a file in the Autoload folder (scripts\Custom\Autoload)

Code: [Select]
# Add Foundation TriggerDef
class MissionStart(Foundation.TriggerDef):
        def __init__(self, name, eventKey, dict = {}):
                Foundation.TriggerDef.__init__(self, name, eventKey, dict)

        def __call__(self, pObject, pEvent, dict = {}):
                MyFunction() # or just write code here
                if pObject and pEvent:
                        pObject.CallNextHandler(pEvent)

MissionStart('Mission Start', App.ET_MISSION_START, dict = { 'modes': [ mode ] } )

def MyFunction():
    print 'foo'

With the following sample listening to Mission Start event and executing its logic.
Acta, non verba.
aka USS Sovereign