aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorShadowNinja <shadowninja@minetest.net>2016-02-27 15:51:09 -0500
committerShadowNinja <shadowninja@minetest.net>2016-03-02 23:23:31 -0500
commit3edb7575a1ccca631994c0f5515b770b7a3e20d2 (patch)
tree7298aa5ac133e57594febab7ac26227f5ec1646b /src
parenteffa24737d6997dc40508533635accca3ed099e9 (diff)
Unlock cursor when opening console
Diffstat (limited to 'src')
-rw-r--r--src/game.cpp3
-rw-r--r--src/guiChatConsole.cpp13
-rw-r--r--src/guiChatConsole.h8
-rw-r--r--src/mainmenumanager.h21
-rw-r--r--src/modalMenu.h4
5 files changed, 26 insertions, 23 deletions
diff --git a/src/game.cpp b/src/game.cpp
index 3d5f86e21..6fba70df6 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -2175,7 +2175,7 @@ bool Game::initGui()
// Chat backend and console
gui_chat_console = new GUIChatConsole(guienv, guienv->getRootGUIElement(),
- -1, chat_backend, client);
+ -1, chat_backend, client, &g_menumgr);
if (!gui_chat_console) {
*error_message = "Could not allocate memory for chat console";
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->replaceAndAddToHistory(line);
}
- guienv->setFocus(gui_chat_console);
}
}
diff --git a/src/guiChatConsole.cpp b/src/guiChatConsole.cpp
index 4c0039e5e..4a084a8e5 100644
--- a/src/guiChatConsole.cpp
+++ b/src/guiChatConsole.cpp
@@ -46,12 +46,14 @@ GUIChatConsole::GUIChatConsole(
gui::IGUIElement* parent,
s32 id,
ChatBackend* backend,
- Client* client
+ Client* client,
+ IMenuManager* menumgr
):
IGUIElement(gui::EGUIET_ELEMENT, env, parent, id,
core::rect<s32>(0,0,100,100)),
m_chat_backend(backend),
m_client(client),
+ m_menumgr(menumgr),
m_screensize(v2u32(0,0)),
m_animate_time_old(0),
m_open(false),
@@ -120,6 +122,8 @@ void GUIChatConsole::openConsole(f32 height)
m_desired_height_fraction = height;
m_desired_height = height * m_screensize.Y;
reformatConsole();
+ Environment->setFocus(this);
+ m_menumgr->createdMenu(this);
}
bool GUIChatConsole::isOpen() const
@@ -135,11 +139,13 @@ bool GUIChatConsole::isOpenInhibited() const
void GUIChatConsole::closeConsole()
{
m_open = false;
+ Environment->removeFocus(this);
+ m_menumgr->deletingMenu(this);
}
void GUIChatConsole::closeConsoleAtOnce()
{
- m_open = false;
+ closeConsole();
m_height = 0;
recalculateConsolePosition();
}
@@ -399,7 +405,6 @@ bool GUIChatConsole::OnEvent(const SEvent& event)
if(KeyPress(event.KeyInput) == getKeySetting("keymap_console"))
{
closeConsole();
- Environment->removeFocus(this);
// inhibit open so the_game doesn't reopen immediately
m_open_inhibited = 50;
@@ -409,7 +414,6 @@ bool GUIChatConsole::OnEvent(const SEvent& event)
else if(event.KeyInput.Key == KEY_ESCAPE)
{
closeConsoleAtOnce();
- Environment->removeFocus(this);
m_close_on_enter = false;
// inhibit open so the_game doesn't reopen immediately
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);
if (m_close_on_enter) {
closeConsoleAtOnce();
- Environment->removeFocus(this);
m_close_on_enter = false;
}
return true;
diff --git a/src/guiChatConsole.h b/src/guiChatConsole.h
index 7b9fc6732..fe595f284 100644
--- a/src/guiChatConsole.h
+++ b/src/guiChatConsole.h
@@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define GUICHATCONSOLE_HEADER
#include "irrlichttypes_extrabloated.h"
+#include "modalMenu.h"
#include "chat.h"
#include "config.h"
@@ -33,7 +34,8 @@ public:
gui::IGUIElement* parent,
s32 id,
ChatBackend* backend,
- Client* client);
+ Client* client,
+ IMenuManager* menumgr);
virtual ~GUIChatConsole();
// Open the console (height = desired fraction of screen size)
@@ -86,11 +88,9 @@ private:
void drawPrompt();
private:
- // pointer to the chat backend
ChatBackend* m_chat_backend;
-
- // pointer to the client
Client* m_client;
+ IMenuManager* m_menumgr;
// current screen size
v2u32 m_screensize;
diff --git a/src/mainmenumanager.h b/src/mainmenumanager.h
index 6f8aa9137..17133b164 100644
--- a/src/mainmenumanager.h
+++ b/src/mainmenumanager.h
@@ -47,9 +47,9 @@ extern gui::IGUIStaticText *guiroot;
class MainMenuManager : public IMenuManager
{
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.end(); ++i)
{
@@ -61,13 +61,13 @@ public:
m_stack.push_back(menu);
}
- virtual void deletingMenu(GUIModalMenu *menu)
+ virtual void deletingMenu(gui::IGUIElement *menu)
{
// Remove all entries if there are duplicates
bool removed_entry;
do{
removed_entry = false;
- for(std::list<GUIModalMenu*>::iterator
+ for(std::list<gui::IGUIElement*>::iterator
i = m_stack.begin();
i != m_stack.end(); ++i)
{
@@ -91,10 +91,10 @@ public:
// Returns true to prevent further processing
virtual bool preprocessEvent(const SEvent& event)
{
- if(!m_stack.empty())
- return m_stack.back()->preprocessEvent(event);
- else
+ if (m_stack.empty())
return false;
+ GUIModalMenu *mm = dynamic_cast<GUIModalMenu*>(m_stack.back());
+ return mm && mm->preprocessEvent(event);
}
u32 menuCount()
@@ -104,16 +104,17 @@ public:
bool pausesGame()
{
- for(std::list<GUIModalMenu*>::iterator
+ for(std::list<gui::IGUIElement*>::iterator
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 false;
}
- std::list<GUIModalMenu*> m_stack;
+ std::list<gui::IGUIElement*> m_stack;
};
extern MainMenuManager g_menumgr;
diff --git a/src/modalMenu.h b/src/modalMenu.h
index d5e975a87..43bb8e1b8 100644
--- a/src/modalMenu.h
+++ b/src/modalMenu.h
@@ -31,8 +31,8 @@ class IMenuManager
{
public:
// A GUIModalMenu calls these when this class is passed as a parameter
- virtual void createdMenu(GUIModalMenu *menu) = 0;
- virtual void deletingMenu(GUIModalMenu *menu) = 0;
+ virtual void createdMenu(gui::IGUIElement *menu) = 0;
+ virtual void deletingMenu(gui::IGUIElement *menu) = 0;
};
/*
class="hl kwa">then --atprint("Called send_command at "..pts) local train_id = par_tid or advtrains.get_train_at_pos(pos) if train_id then if advtrains.trains[train_id] then --atprint("send_command inside if: "..sid(train_id)) if atc.controllers[pts].arrowconn then atlog("ATC controller at",pts,": This controller had an arrowconn of", atc.controllers[pts].arrowconn, "set. Since this field is now deprecated, it was removed.") atc.controllers[pts].arrowconn = nil end local train = advtrains.trains[train_id] local index = advtrains.path_lookup(train, pos) local iconnid = 1 if index then iconnid = train.path_cn[index] else atwarn("ATC rail at", pos, ": Rail not on train's path! Can't determine arrow direction. Assuming +!") end local command = atc.controllers[pts].command command = eval_conditional(command, iconnid==1, train.velocity) if not command then command="" end command=string.match(command, "^%s*(.*)$") if command == "" then atprint("Sending ATC Command to", train_id, ": Not modifying, conditional evaluated empty.") return true end atc.train_set_command(train, command, iconnid==1) atprint("Sending ATC Command to", train_id, ":", command, "iconnid=",iconnid) return true else atwarn("ATC rail at", pos, ": Sending command failed: The train",train_id,"does not exist. This seems to be a bug.") end else atwarn("ATC rail at", pos, ": Sending command failed: There's no train at this position. This seems to be a bug.") end else atwarn("ATC rail at", pos, ": Sending command failed: Entry for controller not found.") atwarn("ATC rail at", pos, ": Please visit controller and click 'Save'") end return false end -- Resets any ATC commands the train is currently executing, including the target speed (tarvelocity) it is instructed to hold -- if keep_tarvel is set, does not clear the tarvelocity function atc.train_reset_command(train, keep_tarvel) train.atc_command=nil train.atc_delay=nil train.atc_brake_target=nil train.atc_wait_finish=nil train.atc_arrow=nil if not keep_tarvel then train.tarvelocity=nil end end --nodes local idxtrans={static=1, mesecon=2, digiline=3} local apn_func=function(pos) -- FIX for long-persisting ndb bug: there's no node in parameter 2 of this function! local meta=minetest.get_meta(pos) if meta then meta:set_string("infotext", attrans("ATC controller, unconfigured.")) meta:set_string("formspec", atc.get_atc_controller_formspec(pos, meta)) end end advtrains.atc_function = function(def, preset, suffix, rotation) return { after_place_node=apn_func, after_dig_node=function(pos) advtrains.invalidate_all_paths(pos) advtrains.ndb.clear(pos) local pts=minetest.pos_to_string(pos) atc.controllers[pts]=nil end, on_receive_fields = function(pos, formname, fields, player) if advtrains.is_protected(pos, player:get_player_name()) then minetest.record_protection_violation(pos, player:get_player_name()) return end local meta=minetest.get_meta(pos) if meta then if not fields.save then --[[--maybe only the dropdown changed if fields.mode then meta:set_string("mode", idxtrans[fields.mode]) if fields.mode=="digiline" then meta:set_string("infotext", attrans("ATC controller, mode @1\nChannel: @2", fields.mode, meta:get_string("command")) ) else meta:set_string("infotext", attrans("ATC controller, mode @1\nCommand: @2", fields.mode, meta:get_string("command")) ) end meta:set_string("formspec", atc.get_atc_controller_formspec(pos, meta)) end]]-- return end --meta:set_string("mode", idxtrans[fields.mode]) meta:set_string("command", fields.command) --meta:set_string("command_on", fields.command_on) meta:set_string("channel", fields.channel) --if fields.mode=="digiline" then -- meta:set_string("infotext", attrans("ATC controller, mode @1\nChannel: @2", fields.mode, meta:get_string("command")) ) --else meta:set_string("infotext", attrans("ATC controller, mode @1\nCommand: @2", "-", meta:get_string("command")) ) --end meta:set_string("formspec", atc.get_atc_controller_formspec(pos, meta)) local pts=minetest.pos_to_string(pos) local _, conns=advtrains.get_rail_info_at(pos, advtrains.all_tracktypes) atc.controllers[pts]={command=fields.command} if #advtrains.occ.get_trains_at(pos) > 0 then atc.send_command(pos) end end end, advtrains = { on_train_enter = function(pos, train_id) atc.send_command(pos) end, }, } end function atc.get_atc_controller_formspec(pos, meta) local mode=tonumber(meta:get_string("mode")) or 1 local command=meta:get_string("command") local command_on=meta:get_string("command_on") local channel=meta:get_string("channel") local formspec="size[8,6]" -- "dropdown[0,0;3;mode;static,mesecon,digiline;"..mode.."]" if mode<3 then formspec=formspec.."field[0.5,1.5;7,1;command;"..attrans("Command")..";"..minetest.formspec_escape(command).."]" if tonumber(mode)==2 then formspec=formspec.."field[0.5,3;7,1;command_on;"..attrans("Command (on)")..";"..minetest.formspec_escape(command_on).."]" end else formspec=formspec.."field[0.5,1.5;7,1;channel;"..attrans("Digiline channel")..";"..minetest.formspec_escape(channel).."]" end return formspec.."button_exit[0.5,4.5;7,1;save;"..attrans("Save").."]" end --from trainlogic.lua train step local matchptn={ ["SM"]=function(id, train) train.tarvelocity=train.max_speed return 2 end, ["S([0-9]+)"]=function(id, train, match) train.tarvelocity=tonumber(match)