Get the GUI2 in-game UI at least appearing

I decided to go with a modular approach, where both in-game and editor UI dialogs inherit
from a single base class, a pointer of which is owned by the display class. That can be
used for common functionality that needs be shared by all in-game dialogs.

Right now the new UI is just static. It works with most stuff, but not key presses. Working
on that...
This commit is contained in:
Charles Dang 2018-03-20 04:47:08 +11:00
parent b2d3da4a1e
commit 075a9bac34
15 changed files with 141 additions and 37 deletions

View file

@ -411,7 +411,7 @@
[background]
[draw]
#ifdef 0
[image]
x = 0
y = 0
@ -422,7 +422,7 @@
name = "terrain/off-map/background.png"
resize_mode = "tile"
[/image]
#endif
[/draw]
[/background]

View file

@ -1742,6 +1742,13 @@
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Test_Debug|Win32'">$(IntDir)Gui\Dialogs\</ObjectFileName>
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Test_Release|Win32'">$(IntDir)Gui\Dialogs\</ObjectFileName>
</ClCompile>
<ClCompile Include="..\..\src\gui\dialogs\ingame_ui_base.cpp">
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(IntDir)Gui\Dialogs\</ObjectFileName>
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='ReleaseDEBUG|Win32'">$(IntDir)Gui\Dialogs\</ObjectFileName>
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Test_Debug|Win32'">$(IntDir)Gui\Dialogs\</ObjectFileName>
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(IntDir)Gui\Dialogs\</ObjectFileName>
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Test_Release|Win32'">$(IntDir)Gui\Dialogs\</ObjectFileName>
</ClCompile>
<ClCompile Include="..\..\src\gui\dialogs\label_settings.cpp">
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(IntDir)Gui\Dialogs\</ObjectFileName>
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='ReleaseDEBUG|Win32'">$(IntDir)Gui\Dialogs\</ObjectFileName>
@ -3785,6 +3792,7 @@
<ClInclude Include="..\..\src\gui\dialogs\game_version.hpp" />
<ClInclude Include="..\..\src\gui\dialogs\help_browser.hpp" />
<ClInclude Include="..\..\src\gui\dialogs\hotkey_bind.hpp" />
<ClInclude Include="..\..\src\gui\dialogs\ingame_ui_base.hpp" />
<ClInclude Include="..\..\src\gui\dialogs\label_settings.hpp" />
<ClInclude Include="..\..\src\gui\dialogs\language_selection.hpp" />
<ClInclude Include="..\..\src\gui\dialogs\loading_screen.hpp" />

View file

@ -1562,6 +1562,9 @@
<ClCompile Include="..\..\src\gui\dialogs\game_ui.cpp">
<Filter>Gui\Dialogs</Filter>
</ClCompile>
<ClCompile Include="..\..\src\gui\dialogs\ingame_ui_base.cpp">
<Filter>Gui\Dialogs</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\src\addon\client.hpp">
@ -3033,6 +3036,9 @@
<ClInclude Include="..\..\src\gui\dialogs\game_ui.hpp">
<Filter>Gui\Dialogs</Filter>
</ClInclude>
<ClInclude Include="..\..\src\gui\dialogs\ingame_ui_base.hpp">
<Filter>Gui\Dialogs</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="..\..\src\tests\test_sdl_utils.hpp">

View file

@ -201,6 +201,7 @@ gui/dialogs/game_version.cpp
gui/dialogs/gamestate_inspector.cpp
gui/dialogs/help_browser.cpp
gui/dialogs/hotkey_bind.cpp
gui/dialogs/ingame_ui_base.cpp
gui/dialogs/label_settings.cpp
gui/dialogs/language_selection.cpp
gui/dialogs/loading_screen.cpp

View file

