Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
  • Need help?

    Create a topic in the appropriate section
    Don't write everything in the chat!
  • Take a look at the marketplace

    There you can buy
    everything related to game servers
  • Don't want a ban?

    Please read our rules
    Don't disturb the order!
  • Sell or buy?

    Use services of the guarantor
    We will make your deal safe
  • 0
LUGU

Пытаюсь сделать меню по кнопке. layout NULL

Решил сделать тестовое меню, которое открывается на кнопку "K". Однако столкнулся с проблемой. Нажимая на кнопку ничего не происходит. Ниже код и

Пожалуйста, Войдите или Зарегистрируйтесь, чтобы увидеть это: Вложение.





ЛОГИ SCRIPTS:

SCRIPT       : [MyMod] Key K Pressed
SCRIPT       : [MyMod] Opening menu...
SCRIPT       : [MyMod] Initializing MyModMenu via Init()...
SCRIPT       : [MyMod]  MyModMenu initialized successfully.
SCRIPT       : [MyMod]  Menu is now visible!
SCRIPT    (E): NullPointerError
Class:      'MyModMenu'
Function: 'Remove'
Stack trace:
scripts/3_Game/tools\uiscriptedmenu.c:186
MyMod/scripts/5_Mission/mymodmenu.c:31
SCRIPT       : [MyMod]  Menu is now hidden!
SCRIPT       : [MyMod] Key K Pressed
SCRIPT       : [MyMod] Opening menu...
SCRIPT       : [MyMod] Initializing MyModMenu via Init()...
SCRIPT       : [MyMod]  MyModMenu initialized successfully.
SCRIPT       : [MyMod]  Menu is now visible!
SCRIPT    (E): NullPointerError
Class:      'MyModMenu'
Function: 'Remove'
Stack trace:
scripts/3_Game/tools\uiscriptedmenu.c:186
MyMod/scripts/5_Mission/mymodmenu.c:31

Насколько я понимаю в layoutRoot передается NULL, но почему я понять не могу. Путь указан правильно. Надеюсь кто-нибудь поможет потому-что в инете инфы про UI минимум.





 

Share this post


Link to post
Share on other sites

1 answer to this question

Recommended Posts

  • 0

ПРОБЛЕМА БЫЛА РЕШЕНА!
Я немного изменил код, но выдавало ту же ошибку.
Дело в том что MyModMenu не был создан во время использовать Toggle(). Поэтому в missiongameplay нужно сохранять ссылку на MyModMenu - private ref MyModMenu m_Menu;
Коду кому нужно:

///MissionGameplay
modded class MissionGameplay {
    private ref MyModMenu m_Menu; 

    override void OnKeyPress(int key) {
        super.OnKeyPress(key);

        if (key == KeyCode.KC_K) {
            Print("[MyMod] Key K Pressed");

            UIManager uiManager = GetGame().GetUIManager();
            MyModMenu menu = MyModMenu.Cast(uiManager.GetMenu());

            if (!menu) {
                Print("[MyMod] Opening new menu...");
                m_Menu = new MyModMenu(); 
                uiManager.ShowScriptedMenu(m_Menu, NULL);
            } else {
                Print("[MyMod] Toggling existing menu...");
                menu.Toggle();
            }
        }
    }
}

///MyModMenu
class MyModMenu : UIScriptedMenu {
    private ButtonWidget m_CloseButton;

    override Widget Init() {
        Print("[MyMod] Initializing MyModMenu via Init()...");

        layoutRoot = GetGame().GetWorkspace().CreateWidgets("MyMod/gui/layouts/MyModUI.layout");

        if (!layoutRoot) {
            Print("[MyMod]  ERROR: Layout file not found! Check the path: MyMod/gui/layouts/MyModUI.layout");
            return null;
        }

        // Находим кнопку закрытия
        m_CloseButton = ButtonWidget.Cast(layoutRoot.FindAnyWidget("TextWidget1"));
        if (!m_CloseButton) {
            Print("[MyMod]  ERROR: CloseButton (TextWidget1) not found in layout!");
        }

        Print("[MyMod]  MyModMenu initialized successfully.");
        return layoutRoot;
    }

    override void OnShow() {
        super.OnShow();
        Print("[MyMod]  Menu is now visible!");

        // 🔒 Блокируем управление игроком
        GetGame().GetInput().ChangeGameFocus(1);
    }

    override void OnHide() {
        super.OnHide();
        Print("[MyMod]  Menu is now hidden!");

        // 🔓 Возвращаем управление игроку
        GetGame().GetInput().ResetGameFocus();
    }

    void Toggle() {
        if (!layoutRoot) {
            Print("[MyMod]  ERROR: layoutRoot is NULL in Toggle()!");
            return;
        }

        if (!layoutRoot.IsVisible()) {
            Show();
        } else {
            Hide();
        }
    }

    void Show() {
        UIManager uiManager = GetGame().GetUIManager();
        
        if (!uiManager) {
            Print("[MyMod]  ERROR: UIManager not found!");
            return;
        }

        if (!layoutRoot) {
            Print("[MyMod]  ERROR: layoutRoot is NULL in Show()!");
            return;
        }

        if (!layoutRoot.IsVisible()) {
            Print("[MyMod] 📌 Showing MyModMenu...");

            uiManager.HideDialog();
            uiManager.CloseAll();
            uiManager.ShowScriptedMenu(this, NULL);
        } else {
            Print("[MyMod]  Menu is already visible.");
        }
    }

    void Hide() {
        UIManager uiManager = GetGame().GetUIManager();
        if (uiManager && layoutRoot && layoutRoot.IsVisible()) {
            Print("[MyMod] 📌 Hiding MyModMenu...");
            uiManager.HideDialog();
            uiManager.CloseAll();
            uiManager.HideScriptedMenu(this);
        }
    }

    override bool OnClick(Widget w, int x, int y, int button) {
        if (w == m_CloseButton) {
            Print("[MyMod]  Close button pressed!");
            Hide();
            return true;
        }
        return false;
    }
}

 

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site, you automaticly agree to our Guidelines and Privacy Policy.
We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.