forked from Mirrorlandia_minetest/minetest
Unlock cursor when opening console
This commit is contained in:
parent
effa24737d
commit
3edb7575a1
@ -2175,7 +2175,7 @@ bool Game::initGui()
|
|||||||
|
|
||||||
// Chat backend and console
|
// Chat backend and console
|
||||||
gui_chat_console = new GUIChatConsole(guienv, guienv->getRootGUIElement(),
|
gui_chat_console = new GUIChatConsole(guienv, guienv->getRootGUIElement(),
|
||||||
-1, chat_backend, client);
|
-1, chat_backend, client, &g_menumgr);
|
||||||
if (!gui_chat_console) {
|
if (!gui_chat_console) {
|
||||||
*error_message = "Could not allocate memory for chat console";
|
*error_message = "Could not allocate memory for chat console";
|
||||||
errorstream << *error_message << std::endl;
|
errorstream << *error_message << std::endl;
|
||||||
@ -2809,7 +2809,6 @@ void Game::openConsole(float height, const wchar_t *line)
|
|||||||
gui_chat_console->setCloseOnEnter(true);
|
gui_chat_console->setCloseOnEnter(true);
|
||||||
gui_chat_console->replaceAndAddToHistory(line);
|
gui_chat_console->replaceAndAddToHistory(line);
|
||||||
}
|
}
|
||||||
guienv->setFocus(gui_chat_console);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,12 +46,14 @@ GUIChatConsole::GUIChatConsole(
|
|||||||
gui::IGUIElement* parent,
|
gui::IGUIElement* parent,
|
||||||
s32 id,
|
s32 id,
|
||||||
ChatBackend* backend,
|
ChatBackend* backend,
|
||||||
Client* client
|
Client* client,
|
||||||
|
IMenuManager* menumgr
|
||||||
):
|
):
|
||||||
IGUIElement(gui::EGUIET_ELEMENT, env, parent, id,
|
IGUIElement(gui::EGUIET_ELEMENT, env, parent, id,
|
||||||
core::rect<s32>(0,0,100,100)),
|
core::rect<s32>(0,0,100,100)),
|
||||||
m_chat_backend(backend),
|
m_chat_backend(backend),
|
||||||
m_client(client),
|
m_client(client),
|
||||||
|
m_menumgr(menumgr),
|
||||||
m_screensize(v2u32(0,0)),
|
m_screensize(v2u32(0,0)),
|
||||||
m_animate_time_old(0),
|
m_animate_time_old(0),
|
||||||
m_open(false),
|
m_open(false),
|
||||||
@ -120,6 +122,8 @@ void GUIChatConsole::openConsole(f32 height)
|
|||||||
m_desired_height_fraction = height;
|
m_desired_height_fraction = height;
|
||||||
m_desired_height = height * m_screensize.Y;
|
m_desired_height = height * m_screensize.Y;
|
||||||
reformatConsole();
|
reformatConsole();
|
||||||
|
Environment->setFocus(this);
|
||||||
|
m_menumgr->createdMenu(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GUIChatConsole::isOpen() const
|
bool GUIChatConsole::isOpen() const
|
||||||
@ -135,11 +139,13 @@ bool GUIChatConsole::isOpenInhibited() const
|
|||||||
void GUIChatConsole::closeConsole()
|
void GUIChatConsole::closeConsole()
|
||||||
{
|
{
|
||||||
m_open = false;
|
m_open = false;
|
||||||
|
Environment->removeFocus(this);
|
||||||
|
m_menumgr->deletingMenu(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUIChatConsole::closeConsoleAtOnce()
|
void GUIChatConsole::closeConsoleAtOnce()
|
||||||
{
|
{
|
||||||
m_open = false;
|
closeConsole();
|
||||||
m_height = 0;
|
m_height = 0;
|
||||||
recalculateConsolePosition();
|
recalculateConsolePosition();
|
||||||
}
|
}
|
||||||
@ -399,7 +405,6 @@ bool GUIChatConsole::OnEvent(const SEvent& event)
|
|||||||
if(KeyPress(event.KeyInput) == getKeySetting("keymap_console"))
|
if(KeyPress(event.KeyInput) == getKeySetting("keymap_console"))
|
||||||
{
|
{
|
||||||
closeConsole();
|
closeConsole();
|
||||||
Environment->removeFocus(this);
|
|
||||||
|
|
||||||
// inhibit open so the_game doesn't reopen immediately
|
// inhibit open so the_game doesn't reopen immediately
|
||||||
m_open_inhibited = 50;
|
m_open_inhibited = 50;
|
||||||
@ -409,7 +414,6 @@ bool GUIChatConsole::OnEvent(const SEvent& event)
|
|||||||
else if(event.KeyInput.Key == KEY_ESCAPE)
|
else if(event.KeyInput.Key == KEY_ESCAPE)
|
||||||
{
|
{
|
||||||
closeConsoleAtOnce();
|
closeConsoleAtOnce();
|
||||||
Environment->removeFocus(this);
|
|
||||||
m_close_on_enter = false;
|
m_close_on_enter = false;
|
||||||
// inhibit open so the_game doesn't reopen immediately
|
// inhibit open so the_game doesn't reopen immediately
|
||||||
m_open_inhibited = 1; // so the ESCAPE button doesn't open the "pause menu"
|
m_open_inhibited = 1; // so the ESCAPE button doesn't open the "pause menu"
|
||||||
@ -432,7 +436,6 @@ bool GUIChatConsole::OnEvent(const SEvent& event)
|
|||||||
m_client->typeChatMessage(text);
|
m_client->typeChatMessage(text);
|
||||||
if (m_close_on_enter) {
|
if (m_close_on_enter) {
|
||||||
closeConsoleAtOnce();
|
closeConsoleAtOnce();
|
||||||
Environment->removeFocus(this);
|
|
||||||
m_close_on_enter = false;
|
m_close_on_enter = false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#define GUICHATCONSOLE_HEADER
|
#define GUICHATCONSOLE_HEADER
|
||||||
|
|
||||||
#include "irrlichttypes_extrabloated.h"
|
#include "irrlichttypes_extrabloated.h"
|
||||||
|
#include "modalMenu.h"
|
||||||
#include "chat.h"
|
#include "chat.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
@ -33,7 +34,8 @@ public:
|
|||||||
gui::IGUIElement* parent,
|
gui::IGUIElement* parent,
|
||||||
s32 id,
|
s32 id,
|
||||||
ChatBackend* backend,
|
ChatBackend* backend,
|
||||||
Client* client);
|
Client* client,
|
||||||
|
IMenuManager* menumgr);
|
||||||
virtual ~GUIChatConsole();
|
virtual ~GUIChatConsole();
|
||||||
|
|
||||||
// Open the console (height = desired fraction of screen size)
|
// Open the console (height = desired fraction of screen size)
|
||||||
@ -86,11 +88,9 @@ private:
|
|||||||
void drawPrompt();
|
void drawPrompt();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// pointer to the chat backend
|
|
||||||
ChatBackend* m_chat_backend;
|
ChatBackend* m_chat_backend;
|
||||||
|
|
||||||
// pointer to the client
|
|
||||||
Client* m_client;
|
Client* m_client;
|
||||||
|
IMenuManager* m_menumgr;
|
||||||
|
|
||||||
// current screen size
|
// current screen size
|
||||||
v2u32 m_screensize;
|
v2u32 m_screensize;
|
||||||
|
@ -47,9 +47,9 @@ extern gui::IGUIStaticText *guiroot;
|
|||||||
class MainMenuManager : public IMenuManager
|
class MainMenuManager : public IMenuManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual void createdMenu(GUIModalMenu *menu)
|
virtual void createdMenu(gui::IGUIElement *menu)
|
||||||
{
|
{
|
||||||
for(std::list<GUIModalMenu*>::iterator
|
for(std::list<gui::IGUIElement*>::iterator
|
||||||
i = m_stack.begin();
|
i = m_stack.begin();
|
||||||
i != m_stack.end(); ++i)
|
i != m_stack.end(); ++i)
|
||||||
{
|
{
|
||||||
@ -61,13 +61,13 @@ public:
|
|||||||
m_stack.push_back(menu);
|
m_stack.push_back(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void deletingMenu(GUIModalMenu *menu)
|
virtual void deletingMenu(gui::IGUIElement *menu)
|
||||||
{
|
{
|
||||||
// Remove all entries if there are duplicates
|
// Remove all entries if there are duplicates
|
||||||
bool removed_entry;
|
bool removed_entry;
|
||||||
do{
|
do{
|
||||||
removed_entry = false;
|
removed_entry = false;
|
||||||
for(std::list<GUIModalMenu*>::iterator
|
for(std::list<gui::IGUIElement*>::iterator
|
||||||
i = m_stack.begin();
|
i = m_stack.begin();
|
||||||
i != m_stack.end(); ++i)
|
i != m_stack.end(); ++i)
|
||||||
{
|
{
|
||||||
@ -91,10 +91,10 @@ public:
|
|||||||
// Returns true to prevent further processing
|
// Returns true to prevent further processing
|
||||||
virtual bool preprocessEvent(const SEvent& event)
|
virtual bool preprocessEvent(const SEvent& event)
|
||||||
{
|
{
|
||||||
if(!m_stack.empty())
|
if (m_stack.empty())
|
||||||
return m_stack.back()->preprocessEvent(event);
|
|
||||||
else
|
|
||||||
return false;
|
return false;
|
||||||
|
GUIModalMenu *mm = dynamic_cast<GUIModalMenu*>(m_stack.back());
|
||||||
|
return mm && mm->preprocessEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 menuCount()
|
u32 menuCount()
|
||||||
@ -104,16 +104,17 @@ public:
|
|||||||
|
|
||||||
bool pausesGame()
|
bool pausesGame()
|
||||||
{
|
{
|
||||||
for(std::list<GUIModalMenu*>::iterator
|
for(std::list<gui::IGUIElement*>::iterator
|
||||||
i = m_stack.begin(); i != m_stack.end(); ++i)
|
i = m_stack.begin(); i != m_stack.end(); ++i)
|
||||||
{
|
{
|
||||||
if((*i)->pausesGame())
|
GUIModalMenu *mm = dynamic_cast<GUIModalMenu*>(*i);
|
||||||
|
if (mm && mm->pausesGame())
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::list<GUIModalMenu*> m_stack;
|
std::list<gui::IGUIElement*> m_stack;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern MainMenuManager g_menumgr;
|
extern MainMenuManager g_menumgr;
|
||||||
|
@ -31,8 +31,8 @@ class IMenuManager
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// A GUIModalMenu calls these when this class is passed as a parameter
|
// A GUIModalMenu calls these when this class is passed as a parameter
|
||||||
virtual void createdMenu(GUIModalMenu *menu) = 0;
|
virtual void createdMenu(gui::IGUIElement *menu) = 0;
|
||||||
virtual void deletingMenu(GUIModalMenu *menu) = 0;
|
virtual void deletingMenu(gui::IGUIElement *menu) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user