Skip to content

Commit 451127f

Browse files
committed
Create C++ backend GUI code
1 parent 1a34c69 commit 451127f

25 files changed

+2818
-16
lines changed

src/client/game.cpp

+17-2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
5050
#include "gui/guiPasswordChange.h"
5151
#include "gui/guiVolumeChange.h"
5252
#include "gui/mainmenumanager.h"
53+
#include "gui/manager.h"
5354
#include "gui/profilergraph.h"
5455
#include "mapblock.h"
5556
#include "minimap.h"
@@ -956,6 +957,7 @@ class Game {
956957

957958
std::unique_ptr<GameUI> m_game_ui;
958959
GUIChatConsole *gui_chat_console = nullptr; // Free using ->Drop()
960+
ui::GUIManagerElem *gui_manager_elem = nullptr; // Free using ->Drop()
959961
MapDrawControl *draw_control = nullptr;
960962
Camera *camera = nullptr;
961963
Clouds *clouds = nullptr; // Free using ->Drop()
@@ -1311,6 +1313,8 @@ void Game::shutdown()
13111313
if (formspec)
13121314
formspec->quitMenu();
13131315

1316+
ui::g_manager.reset();
1317+
13141318
// Clear text when exiting.
13151319
m_game_ui->clearText();
13161320

@@ -1325,6 +1329,8 @@ void Game::shutdown()
13251329

13261330
if (gui_chat_console)
13271331
gui_chat_console->drop();
1332+
if (gui_manager_elem)
1333+
gui_manager_elem->drop();
13281334

13291335
if (sky)
13301336
sky->drop();
@@ -1560,6 +1566,8 @@ bool Game::createClient(const GameStartData &start_data)
15601566
if (mapper && client->modsLoaded())
15611567
client->getScript()->on_minimap_ready(mapper);
15621568

1569+
ui::g_manager.setClient(client);
1570+
15631571
return true;
15641572
}
15651573

@@ -1577,6 +1585,9 @@ bool Game::initGui()
15771585
gui_chat_console = new GUIChatConsole(guienv, guienv->getRootGUIElement(),
15781586
-1, chat_backend, client, &g_menumgr);
15791587

