From b417df720584c101f3799874a0c836a543a8d0a8 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 12 Oct 2008 14:55:10 +0000 Subject: user interface updates, work-in-progress --- src/client/chat.cc | 202 ++++++++++++++++++------------------------------- src/client/chat.h | 46 ++++++----- src/client/client.cc | 28 ++++--- src/client/client.h | 6 ++ src/client/console.cc | 2 +- src/client/input.cc | 61 ++++++++------- src/client/keyboard.cc | 21 ++--- src/client/keyboard.h | 8 +- src/client/video.cc | 148 +++++------------------------------- src/client/video.h | 25 +++--- src/client/view.cc | 170 ++++++++++++++--------------------------- src/client/view.h | 9 ++- 12 files changed, 266 insertions(+), 460 deletions(-) (limited to 'src/client') diff --git a/src/client/chat.cc b/src/client/chat.cc index 6f63a6d..bdeebe2 100644 --- a/src/client/chat.cc +++ b/src/client/chat.cc @@ -5,129 +5,86 @@ */ #include "auxiliary/functions.h" -#include "core/core.h" #include "client/chat.h" +#include "client/client.h" #include "client/console.h" -#include "client/keyboard.h" -#include "client/video.h" +#include "core/core.h" #include "render/render.h" +#include "sys/sys.h" +#include "ui/ui.h" namespace client { -namespace chat { - -// input history -std::deque history; -std::deque::reverse_iterator history_pos; -size_t input_pos = 0; - -// chatbox visibility -bool chat_visible = false; - -//--- public ------------------------------------------------------ - -void init() +Chat::Chat(ui::Widget *parent) : ui::Widget(parent) { - // add engine functions + set_label("chat"); history.clear(); history.push_back(""); history_pos = history.rbegin(); - input_pos = 0; + + chat_label = new ui::Label(this, "^BSay^F:^B"); + chat_label->set_alignment(ui::AlignLeft | ui::AlignVCenter); + + chat_input = new ui::Input(this); + chat_input->set_border(true); + + chat_input->set_focus(); + + set_background(true); + set_visible(false); } -void shutdown() +Chat::~Chat() { history.clear(); - input_pos = 0; } -bool visible() -{ - return chat_visible; -} -void draw() +void Chat::show() { - using namespace render; - - if (console()->visible() || !visible()) - return; + Widget::show(); - size_t width = (size_t) (video::width / Text::fontwidth()) - 8; - float y = video::height*8/10; - Text::draw(4, y, "^BSay^F:^B "); + raise(); + set_focus(); - 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+5*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+5), y, c); - } + history_pos = history.rbegin(); + (*history_pos).clear(); + chat_input->set_text((*history_pos)); +} - // 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+5), y , cursor); - } +void Chat::toggle() +{ + if (visible()) + hide(); + else + show(); } -void toggle() +void Chat::resize() { - chat_visible = !chat_visible; - if (chat_visible) { - input_pos = 0; - history_pos = history.rbegin(); - (*history_pos).clear(); - } + chat_label->set_location(font()->width(), height() / 5.0f); + chat_label->set_size(width() - font()->width() * 2, height() / 5.0f); - setkeyboardmode(console()->visible() || (core::application()->connected() && chat::visible())); + chat_input->set_location(font()->width(), height() / 5.0f * 3.0f); + chat_input->set_size(width() - font()->width() * 2, height() / 5.0f); } -void keypressed(unsigned int key) +bool Chat::on_keypress(const int key, const unsigned int modifier) { - std::deque::reverse_iterator upit; + History::reverse_iterator upit; switch( key ) { case SDLK_ESCAPE: - toggle(); - break; + if (visible()) { + hide(); + return true; + } else { + return false; + } + case SDLK_RETURN: + if (chat_input->text().size()) { + (*history_pos).assign(chat_input->text()); - case SDLK_TAB: - core::CommandBuffer::complete( (*history_pos), input_pos); - break; - case SDLK_RETURN: - if ((*history_pos).size()) { // store input into history while (history.size() >= MAXHISTOLINES) { history.pop_front(); @@ -142,61 +99,46 @@ void keypressed(unsigned int key) history.push_back(""); history_pos = history.rbegin(); - input_pos = 0; + chat_input->set_text((*history_pos)); } - toggle(); + + hide(); + return true; break; + case SDLK_UP: upit = history_pos; ++upit; if (upit != history.rend()) { history_pos = upit; - input_pos = (*history_pos).size(); + chat_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--; - } - break; - default: - if ((key >= 32 ) && (key <175)) { - if (input_pos == (*history_pos).size()) - (*history_pos) += (char)key; - else - (*history_pos).insert(input_pos, 1, (char)key); - input_pos++; + chat_input->set_text((*history_pos)); } + return true; break; } -} + return false; } +void Chat::event_draw() +{ + if (!client()->connected()) { + hide(); + return; + } + + if (ui::root()->active()) + return; + else + Widget::event_draw(); } + +} // namespace client diff --git a/src/client/chat.h b/src/client/chat.h index fdf4c70..0bef2b4 100644 --- a/src/client/chat.h +++ b/src/client/chat.h @@ -7,35 +7,43 @@ #ifndef __INCLUDED_CLIENT_CHAT_H__ #define __INCLUDED_CLIENT_CHAT_H__ -#include "sys/consoleinterface.h" - #include #include -namespace client { +#include "ui/input.h" +#include "ui/label.h" +#include "ui/window.h" -/// the client chatbox -namespace chat { +namespace client { -/// initialize chatbox functions -void init(); +class Chat : public ui::Widget +{ +public: + Chat(ui::Widget *parent = 0); + ~Chat(); -/// shut down chatbox functions -void shutdown(); + virtual void show(); + void toggle(); -/// draw the chatbox -void draw(); +protected: + virtual void event_draw(); + virtual void resize(); + + virtual bool on_keypress(const int key, const unsigned int modifier); + -/// toggle the chatbox -void toggle(); +private: + ui::Label *chat_label; + ui::Input *chat_input; + + typedef std::deque History; + + History history; + History::reverse_iterator history_pos; +}; -/// handle keyboard input -void keypressed(unsigned int key); -/// true of the console is visible -bool visible(); -} +} // namespace client -} #endif // __INCLUDED_CLIENT_CHAT_H__ diff --git a/src/client/client.cc b/src/client/client.cc index 3f368a7..ac4c0e3 100644 --- a/src/client/client.cc +++ b/src/client/client.cc @@ -12,7 +12,6 @@ #include "audio/audio.h" #include "audio/sources.h" -#include "client/chat.h" #include "client/client.h" #include "client/video.h" #include "client/console.h" @@ -52,6 +51,13 @@ void func_r_restart(std::string const &args) video::restart(); } +void func_ui_chat(std::string const &args) +{ + if (core::application()->connected()) { + client()->view()->chat()->toggle(); + } +} + //--- public ------------------------------------------------------ void client_main(int count, char **arguments) @@ -108,16 +114,13 @@ void Client::init(int count, char **arguments) // initialize user interface ui::init(); - new View(ui::root()); + client_view = new View(ui::root()); // Initialize the video subsystem if (!video::init()) { quit(1); } - // initialize console - chat::init(); - // initialize input input::init(); @@ -129,9 +132,12 @@ void Client::init(int count, char **arguments) func = core::Func::add("r_restart", (core::FuncPtr) func_r_restart); func->set_info("restart render subsystem"); + + func = core::Func::add("ui_chat", func_ui_chat); + func->set_info("toggle chat window"); - func = core::Func::add("snd_restart", (core::FuncPtr) func_snd_restart); - func->set_info("restart audio subsystem"); + //func = core::Func::add("snd_restart", (core::FuncPtr) func_snd_restart); + //func->set_info("restart audio subsystem"); } void Client::run() @@ -215,10 +221,8 @@ void Client::shutdown() if (connected()) disconnect(); core::Func::remove("r_restart"); - - core::Func::remove("snd_restart"); - - chat::shutdown(); + core::Func::remove("ui_chat"); + //core::Func::remove("snd_restart"); audio::shutdown(); @@ -245,8 +249,8 @@ void Client::notify_connect() void Client::notify_disconnect() { // FIXME unload sounds - //audio::reset(); render::reset(); + input::reset(); } void Client::notify_zonechange() diff --git a/src/client/client.h b/src/client/client.h index bd7af6b..dc70e16 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/view.h" /// client part of the engine namespace client { @@ -46,10 +47,15 @@ public: /// disconnect notification virtual void notify_disconnect(); + /// the main client view + inline View *view() { return client_view; } + protected: /// run a client frame virtual void frame(float seconds); +private: + View *client_view; }; diff --git a/src/client/console.cc b/src/client/console.cc index 96da900..47f95f7 100644 --- a/src/client/console.cc +++ b/src/client/console.cc @@ -92,7 +92,7 @@ void Console::toggle() SDL_ShowCursor(SDL_DISABLE); } - setkeyboardmode(console()->visible() || (core::application()->connected() && chat::visible())); + //setkeyboardmode(console()->visible() || (core::application()->connected() && chat::visible())); audio::play("ui/console"); } diff --git a/src/client/input.cc b/src/client/input.cc index d2a53e1..d2c290b 100644 --- a/src/client/input.cc +++ b/src/client/input.cc @@ -108,7 +108,7 @@ float joystick_lastmoved_time() void func_screenshot(std::string const & args) { - video::screenshot(); + render::screenshot(); } void func_ui_control(std::string const &args) @@ -138,13 +138,6 @@ void func_ui_console(std::string const &args) console()->toggle(); } -void func_ui_chat(std::string const &args) -{ - if (core::application()->connected()) { - chat::toggle(); - } -} - void func_view_next(std::string const &args) { if (core::application()->connected() && core::localcontrol()) { @@ -256,8 +249,6 @@ void init() keyboard = new Keyboard(); - client::setkeyboardmode(false); - SDL_ShowCursor(SDL_DISABLE); SDL_WM_GrabInput(SDL_GRAB_ON); // SDL_EnableUNICODE(1); @@ -280,8 +271,8 @@ void init() 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_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"); @@ -333,8 +324,8 @@ 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_chat"); core::Func::remove("ui_view"); keyboard->save_binds(); @@ -498,21 +489,37 @@ 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 (chat::visible()) { - chat::toggle(); - } else { + + 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); - console()->toggle(); + } else { + if (ui::root()->active()) { + ui::root()->hide_window(); + 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_window("game"); + } else { + ui::root()->show_window("main"); + } + } } - + } else if (key->bind(Key::None).compare("ui_console") == 0) { local_direction = 0.0f; local_pitch = 0.0f; @@ -526,16 +533,16 @@ void key_pressed(Key *key) } else if (console()->visible()) { // send key events to the console if (key->sym() < 512) - console()->keypressed(translate_keysym(key->sym(), keyboard_modifiers)); + console()->keypressed(Keyboard::translate_keysym(key->sym(), keyboard_modifiers)); } else if (ui::root()->active()) { - ui::root()->input_key(true, key->sym(), keyboard_modifiers); - - } else if (chat::visible()) { +/* 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]; @@ -559,9 +566,7 @@ void key_pressed(Key *key) void key_released(Key *key) { - if (ui::root()->active()) { - ui::root()->input_key(false, key->sym(), keyboard_modifiers); - } + ui::root()->input_key(false, Keyboard::translate_keysym(key->sym(), keyboard_modifiers), keyboard_modifiers); if (core::application()->connected() && core::localcontrol()) { diff --git a/src/client/keyboard.cc b/src/client/keyboard.cc index b420fb8..80e0d5c 100644 --- a/src/client/keyboard.cc +++ b/src/client/keyboard.cc @@ -515,16 +515,7 @@ void Keyboard::list_binds() con_print << n << " registered binds" << std::endl; } -void setkeyboardmode(bool input) -{ - /* if(input) - SDL_EnableKeyRepeat(250, SDL_DEFAULT_REPEAT_INTERVAL); - else - SDL_EnableKeyRepeat(10, SDL_DEFAULT_REPEAT_INTERVAL); - */ -} - -unsigned int translate_keysym(int keysym, int modifier) +unsigned int Keyboard::translate_keysym(int keysym, int modifier) { bool shift = false; @@ -715,4 +706,14 @@ unsigned int translate_keysym(int keysym, int modifier) return keysym; } +/* +void setkeyboardmode(bool input) +{ + if(input) + SDL_EnableKeyRepeat(250, SDL_DEFAULT_REPEAT_INTERVAL); + else + SDL_EnableKeyRepeat(10, SDL_DEFAULT_REPEAT_INTERVAL); + +} +*/ } // namespace client diff --git a/src/client/keyboard.h b/src/client/keyboard.h index 87a67c4..f63bce1 100644 --- a/src/client/keyboard.h +++ b/src/client/keyboard.h @@ -69,6 +69,9 @@ public: inline iterator end() { return keys.end(); } + /// convert SDL_keysym to a keystroke + static unsigned int translate_keysym(int keysym, int modifier); + private: Key *add_key(const char *name, const unsigned int keysym, const char ascii=0, const char *bind=0); @@ -81,13 +84,10 @@ private: bool capslock; }; -/// convert SDL_keysym to a keystroke -unsigned int translate_keysym(int keysym, int modifier); - /// set the keyboard input mode /** @param input true for console input, false for game input */ -void setkeyboardmode(bool input); +//void setkeyboardmode(bool input); } diff --git a/src/client/video.cc b/src/client/video.cc index 123bd88..7338d70 100644 --- a/src/client/video.cc +++ b/src/client/video.cc @@ -4,10 +4,6 @@ the terms and conditions of the GNU General Public License version 2 */ -#include -#include - -#include "auxiliary/functions.h" #include "client/video.h" #include "client/input.h" #include "client/view.h" @@ -38,49 +34,15 @@ int height = 0; int width_prev = 0; int height_prev = 0; -int screenshot_number = 0; - const int width_default = 1024; const int height_default = 768; -//--- cvars ------------------------------------------------------- +/* -- engine variables --------------------------------------------- */ core::Cvar *r_width; core::Cvar *r_height; core::Cvar *r_fullscreen; -core::Cvar *screenshotformat; -core::Cvar *screenshotquality; - -void restart() -{ - shutdown(); - - if (!init()) { - client()->quit(1); - } - - input::reset(); -} - -void reset() -{ - // setup our viewport. - gl::viewport(0, 0, width, height ); - - // recalculate the video aspect - render::Camera::set_aspect(width, height); - - // resize user interface - if (ui::root()) { - ui::root()->set_size((float) width, (float) height); - ui::root()->event_resize(); - } - - // reset the view - view::reset(); -} - bool init() { con_print << "^BInitializing video..." << std::endl; @@ -95,12 +57,6 @@ bool init() r_fullscreen = core::Cvar::get("r_fullscreen", "0", core::Cvar::Archive); r_fullscreen->set_info("[bool] enable or disable fullscreen video"); - screenshotformat = core::Cvar::get("screenshotformat", "jpg", core::Cvar::Archive); - screenshotformat->set_info("[string] screenshot format: jpg png tga"); - - screenshotquality = core::Cvar::get("screenshotquality", "85", core::Cvar::Archive); - screenshotquality->set_info("[int] screenshot jpg quality"); - int bpp = 0; int flags = 0; @@ -162,7 +118,7 @@ bool init() } else return false; } - con_print << " video mode " << width << "x" << height << "x" << bpp << "bpp" << std::endl; + con_print << " video mode " << width << "x" << height << "x" << bpp << "bpp " << (fullscreen ? "fullscreen " : "window") << std::endl; #ifdef HAVE_DEBUG_MESSAGES @@ -178,24 +134,40 @@ bool init() #endif // HAVE_DEBUG_MESSAGES - render::Camera::set_aspect(width, height); + // save r_width and r_height variables (*r_width) = width; (*r_height) = height; + // set window caption std::string version(core::name()); version += ' '; version.append(core::version()); SDL_WM_SetCaption(version.c_str(), 0); - render::init(); + // resize user interface + ui::root()->set_size((float) width, (float) height); + ui::root()->event_resize(); - video::reset(); + // initialize renderer + render::Camera::resize(width, height); + render::init(); + render::Camera::resize(width, height); // yes twice, bug view::init(); return true; } +void restart() +{ + shutdown(); + if (!init()) { + client()->quit(1); + } + + input::reset(); +} + void frame(float seconds) { // detect fullscreen/windowed mode switch @@ -222,84 +194,6 @@ void shutdown() SDL_QuitSubSystem(SDL_INIT_VIDEO); } -void screenshot() -{ - bool available = false; - std::string shortname; - std::string filename; - const int TYPETGA = 0; - const int TYPEPNG = 1; - const int TYPEJPG = 2; - int filetype = TYPETGA; - - // make sure the screenshots folder exists - filename.assign(filesystem::writedir()); - filename.append("screenshots/"); - sys::mkdir(filename); - - aux::lowercase(screenshotformat->str()); - - if ((screenshotformat->str().compare("jpg") == 0) || (screenshotformat->str().compare("jpeg") == 0)) { - filetype = TYPEJPG; - if (screenshotquality->value() < 10) { - (*screenshotquality) = 10; - } else if (screenshotquality->value() > 100) { - (*screenshotquality) = 100; - } - - } else if (screenshotformat->str().compare("png") == 0) { - filetype = TYPEPNG; - - } else if (screenshotformat->str().compare("tga") == 0) { - filetype = TYPETGA; - - } else { - filetype = TYPETGA; - (*screenshotformat) = "tga"; - } - - // find the first available screenshotxxxx - do { - std::stringstream nstr; - nstr << screenshot_number; - shortname.assign(nstr.str()); - - while(shortname.size() < 4) - shortname.insert(0, 1, '0'); - - shortname.insert(0, "screenshots/osirion"); - shortname.append("."); - shortname.append(screenshotformat->str()); - - filename.assign(filesystem::writedir()); - filename.append(shortname); - - FILE *handle = fopen(filename.c_str(), "r"); - if (handle) { - fclose(handle); - } else { - available = true; - } - screenshot_number++; - } while (!available); - - render::Image image((unsigned int)video::width, (unsigned int)video::height, 3); - - glReadPixels(0, 0, (GLsizei) video::width, (GLsizei) video::height, - GL_RGB, GL_UNSIGNED_BYTE, (void *) image.data()); - - image.flip(); - - if (filetype == TYPEPNG) { - render::PNG::save(filename.c_str(), image); - } else if (filetype == TYPEJPG) { - render::JPG::save(filename.c_str(), image, (int) screenshotquality->value()); - } else if (filetype == TYPETGA) { - render::TGA::save(filename.c_str(), image); - } -} - - } // namespace video } // namespace client diff --git a/src/client/video.h b/src/client/video.h index 59939e6..daa136c 100644 --- a/src/client/video.h +++ b/src/client/video.h @@ -9,31 +9,28 @@ namespace client { -/// the client video subsystem +/// the video subsystem namespace video { - /// initialize the client video subsystem + /// initialize the video subsystem bool init(); - /// shutdown the client video subsystem + /// shutdown the video subsystem void shutdown(); - /// draw the next client video frame - void frame(float seconds); - - /// reset and clear the viewport - void reset(); - - /// restart the video subsystem + /// re-initialize the video subsystems + /** the restart functions performs a full shutdown + * and re-initializes the video subsystem + */ void restart(); - /// make a screenshot - void screenshot(); + /// draw the next client video frame + void frame(float seconds); - /// width of the window in pixels + /// width of the application window in pixels extern int width; - /// height of the window in pixels + /// height of the application window in pixels extern int height; } // namespace video diff --git a/src/client/view.cc b/src/client/view.cc index 15f70bc..463d254 100644 --- a/src/client/view.cc +++ b/src/client/view.cc @@ -38,6 +38,15 @@ core::Cvar *draw_keypress = 0; core::Cvar *ui_pointercolor = 0; core::Cvar *ui_pointerhovercolor = 0; +const float pointer_size = 48.0f; + +void time_to_stream(std::stringstream &str, float time) +{ + int minutes = (int) floorf(time / 60.0f); + int seconds = (int) floorf( time - (float) minutes* 60.0f); + str << std::setfill(' ') << std::setw(4) << minutes << ":" << std::setfill('0') << std::setw(2) << seconds; +} + /* -- DevInfo------------------------------------------------------- */ DevInfo::DevInfo(ui::Widget *parent) : ui::Widget(parent) @@ -54,24 +63,27 @@ void DevInfo::draw() core::Entity *target = targets::current(); float d = 0; - textstream << "^Ntime: ^B" << std::fixed << std::setprecision(4) << client()->time() << '\n'; + textstream << "^Ncore ^B"; + time_to_stream(textstream, core::application()->time()); + textstream << '\n'; if (core::game()) { - textstream << "^Ngame: ^B" << core::game()->time(); + textstream << "^Ntime ^B"; + time_to_stream(textstream, core::game()->time()); } textstream << '\n'; if (core::localcontrol()) { textstream << std::fixed << std::setprecision(2) - << "^Nx:^B" << core::localcontrol()->location().x << " " - << "^Ny:^B" << core::localcontrol()->location().y << " " - << "^Nz:^B" << core::localcontrol()->location().z << '\n'; + << "^Nx ^B" << core::localcontrol()->location().x << " " + << "^Ny ^B" << core::localcontrol()->location().y << " " + << "^Nz ^B" << core::localcontrol()->location().z << '\n'; - textstream << "^Nthurst:^B " << core::localcontrol()->thrust() << " " - << "^Nspeed:^B " << core::localcontrol()->speed() << '\n'; + textstream << "^Nthurst ^B" << core::localcontrol()->thrust() << " " + << "^Nspeed ^B" << core::localcontrol()->speed() << '\n'; if (target) { d = math::distance(core::localcontrol()->location(), target->state()->location()) - target->radius() - core::localcontrol()->radius(); - textstream << "^Ndist:^B " << d << '\n'; + textstream << "^Ndist ^B" << d << '\n'; } } @@ -114,10 +126,8 @@ void Stats::draw() std::stringstream textstream; if (core::game()) { - int minutes = (int) floorf(core::game()->clientframetime() / 60.0f); - int seconds = (int) floorf( core::game()->clientframetime() - (float) minutes* 60.0f); - - textstream << "^Ntime ^B" << std::setfill(' ') << std::setw(3) << minutes << ":" << std::setfill('0') << std::setw(2) << seconds; + textstream << "^Ntime ^B"; + time_to_stream(textstream, core::game()->clientframetime()); } textstream << std::setfill(' ') << "\n"; @@ -183,10 +193,13 @@ View::View(ui::Widget *parent) : ui::Widget(parent) draw_keypress->set_info("[bool] draw keypress key names"); // add child widgets + view_center = new ui::Bitmap(this, "pointers/center"); view_devinfo = new DevInfo(this); view_stats = new Stats(this); view_keypress = new KeyPress(this); + view_chat = new Chat(this); + // make sure the view is at the bottom of the draw stack lower(); } @@ -195,6 +208,10 @@ void View::resize() { set_size(parent()->size()); + // reposition chat widget + view_chat->set_size(font()->width()*64, font()->height()*5); + view_chat->set_location(font()->width() * 0.5f, height() *0.5f); + // reposition devinfo widget view_devinfo->set_size(font()->width()*32, font()->height()*5); view_devinfo->set_location(font()->width() * 0.5f, font()->height() * 0.5f); @@ -207,6 +224,11 @@ void View::resize() view_keypress->set_size(font()->width()*12, font()->height()*1); view_keypress->set_location(width() - view_keypress->width() - font()->width() * 0.5, height() - view_keypress->height() - font()->height() * 0.5f); + + // reposition center + view_center->set_size(pointer_size, pointer_size); + view_center->set_location((size() - view_center->size()) * 0.5f); + view_center->set_color(palette()->pointer()); } void View::draw() @@ -214,8 +236,19 @@ void View::draw() view_devinfo->set_visible(draw_devinfo->value() ? true : false); view_stats->set_visible(draw_stats->value() ? true : false); view_keypress->set_visible(draw_keypress->value() ? true : false); + + if (core::localcontrol() && (input::mouse_control || input::joystick_control) && + (render::Camera::mode() == render::Camera::Cockpit || render::Camera::mode() == render::Camera::Track)) { + view_center->set_visible(true); + } else { + view_center->set_visible(false); + } + + if (!ui::root()->active() && !has_input_focus()) { + set_focus(); + } + - //draw_world(); } /* -- namespace view ----------------------------------------------- */ @@ -599,7 +632,7 @@ void draw_cursor() return; float angle = 0; - const float pointer_size = 48.0f; + float x = (float) input::mouse_position_x() - (pointer_size / 2.0f); float y = (float) input::mouse_position_y() - (pointer_size / 2.0f); bool cursor_animated = false; @@ -614,37 +647,6 @@ void draw_cursor() render::Textures::bind("bitmaps/pointers/aim"); } else { - // draw center cursor in Cockpit and Track mode - if ((input::mouse_control || input::joystick_control) && - (render::Camera::mode() == render::Camera::Cockpit || render::Camera::mode() == render::Camera::Track)) { - - if (ui_pointercolor) { - std::stringstream colorstr(ui_pointercolor->str()); - colorstr >> color; - } - - render::Textures::bind("bitmaps/pointers/center"); - float cx = (video::width - pointer_size) /2; - float cy = (video::height - pointer_size) /2; - - render::gl::color(color); - render::gl::begin(render::gl::Quads); - - glTexCoord2f(0,0 ); - render::gl::vertex(cx,cy,0.0f); - - glTexCoord2f(1, 0); - render::gl::vertex(cx+pointer_size, cy, 0.0f); - - glTexCoord2f(1, 1); - render::gl::vertex(cx+pointer_size, cy+pointer_size, 0.0f); - - glTexCoord2f(0, 1); - render::gl::vertex(cx, cy+pointer_size, 0.0f); - - render::gl::end(); - } - if (targets::hover()) { if (ui_pointerhovercolor) { @@ -725,63 +727,7 @@ void draw_cursor() } } -void reset() -{ - using namespace render; - - // set clear color - gl::clearcolor(0.0f, 0.0f, 0.0f, 1.0f); - - // load identity matrices - gl::matrixmode(GL_MODELVIEW); - gl::loadidentity(); - - gl::matrixmode(GL_MODELVIEW); - gl::loadidentity(); - - // shading model: Gouraud (smooth, the default) - gl::shademodel(GL_SMOOTH); - //gl::shademodel(GL_FLAT); - - // lighting settings for the default light GL_LIGHT0 - GLfloat light_position[] = { 0.0, 0.0, 0.0, 1.0 }; - GLfloat ambient_light[] = { 0.01f, 0.01f, 0.01f, 1.0f }; - GLfloat diffuse_light[] = { 0.2f, 0.2f, 0.2f, 1.0f }; - GLfloat specular_light[] = { 0.2f, 0.2f, 0.2f, 1.0f }; - - glLightfv(GL_LIGHT0, GL_POSITION, light_position); - glLightfv(GL_LIGHT0, GL_AMBIENT, ambient_light); - glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse_light); - glLightfv(GL_LIGHT0, GL_SPECULAR, specular_light); - - // GL_LIGHT0 is always enabled - gl::enable(GL_LIGHT0); - - // color tracking - glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); - - // material settings - GLfloat specular_reflectance[] = { 0.2f, 0.2f, 0.2f, 1.0f }; - glMaterialfv(GL_FRONT, GL_SPECULAR, specular_reflectance); - glMateriali(GL_FRONT, GL_SHININESS, 128); // shininess 1-128 - - // alpha blending function - gl::blendfunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - gl::disable(GL_LIGHTING); - gl::disable(GL_COLOR_MATERIAL); - - gl::cullface(GL_BACK); - gl::frontface(GL_CCW); - gl::disable(GL_CULL_FACE); - gl::disable(GL_DEPTH_TEST); - gl::disable(GL_BLEND); - - gl::disable(GL_TEXTURE_2D); - -} - -void frame(float seconds) +void frame(float elapsed) { using namespace render; @@ -793,22 +739,21 @@ void frame(float seconds) render::Stats::clear(); - if (core::application()->connected() && core::game()->serverframetime()) { + if (core::application()->connected() && core::game()->serverframetime() && core::localplayer()->zone()) { + render::Camera::frame(elapsed); + render::Camera::frustum(); - render::draw(seconds); // draw the world + render::draw(elapsed); // draw the world targets::draw(); // validate current target, render sound if (targets::current()) // draw target docks etc draw_entity_world_target(targets::current()); - } - // switch to orthographic projection to draw the GUI - gl::matrixmode(GL_PROJECTION); - gl::loadidentity(); - glOrtho(0, video::width, video::height, 0, -16.0f, 16.0f); + render::Camera::ortho(); - gl::matrixmode(GL_MODELVIEW); - gl::loadidentity(); + } else { + render::Camera::ortho(); + } // draw the user interface gl::color(1.0f, 1.0f, 1.0f, 1.0f); @@ -829,9 +774,6 @@ void frame(float seconds) // draw the hud draw_hud(); - // draw the chat box - chat::draw(); - // draw the mouse cursor draw_cursor(); } diff --git a/src/client/view.h b/src/client/view.h index e5e42bc..dbbd7be 100644 --- a/src/client/view.h +++ b/src/client/view.h @@ -7,7 +7,9 @@ #define __INCLUDED_CLIENT_VIEW_H__ #include "core/zone.h" +#include "client/chat.h" #include "ui/widget.h" +#include "ui/bitmap.h" namespace client { @@ -68,14 +70,19 @@ class View : public ui::Widget public: View(ui::Widget *parent=0); + inline Chat *chat() { return view_chat; } + protected: virtual void draw(); + virtual void resize(); private: + Chat *view_chat; DevInfo *view_devinfo; Stats *view_stats; KeyPress *view_keypress; + ui::Bitmap *view_center; }; /// functions to draw the client view @@ -88,7 +95,7 @@ namespace view void shutdown(); /// draw the next frame - void frame(float seconds); + void frame(float elapsed); /// reset OpenGL state void reset(); -- cgit v1.2.3