@ -30,6 +30,7 @@
#include "language.hpp"
#include "log.hpp"
#include "font/marked-up_text.hpp"
#include "gui/dialogs/ingame_ui_base.hpp"
#include "map/map.hpp"
#include "map/label.hpp"
#include "minimap.hpp"
@ -147,6 +148,7 @@ display::display(const display_context * dc, std::weak_ptr<wb::manager> wb, repo
, wb_(wb)
, exclusive_unit_draw_requests_()
, video_(CVideo::get_singleton())
, ui_(nullptr)
, currentTeam_(0)
, dont_show_all_(false)
, xpos_(0)
@ -2631,8 +2633,8 @@ void display::draw()
pre_draw();
// Draw theme background.
const SDL_Rect outside_area = map_outside_area();
draw_background(outside_area, theme_.border().background_image);
//const SDL_Rect outside_area = map_outside_area();
//draw_background(outside_area, theme_.border().background_image);
// Progress animations.
invalidate_animations();

View file

@ -78,9 +78,19 @@ class manager;
class gamemap;
namespace gui2
{
namespace dialogs
{
class ingame_ui_base;
}
}
class display : public events::sdl_handler
{
public:
using ui_t = gui2::dialogs::ingame_ui_base;
display(const display_context* dc,
std::weak_ptr<wb::manager> wb,
reports& reports_object,
@ -865,6 +875,12 @@ protected:
/** Draws the minimap. */
void draw_minimap();
public:
virtual void initialize_ui()
{
}
private:
enum TERRAIN_TYPE { FOREGROUND, BACKGROUND };
@ -990,6 +1006,9 @@ protected:
exclusive_unit_draw_requests_t exclusive_unit_draw_requests_;
CVideo& video_;
std::unique_ptr<ui_t> ui_;
std::size_t currentTeam_;
bool dont_show_all_; // const team *viewpoint_;
int xpos_, ypos_;

View file

@ -598,7 +598,7 @@ void pump()
global_handler->handle_event(event);
}
if(event_contexts.empty() == false) {
if(event_contexts.size() > 1) {
for(auto handler : event_contexts.back().handlers) {
handler->handle_event(event);
}

View file

@ -28,6 +28,7 @@
#include "font/standard_colors.hpp"
#include "game_board.hpp"
#include "gettext.hpp"
#include "gui/dialogs/game_ui.hpp"
#include "halo.hpp"
#include "log.hpp"
#include "map/label.hpp"
@ -78,6 +79,7 @@ game_display::game_display(game_board& board, std::weak_ptr<wb::manager> wb,
#else
video().clear_screen();
#endif
}
game_display::~game_display()
@ -89,6 +91,15 @@ game_display::~game_display()
}
}
void game_display::initialize_ui()
{
// Set member in the base class
ui_.reset(new gui2::dialogs::game_ui());
assert(ui_);
ui_->show(true);
}
void game_display::new_turn()
{
const time_of_day& tod = resources::tod_manager->get_time_of_day();

View file

@ -145,7 +145,9 @@ protected:
virtual void draw_hex_cursor(const map_location& loc) override;
virtual void draw_hex_overlays() override;
public:
virtual void initialize_ui() override;
/** Set the attack direction indicator. */
void set_attack_indicator(const map_location& src, const map_location& dst);

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 2017 by Charles Dang <exodia339@gmail.com>
Copyright (C) 2017-2018 by Charles Dang <exodia339@gmail.com>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
@ -17,6 +17,7 @@
#include "gui/dialogs/game_ui.hpp"
#include "gui/auxiliary/find_widget.hpp"
#include "gui/dialogs/modal_dialog.hpp"
#include "gui/widgets/label.hpp"
#include "gui/widgets/minimap.hpp"
#include "gui/widgets/settings.hpp"
@ -34,9 +35,7 @@ namespace dialogs
REGISTER_DIALOG(game_ui)
game_ui::game_ui()
: disp_(display::get_singleton())
, game_config_(game_config_manager::get()->game_config())
, scenario_(game_config_.child("scenario"))
: ingame_ui_base()
{
}
@ -48,9 +47,5 @@ void game_ui::pre_show(window& window)
mmap.set_map_data(scenario_["map_data"].str());
}
void game_ui::post_show(window& /*window*/)
{
}
} // namespace dialogs
} // namespace gui2

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 2017 by Charles Dang <exodia339@gmail.com>
Copyright (C) 2017-2018 by Charles Dang <exodia339@gmail.com>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
@ -14,40 +14,23 @@
#pragma once
#include "gui/dialogs/modal_dialog.hpp"
class config;
class CVideo;
class display;
#include "gui/dialogs/ingame_ui_base.hpp"
namespace gui2
{
namespace dialogs
{
class game_ui : public modal_dialog
class game_ui : public ingame_ui_base
{
public:
game_ui();
DEFINE_SIMPLE_DISPLAY_WRAPPER(game_ui)
private:
/** Inherited from modal_dialog, implemented by REGISTER_DIALOG. */
virtual const std::string& window_id() const override;
/** Inherited from modal_dialog. */
virtual void pre_show(window& window) override;
/** Inherited from modal_dialog. */
virtual void post_show(window& window) override;
::display* disp_; // TODO: needed?
/** Reference to the entire master game config object. */
const config& game_config_;
/** Reference to the current scenario's config. */
const config& scenario_;
};
} // namespace dialogs

View file

@ -0,0 +1,35 @@
/*
Copyright (C) 2018 by Charles Dang <exodia339@gmail.com>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#define GETTEXT_DOMAIN "wesnoth-lib"
#include "gui/dialogs/ingame_ui_base.hpp"
#include "display.hpp"
#include "game_config_manager.hpp"
#include "gettext.hpp"
namespace gui2
{
namespace dialogs
{
ingame_ui_base::ingame_ui_base()
: disp_(display::get_singleton())
, game_config_(game_config_manager::get()->game_config())
, scenario_(game_config_.child("scenario"))
{
}
} // namespace dialogs
} // namespace gui2

View file

@ -0,0 +1,45 @@
/*
Copyright (C) 2018 by Charles Dang <exodia339@gmail.com>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#pragma once
#include "gui/dialogs/modeless_dialog.hpp"
class config;
class display;
namespace gui2
{
namespace dialogs
{
/**
* Base dialog class intended for in-game UIs for the main game and editor.
*/
class ingame_ui_base : public modeless_dialog
{
public:
ingame_ui_base();
protected:
::display* disp_; // TODO: needed?
/** Reference to the entire master game config object. */
const config& game_config_;
/** Reference to the current scenario's config. */
const config& scenario_;
};
} // namespace dialogs
} // namespace gui2

View file

@ -289,6 +289,7 @@ void play_controller::init(const config& level)
});
//Do this after the loadingscreen, so that ita happens in the main thread.
gui_->join();
gui_->initialize_ui();
}
void play_controller::reset_gamestate(const config& level, int replay_pos)

View file

@ -28,7 +28,6 @@
#include "game_events/pump.hpp"
#include "preferences/game.hpp"
#include "gettext.hpp"
#include "gui/dialogs/game_ui.hpp"
#include "gui/dialogs/story_viewer.hpp"
#include "gui/dialogs/transient_message.hpp"
#include "hotkey/hotkey_handler_sp.hpp"
@ -241,9 +240,6 @@ LEVEL_RESULT playsingle_controller::play_scenario(const config& level)
}
}
// FIXME
//gui2::dialogs::game_ui::display(gui_->video());
gui_->labels().read(level);
// Read sound sources