]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/game.cpp
Right mouse button behaviour for craft/inventory If right mousebutton clicked once...
[dragonfireclient.git] / src / game.cpp
index 2c969b931ba176f996b17bcaf5ef44e4da490ecb..aa12e6c3f479b41ba07a57120ed7ea3ee99ab37b 100644 (file)
@@ -70,6 +70,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "util/pointedthing.h"
 #include "drawscene.h"
 #include "content_cao.h"
+#include "fontengine.h"
 
 #ifdef HAVE_TOUCHSCREENGUI
 #include "touchscreengui.h"
@@ -437,9 +438,8 @@ PointedThing getPointedThing(Client *client, v3f player_position,
 
 /* Profiler display */
 
-void update_profiler_gui(gui::IGUIStaticText *guitext_profiler,
-               gui::IGUIFont *font, u32 text_height, u32 show_profiler,
-               u32 show_profiler_max)
+void update_profiler_gui(gui::IGUIStaticText *guitext_profiler, FontEngine *fe,
+               u32 show_profiler, u32 show_profiler_max)
 {
        if (show_profiler == 0) {
                guitext_profiler->setVisible(false);
@@ -451,14 +451,14 @@ void update_profiler_gui(gui::IGUIStaticText *guitext_profiler,
                guitext_profiler->setText(text.c_str());
                guitext_profiler->setVisible(true);
 
-               s32 w = font->getDimension(text.c_str()).Width;
+               s32 w = fe->getTextWidth(text.c_str());
 
                if (w < 400)
                        w = 400;
 
-               core::rect<s32> rect(6, 4 + (text_height + 5) * 2, 12 + w,
-                                    8 + (text_height + 5) * 2 +
-                                    font->getDimension(text.c_str()).Height);
+               core::rect<s32> rect(6, 4 + (fe->getTextHeight() + 5) * 2, 12 + w,
+                                    8 + (fe->getTextHeight() + 5) * 2 +
+                                    fe->getTextHeight());
                guitext_profiler->setRelativePosition(rect);
                guitext_profiler->setVisible(true);
        }
@@ -967,6 +967,7 @@ bool nodePlacementPrediction(Client &client,
                        // Dont place node when player would be inside new node
                        // NOTE: This is to be eventually implemented by a mod as client-side Lua
                        if (!nodedef->get(n).walkable ||
+                                       g_settings->getBool("enable_build_where_you_stand") ||
                                        (client.checkPrivilege("noclip") && g_settings->getBool("noclip")) ||
                                        (nodedef->get(n).walkable &&
                                         neighbourpos != player->getStandingNodePos() + v3s16(0, 1, 0) &&
@@ -1135,8 +1136,7 @@ static void show_pause_menu(GUIFormSpecMenu **cur_formspec,
 /******************************************************************************/
 static void updateChat(Client &client, f32 dtime, bool show_debug,
                const v2u32 &screensize, bool show_chat, u32 show_profiler,
-               ChatBackend &chat_backend, gui::IGUIStaticText *guitext_chat,
-               gui::IGUIFont *font)
+               ChatBackend &chat_backend, gui::IGUIStaticText *guitext_chat)
 {
        // Add chat log output for errors to be shown in chat
        static LogOutputBuffer chat_log_error_buf(LMT_ERROR);
@@ -1159,9 +1159,7 @@ static void updateChat(Client &client, f32 dtime, bool show_debug,
        // Display all messages in a static text element
        unsigned int recent_chat_count = chat_backend.getRecentBuffer().getLineCount();
        std::wstring recent_chat       = chat_backend.getRecentChat();
-
-       // TODO replace by fontengine fcts
-       unsigned int line_height       = font->getDimension(L"Ay").Height + font->getKerningHeight();
+       unsigned int line_height       = g_fontengine->getLineHeight();
 
        guitext_chat->setText(recent_chat.c_str());
 
@@ -1172,7 +1170,7 @@ static void updateChat(Client &client, f32 dtime, bool show_debug,
                chat_y += line_height;
 
        // first pass to calculate height of text to be set
-       s32 width = std::min(font->getDimension(recent_chat.c_str()).Width + 10,
+       s32 width = std::min(g_fontengine->getTextWidth(recent_chat) + 10,
                             porting::getWindowSize().X - 20);
        core::rect<s32> rect(10, chat_y, width, chat_y + porting::getWindowSize().Y);
        guitext_chat->setRelativePosition(rect);
@@ -1401,7 +1399,6 @@ class Game
                        bool random_input,
                        InputHandler *input,
                        IrrlichtDevice *device,
-                       gui::IGUIFont *font,
                        const std::string &map_dir,
                        const std::string &playername,
                        const std::string &password,
@@ -1521,8 +1518,6 @@ class Game
        Client *client;
        Server *server;
 
-       gui::IGUIFont *font;
-
        IWritableTextureSource *texture_src;
        IWritableShaderSource *shader_src;
 
@@ -1557,7 +1552,6 @@ class Game
        IrrlichtDevice *device;
        video::IVideoDriver *driver;
        scene::ISceneManager *smgr;
-       u32 text_height;
        bool *kill;
        std::wstring *error_message;
        IGameDef *gamedef;                     // Convenience (same as *client)
@@ -1591,7 +1585,6 @@ class Game
 Game::Game() :
        client(NULL),
        server(NULL),
-       font(NULL),
        texture_src(NULL),
        shader_src(NULL),
        itemdef_manager(NULL),
@@ -1647,7 +1640,6 @@ bool Game::startup(bool *kill,
                bool random_input,
                InputHandler *input,
                IrrlichtDevice *device,
-               gui::IGUIFont *font,
                const std::string &map_dir,
                const std::string &playername,
                const std::string &password,
@@ -1660,7 +1652,6 @@ bool Game::startup(bool *kill,
 {
        // "cache"
        this->device        = device;
-       this->font          = font;
        this->kill          = kill;
        this->error_message = error_message;
        this->random_input  = random_input;
@@ -1670,7 +1661,6 @@ bool Game::startup(bool *kill,
 
        driver              = device->getVideoDriver();
        smgr                = device->getSceneManager();
-       text_height         = font->getDimension(L"Random test string").Height;
 
        if (!init(map_dir, address, port, gamespec))
                return false;
@@ -1933,7 +1923,7 @@ bool Game::createClient(const std::string &playername,
        }
 
        // Update cached textures, meshes and materials
-       client->afterContentReceived(device, font);
+       client->afterContentReceived(device, g_fontengine->getFont());
 
        /* Camera
         */
@@ -1991,8 +1981,7 @@ bool Game::createClient(const std::string &playername,
        player->hurt_tilt_timer = 0;
        player->hurt_tilt_strength = 0;
 
-       hud = new Hud(driver, smgr, guienv, font, text_height, gamedef,
-                       player, local_inventory);
+       hud = new Hud(driver, smgr, guienv, gamedef, player, local_inventory);
 
        if (!hud) {
                *error_message = L"Memory error: could not create HUD";
@@ -2021,7 +2010,7 @@ bool Game::initGui(std::wstring *error_message)
        // Object infos are shown in this
        guitext_info = guienv->addStaticText(
                        L"",
-                       core::rect<s32>(0, 0, 400, text_height * 5 + 5) + v2s32(100, 200),
+                       core::rect<s32>(0, 0, 400, g_fontengine->getTextHeight() * 5 + 5) + v2s32(100, 200),
                        false, true, guiroot);
 
        // Status text (displays info when showing and hiding GUI stuff, etc.)
@@ -2061,7 +2050,7 @@ bool Game::initGui(std::wstring *error_message)
 #ifdef HAVE_TOUCHSCREENGUI
 
        if (g_touchscreengui)
-               g_touchscreengui->init(tsrc, porting::getDisplayDensity());
+               g_touchscreengui->init(texture_src, porting::getDisplayDensity());
 
 #endif
 
@@ -2103,9 +2092,11 @@ bool Game::connectToServer(const std::string &playername,
                return false;
        }
 
-       client = new Client(device, playername.c_str(), password, *draw_control,
-                   texture_src, shader_src, itemdef_manager, nodedef_manager, sound,
-                       eventmgr, connect_address.isIPv6());
+       client = new Client(device,
+                       playername.c_str(), password, simple_singleplayer_mode,
+                       *draw_control, texture_src, shader_src,
+                       itemdef_manager, nodedef_manager, sound, eventmgr,
+                       connect_address.isIPv6());
 
        if (!client)
                return false;
@@ -2221,12 +2212,12 @@ bool Game::getServerContent(bool *aborted)
                if (!client->itemdefReceived()) {
                        wchar_t *text = wgettext("Item definitions...");
                        progress = 0;
-                       draw_load_screen(text, device, guienv, font, dtime, progress);
+                       draw_load_screen(text, device, guienv, dtime, progress);
                        delete[] text;
                } else if (!client->nodedefReceived()) {
                        wchar_t *text = wgettext("Node definitions...");
                        progress = 25;
-                       draw_load_screen(text, device, guienv, font, dtime, progress);
+                       draw_load_screen(text, device, guienv, dtime, progress);
                        delete[] text;
                } else {
                        std::stringstream message;
@@ -2248,7 +2239,7 @@ bool Game::getServerContent(bool *aborted)
 
                        progress = 50 + client->mediaReceiveProgress() * 50 + 0.5;
                        draw_load_screen(narrow_to_wide(message.str().c_str()), device,
-                                       guienv, font, dtime, progress);
+                                       guienv, dtime, progress);
                }
        }
 
@@ -2350,7 +2341,7 @@ void Game::updateProfilers(const GameRunData &run_data, const RunStats &stats,
                        g_profiler->print(infostream);
                }
 
-               update_profiler_gui(guitext_profiler, font, text_height,
+               update_profiler_gui(guitext_profiler, g_fontengine,
                                run_data.profiler_current_page, run_data.profiler_max_page);
 
                g_profiler->clear();
@@ -2706,7 +2697,8 @@ void Game::toggleHud(float *statustext_time, bool *flag)
        *flag = !*flag;
        *statustext_time = 0;
        statustext = msg[*flag];
-       client->setHighlighted(client->getHighlighted(), *flag);
+       if (g_settings->getBool("enable_node_highlighting"))
+               client->setHighlighted(client->getHighlighted(), *flag);
 }
 
 
@@ -2761,8 +2753,8 @@ void Game::toggleProfiler(float *statustext_time, u32 *profiler_current_page,
        *profiler_current_page = (*profiler_current_page + 1) % (profiler_max_page + 1);
 
        // FIXME: This updates the profiler with incomplete values
-       update_profiler_gui(guitext_profiler, font, text_height,
-                           *profiler_current_page, profiler_max_page);
+       update_profiler_gui(guitext_profiler, g_fontengine, *profiler_current_page,
+                       profiler_max_page);
 
        if (*profiler_current_page != 0) {
                std::wstringstream sstr;
@@ -2852,8 +2844,8 @@ void Game::updateCameraDirection(CameraOrientation *cam,
 #ifdef HAVE_TOUCHSCREENGUI
 
                if (g_touchscreengui) {
-                       camera_yaw   = g_touchscreengui->getYaw();
-                       camera_pitch = g_touchscreengui->getPitch();
+                       cam->camera_yaw   = g_touchscreengui->getYaw();
+                       cam->camera_pitch = g_touchscreengui->getPitch();
                } else {
 #endif
                        s32 dx = input->getMousePos().X - (driver->getScreenSize().Width / 2);
@@ -3802,7 +3794,7 @@ void Game::updateFrame(std::vector<aabb3f> &highlight_boxes,
 
        updateChat(*client, dtime, flags.show_debug, screensize,
                        flags.show_chat, runData->profiler_current_page,
-                       *chat_backend, guitext_chat, font);
+                       *chat_backend, guitext_chat);
 
        /*
                Inventory
@@ -3880,7 +3872,7 @@ void Game::updateFrame(std::vector<aabb3f> &highlight_boxes,
                Profiler graph
        */
        if (flags.show_profiler_graph)
-               graph->draw(10, screensize.Y - 10, driver, font);
+               graph->draw(10, screensize.Y - 10, driver, g_fontengine->getFont());
 
        /*
                Damage flash
@@ -3963,7 +3955,7 @@ void Game::updateGui(float *statustext_time, const RunStats& stats,
        if (guitext->isVisible()) {
                core::rect<s32> rect(
                                5,              5,
-                               screensize.X,   5 + text_height
+                               screensize.X,   5 + g_fontengine->getTextHeight()
                );
                guitext->setRelativePosition(rect);
        }
@@ -3981,8 +3973,8 @@ void Game::updateGui(float *statustext_time, const RunStats& stats,
                guitext2->setVisible(true);
 
                core::rect<s32> rect(
-                               5,             5 + text_height,
-                               screensize.X,  5 + text_height * 2
+                               5,             5 + g_fontengine->getTextHeight(),
+                               screensize.X,  5 + g_fontengine->getTextHeight() * 2
                );
                guitext2->setRelativePosition(rect);
        } else {
@@ -4093,7 +4085,7 @@ void Game::showOverlayMessage(const char *msg, float dtime,
                int percent, bool draw_clouds)
 {
        wchar_t *text = wgettext(msg);
-       draw_load_screen(text, device, guienv, font, dtime, percent, draw_clouds);
+       draw_load_screen(text, device, guienv, dtime, percent, draw_clouds);
        delete[] text;
 }
 
@@ -4133,7 +4125,6 @@ void the_game(bool *kill,
                bool random_input,
                InputHandler *input,
                IrrlichtDevice *device,
-               gui::IGUIFont *font,
 
                const std::string &map_dir,
                const std::string &playername,
@@ -4156,7 +4147,7 @@ void the_game(bool *kill,
 
        try {
 
-               if (game.startup(kill, random_input, input, device, font, map_dir,
+               if (game.startup(kill, random_input, input, device, map_dir,
                                        playername, password, &server_address, port,
                                        &error_message, &chat_backend, gamespec,
                                        simple_singleplayer_mode)) {