Skip to content

Commit

Permalink
Use the console instead of a dedicated window when pressing keymap_ch…
Browse files Browse the repository at this point in the history
…at/cmd

and remove guiTextInputMenu and deprecated sign_hack "formspec"
  • Loading branch information
EXio4 committed Jun 15, 2013
1 parent c25102a commit 648a6fc
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 347 deletions.
1 change: 0 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,6 @@ set(minetest_SRCS
guiMainMenu.cpp
guiKeyChangeMenu.cpp
guiMessageMenu.cpp
guiTextInputMenu.cpp
guiFormSpecMenu.cpp
guiPauseMenu.cpp
guiPasswordChange.cpp
Expand Down
18 changes: 9 additions & 9 deletions src/chat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,20 +407,18 @@ void ChatPrompt::input(wchar_t ch)
m_nick_completion_end = 0;
}

std::wstring ChatPrompt::submit()
void ChatPrompt::addToHistory(std::wstring line)
{
std::wstring line = m_line;
m_line.clear();
if (!line.empty())
m_history.push_back(line);
if (m_history.size() > m_history_limit)
m_history.erase(m_history.begin());
m_history_index = m_history.size();
m_view = 0;
m_cursor = 0;
m_nick_completion_start = 0;
m_nick_completion_end = 0;
return line;
}

std::wstring ChatPrompt::getLine()
{
return m_line;
}

void ChatPrompt::clear()
Expand All @@ -432,13 +430,15 @@ void ChatPrompt::clear()
m_nick_completion_end = 0;
}

void ChatPrompt::replace(std::wstring line)
std::wstring ChatPrompt::replace(std::wstring line)
{
std::wstring old_line = m_line;
m_line = line;
m_view = m_cursor = line.size();
clampView();
m_nick_completion_start = 0;
m_nick_completion_end = 0;
return old_line;
}

void ChatPrompt::historyPrev()
Expand Down
9 changes: 6 additions & 3 deletions src/chat.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,17 @@ class ChatPrompt
// Input character
void input(wchar_t ch);

// Submit, clear and return current line
std::wstring submit();
// Add a string to the history
void addToHistory(std::wstring line);

// Get current line
std::wstring getLine();

// Clear the current line
void clear();

// Replace the current line with the given text
void replace(std::wstring line);
std::wstring replace(std::wstring line);

