Some problems with imput system when UI active [Solved]

#1
So I tried to add some UI to my game in C++ recently and everythings works fine except some tiny problems.
When I pause game and click " Resume", it comes back to game imediately and work fine.
But when I pause game again, I need to click "Resume" twice to resume game( and cyrlogalways tells me the first time i click "Resume" it doesn't receive any event);
And when I pause game for the third time, I need to click "Resume" three time to resume game. And every butom needs 3 clicks to receive events from now on.(Well it didn't comes up to four times or more.)
Here are my codes(the name "mainmenu" is in fact an in game menu):
mainmenu.h

Code: Select all

#pragma once
#include <CrySystem/Scaleform/IFlashUI.h>

class CMainmenu
{
public:
CMainmenu() = default;
virtual ~CMainmenu() {}

void Initialize();
void SetVisiable(bool bvisiable);

public:
IUIElement* pMainmenuElement = nullptr;
};
class CMainmenuEventListener : public IUIElementEventListener
{
public:
virtual void OnUIEvent(IUIElement* pSender, const SUIEventDesc& event, const SUIArguments& args);
void Register();

IUIElement* pMainmenuElement = nullptr;

};
mainmenu.cpp

Code: Select all

#include "StdAfx.h"
#include "Mainmenu.h"
#include <CryGame/IGameFramework.h>
#include <IActionMapManager.h>

void CMainmenu::Initialize()
{
pMainmenuElement = gEnv->pFlashUI->GetUIElement("mainmenu");
pMainmenuElement->Init();
SUIArguments Args;
Args.AddArgument("Resume");
Args.AddArgument("Settings");
Args.AddArgument("StartMenu");
Args.AddArgument("Exit");
TUIData res;
pMainmenuElement->CallFunction("setbuttonlable", Args, &res);

}

void CMainmenu::SetVisiable(bool bvisiable)
{
pMainmenuElement->SetVisible(bvisiable);
}


void CMainmenuEventListener::Register()
{
// Registering the listener
if (gEnv->pFlashUI)
{
pMainmenuElement = gEnv->pFlashUI->GetUIElement("mainmenu");
if (pMainmenuElement)
{
pMainmenuElement->AddEventListener(this,"mainmenuEventListener");
}
}

}

void CMainmenuEventListener::OnUIEvent(IUIElement* pSender, const SUIEventDesc& event, const SUIArguments& args)
{
if (pSender == pMainmenuElement)
{
CryLogAlways("received some events from mainmenu");

string eventname = event.sDisplayName; //This is a must for string comparing correctly!

if (eventname == "resumegame")
{
CryLogAlways("resumegame event received");

gEnv->pGameFramework->PauseGame(false, true);
pMainmenuElement->SetVisible(false);
gEnv->pGameFramework->GetIActionMapManager()->EnableActionMap("player", true);
}
else if (eventname == "goto_settings")
{
}
else if (eventname == "goto_startmenu")
{
}
else if (eventname == "exitgame")
{
gEnv->pSystem->Quit();
}
}
}
these two class are instanced in actionlistener and the relative code :
PlayerInputActionListener.h

Code: Select all

#pragma once
#include <IActionMapManager.h>

class CMainmenu;
class CMainmenuEventListener;
class CPlayerInputActionListener final:public IActionListener
{
//...
public:
CMainmenu* pMainmenu = nullptr;
CMainmenuEventListener* pMainmenuEventListener = nullptr;
};
PlayerInputActionListener.cpp

Code: Select all

#include "StdAfx.h"
#include "PlayerInputActionMapListener.h"

//UI interface
#include "Components/UI/Mainmenu.h"

void CPlayerInputActionListener::Init(CPlayerController* PlayerController)
{
pPlayerController = PlayerController;
m_pActionMapManager = gEnv->pGameFramework->GetIActionMapManager(); //get actionMap manager
m_pActionMapManager->InitActionMaps("Libs/Config/defaultprofile.xml");
m_pActionMapManager->EnableActionMap("player", true);
m_pActionMapManager->AddExtraActionListener(this, "player");

//initialize main menu
pMainmenu = new CMainmenu();
pMainmenu->Initialize();
pMainmenuEventListener = new CMainmenuEventListener();
pMainmenuEventListener->Register();
}
//...
void CPlayerInputActionListener::OnAction(const ActionId & actionId, int activationMode, float value)
{
//...
if (actionId == ActionId("gamepause"))
{
if (activationMode == eIS_Pressed)
{
//bPause game
bool bGamePaused = !gEnv->pGameFramework->IsGamePaused();
gEnv->pGameFramework->PauseGame(bGamePaused,true);

m_pActionMapManager->EnableActionMap("player", false);
pMainmenu->SetVisiable(bGamePaused);

}
}
}

Re: Some problems with imput system when UI active [Solved]

#2
I have found a solution.
I write script in actionScript earlier as:

Code: Select all

resumeBtn.onPress(){
fscommand("resumeGame");
}
The problem does not exist any more as I replaced them by:

Code: Select all

function resumeGame(){
fscommand("resumeGame");
}
resumeBtn.addEventListener("click",this,"resumeGame");
It's weird isn't it? I mean every tutorial uses onPress to create an event. Only when I watched the very early tutorials made by autodesk scaleform on youtube about CLK did I realize this. CLK is really convient by the way. :D

Who is online

Users browsing this forum: hodirt and 0 guests