can't interact with ui

#1
Whenever i try to run my ui code, my button never seems to respond to when i click on it. I've tried looking for different solutions online but cannot find a single thing.
Here is the code for mu ui.

Code: Select all

void MainMenuUI::LoadUI() { CMenuUIListener menuLis; auto pMenuUI = gEnv->pFlashUI->GetUIElement("TutorialButton");//get the menu gfx file to load in. std::shared_ptr<IFlashPlayer> flashplayer = pMenuUI->GetFlashPlayer(); if (pMenuUI) { gEnv->pHardwareMouse->IncrementCounter(); gEnv->pHardwareMouse->IncrementCounter(); pMenuUI->AddEventListener(&menuLis, "Listener"); pMenuUI->SetVisible(true); } return; }

Code: Select all

void CMenuUIListener::OnUIEvent(IUIElement* pSender, const SUIEventDesc& event, const SUIArguments& args) { CryLogAlways(pSender->GetName()); if (string{ event.sDisplayName } == string{ "OnClick" }) { CryLogAlways("button was pressed"); } }
Here is what it looks like in my code
Image

Here is what it shoudl look like when my mouse hovers over it
Image

Here is a link to my xml file
https://drive.google.com/file/d/1VusVnJ ... sp=sharing

Re: can't interact with ui

#2
Hi, Detrixukaon58

1)
Open your file TutorialButton.xml
replace this line

Code: Select all

<UIElements name="TutorialButton">
to

Code: Select all

<UIElements name="TutorialButtons">
Because possible name collisions!

2)
replace this line

Code: Select all

<UIElement name="TutorialButton" render_lockless="1">
to

Code: Select all

<UIElement name="TutorialButton" render_lockless="1" mouseevents="1" cursor="1">
Check fscommand="btnPressed" in ButtonInjection.swf/ButtonInjection.gfx and file exist.

3)
Hope you call this method on ESYSTEM_EVENT_LEVEL_LOAD_END (if use CE5.3+ and GamePlugin)

Code: Select all

void MainMenuUI::LoadUI() { if (gEnv->pFlashUI) { auto pUIElement = gEnv->pFlashUI->GetUIElement("TutorialButton"); if (pUIElement) { CMenuUIListener menuLis; pUIElement->AddEventListener(&menuLis, "Listener"); } } }

Code: Select all

void CMenuUIListener::OnUIEvent(IUIElement* pSender, const SUIEventDesc& event, const SUIArguments& args) { CryLog("event.sDisplayName: %s", event.sDisplayName); CryStringLocal eventName = event.sDisplayName; if (eventName == "OnClick") { CryLog("OnClick detected!"); } }

Help with C/C++ or creating lessons/tutorials.
Discord: Andrew2015#9014
e-mail: mrbindraw@gmail.com
My GitHub

Re: can't interact with ui

#3
Hi, Detrixukaon58

1)
Open your file TutorialButton.xml
replace this line

Code: Select all

<UIElements name="TutorialButton">
to

Code: Select all

<UIElements name="TutorialButtons">
Because possible name collisions!

2)
replace this line

Code: Select all

<UIElement name="TutorialButton" render_lockless="1">
to

Code: Select all

<UIElement name="TutorialButton" render_lockless="1" mouseevents="1" cursor="1">
Check fscommand="btnPressed" in ButtonInjection.swf/ButtonInjection.gfx and file exist.

3)
Hope you call this method on ESYSTEM_EVENT_LEVEL_LOAD_END (if use CE5.3+ and GamePlugin)

Code: Select all

void MainMenuUI::LoadUI() { if (gEnv->pFlashUI) { auto pUIElement = gEnv->pFlashUI->GetUIElement("TutorialButton"); if (pUIElement) { CMenuUIListener menuLis; pUIElement->AddEventListener(&menuLis, "Listener"); } } }

Code: Select all

void CMenuUIListener::OnUIEvent(IUIElement* pSender, const SUIEventDesc& event, const SUIArguments& args) { CryLog("event.sDisplayName: %s", event.sDisplayName); CryStringLocal eventName = event.sDisplayName; if (eventName == "OnClick") { CryLog("OnClick detected!"); } }
hey andrei2015,

the fixes you suggested got the ui to work in the way i would like, but there are times when the ui will load and then instantly disappear or if it stays it will cause a crash. Is there anything I could do to prevent this?


EDIT: I have found the reason why it crashes. It was due to the way i was implementing the event listener. It should have been

Code: Select all

CMenuUIListener *menuLis = new CMenuUIListener();
.

I'm still getting the issue where my UI appears and disappears when it is run on ESYSTEM_EVENT_LEVEL_LOAD_END.
It works under ESYSTEM_EVENT_GAME_POST_INIT.

Who is online

Users browsing this forum: No registered users and 0 guests

cron