// Select previous command from history
void historyPrev();
Expand Down
72 changes: 31 additions & 41 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "guiPasswordChange.h"
#include "guiVolumeChange.h"
#include "guiFormSpecMenu.h"
#include "guiTextInputMenu.h"
#include "guiDeathScreen.h"
#include "tool.h"
#include "guiChatConsole.h"
Expand Down Expand Up @@ -1727,33 +1726,42 @@ void the_game(
}
else if(input->wasKeyDown(EscapeKey))
{
infostream<<"the_game: "
<<"Launching pause menu"<<std::endl;
// It will delete itself by itself
(new GUIPauseMenu(guienv, guiroot, -1, g_gamecallback,
&g_menumgr, simple_singleplayer_mode))->drop();

// Move mouse cursor on top of the disconnect button
if(simple_singleplayer_mode)
input->setMousePos(displaycenter.X, displaycenter.Y+0);
else
input->setMousePos(displaycenter.X, displaycenter.Y+25);
if (!gui_chat_console->isOpenInhibited())
{
infostream<<"the_game: "
<<"Launching pause menu"<<std::endl;
// It will delete itself by itself
(new GUIPauseMenu(guienv, guiroot, -1, g_gamecallback,
&g_menumgr, simple_singleplayer_mode))->drop();

// Move mouse cursor on top of the disconnect button
if(simple_singleplayer_mode)
input->setMousePos(displaycenter.X, displaycenter.Y+0);
else
input->setMousePos(displaycenter.X, displaycenter.Y+25);
}
}
else if(input->wasKeyDown(getKeySetting("keymap_chat")))
{
TextDest *dest = new TextDestChat(&client);

(new GUITextInputMenu(guienv, guiroot, -1,
&g_menumgr, dest,
L""))->drop();
if (!gui_chat_console->isOpenInhibited())
{
// Open up to over half of the screen
gui_chat_console->openConsole(0.6);
gui_chat_console->closeConsoleOnEnter(true);
gui_chat_console->replaceAndAddToHistory(L"");
guienv->setFocus(gui_chat_console);
}
}
else if(input->wasKeyDown(getKeySetting("keymap_cmd")))
{
TextDest *dest = new TextDestChat(&client);

(new GUITextInputMenu(guienv, guiroot, -1,
&g_menumgr, dest,
L"/"))->drop();
if (!gui_chat_console->isOpenInhibited())
{
// Open up to over half of the screen
gui_chat_console->openConsole(0.6);
gui_chat_console->closeConsoleOnEnter(true);
gui_chat_console->replaceAndAddToHistory(L"/");
guienv->setFocus(gui_chat_console);
}
}
else if(input->wasKeyDown(getKeySetting("keymap_console")))
{
Expand Down Expand Up @@ -2695,26 +2703,8 @@ void the_game(
repeat_rightclick_timer = 0;
infostream<<"Ground right-clicked"<<std::endl;

// Sign special case, at least until formspec is properly implemented.
// Deprecated?
if(meta && meta->getString("formspec") == "hack:sign_text_input"
&& !random_input
&& !input->isKeyDown(getKeySetting("keymap_sneak")))
{
infostream<<"Launching metadata text input"<<std::endl;

// Get a new text for it

TextDest *dest = new TextDestNodeMetadata(nodepos, &client);

std::wstring wtext = narrow_to_wide(meta->getString("text"));

(new GUITextInputMenu(guienv, guiroot, -1,
&g_menumgr, dest,
wtext))->drop();
}
// If metadata provides an inventory view, activate it
else if(meta && meta->getString("formspec") != "" && !random_input
if(meta && meta->getString("formspec") != "" && !random_input
&& !input->isKeyDown(getKeySetting("keymap_sneak")))
{
infostream<<"Launching custom inventory view"<<std::endl;
Expand Down
53 changes: 39 additions & 14 deletions src/guiChatConsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ GUIChatConsole::GUIChatConsole(
m_screensize(v2u32(0,0)),
m_animate_time_old(0),
m_open(false),
m_close_on_enter(false),
m_height(0),
m_desired_height(0),
m_desired_height_fraction(0.0),
Expand Down Expand Up @@ -151,11 +152,23 @@ void GUIChatConsole::closeConsoleAtOnce()
recalculateConsolePosition();
}

void GUIChatConsole::closeConsoleOnEnter(bool close) {
m_close_on_enter = close;
}

f32 GUIChatConsole::getDesiredHeight() const
{
return m_desired_height_fraction;
}

void GUIChatConsole::replaceAndAddToHistory(std::wstring line)
{
ChatPrompt& prompt = m_chat_backend->getPrompt();
prompt.addToHistory(prompt.getLine());
prompt.replace(line);
}


void GUIChatConsole::setCursor(
bool visible, bool blinking, f32 blink_speed, f32 relative_height)
{
Expand Down Expand Up @@ -389,6 +402,9 @@ void GUIChatConsole::drawPrompt()

bool GUIChatConsole::OnEvent(const SEvent& event)
{

ChatPrompt& prompt = m_chat_backend->getPrompt();

if(event.EventType == EET_KEY_INPUT_EVENT && event.KeyInput.PressedDown)
{
// Key input
Expand All @@ -399,13 +415,16 @@ bool GUIChatConsole::OnEvent(const SEvent& event)

// inhibit open so the_game doesn't reopen immediately
m_open_inhibited = 50;
m_close_on_enter = false;
return true;
}
else if(event.KeyInput.Key == KEY_ESCAPE)
{
closeConsoleAtOnce();
Environment->removeFocus(this);
// the_game will open the pause menu
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"
return true;
}
else if(event.KeyInput.Key == KEY_PRIOR)
Expand All @@ -420,22 +439,28 @@ bool GUIChatConsole::OnEvent(const SEvent& event)
}
else if(event.KeyInput.Key == KEY_RETURN)
{
std::wstring text = m_chat_backend->getPrompt().submit();
prompt.addToHistory(prompt.getLine());
std::wstring text = prompt.replace(L"");
m_client->typeChatMessage(text);
if (m_close_on_enter) {
closeConsoleAtOnce();
Environment->removeFocus(this);
m_close_on_enter = false;
}
return true;
}
else if(event.KeyInput.Key == KEY_UP)
{
// Up pressed
// Move back in history
m_chat_backend->getPrompt().historyPrev();
prompt.historyPrev();
return true;
}
else if(event.KeyInput.Key == KEY_DOWN)
{
// Down pressed
// Move forward in history
m_chat_backend->getPrompt().historyNext();
prompt.historyNext();
return true;
}
else if(event.KeyInput.Key == KEY_LEFT)
Expand All @@ -446,7 +471,7 @@ bool GUIChatConsole::OnEvent(const SEvent& event)
event.KeyInput.Control ?
ChatPrompt::CURSOROP_SCOPE_WORD :
ChatPrompt::CURSOROP_SCOPE_CHARACTER;
m_chat_backend->getPrompt().cursorOperation(
prompt.cursorOperation(
ChatPrompt::CURSOROP_MOVE,
ChatPrompt::CURSOROP_DIR_LEFT,
scope);
Expand All @@ -460,7 +485,7 @@ bool GUIChatConsole::OnEvent(const SEvent& event)
event.KeyInput.Control ?
ChatPrompt::CURSOROP_SCOPE_WORD :
ChatPrompt::CURSOROP_SCOPE_CHARACTER;
m_chat_backend->getPrompt().cursorOperation(
prompt.cursorOperation(
ChatPrompt::CURSOROP_MOVE,
ChatPrompt::CURSOROP_DIR_RIGHT,
scope);
Expand All @@ -470,7 +495,7 @@ bool GUIChatConsole::OnEvent(const SEvent& event)
{
// Home pressed
// move to beginning of line
m_chat_backend->getPrompt().cursorOperation(
prompt.cursorOperation(
ChatPrompt::CURSOROP_MOVE,
ChatPrompt::CURSOROP_DIR_LEFT,
ChatPrompt::CURSOROP_SCOPE_LINE);
Expand All @@ -480,7 +505,7 @@ bool GUIChatConsole::OnEvent(const SEvent& event)
{
// End pressed
// move to end of line
m_chat_backend->getPrompt().cursorOperation(
prompt.cursorOperation(
ChatPrompt::CURSOROP_MOVE,
ChatPrompt::CURSOROP_DIR_RIGHT,
ChatPrompt::CURSOROP_SCOPE_LINE);
Expand All @@ -494,7 +519,7 @@ bool GUIChatConsole::OnEvent(const SEvent& event)
event.KeyInput.Control ?
ChatPrompt::CURSOROP_SCOPE_WORD :
ChatPrompt::CURSOROP_SCOPE_CHARACTER;
m_chat_backend->getPrompt().cursorOperation(
prompt.cursorOperation(
ChatPrompt::CURSOROP_DELETE,
ChatPrompt::CURSOROP_DIR_LEFT,
scope);
Expand All @@ -508,7 +533,7 @@ bool GUIChatConsole::OnEvent(const SEvent& event)
event.KeyInput.Control ?
ChatPrompt::CURSOROP_SCOPE_WORD :
ChatPrompt::CURSOROP_SCOPE_CHARACTER;
m_chat_backend->getPrompt().cursorOperation(
prompt.cursorOperation(
ChatPrompt::CURSOROP_DELETE,
ChatPrompt::CURSOROP_DIR_RIGHT,
scope);
Expand All @@ -518,7 +543,7 @@ bool GUIChatConsole::OnEvent(const SEvent& event)
{
// Ctrl-U pressed
// kill line to left end
m_chat_backend->getPrompt().cursorOperation(
prompt.cursorOperation(
ChatPrompt::CURSOROP_DELETE,
ChatPrompt::CURSOROP_DIR_LEFT,
ChatPrompt::CURSOROP_SCOPE_LINE);
Expand All @@ -528,7 +553,7 @@ bool GUIChatConsole::OnEvent(const SEvent& event)
{
// Ctrl-K pressed
// kill line to right end
m_chat_backend->getPrompt().cursorOperation(
prompt.cursorOperation(
ChatPrompt::CURSOROP_DELETE,
ChatPrompt::CURSOROP_DIR_RIGHT,
ChatPrompt::CURSOROP_SCOPE_LINE);
Expand All @@ -540,12 +565,12 @@ bool GUIChatConsole::OnEvent(const SEvent& event)
// Nick completion
std::list<std::string> names = m_client->getConnectedPlayerNames();
bool backwards = event.KeyInput.Shift;
m_chat_backend->getPrompt().nickCompletion(names, backwards);
prompt.nickCompletion(names, backwards);
return true;
}
else if(event.KeyInput.Char != 0 && !event.KeyInput.Control)
{
m_chat_backend->getPrompt().input(event.KeyInput.Char);
prompt.input(event.KeyInput.Char);
return true;
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/guiChatConsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,16 @@ class GUIChatConsole : public gui::IGUIElement
void closeConsole();
// Close the console immediately, without animation.
void closeConsoleAtOnce();
// Close the console, after pressing RETURN
void closeConsoleOnEnter(bool close);

// Return the desired height (fraction of screen size)
// Zero if the console is closed or getting closed
f32 getDesiredHeight() const;

// Replace actual line when adding the actual to the history (if there is any)
void replaceAndAddToHistory(std::wstring line);

// Change how the cursor looks
void setCursor(
bool visible,
Expand Down Expand Up @@ -91,6 +96,8 @@ class GUIChatConsole : public gui::IGUIElement

// should the console be opened or closed?
bool m_open;
// should it close after you press enter?
bool m_close_on_enter;
// current console height [pixels]
s32 m_height;
// desired height [pixels]
Expand Down
Loading

0 comments on commit 648a6fc

Please sign in to comment.