diff --git a/install_vr4life.py b/install_vr4life.py index 1f3e7bd..287323f 100644 --- a/install_vr4life.py +++ b/install_vr4life.py @@ -1,20 +1,13 @@ import os from pymxs import runtime as rt -def carregar_menu_mnx(): - print("\n" + "="*50) - print("AGENDANDO CARREGAMENTO - VR4LIFE (MODO SEGURO)") - print("="*50) - +def install_vr4life_menu_official(): try: - # 1. Definir caminhos - pasta_macros = rt.getDir(rt.name("userMacros")) - pasta_enu = os.path.dirname(pasta_macros) - caminho_mnx = os.path.join(pasta_enu, "en-US", "UI", "vr4life.mnx").replace("\\", "/") + # 1. PEGAR CAMINHOS plugin_dir = os.path.dirname(os.path.realpath(__file__)).replace("\\", "/") run_script = f"{plugin_dir}/run_vr4life.py" - # 2. Registrar MacroScript + # 2. REGISTRAR MACROS (O padrão que o Babylon usa) macro_cmd = ( 'macroScript VR4Life_Launcher\n' 'category:"Immerse Games"\n' @@ -25,34 +18,42 @@ def carregar_menu_mnx(): ) rt.execute(macro_cmd) - # 3. TIMER COM EXECUÇÃO TARDIA (Late Bound) - # Usamos execute dentro do timer para o compilador não travar no 'menuMan' agora - timer_cmd = f""" + # 3. CONSTRUÇÃO DO MENU (Lógica idêntica ao CreateBabylonMenus.ms) + # Usamos um bloco MaxScript puro para garantir acesso às interfaces core + setup_script = """ ( - global _vr4life_timer = dotNetObject "System.Windows.Forms.Timer" - _vr4life_timer.interval = 3000 -- 3 segundos para garantir + -- 1. Acessar o Menu Manager + local menuMgr = menuMan + local mainMenuBar = menuMgr.getMainMenuBar() + + -- 2. Limpar se já existir (evita duplicados) + local existingMenu = menuMgr.findMenu "VR4Life" + if existingMenu != undefined do menuMgr.unRegisterMenu existingMenu + + -- 3. Criar o novo menu + local newMenu = menuMgr.createMenu "VR4Life" + + -- 4. Criar o item da Action (vinculado à categoria Immerse Games) + local actionItem = menuMgr.createActionItem "VR4Life_Launcher" "Immerse Games" + newMenu.addItem actionItem -1 + + -- 5. Criar o SubMenu na Barra Principal + local subMenuItem = menuMgr.createSubMenuItem "VR4Life" newMenu - dotNet.addEventHandler _vr4life_timer "Tick" (fn onTick s e = ( - -- Só tentamos acessar o menuMan aqui dentro, após o tempo passar - if (execute "menuMan") != undefined then ( - execute "menuMan.loadMenuFile \\"{caminho_mnx}\\"" - execute "menuMan.updateMenuBar()" - format ">> VR4Life: Menu carregado com sucesso apos espera.\\n" - s.stop() - s.dispose() - ) else ( - format ">> VR4Life: Interface ainda carregando...\\n" - ) - )) + -- 6. Inserir antes do Help (ou no final) + mainMenuBar.addItem subMenuItem (mainMenuBar.numItems()) - _vr4life_timer.start() - format "[*] Aguardando 3 segundos para injetar o menu...\\n" + -- 7. Forçar atualização visual + menuMgr.updateMenuBar() + format ">> VR4Life: Menu instalado seguindo padrao BabylonJS.\\n" ) """ - rt.execute(timer_cmd) + rt.execute(setup_script) + return True except Exception as e: - print(f"\n[EXCEPTION] Falha no agendamento:\n{str(e)}") + print(f"Erro na instalacao: {str(e)}") + return False if __name__ == "__main__": - carregar_menu_mnx() \ No newline at end of file + install_vr4life_menu_official() \ No newline at end of file