Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/client')
-rw-r--r--src/client/chat.cc9
-rw-r--r--src/client/client.cc22
-rw-r--r--src/client/client.h5
-rw-r--r--src/client/console.cc424
-rw-r--r--src/client/console.h77
-rw-r--r--src/client/input.cc69
-rw-r--r--src/client/view.cc17
7 files changed, 255 insertions, 368 deletions
diff --git a/src/client/chat.cc b/src/client/chat.cc
index 87ba437..6d294ba 100644
--- a/src/client/chat.cc
+++ b/src/client/chat.cc
@@ -6,15 +6,14 @@
#include "auxiliary/functions.h"
#include "client/chat.h"
-#include "client/client.h"
-#include "client/console.h"
#include "core/core.h"
-#include "render/render.h"
#include "sys/sys.h"
#include "ui/ui.h"
namespace client {
+const size_t DEFAULT_MAX_HISTO_LINES = 512;
+
Chat::Chat(ui::Widget *parent) : ui::Window(parent)
{
set_label("chat");
@@ -83,7 +82,7 @@ bool Chat::on_keypress(const int key, const unsigned int modifier)
(*history_pos).assign(chat_input->text());
// store input into history
- while (history.size() >= MAXHISTOLINES) {
+ while (history.size() >= DEFAULT_MAX_HISTO_LINES) {
history.pop_front();
}
@@ -127,7 +126,7 @@ bool Chat::on_keypress(const int key, const unsigned int modifier)
void Chat::event_draw()
{
- if (!client()->connected()) {
+ if (!core::application()->connected()) {
hide();
return;
}
diff --git a/src/client/client.cc b/src/client/client.cc
index ae4f232..200becd 100644
--- a/src/client/client.cc
+++ b/src/client/client.cc
@@ -58,6 +58,11 @@ void func_ui_chat(std::string const &args)
}
}
+void func_ui_console(std::string const &args)
+{
+ client()->console()->toggle();
+}
+
//--- public ------------------------------------------------------
void client_main(int count, char **arguments)
@@ -93,7 +98,6 @@ void Client::init(int count, char **arguments)
// initialize core
core::Cvar::sv_dedicated = core::Cvar::set("sv_private", "0");
core::Application::init(count, arguments);
- Console::init();
// client variables
core::Cvar *cvar = 0;
@@ -114,7 +118,9 @@ void Client::init(int count, char **arguments)
// initialize user interface
ui::init();
+
client_view = new View(ui::root());
+ client_console = new Console(ui::root());
// Initialize the video subsystem
if (!video::init()) {
@@ -136,6 +142,9 @@ void Client::init(int count, char **arguments)
func = core::Func::add("ui_chat", func_ui_chat);
func->set_info("toggle chat window");
+ func = core::Func::add("ui_console", func_ui_console);
+ func->set_info("toggle console on or off");
+
//func = core::Func::add("snd_restart", (core::FuncPtr) func_snd_restart);
//func->set_info("restart audio subsystem");
}
@@ -149,10 +158,8 @@ void Client::run()
Uint32 client_current_timestamp = 0;
Uint32 client_previous_timestamp = 0;
-
-
- console()->flush();
- console()->clear_notify();
+
+ //console()->clear_notify();
while (true) {
// current time in microseconds
@@ -222,12 +229,11 @@ void Client::shutdown()
core::Func::remove("r_restart");
core::Func::remove("ui_chat");
+ core::Func::remove("ui_console");
//core::Func::remove("snd_restart");
audio::shutdown();
- Console::shutdown();
-
input::shutdown();
video::shutdown();
@@ -290,7 +296,7 @@ void Client::notify_message(core::Message::Channel const channel, std::string co
}
con_print << message << std::endl;
- console()->notify(message);
+ //console()->notify(message);
}
/* FIXME
diff --git a/src/client/client.h b/src/client/client.h
index dc70e16..6e19848 100644
--- a/src/client/client.h
+++ b/src/client/client.h
@@ -8,6 +8,7 @@
#define __INCLUDED_CLIENT_H__
#include "core/application.h"
+#include "client/console.h"
#include "client/view.h"
/// client part of the engine
@@ -50,12 +51,16 @@ public:
/// the main client view
inline View *view() { return client_view; }
+ /// the client console
+ inline Console *console() { return client_console; }
+
protected:
/// run a client frame
virtual void frame(float seconds);
private:
View *client_view;
+ Console *client_console;
};
diff --git a/src/client/console.cc b/src/client/console.cc
index 47f95f7..0ab0767 100644
--- a/src/client/console.cc
+++ b/src/client/console.cc
@@ -21,97 +21,112 @@
namespace client {
-Console client_console;
+const float DEFAULT_CONSOLE_HEIGHT = 0.7f;
+const size_t DEFAULT_MAX_HISTO_LINES = 512;
-Console *console() {
- return &client_console;
-}
-
-//--- public ------------------------------------------------------
-
-void Console::init()
+/* -- ConsoleBuffer ------------------------------------------------ */
+ConsoleBuffer::ConsoleBuffer()
{
con_print << "^BInitializing console..." << std::endl;
- console()->load_history();
+
}
-void Console::shutdown()
+ConsoleBuffer::~ConsoleBuffer()
{
con_print << "^BShutting down console..." << std::endl;
- console()->save_history();
}
+// the global console buffer object
+ConsoleBuffer Console::con_buffer;
+
//--- Console -----------------------------------------------------
-Console::Console()
+Console::Console(ui::Widget *parent) : ui::Window(parent)
{
- clear();
-}
+ set_visible(false);
+ set_border(false);
+ set_background(true);
+ set_label("console");
-Console::~Console()
-{
- history.clear();
-}
+ //clear_notify();
+ load_history();
-void Console::clear()
-{
- console_visible = false;
- console_scroll = 0;
+ console_scroll = 0;
history.clear();
history.push_back("");
history_pos = history.rbegin();
- input_pos = 0;
-
- clear_notify();
+ console_input = new ui::Input(this);
+ console_input->set_focus();
+ console_input->set_border(false);
+ console_input->set_background(false);
}
-void Console::draw(bool draw_ui_notifications) {
- flush();
- if (visible())
- draw_console();
- else if (draw_ui_notifications)
- draw_notify();
+Console::~Console()
+{
+ save_history();
+ history.clear();
}
-void Console::toggle()
+void Console::show()
{
- console_visible = !console_visible;
-
- if (console_visible) {
- console_scroll = 0;
- input_pos = 0;
+ ui::Window::show();
+ SDL_WM_GrabInput(SDL_GRAB_OFF);
+ SDL_ShowCursor(SDL_ENABLE);
- history_pos = history.rbegin();
- (*history_pos).clear();
+ console_scroll = 0;
+ history_pos = history.rbegin();
+ (*history_pos).clear();
+ console_input->set_text((*history_pos));
- SDL_WM_GrabInput(SDL_GRAB_OFF);
- SDL_ShowCursor(SDL_ENABLE);
- } else {
- SDL_WM_GrabInput(SDL_GRAB_ON);
- SDL_ShowCursor(SDL_DISABLE);
- }
+ audio::play("ui/console");
+}
- //setkeyboardmode(console()->visible() || (core::application()->connected() && chat::visible()));
+void Console::hide()
+{
+ ui::Window::hide();
+ SDL_WM_GrabInput(SDL_GRAB_ON);
+ SDL_ShowCursor(SDL_DISABLE);
audio::play("ui/console");
}
-void Console::keypressed(unsigned int key)
+void Console::toggle()
+{
+ if (visible())
+ hide();
+ else
+ show();
+}
+
+bool Console::on_keypress(const int key, const unsigned int modifier)
{
// number of lines to scroll
const size_t scroll_offset = 3;
- std::deque<std::string>::reverse_iterator upit;
+ Text::reverse_iterator upit;
switch( key ) {
+
+ case SDLK_ESCAPE:
+ if (visible()) {
+ hide();
+ return true;
+ } else {
+ return false;
+ }
+ break;
+/*
case SDLK_TAB:
core::CommandBuffer::complete( (*history_pos), input_pos);
+ return true;
break;
+*/
case SDLK_RETURN:
- if ((*history_pos).size()) {
- // store input into history
- while (history.size() >= MAXHISTOLINES) {
+ if (console_input->text().size()) {
+ // store input in history
+ (*history_pos).assign(console_input->text());
+ while (history.size() >= DEFAULT_MAX_HISTO_LINES) {
history.pop_front();
}
@@ -121,132 +136,88 @@ void Console::keypressed(unsigned int key)
history.push_back("");
history_pos = history.rbegin();
- input_pos = 0;
+ console_input->set_text((*history_pos));
}
+ return true;
break;
+
case SDLK_UP:
upit = history_pos;
++upit;
if (upit != history.rend()) {
history_pos = upit;
- input_pos = (*history_pos).size();
+ console_input->set_text((*history_pos));
}
+ return true;
break;
case SDLK_DOWN:
if (history_pos != history.rbegin()) {
--history_pos;
- input_pos = (*history_pos).size();
- }
- break;
- case SDLK_HOME:
- input_pos = 0;
- break;
- case SDLK_END:
- input_pos = (*history_pos).size();
- break;
- case SDLK_LEFT:
- if (input_pos > 0)
- input_pos--;
- break;
- case SDLK_RIGHT:
- if (input_pos < (*history_pos).size())
- input_pos++;
- break;
- case SDLK_DELETE:
- if ((*history_pos).size() && input_pos < (*history_pos).size()) {
- (*history_pos).erase(input_pos, 1);
- }
- break;
- case SDLK_BACKSPACE:
- if ((*history_pos).size() && input_pos) {
- (*history_pos).erase(input_pos-1, 1);
- input_pos--;
+ console_input->set_text((*history_pos));
}
+ return true;
break;
case SDLK_PAGEUP:
console_scroll += scroll_offset;
- if (console_scroll > consoleinterface_text.size())
- console_scroll = consoleinterface_text.size();
+ if (console_scroll > log().size())
+ console_scroll = log().size();
+ return true;
break;
+
case SDLK_PAGEDOWN:
if (console_scroll > scroll_offset)
console_scroll -= scroll_offset;
else
console_scroll = 0;
- break;
- default:
- if ((key >= 32 ) && (key <175) && ((*history_pos).size() < MAXCMDSIZE)) {
- if (input_pos == (*history_pos).size())
- (*history_pos) += (char)key;
- else
- (*history_pos).insert(input_pos, 1, (char)key);
- input_pos++;
- }
+ return true;
break;
}
-
+ return false;
}
-void Console::save_history()
+void Console::event_draw()
{
- if (history.size() <= 1)
- return;
-
- std::string filename(filesystem::writedir());
- filename.append("history.txt");
- std::ofstream ofs(filename.c_str());
-
- if (!ofs.is_open()) {
- con_warn << "Could not write " << filename << std::endl;
- return;
- }
- std::deque<std::string>::iterator it;
- size_t l = 1;
- for (it = history.begin(); it != history.end(); it++) {
- if (l < history.size())
- ofs << (*it) << std::endl;
- l++;
+ if (core::application()->connected()) {
+ set_size(parent()->size().width(), parent()->size().height() * DEFAULT_CONSOLE_HEIGHT);
+ } else {
+ set_size(parent()->size());
}
- ofs.close();
+ ui::Window::event_draw();
}
-void Console::load_history()
+void Console::draw()
{
- std::string filename(filesystem::writedir());
- filename.append("history.txt");
- std::ifstream ifs(filename.c_str(), std::ifstream::in);
-
- if (!ifs.is_open()) {
- con_warn << "Could not read " << filename << std::endl;
- return;
- }
+ console_input->set_size(this->width(), font()->height());
+ console_input->set_location(0, this->height()-font()->height());
- history.clear();
- char line[MAXCMDSIZE];
- while (ifs.getline(line, MAXCMDSIZE-1)) {
- history.push_back(line);
- }
+ draw_background();
+ draw_border();
- ifs.close();
+ render::Text::setfont(font()->name().c_str(), font()->width(), font()->height());
+ render::gl::enable(GL_TEXTURE_2D);
- history.push_back("");
- history_pos = history.rbegin();
- input_pos = 0;
-}
+ // draw version below the bottom of the console
+ std::string version(core::name());
+ version += ' ';
+ version.append(core::version());
+ render::gl::color(0.0f, 1.0f, 0.0f, 0.5f);
+ render::Text::draw(width()-font()->width()*(version.size()+1), height()-font()->height()-4, version);
-void Console::draw_notify()
-{
- using namespace render;
+ // draw the console log()
+ if (console_scroll > log().size())
+ console_scroll = log().size();
+
+ size_t height = (size_t) (this->height() / font()->height()) -1;
+ size_t width = (size_t) ((this->width()-8) / font()->width());
+ size_t bottom = log().size() - console_scroll;
+ size_t current_line = 0;
- // draw notifications
- size_t width = (size_t) ((video::width-8) / Text::fontwidth());
- size_t n = notify_pos % MAXNOTIFYLINES;
- float h = video::height/2;
- for (size_t l = 0; l < MAXNOTIFYLINES; l++) {
- if (notify_text[n].size() > 2 && notify_time[n] + 5 > core::application()->time()) {
- std::string linedata(notify_text[n]);
+ Text lines;
+ for (Text::iterator it = log().begin(); it != log().end() && current_line < bottom; it++) {
+ if (current_line >= bottom - height) {
+ std::string linedata(*it);
linedata += '\n';
std::string word;
@@ -258,7 +229,6 @@ void Console::draw_notify()
const char *c = linedata.c_str();
char pen = 'N';
char wordpen = 'N';
- Text::setcolor('N');
while (*c) {
@@ -275,8 +245,7 @@ void Console::draw_notify()
if (line_length + word_length > width) {
if (line.size()) {
- Text::draw(4, h, line);
- h += Text::fontheight();
+ lines.push_back(line);
line.clear();
line += '^';
line += wordpen;
@@ -293,8 +262,7 @@ void Console::draw_notify()
// new line
if (*c == '\n' ) {
- Text::draw(4, h, line);
- h += Text::fontheight();
+ lines.push_back(line);
line.clear();
line_length = 0;
// new word
@@ -311,8 +279,7 @@ void Console::draw_notify()
if (word_length == width) {
if (line.size()) {
- Text::draw(4, h, line);
- h += Text::fontheight();
+ lines.push_back(line);
line.clear();
line += '^';
line += wordpen;
@@ -332,49 +299,78 @@ void Console::draw_notify()
}
}
- n = (n+1) % MAXNOTIFYLINES;
+ current_line++;
+ }
+
+ float y = this->height()-2*font()->height()-4;
+ render::Text::setcolor('N');
+ for (Text::reverse_iterator rit = lines.rbegin(); (y >= 4) && (rit != lines.rend()); ++rit) {
+ render::Text::draw(4, y, (*rit));
+ y -= font()->height();
}
+
+ render::gl::disable(GL_TEXTURE_2D);
+
}
-void Console::draw_console()
+void Console::save_history()
{
- using namespace render;
+ if (history.size() <= 1)
+ return;
- float con_height = 0.70f;
-
- gl::disable(GL_TEXTURE_2D);
+ std::string filename(filesystem::writedir());
+ filename.append("history.txt");
+ std::ofstream ofs(filename.c_str());
- // draw the transparent console background
- gl::color(0.0f, 0.0f, 0.0f, 0.5f);
- gl::begin(gl::Quads);
- gl::vertex(0.0f, 0.0f, 0.0f);
- gl::vertex(video::width, 0.0f,0.0f);
- gl::vertex(video::width,video::height*con_height,0.0f);
- gl::vertex(0,video::height*con_height,0.0f);
- gl::end();
+ if (!ofs.is_open()) {
+ con_warn << "Could not write " << filename << std::endl;
+ return;
+ }
+ Text::iterator it;
+ size_t l = 1;
+ for (it = history.begin(); it != history.end(); it++) {
+ if (l < history.size())
+ ofs << (*it) << std::endl;
+ l++;
+ }
- gl::enable(GL_TEXTURE_2D);
+ ofs.close();
+}
- // draw version below the bottom of the console
- std::string version(core::name());
- version += ' ';
- version.append(core::version());
- gl::color(0.0f, 1.0f, 0.0f, 0.5f);
- Text::draw(video::width-Text::fontwidth()*(version.size()+1), video::height*con_height-Text::fontheight()-4, version);
+void Console::load_history()
+{
+ std::string filename(filesystem::writedir());
+ filename.append("history.txt");
+ std::ifstream ifs(filename.c_str(), std::ifstream::in);
- // draw the console consoleinterface_text
- if (console_scroll > consoleinterface_text.size())
- console_scroll = consoleinterface_text.size();
-
- size_t height = (size_t) (video::height * con_height / Text::fontheight()) -1;
- size_t width = (size_t) ((video::width-8) / Text::fontwidth());
- size_t bottom = consoleinterface_text.size() - console_scroll;
- size_t current_line = 0;
+ if (!ifs.is_open()) {
+ con_warn << "Could not read " << filename << std::endl;
+ return;
+ }
- std::deque<std::string> lines;
- for (std::deque<std::string>::iterator it = consoleinterface_text.begin(); it != consoleinterface_text.end() && current_line < bottom; it++) {
- if (current_line >= bottom - height) {
- std::string linedata(*it);
+ history.clear();
+ char line[MAXCMDSIZE];
+ while (ifs.getline(line, MAXCMDSIZE-1)) {
+ history.push_back(line);
+ }
+
+ ifs.close();
+
+ history.push_back("");
+ history_pos = history.rbegin();
+}
+
+
+/*
+void Console::draw_notify()
+{
+ // draw notifications
+ size_t width = (size_t) ((width()-8) / font()->width());
+ size_t n = notify_pos % MAXNOTIFYLINES;
+ float h = height()/2;
+ for (size_t l = 0; l < MAXNOTIFYLINES; l++) {
+ if (notify_text[n].size() > 2 && notify_time[n] + 5 > core::application()->time()) {
+ std::string linedata(notify_text[n]);
linedata += '\n';
std::string word;
@@ -386,6 +382,7 @@ void Console::draw_console()
const char *c = linedata.c_str();
char pen = 'N';
char wordpen = 'N';
+ render::Text::setcolor('N');
while (*c) {
@@ -402,7 +399,8 @@ void Console::draw_console()
if (line_length + word_length > width) {
if (line.size()) {
- lines.push_back(line);
+ render::Text::draw(4, h, line);
+ h += font()->width();
line.clear();
line += '^';
line += wordpen;
@@ -419,7 +417,8 @@ void Console::draw_console()
// new line
if (*c == '\n' ) {
- lines.push_back(line);
+ render::Text::draw(4, h, line);
+ h += font()->width();
line.clear();
line_length = 0;
// new word
@@ -436,7 +435,8 @@ void Console::draw_console()
if (word_length == width) {
if (line.size()) {
- lines.push_back(line);
+ render::Text::draw(4, h, line);
+ h += font()->width();
line.clear();
line += '^';
line += wordpen;
@@ -456,65 +456,8 @@ void Console::draw_console()
}
}
- current_line++;
- }
-
- float y = video::height*con_height-2*Text::fontheight()-4;
- Text::setcolor('N');
- for (std::deque<std::string>::reverse_iterator rit = lines.rbegin(); (y >= 4) && (rit != lines.rend()); ++rit) {
- Text::draw(4, y, (*rit));
- y -= Text::fontheight();
- }
-
-
- // draw the console input
- y = video::height*con_height - Text::fontheight() - 4;
- Text::draw(4, y, "^B>");
-
- std::string firstpart((*history_pos).substr(0, input_pos));
- size_t draw_width = 0;
- const char *c = firstpart.c_str();
-
- while (*c) {
- if (aux::is_color_code(c)) {
- c++;
- } else {
- draw_width++;
- }
- c++;
- }
-
- c = firstpart.c_str();
- while (*c && draw_width > width - 2) {
- if (aux::is_color_code(c)) {
- c++;
- Text::setcolor(*c);
- } else {
- draw_width--;
- }
- c++;
- }
-
- if (*c) {
- Text::draw(4+Text::fontwidth(), y, c);
- }
-
- if (input_pos < (*history_pos).size()) {
- // FIXME limit to width
- if (input_pos > 1 && aux::is_color_code((*history_pos).c_str() + input_pos -1)) {
- Text::setcolor((*history_pos)[input_pos]);
- }
- c = (*history_pos).c_str() + input_pos;
- Text::draw(4+Text::fontwidth()*(draw_width+1), y, c);
- }
-
- // draw cursor
- if ((core::application()->time() - ::floorf(core::application()->time())) < 0.5f) {
- std::string cursor("^B");
- cursor += (char) 11;
- Text::draw(4+Text::fontwidth()*(draw_width+1), y , cursor);
+ n = (n+1) % MAXNOTIFYLINES;
}
-
}
@@ -534,6 +477,7 @@ void Console::notify(std::string const & message)
notify_time[notify_pos] = core::application()->time();
notify_pos = (notify_pos+1) % MAXNOTIFYLINES;
}
+*/
} // namespace client
diff --git a/src/client/console.h b/src/client/console.h
index e280e9d..4b2df20 100644
--- a/src/client/console.h
+++ b/src/client/console.h
@@ -8,35 +8,31 @@
#define __INCLUDED_CLIENT_CONSOLE_H__
#include "sys/consoleinterface.h"
+#include "ui/window.h"
+#include "ui/input.h"
namespace client {
-const size_t MAXNOTIFYLINES = 5;
-const size_t MAXHISTOLINES = 512;
+/* -- class ConsoleBuffer ------------------------------------------ */
-/// client console implementation
-class Console : public sys::ConsoleInterface {
+/// client console buffer
+/** stores incoming console messages
+ */
+class ConsoleBuffer : public sys::ConsoleInterface {
public:
- Console();
- virtual ~Console();
-
- /// add notification
- void notify(std::string const &message);
-
- /// clear notifications
- void clear_notify();
-
- /// draw client notifications or console text
- void draw(bool draw_ui_notifications);
+ ConsoleBuffer();
+ ~ConsoleBuffer();
+};
- /// toggle the console on or off
- void toggle();
+/* -- class Console ------------------------------------------------ */
- /// handle keyboard input
- void keypressed(unsigned int key);
+/// client system console widget
+class Console : public ui::Window {
+public:
+ typedef std::deque<std::string> Text;
- /// true of the console is visible
- inline bool visible() { return console_visible; }
+ Console(Widget *parent);
+ virtual ~Console();
/// load input history
void load_history();
@@ -44,37 +40,40 @@ public:
/// save input history
void save_history();
- /// clear console
- void clear();
+ /// show console
+ virtual void show();
- /// initialize client console
- static void init();
+ /// hide console
+ virtual void hide();
- /// shutdown the client console
- static void shutdown();
+ void toggle();
protected:
- void draw_console();
+ /// draw event
+ virtual void event_draw();
- void draw_notify();
+ /// draw the client console text
+ virtual void draw();
+
+ /// handle keypress events
+ virtual bool on_keypress(const int key, const unsigned int modifier);
private:
- // notifications
- size_t notify_pos;
- std::string notify_text[MAXNOTIFYLINES];
- float notify_time[MAXNOTIFYLINES];
+ inline Text & log() { return con_buffer.log(); }
// input history
- std::deque<std::string> history;
- std::deque<std::string>::reverse_iterator history_pos;
- size_t input_pos;
+ Text history;
+ Text::reverse_iterator history_pos;
- bool console_visible;
+ // scroll position
size_t console_scroll;
-};
+ // input widget
+ ui::Input *console_input;
-Console *console();
+ // console buffer
+ static ConsoleBuffer con_buffer;
+};
}
diff --git a/src/client/input.cc b/src/client/input.cc
index 22fd1c0..a72999e 100644
--- a/src/client/input.cc
+++ b/src/client/input.cc
@@ -133,11 +133,6 @@ void func_ui_control(std::string const &args)
audio::play("ui/control");
}
-void func_ui_console(std::string const &args)
-{
- console()->toggle();
-}
-
void func_view_next(std::string const &args)
{
if (core::application()->connected() && core::localcontrol()) {
@@ -268,12 +263,6 @@ void init()
input_mousedelay->set_info("[int] mouse click time-out in milliseconds");
core::Func *func = 0;
- func = core::Func::add("ui_console", func_ui_console);
- func->set_info("toggle console on or off");
-
- //func = core::Func::add("ui_chat", func_ui_chat);
- //func->set_info("toggle chatbox on or of");
-
func = core::Func::add("ui_control",func_ui_control);
func->set_info("toggle mouse control");
@@ -323,9 +312,7 @@ void shutdown()
core::Func::remove("screenshot");
- core::Func::remove("ui_console");
- //core::Func::remove("ui_control");
- //core::Func::remove("ui_chat");
+ core::Func::remove("ui_control");
core::Func::remove("ui_view");
keyboard->save_binds();
@@ -489,38 +476,8 @@ Key::Modifier convert_SDL_modifier(int const sdlmodifier)
void key_pressed(Key *key)
{
- ui::root()->input_key(true, Keyboard::translate_keysym(key->sym(), keyboard_modifiers), keyboard_modifiers);
-
- if (key->sym() == SDLK_ESCAPE) {
-
- if (console()->visible()) {
- console()->toggle();
- local_direction = 0.0f;
- local_pitch = 0.0f;
- local_roll = 0.0f;
-
- render::Camera::set_direction(0.0f);
- render::Camera::set_pitch(0.0f);
-
- } else {
- if (ui::root()->active()) {
- ui::root()->hide_menu();
- local_direction = 0.0f;
- local_pitch = 0.0f;
- local_roll = 0.0f;
-
- render::Camera::set_direction(0.0f);
- render::Camera::set_pitch(0.0f);
- } else {
- if (core::application()->connected()) {
- ui::root()->show_menu("game");
- } else {
- ui::root()->show_menu("main");
- }
- }
- }
-
- } else if (key->bind(Key::None).compare("ui_console") == 0) {
+ if (key->bind(Key::None).compare("ui_console") == 0) {
+ // FIXME bah
local_direction = 0.0f;
local_pitch = 0.0f;
local_roll = 0.0f;
@@ -528,21 +485,11 @@ void key_pressed(Key *key)
render::Camera::set_direction(0.0f);
render::Camera::set_pitch(0.0f);
- console()->toggle();
+ client()->console()->toggle();
- } else if (console()->visible()) {
- // send key events to the console
- if (key->sym() < 512)
- console()->keypressed(Keyboard::translate_keysym(key->sym(), keyboard_modifiers));
+ } else if (ui::root()->input_key(true, Keyboard::translate_keysym(key->sym(), keyboard_modifiers), keyboard_modifiers)) {
+ return;
- } else if (ui::root()->active()) {
-/* ui::root()->input_key(true, key->sym(), keyboard_modifiers);
-*/
-/* } else if (chat::visible()) {
- // send key events to the chat box
- if (key->sym() < 512)
- chat::keypressed(translate_keysym(key->sym(), keyboard_modifiers));
-*/
} else if (core::application()->connected() && core::localcontrol()) {
char c = key->bind(convert_SDL_modifier(keyboard_modifiers)).c_str()[0];
@@ -553,6 +500,7 @@ void key_pressed(Key *key)
// normal bind
core::cmd() << key->bind(convert_SDL_modifier(keyboard_modifiers)) << "\n";
}
+
} else if (core::application()->connected()) {
char c = key->bind(convert_SDL_modifier(keyboard_modifiers)).c_str()[0];
@@ -561,7 +509,6 @@ void key_pressed(Key *key)
core::cmd() << key->bind(convert_SDL_modifier(keyboard_modifiers)) << "\n";
}
}
-
}
void key_released(Key *key)
@@ -813,7 +760,7 @@ void frame(float seconds)
mouse_deadzone = false;
if (core::application()->connected() && core::localcontrol()) {
- mouse_control = !console()->visible() && ((input_mousecontrol->value() > 0) || (mouse_control_override && (mouse_control_override_time + (input_mousedelay->value() / 1000.0f) < core::application()->time())));
+ mouse_control = client()->console()->hidden() && !ui::root()->active() && ((input_mousecontrol->value() > 0) || (mouse_control_override && (mouse_control_override_time + (input_mousedelay->value() / 1000.0f) < core::application()->time())));
if (mouse_control && joystick_control && ((render::Camera::mode() == render::Camera::Track) || (render::Camera::mode() == render::Camera::Cockpit))) {
if (!(mouse_control_override && (mouse_control_override_time + (input_mousedelay->value() / 1000.0f) < core::application()->time()))) {
diff --git a/src/client/view.cc b/src/client/view.cc
index 463d254..a8d9c4f 100644
--- a/src/client/view.cc
+++ b/src/client/view.cc
@@ -243,12 +243,6 @@ void View::draw()
} else {
view_center->set_visible(false);
}
-
- if (!ui::root()->active() && !has_input_focus()) {
- set_focus();
- }
-
-
}
/* -- namespace view ----------------------------------------------- */
@@ -628,7 +622,7 @@ void draw_hud()
void draw_cursor()
{
- if (console()->visible())
+ if (client()->console()->visible())
return;
float angle = 0;
@@ -731,9 +725,6 @@ void frame(float elapsed)
{
using namespace render;
- // flush console messages
- console()->flush();
-
// Clear the color and depth buffers.
gl::clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@@ -778,11 +769,7 @@ void frame(float elapsed)
draw_cursor();
}
- // draw console or notifications
- Text::setfont("gui", 12, 18);
-
- console()->draw((bool) draw_ui->value());
-
+
gl::disable(GL_TEXTURE_2D);
gl::disable(GL_BLEND);
}