1588+
// Thingy to draw UI manager after chat but before formspecs.
1589+
gui_manager_elem = new ui::GUIManagerElem(guienv, guiroot, -1);
1590+
15801591
#ifdef HAVE_TOUCHSCREENGUI
15811592
if (g_touchscreengui)
15821593
g_touchscreengui->init(texture_src);
@@ -2890,7 +2901,10 @@ void Game::handleClientEvent_Deathscreen(ClientEvent *event, CameraOrientation *
28902901

28912902
void Game::handleClientEvent_ShowFormSpec(ClientEvent *event, CameraOrientation *cam)
28922903
{
2893-
if (event->show_formspec.formspec->empty()) {
2904+
if (*event->show_formspec.formname == "__ui__") {
2905+
std::istringstream is(*event->show_formspec.formspec, std::ios_base::binary);
2906+
ui::g_manager.read(is);
2907+
} else if (event->show_formspec.formspec->empty()) {
28942908
auto formspec = m_game_ui->getFormspecGUI();
28952909
if (formspec && (event->show_formspec.formname->empty()
28962910
|| *(event->show_formspec.formname) == m_game_ui->getFormspecName())) {
@@ -4301,7 +4315,8 @@ void Game::drawScene(ProfilerGraph *graph, RunStats *stats)
43014315
draw_crosshair = false;
43024316
#endif
43034317
this->m_rendering_engine->draw_scene(sky_color, this->m_game_ui->m_flags.show_hud,
4304-
this->m_game_ui->m_flags.show_minimap, draw_wield_tool, draw_crosshair);
4318+
this->m_game_ui->m_flags.show_chat, this->m_game_ui->m_flags.show_minimap,
4319+
draw_wield_tool, draw_crosshair);
43054320

43064321
/*
43074322
Profiler graph

src/client/render/core.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ RenderingCore::~RenderingCore()
3636
delete shadow_renderer;
3737
}
3838

39-
void RenderingCore::draw(video::SColor _skycolor, bool _show_hud, bool _show_minimap,
40-
bool _draw_wield_tool, bool _draw_crosshair)
39+
void RenderingCore::draw(video::SColor _skycolor, bool _show_hud, bool _show_chat,
40+
bool _show_minimap, bool _draw_wield_tool, bool _draw_crosshair)
4141
{
4242
v2u32 screensize = device->getVideoDriver()->getScreenSize();
4343
virtual_size = v2u32(screensize.X * virtual_size_scale.X, screensize.Y * virtual_size_scale.Y);
@@ -46,6 +46,7 @@ void RenderingCore::draw(video::SColor _skycolor, bool _show_hud, bool _show_min
4646
context.draw_crosshair = _draw_crosshair;
4747
context.draw_wield_tool = _draw_wield_tool;
4848
context.show_hud = _show_hud;
49+
context.show_chat = _show_chat;
4950
context.show_minimap = _show_minimap;
5051

5152
pipeline->reset(context);
@@ -55,4 +56,4 @@ void RenderingCore::draw(video::SColor _skycolor, bool _show_hud, bool _show_min
5556
v2u32 RenderingCore::getVirtualSize() const
5657
{
5758
return virtual_size;
58-
}
59+
}

src/client/render/core.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ class RenderingCore
5353
RenderingCore &operator=(const RenderingCore &) = delete;
5454
RenderingCore &operator=(RenderingCore &&) = delete;
5555

56-
void draw(video::SColor _skycolor, bool _show_hud, bool _show_minimap,
57-
bool _draw_wield_tool, bool _draw_crosshair);
56+
void draw(video::SColor _skycolor, bool _show_hud, bool _show_chat,
57+
bool _show_minimap, bool _draw_wield_tool, bool _draw_crosshair);
5858

5959
v2u32 getVirtualSize() const;
6060

src/client/render/pipeline.h

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ struct PipelineContext
4646
v2u32 target_size;
4747

4848
bool show_hud {true};
49+
bool show_chat {true};
4950
bool show_minimap {true};
5051
bool draw_wield_tool {true};
5152
bool draw_crosshair {true};

src/client/render/plain.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2626
#include "client/hud.h"
2727
#include "client/minimap.h"
2828
#include "client/shadows/dynamicshadowsrender.h"
29+
#include "gui/manager.h"
2930

3031
/// Draw3D pipeline step
3132
void Draw3D::run(PipelineContext &context)
@@ -43,6 +44,8 @@ void Draw3D::run(PipelineContext &context)
4344

4445
void DrawWield::run(PipelineContext &context)
4546
{
47+
ui::g_manager.drawType(ui::WindowType::BG);
48+
4649
if (m_target)
4750
m_target->activate(context);
4851

@@ -60,15 +63,27 @@ void DrawHUD::run(PipelineContext &context)
6063

6164
if (context.draw_crosshair)
6265
context.hud->drawCrosshair();
66+
}
6367

68+
ui::g_manager.drawType(ui::WindowType::MASK);
69+
70+
if (context.show_hud) {
6471
context.hud->drawHotbar(context.client->getEnv().getLocalPlayer()->getWieldIndex());
72+
6573
context.hud->drawLuaElements(context.client->getCamera()->getOffset());
74+
ui::g_manager.drawType(ui::WindowType::HUD);
75+
6676
context.client->getCamera()->drawNametags();
6777
auto mapper = context.client->getMinimap();
6878
if (mapper && context.show_minimap)
6979
mapper->drawMinimap();
7080
}
81+
82+
if (context.show_chat)
83+
ui::g_manager.drawType(ui::WindowType::MESSAGE);
84+
7185
context.device->getGUIEnvironment()->drawAll();
86+
ui::g_manager.drawType(ui::WindowType::FG);
7287
}
7388

7489

src/client/renderingengine.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -317,10 +317,10 @@ void RenderingEngine::finalize()
317317
core.reset();
318318
}
319319

320-
void RenderingEngine::draw_scene(video::SColor skycolor, bool show_hud,
320+
void RenderingEngine::draw_scene(video::SColor skycolor, bool show_hud, bool show_chat,
321321
bool show_minimap, bool draw_wield_tool, bool draw_crosshair)
322322
{
323-
core->draw(skycolor, show_hud, show_minimap, draw_wield_tool, draw_crosshair);
323+
core->draw(skycolor, show_hud, show_chat, show_minimap, draw_wield_tool, draw_crosshair);
324324
}
325325

326326
const VideoDriverInfo &RenderingEngine::getVideoDriverInfo(irr::video::E_DRIVER_TYPE type)

src/client/renderingengine.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class RenderingEngine
114114
gui::IGUIEnvironment *guienv, ITextureSource *tsrc,
115115
float dtime = 0, int percent = 0, bool sky = true);
116116

117-
void draw_scene(video::SColor skycolor, bool show_hud,
117+
void draw_scene(video::SColor skycolor, bool show_hud, bool show_chat,
118118
bool show_minimap, bool draw_wield_tool, bool draw_crosshair);
119119

120120
void initialize(Client *client, Hud *hud);

src/gui/CMakeLists.txt

+7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ if(ENABLE_TOUCH)
44
endif()
55

66
set(gui_SRCS
7+
${CMAKE_CURRENT_SOURCE_DIR}/box.cpp
8+
${CMAKE_CURRENT_SOURCE_DIR}/elem.cpp
9+
${CMAKE_CURRENT_SOURCE_DIR}/generic_elems.cpp
710
${CMAKE_CURRENT_SOURCE_DIR}/guiAnimatedImage.cpp
811
${CMAKE_CURRENT_SOURCE_DIR}/guiBackgroundImage.cpp
912
${CMAKE_CURRENT_SOURCE_DIR}/guiBox.cpp
@@ -27,8 +30,12 @@ set(gui_SRCS
2730
${CMAKE_CURRENT_SOURCE_DIR}/guiTable.cpp
2831
${CMAKE_CURRENT_SOURCE_DIR}/guiHyperText.cpp
2932
${CMAKE_CURRENT_SOURCE_DIR}/guiVolumeChange.cpp
33+
${CMAKE_CURRENT_SOURCE_DIR}/manager.cpp
3034
${CMAKE_CURRENT_SOURCE_DIR}/modalMenu.cpp
3135
${CMAKE_CURRENT_SOURCE_DIR}/profilergraph.cpp
36+
${CMAKE_CURRENT_SOURCE_DIR}/sizer_elems.cpp
37+
${CMAKE_CURRENT_SOURCE_DIR}/texture.cpp
38+
${CMAKE_CURRENT_SOURCE_DIR}/window.cpp
3239
${extra_gui_SRCS}
3340
PARENT_SCOPE
3441
)

0 commit comments

Comments
 (0)