Skip to content

Commit 9eb72c5

Browse files
committed
Create C++ backend GUI code
1 parent 1a34c69 commit 9eb72c5

30 files changed

+2164
-11
lines changed

src/client/client.h

+1
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
204204
void handleCommand_InventoryFormSpec(NetworkPacket* pkt);
205205
void handleCommand_DetachedInventory(NetworkPacket* pkt);
206206
void handleCommand_ShowFormSpec(NetworkPacket* pkt);
207+
void handleCommand_UiMessage(NetworkPacket* pkt);
207208
void handleCommand_SpawnParticle(NetworkPacket* pkt);
208209
void handleCommand_AddParticleSpawner(NetworkPacket* pkt);
209210
void handleCommand_DeleteParticleSpawner(NetworkPacket* pkt);

src/client/clientevent.h

+5
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ enum ClientEventType : u8
3737
CE_DEATHSCREEN,
3838
CE_SHOW_FORMSPEC,
3939
CE_SHOW_LOCAL_FORMSPEC,
40+
CE_UI_MESSAGE,
4041
CE_SPAWN_PARTICLE,
4142
CE_ADD_PARTICLESPAWNER,
4243
CE_DELETE_PARTICLESPAWNER,
@@ -106,6 +107,10 @@ struct ClientEvent
106107
std::string *formspec;
107108
std::string *formname;
108109
} show_formspec;
110+
struct
111+
{
112+
std::string *data;
113+
} ui_message;
109114
// struct{
110115
//} textures_updated;
111116
ParticleParameters *spawn_particle;

src/client/game.cpp

+23-1
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"
@@ -908,6 +909,7 @@ class Game {
908909
void handleClientEvent_Deathscreen(ClientEvent *event, CameraOrientation *cam);
909910
void handleClientEvent_ShowFormSpec(ClientEvent *event, CameraOrientation *cam);
910911
void handleClientEvent_ShowLocalFormSpec(ClientEvent *event, CameraOrientation *cam);
912+
void handleClientEvent_UiMessage(ClientEvent *event, CameraOrientation *cam);
911913
void handleClientEvent_HandleParticleEvent(ClientEvent *event,
912914
CameraOrientation *cam);
913915
void handleClientEvent_HudAdd(ClientEvent *event, CameraOrientation *cam);
@@ -956,6 +958,7 @@ class Game {
956958

957959
std::unique_ptr<GameUI> m_game_ui;
958960
GUIChatConsole *gui_chat_console = nullptr; // Free using ->Drop()
961+
ui::GUIManagerElem *gui_manager_elem = nullptr; // Free using ->Drop()
959962
MapDrawControl *draw_control = nullptr;
960963
Camera *camera = nullptr;
961964
Clouds *clouds = nullptr; // Free using ->Drop()
@@ -1311,6 +1314,8 @@ void Game::shutdown()
13111314
if (formspec)
13121315
formspec->quitMenu();
13131316

1317+
ui::g_manager.reset();
1318+
13141319
// Clear text when exiting.
13151320
m_game_ui->clearText();
13161321

@@ -1325,6 +1330,8 @@ void Game::shutdown()
13251330

13261331
if (gui_chat_console)
13271332
gui_chat_console->drop();
1333+
if (gui_manager_elem)
1334+
gui_manager_elem->drop();
13281335

13291336
if (sky)
13301337
sky->drop();
@@ -1560,6 +1567,8 @@ bool Game::createClient(const GameStartData &start_data)
15601567
if (mapper && client->modsLoaded())
15611568
client->getScript()->on_minimap_ready(mapper);
15621569

1570+
ui::g_manager.setClient(client);
1571+
15631572
return true;
15641573
}
15651574

@@ -1577,6 +1586,9 @@ bool Game::initGui()
15771586
gui_chat_console = new GUIChatConsole(guienv, guienv->getRootGUIElement(),
15781587
-1, chat_backend, client, &g_menumgr);
15791588

1589+
// Thingy to draw UI manager after chat but before formspecs.
1590+
gui_manager_elem = new ui::GUIManagerElem(guienv, guiroot, -1);
1591+
15801592
#ifdef HAVE_TOUCHSCREENGUI
15811593
if (g_touchscreengui)
15821594
g_touchscreengui->init(texture_src);
@@ -2819,6 +2831,7 @@ const ClientEventHandler Game::clientEventHandler[CLIENTEVENT_MAX] = {
28192831
{&Game::handleClientEvent_Deathscreen},
28202832
{&Game::handleClientEvent_ShowFormSpec},
28212833
{&Game::handleClientEvent_ShowLocalFormSpec},
2834+
{&Game::handleClientEvent_UiMessage},
28222835
{&Game::handleClientEvent_HandleParticleEvent},
28232836
{&Game::handleClientEvent_HandleParticleEvent},
28242837
{&Game::handleClientEvent_HandleParticleEvent},
@@ -2924,6 +2937,14 @@ void Game::handleClientEvent_ShowLocalFormSpec(ClientEvent *event, CameraOrienta
29242937
delete event->show_formspec.formname;
29252938
}
29262939

2940+
void Game::handleClientEvent_UiMessage(ClientEvent *event, CameraOrientation *cam)
2941+
{
2942+
std::istringstream is(*event->ui_message.data, std::ios_base::binary);
2943+
ui::g_manager.read(is);
2944+
2945+
delete event->ui_message.data;
2946+
}
2947+
29272948
void Game::handleClientEvent_HandleParticleEvent(ClientEvent *event,
29282949
CameraOrientation *cam)
29292950
{
@@ -4301,7 +4322,8 @@ void Game::drawScene(ProfilerGraph *graph, RunStats *stats)
43014322
draw_crosshair = false;
43024323
#endif
43034324
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);
4325+
this->m_game_ui->m_flags.show_chat, this->m_game_ui->m_flags.show_minimap,
4326+
draw_wield_tool, draw_crosshair);
43054327

43064328
/*
43074329
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

+16
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,9 @@ void Draw3D::run(PipelineContext &context)
4344

4445
void DrawWield::run(PipelineContext &context)
4546
{
47+
ui::g_manager.preDraw();
48+
ui::g_manager.drawType(ui::WindowType::BG);
49+
4650
if (m_target)
4751
m_target->activate(context);
4852

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

6165
if (context.draw_crosshair)
6266
context.hud->drawCrosshair();
67+
}
6368

69+
ui::g_manager.drawType(ui::WindowType::MASK);
70+
71+
if (context.show_hud) {
6472
context.hud->drawHotbar(context.client->getEnv().getLocalPlayer()->getWieldIndex());
73+
6574
context.hud->drawLuaElements(context.client->getCamera()->getOffset());
75+
ui::g_manager.drawType(ui::WindowType::HUD);
76+
6677
context.client->getCamera()->drawNametags();
6778
auto mapper = context.client->getMinimap();
6879
if (mapper && context.show_minimap)
6980
mapper->drawMinimap();
7081
}
82+
83+
if (context.show_chat)
84+
ui::g_manager.drawType(ui::WindowType::MESSAGE);
85+
7186
context.device->getGUIEnvironment()->drawAll();
87+
ui::g_manager.drawType(ui::WindowType::FG);
7288
}
7389

7490

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

+6
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,11 @@ 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}/texture.cpp
37+
${CMAKE_CURRENT_SOURCE_DIR}/window.cpp
3238
${extra_gui_SRCS}
3339
PARENT_SCOPE
3440
)

0 commit comments

Comments
 (0)