From ecab22b2c5f227c38540be50cefd71648c1d11b9 Mon Sep 17 00:00:00 2001 From: MaanooAk Date: Fri, 20 Sep 2019 16:45:32 +0300 Subject: [PATCH 01/11] Fps and debug overlay imporve --- libopenage/engine.cpp | 17 ++++++++--------- libopenage/renderer/color.cpp | 3 +++ libopenage/renderer/color.h | 9 +++++++++ libopenage/util/fps.cpp | 4 ++++ libopenage/util/fps.h | 3 +++ libopenage/util/profiler.cpp | 3 ++- 6 files changed, 29 insertions(+), 10 deletions(-) diff --git a/libopenage/engine.cpp b/libopenage/engine.cpp index 72731f3d77..bd345f5d58 100644 --- a/libopenage/engine.cpp +++ b/libopenage/engine.cpp @@ -43,7 +43,7 @@ Engine::Engine(const util::Path &root_dir, : OptionNode{"Engine"}, running{false}, - drawing_debug_overlay{this, "drawing_debug_overlay", true}, + drawing_debug_overlay{this, "drawing_debug_overlay", false}, drawing_huds{this, "drawing_huds", true}, root_dir{root_dir}, job_manager{SDL_GetCPUCount()}, @@ -56,7 +56,6 @@ Engine::Engine(const util::Path &root_dir, profiler{this}, gui_link{} { - if (fps_limit > 0) { this->ns_per_frame = 1e9 / fps_limit; } else { @@ -64,7 +63,7 @@ Engine::Engine(const util::Path &root_dir, } this->font_manager = std::make_unique(); - for (uint32_t size : {12, 20}) { + for (uint32_t size : {12, 14, 20}) { fonts[size] = this->font_manager->get_font("DejaVu Serif", "Book", size); } @@ -272,21 +271,20 @@ bool Engine::on_resize(coord::viewport_delta new_size) { } bool Engine::draw_debug_overlay() { - util::col {255, 255, 255, 255}.use(); // Draw FPS counter in the lower right corner this->render_text( - {this->coord.viewport_size.x - 100, 15}, 20, - "%.1f fps", this->fps_counter.fps + {this->coord.viewport_size.x - 70, 15}, 20, renderer::Colors::WHITE, + "%.0f fps", this->fps_counter.display_fps ); // Draw version string in the lower left corner this->render_text( - {5, 35}, 20, + {5, 35}, 20, renderer::Colors::WHITE, "openage %s", config::version ); this->render_text( - {5, 15}, 12, + {5, 15}, 12, renderer::Colors::WHITE, "%s", config::config_option_string ); @@ -530,7 +528,7 @@ time_nsec_t Engine::lastframe_duration_nsec() const { return this->fps_counter.nsec_lastframe; } -void Engine::render_text(coord::viewport position, size_t size, const char *format, ...) { +void Engine::render_text(coord::viewport position, size_t size, const renderer::Color &color, const char *format, ...) { auto it = this->fonts.find(size); if (it == this->fonts.end()) { throw Error(MSG(err) << "Unknown font size requested: " << size); @@ -545,6 +543,7 @@ void Engine::render_text(coord::viewport position, size_t size, const char *form va_end(vl); this->text_renderer->set_font(font); + this->text_renderer->set_color(color); this->text_renderer->draw(position.x, position.y, buf); } diff --git a/libopenage/renderer/color.cpp b/libopenage/renderer/color.cpp index cac7f9a1ed..a632c01b13 100644 --- a/libopenage/renderer/color.cpp +++ b/libopenage/renderer/color.cpp @@ -31,4 +31,7 @@ bool Color::operator!=(const Color &other) const { return !operator==(other); } +Color Colors::WHITE = {255, 255, 255, 255}; +Color Colors::BLACK = { 0, 0, 0, 255}; + }} // openage::renderer diff --git a/libopenage/renderer/color.h b/libopenage/renderer/color.h index dfd44666b9..23b6ea5f0b 100644 --- a/libopenage/renderer/color.h +++ b/libopenage/renderer/color.h @@ -9,6 +9,7 @@ namespace renderer { class Color { public: + Color(); Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a); @@ -24,4 +25,12 @@ class Color { }; +class Colors { +public: + + static Color WHITE; + static Color BLACK; + +}; + }} // openage::renderer diff --git a/libopenage/util/fps.cpp b/libopenage/util/fps.cpp index 6d5d54f346..594e094acf 100644 --- a/libopenage/util/fps.cpp +++ b/libopenage/util/fps.cpp @@ -42,6 +42,10 @@ void FrameCounter::frame() { fps = 1e9 * this->frame_count_weighted / this->frame_length_sum_weighted; } + if (count % 20 == 0) { + display_fps = fps; + } + count += 1; } diff --git a/libopenage/util/fps.h b/libopenage/util/fps.h index 33eddc3153..e9066f7e17 100644 --- a/libopenage/util/fps.h +++ b/libopenage/util/fps.h @@ -18,6 +18,9 @@ class FrameCounter { /** auto-updated to always contain the current FPS value */ float fps; + /** auto-updated every 20 frames to always contain the current FPS value */ + float display_fps; + /** contains the number of completed frames */ uint64_t count; diff --git a/libopenage/util/profiler.cpp b/libopenage/util/profiler.cpp index e42ba11ede..1ead9b6e67 100644 --- a/libopenage/util/profiler.cpp +++ b/libopenage/util/profiler.cpp @@ -2,6 +2,7 @@ #include "profiler.h" #include "../engine.h" +#include "../renderer/color.h" #include "misc.h" #include @@ -171,7 +172,7 @@ void Profiler::draw_legend() { glColor4f(0.2, 0.2, 0.2, 1); coord::viewport position = coord::viewport{box_x + PROFILER_COM_BOX_WIDTH + 2, box_y + 2}; - this->engine->render_text(position, 12, "%s", com.second.display_name.c_str()); + this->engine->render_text(position, 12, renderer::Colors::WHITE, "%s", com.second.display_name.c_str()); offset += PROFILER_COM_BOX_HEIGHT + 2; } From 59239da34e60e8a6830a80f40ad4bc21d26aa2e8 Mon Sep 17 00:00:00 2001 From: MaanooAk Date: Fri, 20 Sep 2019 16:50:47 +0300 Subject: [PATCH 02/11] Model the unit selected info to qml --- assets/qml/IngameHud.qml | 79 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/assets/qml/IngameHud.qml b/assets/qml/IngameHud.qml index 3375e933b0..971cc4f256 100644 --- a/assets/qml/IngameHud.qml +++ b/assets/qml/IngameHud.qml @@ -230,6 +230,85 @@ Item { anchors.fill: parent tornBottom: false } + + Item { + anchors.fill: parent + id: selection_single_panel + visible: root.actionMode.selection_size == 1 + + Text { + anchors.top: parent.top + anchors.topMargin: metricsUnit * 2 + anchors.left: parent.left + anchors.leftMargin: metricsUnit * 2 + + id: selected_name + + color: "black" + text: root.actionMode.selection_name + font.pointSize: 16 + } + + Text { + anchors.bottom: selected_name.bottom + anchors.left: selected_name.right + anchors.leftMargin: metricsUnit * 1 + + id: selected_type + + color: "black" + opacity: 0.8 + text: root.actionMode.selection_type + } + + Text { + anchors.top: selected_name.bottom + anchors.left: selected_name.left + anchors.topMargin: metricsUnit / 2 + + id: selected_owner + + color: "black" + text: root.actionMode.selection_hp + } + + Text { + anchors.top: selected_owner.bottom + anchors.left: selected_owner.left + anchors.topMargin: metricsUnit * 2 + + color: "black" + text: root.actionMode.selection_attrs + } + + Text { + anchors.top: parent.top + anchors.right: parent.right + anchors.topMargin: metricsUnit * 2 + anchors.rightMargin: metricsUnit * 2 + + color: "black" + text: root.actionMode.selection_owner + } + + } + + Item { + anchors.fill: parent + id: selection_group_panel + visible: root.actionMode.selection_size > 1 + + Text { + anchors.top: parent.top + anchors.topMargin: metricsUnit * 2 + anchors.left: parent.left + anchors.leftMargin: metricsUnit * 2 + + color: "black" + text: root.actionMode.selection_name + font.pointSize: 14 + } + } } } From d7c9b15e6c0859875cfeeafc06a51e5b95acbc35 Mon Sep 17 00:00:00 2001 From: MaanooAk Date: Fri, 20 Sep 2019 16:54:12 +0300 Subject: [PATCH 03/11] Move unit info from overlay to gui --- libopenage/engine.h | 3 +- libopenage/game_control.cpp | 15 ++++++- libopenage/game_control.h | 4 ++ libopenage/gui/game_control_link.cpp | 62 ++++++++++++++++++++++++++++ libopenage/gui/game_control_link.h | 18 ++++++++ libopenage/unit/selection.cpp | 47 +-------------------- libopenage/unit/selection.h | 8 ++-- 7 files changed, 106 insertions(+), 51 deletions(-) diff --git a/libopenage/engine.h b/libopenage/engine.h index dd0bcaad2a..660f00bd5b 100644 --- a/libopenage/engine.h +++ b/libopenage/engine.h @@ -44,6 +44,7 @@ namespace renderer { class Font; class FontManager; class TextRenderer; +class Color; } // openage::renderer @@ -260,7 +261,7 @@ class Engine : public ResizeHandler, public options::OptionNode { /** * render text with the at a position with specified font size */ - void render_text(coord::viewport position, size_t size, const char *format, ...) ATTRIBUTE_FORMAT(4, 5); + void render_text(coord::viewport position, size_t size, const renderer::Color &color, const char *format, ...) ATTRIBUTE_FORMAT(5, 6); /** * move the phys3 camera incorporated in the engine diff --git a/libopenage/game_control.cpp b/libopenage/game_control.cpp index 71f194f114..7de5d76429 100644 --- a/libopenage/game_control.cpp +++ b/libopenage/game_control.cpp @@ -6,6 +6,7 @@ #include "error/error.h" #include "gamestate/game_spec.h" #include "log/log.h" +#include "renderer/color.h" #include "terrain/terrain_chunk.h" #include "util/strings.h" @@ -308,6 +309,7 @@ void ActionMode::on_game_control_set() { input->remove_context(top_ctxt); } this->announce_buttons_type(); + this->announce_current_selection(); }); }; @@ -346,6 +348,7 @@ void ActionMode::on_game_control_set() { this->selecting && !this->type_focus) { this->selection->drag_update(mousepos_camgame); + this->announce_current_selection(); return true; } return false; @@ -453,6 +456,10 @@ void ActionMode::render() { this->announce_resources(); + if (this->selection && this->selection->get_units_count() > 0) { + this->announce_current_selection(); + } + // when a building is being placed if (this->type_focus) { auto txt = this->type_focus->default_texture(); @@ -463,7 +470,7 @@ void ActionMode::render() { } } else { - engine->render_text({0, 140}, 12, "Action Mode requires a game"); + engine->render_text({0, 140}, 12, renderer::Colors::WHITE, "Action Mode requires a game"); } ENSURE(this->selection != nullptr, "selection not set"); @@ -834,9 +841,15 @@ void GameControl::announce_current_player_name() { emit this->gui_signals.current_player_name_changed( "[" + std::to_string(player->color) + "] " + player->name); emit this->gui_signals.current_civ_index_changed(player->civ->civ_id); + } } +void ActionMode::announce_current_selection() { + + emit this->gui_signals.selection_changed(this->selection); +} + bool GameControl::on_drawhud() { // render the active mode if (this->active_mode) diff --git a/libopenage/game_control.h b/libopenage/game_control.h index bf1aff5831..d4bb326eb1 100644 --- a/libopenage/game_control.h +++ b/libopenage/game_control.h @@ -148,6 +148,7 @@ public slots: signals: void resource_changed(game_resource resource, int amount); void population_changed(int demand, int capacity, bool warn); + void selection_changed(UnitSelection *unit_selection); void ability_changed(const std::string &ability); void buttons_type_changed(const ActionButtonsType type); @@ -191,6 +192,8 @@ class ActionMode : public OutputMode { */ void announce_buttons_type(); + void announce_current_selection(); + /** * decides which type of right mouse click command * to issue based on position. @@ -335,6 +338,7 @@ public slots: void current_player_name_changed(const std::string ¤t_player_name); void current_civ_index_changed(int current_civ_index); + void is_selected_unit_changed(bool is_selected_unit); private: GameControl *game_control; diff --git a/libopenage/gui/game_control_link.cpp b/libopenage/gui/game_control_link.cpp index 3b0466ca56..cbee875a46 100644 --- a/libopenage/gui/game_control_link.cpp +++ b/libopenage/gui/game_control_link.cpp @@ -9,6 +9,8 @@ #include "../engine.h" #include "engine_link.h" #include "game_main_link.h" +#include "../unit/action.h" +#include "../unit/unit.h" namespace openage { namespace gui { @@ -115,6 +117,10 @@ QString ActionModeLink::get_population() const { return this->population; } +int ActionModeLink::get_selection_size() const { + return this->selection ? this->selection->get_units_count() : 0; +} + bool ActionModeLink::get_population_warn() const { return this->population_warn; } @@ -138,6 +144,58 @@ void ActionModeLink::on_population_changed(int demand, int capacity, bool warn) emit this->population_changed(); } +void ActionModeLink::on_selection_changed(UnitSelection *unit_selection) { + this->selection = unit_selection; + + if (this->selection->get_units_count() == 1) { + auto &ref = this->selection->get_first_unit(); + if (ref.is_valid()) { + Unit *u = ref.get(); + + this->selection_name = QString::fromStdString(u->unit_type->name()); + this->selection_type = QString::fromStdString("(type: " + std::to_string(u->unit_type->id()) + " " + u->top()->name() + ")"); + + if (u->has_attribute(attr_type::owner)) { + auto &own_attr = u->get_attribute(); + this->selection_owner = QString::fromStdString( + own_attr.player.name + "\n" + own_attr.player.civ->civ_name); + } + + if (u->has_attribute(attr_type::hitpoints) && u->has_attribute(attr_type::damaged)) { + auto &hp = u->get_attribute(); + auto &dm = u->get_attribute(); + this->selection_hp = QString::fromStdString("[====] "+std::to_string(dm.hp)+"/"+std::to_string(hp.hp)); + } else { + this->selection_hp = QString::fromStdString("-"); + } + + std::string lines; + if (u->has_attribute(attr_type::resource)) { + auto &res_attr = u->get_attribute(); + lines += ("resource: "+std::to_string(res_attr.amount)+" "+std::to_string(res_attr.resource_type)) + "\n"; + } + if (u->has_attribute(attr_type::building)) { + auto &build_attr = u->get_attribute(); + lines += ("built: "+std::to_string(build_attr.completed)) + "\n"; + } + if (u->has_attribute(attr_type::garrison)) { + auto &garrison_attr = u->get_attribute(); + lines += ("garrison: "+std::to_string(garrison_attr.content.size())) + "\n"; + } + this->selection_attrs = QString::fromStdString(lines); + + } + + } else if (this->selection->get_units_count() > 1) { + + this->selection_name = QString::fromStdString( + std::to_string(this->selection->get_units_count()) + " units"); + } + + + emit this->selection_changed(); +} + void ActionModeLink::on_core_adopted() { this->Inherits::on_core_adopted(); QObject::connect(&unwrap(this)->gui_signals, @@ -148,6 +206,10 @@ void ActionModeLink::on_core_adopted() { &ActionModeSignals::population_changed, this, &ActionModeLink::on_population_changed); + QObject::connect(&unwrap(this)->gui_signals, + &ActionModeSignals::selection_changed, + this, + &ActionModeLink::on_selection_changed); QObject::connect(&unwrap(this)->gui_signals, &ActionModeSignals::buttons_type_changed, this, diff --git a/libopenage/gui/game_control_link.h b/libopenage/gui/game_control_link.h index b4e2c09f8b..0be28d5c91 100644 --- a/libopenage/gui/game_control_link.h +++ b/libopenage/gui/game_control_link.h @@ -119,6 +119,14 @@ class ActionModeLink : public qtsdl::Inherits { Q_PROPERTY(QString population READ get_population NOTIFY population_changed) Q_PROPERTY(bool population_warn READ get_population_warn NOTIFY population_changed) + Q_PROPERTY(int selection_size READ get_selection_size NOTIFY selection_changed) + + Q_PROPERTY(QString selection_name MEMBER selection_name NOTIFY selection_changed) + Q_PROPERTY(QString selection_type MEMBER selection_type NOTIFY selection_changed) + Q_PROPERTY(QString selection_owner MEMBER selection_owner NOTIFY selection_changed) + Q_PROPERTY(QString selection_hp MEMBER selection_hp NOTIFY selection_changed) + Q_PROPERTY(QString selection_attrs MEMBER selection_attrs NOTIFY selection_changed) + public: ActionModeLink(QObject *parent=nullptr); virtual ~ActionModeLink(); @@ -126,6 +134,7 @@ class ActionModeLink : public qtsdl::Inherits { QString get_ability() const; QString get_population() const; bool get_population_warn() const; + int get_selection_size() const; Q_INVOKABLE void act(const QString &action); @@ -134,11 +143,13 @@ class ActionModeLink : public qtsdl::Inherits { void action_triggered(const std::string &ability); void buttons_type_changed(const ActionButtonsType buttons_type); void population_changed(); + void selection_changed(); private slots: void on_ability_changed(const std::string &ability); void on_buttons_type_changed(const ActionButtonsType buttons_type); void on_population_changed(int demand, int capacity, bool warn); + void on_selection_changed(UnitSelection *unit_selection); private: virtual void on_core_adopted() override; @@ -146,6 +157,13 @@ private slots: QString ability; QString population; bool population_warn; + UnitSelection *selection; + + QString selection_name; + QString selection_type; + QString selection_owner; + QString selection_hp; + QString selection_attrs; }; class EditorModeLink; diff --git a/libopenage/unit/selection.cpp b/libopenage/unit/selection.cpp index ff6c59a307..124cf60ce0 100644 --- a/libopenage/unit/selection.cpp +++ b/libopenage/unit/selection.cpp @@ -8,6 +8,7 @@ #include "../coord/tile.h" #include "../engine.h" #include "../log/log.h" +#include "../renderer/text.h" #include "../terrain/terrain.h" #include "action.h" #include "command.h" @@ -21,7 +22,7 @@ UnitSelection::UnitSelection(Engine *engine) : selection_type{selection_type_t::nothing}, drag_active{false}, - font_size{12}, + font_size{14}, engine{engine} { } @@ -78,14 +79,6 @@ bool UnitSelection::on_drawhud() { } glColor3f(1.0, 1.0, 1.0); // reset - // display details of single selected unit - if (this->units.size() == 1) { - auto &ref = this->units.begin()->second; - if (ref.is_valid()) { - this->show_attributes(ref.get()); - } - } - // ui graphics 3404 and 3405 return true; } @@ -280,42 +273,6 @@ void UnitSelection::all_invoke(Command &cmd) { } } -void UnitSelection::show_attributes(Unit *u) { - std::vector lines; - lines.push_back(u->top()->name()); - lines.push_back("type: "+std::to_string(u->unit_type->id())); - - if (u->has_attribute(attr_type::owner)) { - auto &own_attr = u->get_attribute(); - lines.push_back(own_attr.player.name); - } - if (u->has_attribute(attr_type::hitpoints) && u->has_attribute(attr_type::damaged)) { - auto &hp = u->get_attribute(); - auto &dm = u->get_attribute(); - lines.push_back("hitpoints: "+std::to_string(dm.hp)+"/"+std::to_string(hp.hp)); - } - if (u->has_attribute(attr_type::resource)) { - auto &res_attr = u->get_attribute(); - lines.push_back("resource: "+std::to_string(res_attr.amount)+" "+std::to_string(res_attr.resource_type)); - } - if (u->has_attribute(attr_type::building)) { - auto &build_attr = u->get_attribute(); - lines.push_back("built: "+std::to_string(build_attr.completed)); - } - if (u->has_attribute(attr_type::garrison)) { - auto &garrison_attr = u->get_attribute(); - lines.push_back("garrison: "+std::to_string(garrison_attr.content.size())); - } - - // render text - int vpos = 160; - this->engine->render_text({0, vpos}, 20, "%s", u->unit_type->name().c_str()); - for (auto &s : lines) { - vpos -= this->font_size; - engine->render_text({0, vpos}, this->font_size, "%s", s.c_str()); - } -} - selection_type_t UnitSelection::get_unit_selection_type(const Player &player, Unit *u) { bool is_building = u->has_attribute(attr_type::building); diff --git a/libopenage/unit/selection.h b/libopenage/unit/selection.h index 43fc41b5cd..cf978157c0 100644 --- a/libopenage/unit/selection.h +++ b/libopenage/unit/selection.h @@ -82,11 +82,11 @@ class UnitSelection: public HudHandler { */ void all_invoke(Command &cmd); + int get_units_count() { return this->units.size(); } + + UnitReference & get_first_unit() { return this->units.begin()->second; } + private: - /** - * Must be given a valid unit to display text attribute indicators. - */ - void show_attributes(Unit *); /** * Check whether the currently selected units may be selected at the same time From 8827ce1d1a29b3abf470d240d12ae9c741927e8a Mon Sep 17 00:00:00 2001 From: MaanooAk Date: Fri, 20 Sep 2019 17:06:25 +0300 Subject: [PATCH 04/11] Move the ability info the middle panel --- assets/qml/IngameHud.qml | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/assets/qml/IngameHud.qml b/assets/qml/IngameHud.qml index 971cc4f256..1d2647f90b 100644 --- a/assets/qml/IngameHud.qml +++ b/assets/qml/IngameHud.qml @@ -141,7 +141,7 @@ Item { id: epoch anchors.centerIn: parent color: "white" - text: root.playerName + (actionMode.ability.length ? (" (" + actionMode.ability + ")") : "") + text: root.playerName } } @@ -309,6 +309,21 @@ Item { font.pointSize: 14 } } + + Item { + anchors.left: parent.left + anchors.right: parent.right + anchors.bottom: parent.bottom + anchors.bottomMargin: metricsUnit * 3 + visible: actionMode.ability.length + + Text { + anchors.centerIn: parent + + text: actionMode.ability + font.pointSize: 14 + } + } } } From 097010fb0583987ff7146926e3480e0f9820a71d Mon Sep 17 00:00:00 2001 From: MaanooAk Date: Fri, 20 Sep 2019 17:37:01 +0300 Subject: [PATCH 05/11] Better player names and name rectangle --- assets/qml/IngameHud.qml | 18 ++++++++++++++---- libopenage/gamestate/generator.cpp | 5 +++-- libopenage/gui/game_control_link.cpp | 7 ++++++- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/assets/qml/IngameHud.qml b/assets/qml/IngameHud.qml index 1d2647f90b..3a2986b7c9 100644 --- a/assets/qml/IngameHud.qml +++ b/assets/qml/IngameHud.qml @@ -137,11 +137,20 @@ Item { Layout.fillWidth: true Layout.minimumWidth: epoch.implicitWidth - Text { - id: epoch + Rectangle { anchors.centerIn: parent - color: "white" - text: root.playerName + width: 200 + height: metricsUnit * 2.5 + + color: "black" + + Text { + id: epoch + anchors.centerIn: parent + + color: "white" + text: root.playerName + } } } @@ -289,6 +298,7 @@ Item { color: "black" text: root.actionMode.selection_owner + horizontalAlignment: Text.AlignRight } } diff --git a/libopenage/gamestate/generator.cpp b/libopenage/gamestate/generator.cpp index 0d3f616cbb..02bc2eae39 100644 --- a/libopenage/gamestate/generator.cpp +++ b/libopenage/gamestate/generator.cpp @@ -134,7 +134,8 @@ Generator::Generator(qtsdl::GuiItemLink *gui_link) this->setv("player_radius", 10); this->setv("load_filename", "/tmp/default_save.oas"); this->setv("from_file", false); - this->set_csv("player_names", std::vector{"name1", "name2"}); + // TODO pick the users name + this->set_csv("player_names", std::vector{"Jonas", "Michael"}); } std::shared_ptr Generator::get_spec() const { @@ -145,7 +146,7 @@ std::vector Generator::player_names() const { auto result = this->get_csv("player_names"); // gaia is player 0 - result.insert(result.begin(), "gaia"); + result.insert(result.begin(), "Gaia"); return result; } diff --git a/libopenage/gui/game_control_link.cpp b/libopenage/gui/game_control_link.cpp index cbee875a46..9bcd474f82 100644 --- a/libopenage/gui/game_control_link.cpp +++ b/libopenage/gui/game_control_link.cpp @@ -164,7 +164,12 @@ void ActionModeLink::on_selection_changed(UnitSelection *unit_selection) { if (u->has_attribute(attr_type::hitpoints) && u->has_attribute(attr_type::damaged)) { auto &hp = u->get_attribute(); auto &dm = u->get_attribute(); - this->selection_hp = QString::fromStdString("[====] "+std::to_string(dm.hp)+"/"+std::to_string(hp.hp)); + // TODO replace ascii health bar with real one + if (hp.hp >= 200) { + this->selection_hp = QString::fromStdString("[========] "+std::to_string(dm.hp)+"/"+std::to_string(hp.hp)); + } else { + this->selection_hp = QString::fromStdString("[====] "+std::to_string(dm.hp)+"/"+std::to_string(hp.hp)); + } } else { this->selection_hp = QString::fromStdString("-"); } From 4ee0369802f1607c19027ce51865c2ca9915881f Mon Sep 17 00:00:00 2001 From: MaanooAk Date: Fri, 20 Sep 2019 17:56:24 +0300 Subject: [PATCH 06/11] Binds help text sort and smaller font --- assets/qml/BindsHelp.qml | 7 +++++-- libopenage/engine.cpp | 2 +- libopenage/engine.h | 2 +- libopenage/game_control.cpp | 2 +- libopenage/game_control.h | 2 +- libopenage/gamestate/generator.cpp | 2 +- libopenage/gui/engine_link.cpp | 4 +++- libopenage/gui/game_control_link.cpp | 3 ++- libopenage/gui/game_control_link.h | 2 +- libopenage/renderer/color.cpp | 2 +- libopenage/renderer/color.h | 2 +- libopenage/unit/selection.cpp | 3 +-- libopenage/unit/selection.h | 3 +-- libopenage/util/fps.cpp | 2 +- libopenage/util/fps.h | 2 +- libopenage/util/profiler.cpp | 2 +- 16 files changed, 23 insertions(+), 19 deletions(-) diff --git a/assets/qml/BindsHelp.qml b/assets/qml/BindsHelp.qml index 03e7ec06d1..8afed86fdb 100644 --- a/assets/qml/BindsHelp.qml +++ b/assets/qml/BindsHelp.qml @@ -10,10 +10,11 @@ Column { Text { id: dummyText + font.pointSize: 9 } Text { - font.pointSize: dummyText.font.pointSize + 7 + font.pointSize: dummyText.font.pointSize + 3 color: "white" text: gameControl.mode ? gameControl.mode.name : "No Mode" @@ -23,13 +24,14 @@ Column { model: gameControlObj.mode ? gameControlObj.mode.binds : undefined Text { + font.pointSize: dummyText.font.pointSize color: "white" text: modelData } } Text { - font.pointSize: dummyText.font.pointSize + 7 + font.pointSize: dummyText.font.pointSize + 3 color: "white" text: "Global Bindings" @@ -39,6 +41,7 @@ Column { model: OA.Engine.globalBinds Text { + font.pointSize: dummyText.font.pointSize color: "white" text: modelData } diff --git a/libopenage/engine.cpp b/libopenage/engine.cpp index bd345f5d58..0c028f9118 100644 --- a/libopenage/engine.cpp +++ b/libopenage/engine.cpp @@ -1,4 +1,4 @@ -// Copyright 2013-2018 the openage authors. See copying.md for legal info. +// Copyright 2013-2019 the openage authors. See copying.md for legal info. #include "engine.h" diff --git a/libopenage/engine.h b/libopenage/engine.h index 660f00bd5b..77212e9990 100644 --- a/libopenage/engine.h +++ b/libopenage/engine.h @@ -1,4 +1,4 @@ -// Copyright 2013-2018 the openage authors. See copying.md for legal info. +// Copyright 2013-2019 the openage authors. See copying.md for legal info. #pragma once diff --git a/libopenage/game_control.cpp b/libopenage/game_control.cpp index 7de5d76429..5e4b0ba9ac 100644 --- a/libopenage/game_control.cpp +++ b/libopenage/game_control.cpp @@ -1,4 +1,4 @@ -// Copyright 2015-2018 the openage authors. See copying.md for legal info. +// Copyright 2015-2019 the openage authors. See copying.md for legal info. #include "game_control.h" diff --git a/libopenage/game_control.h b/libopenage/game_control.h index d4bb326eb1..c671cb1f9e 100644 --- a/libopenage/game_control.h +++ b/libopenage/game_control.h @@ -1,4 +1,4 @@ -// Copyright 2015-2018 the openage authors. See copying.md for legal info. +// Copyright 2015-2019 the openage authors. See copying.md for legal info. #pragma once diff --git a/libopenage/gamestate/generator.cpp b/libopenage/gamestate/generator.cpp index 02bc2eae39..084ee5604c 100644 --- a/libopenage/gamestate/generator.cpp +++ b/libopenage/gamestate/generator.cpp @@ -1,4 +1,4 @@ -// Copyright 2015-2018 the openage authors. See copying.md for legal info. +// Copyright 2015-2019 the openage authors. See copying.md for legal info. #include "generator.h" diff --git a/libopenage/gui/engine_link.cpp b/libopenage/gui/engine_link.cpp index 3c44f9a772..780ab61dfe 100644 --- a/libopenage/gui/engine_link.cpp +++ b/libopenage/gui/engine_link.cpp @@ -1,4 +1,4 @@ -// Copyright 2015-2018 the openage authors. See copying.md for legal info. +// Copyright 2015-2019 the openage authors. See copying.md for legal info. #include "engine_link.h" @@ -90,6 +90,8 @@ void EngineLink::on_global_binds_changed(const std::vector& global_ } ); + new_global_binds.sort(); + if (this->global_binds != new_global_binds) { this->global_binds = new_global_binds; emit this->global_binds_changed(); diff --git a/libopenage/gui/game_control_link.cpp b/libopenage/gui/game_control_link.cpp index 9bcd474f82..45334606b7 100644 --- a/libopenage/gui/game_control_link.cpp +++ b/libopenage/gui/game_control_link.cpp @@ -1,4 +1,4 @@ -// Copyright 2015-2017 the openage authors. See copying.md for legal info. +// Copyright 2015-2019 the openage authors. See copying.md for legal info. #include "game_control_link.h" @@ -159,6 +159,7 @@ void ActionModeLink::on_selection_changed(UnitSelection *unit_selection) { auto &own_attr = u->get_attribute(); this->selection_owner = QString::fromStdString( own_attr.player.name + "\n" + own_attr.player.civ->civ_name); + // TODO find the team status of the player } if (u->has_attribute(attr_type::hitpoints) && u->has_attribute(attr_type::damaged)) { diff --git a/libopenage/gui/game_control_link.h b/libopenage/gui/game_control_link.h index 0be28d5c91..dcb92c3159 100644 --- a/libopenage/gui/game_control_link.h +++ b/libopenage/gui/game_control_link.h @@ -1,4 +1,4 @@ -// Copyright 2015-2017 the openage authors. See copying.md for legal info. +// Copyright 2015-2019 the openage authors. See copying.md for legal info. #pragma once diff --git a/libopenage/renderer/color.cpp b/libopenage/renderer/color.cpp index a632c01b13..7333dfb073 100644 --- a/libopenage/renderer/color.cpp +++ b/libopenage/renderer/color.cpp @@ -1,4 +1,4 @@ -// Copyright 2015-2017 the openage authors. See copying.md for legal info. +// Copyright 2015-2019 the openage authors. See copying.md for legal info. #include "color.h" diff --git a/libopenage/renderer/color.h b/libopenage/renderer/color.h index 23b6ea5f0b..96b13f81f7 100644 --- a/libopenage/renderer/color.h +++ b/libopenage/renderer/color.h @@ -1,4 +1,4 @@ -// Copyright 2015-2017 the openage authors. See copying.md for legal info. +// Copyright 2015-2019 the openage authors. See copying.md for legal info. #pragma once diff --git a/libopenage/unit/selection.cpp b/libopenage/unit/selection.cpp index 124cf60ce0..a2d3f7ef32 100644 --- a/libopenage/unit/selection.cpp +++ b/libopenage/unit/selection.cpp @@ -1,4 +1,4 @@ -// Copyright 2015-2018 the openage authors. See copying.md for legal info. +// Copyright 2015-2019 the openage authors. See copying.md for legal info. #include "selection.h" @@ -22,7 +22,6 @@ UnitSelection::UnitSelection(Engine *engine) : selection_type{selection_type_t::nothing}, drag_active{false}, - font_size{14}, engine{engine} { } diff --git a/libopenage/unit/selection.h b/libopenage/unit/selection.h index cf978157c0..4ee7336b69 100644 --- a/libopenage/unit/selection.h +++ b/libopenage/unit/selection.h @@ -1,4 +1,4 @@ -// Copyright 2015-2018 the openage authors. See copying.md for legal info. +// Copyright 2015-2019 the openage authors. See copying.md for legal info. #pragma once @@ -105,7 +105,6 @@ class UnitSelection: public HudHandler { bool drag_active; // TODO: turn these into a C++17 optional coord::camgame start = {0, 0}, end = {0, 0}; - int font_size; /** * Engine where this selection is attached to. diff --git a/libopenage/util/fps.cpp b/libopenage/util/fps.cpp index 594e094acf..4d7cb2eae8 100644 --- a/libopenage/util/fps.cpp +++ b/libopenage/util/fps.cpp @@ -1,4 +1,4 @@ -// Copyright 2013-2016 the openage authors. See copying.md for legal info. +// Copyright 2013-2019 the openage authors. See copying.md for legal info. #include "fps.h" diff --git a/libopenage/util/fps.h b/libopenage/util/fps.h index e9066f7e17..45959126c3 100644 --- a/libopenage/util/fps.h +++ b/libopenage/util/fps.h @@ -1,4 +1,4 @@ -// Copyright 2013-2016 the openage authors. See copying.md for legal info. +// Copyright 2013-2019 the openage authors. See copying.md for legal info. #pragma once diff --git a/libopenage/util/profiler.cpp b/libopenage/util/profiler.cpp index 1ead9b6e67..d656e95ebf 100644 --- a/libopenage/util/profiler.cpp +++ b/libopenage/util/profiler.cpp @@ -1,4 +1,4 @@ -// Copyright 2015-2018 the openage authors. See copying.md for legal info. +// Copyright 2015-2019 the openage authors. See copying.md for legal info. #include "profiler.h" #include "../engine.h" From 20c156c1c4d0b1ca005d28d2fe74c1bab79e3d34 Mon Sep 17 00:00:00 2001 From: MaanooAk Date: Fri, 20 Sep 2019 23:43:28 +0300 Subject: [PATCH 07/11] Added image placeholder to the unit info --- assets/qml/IngameHud.qml | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/assets/qml/IngameHud.qml b/assets/qml/IngameHud.qml index 3a2986b7c9..931230339b 100644 --- a/assets/qml/IngameHud.qml +++ b/assets/qml/IngameHud.qml @@ -245,12 +245,25 @@ Item { id: selection_single_panel visible: root.actionMode.selection_size == 1 - Text { + Image { anchors.top: parent.top anchors.topMargin: metricsUnit * 2 anchors.left: parent.left anchors.leftMargin: metricsUnit * 2 + width: 50 + height: 50 + + id: selected_icon + + source: "image://by-filename/converted/interface/50730.slp.png.2" + } + + Text { + anchors.top: selected_icon.top + anchors.left: selected_icon.right + anchors.leftMargin: metricsUnit * 1.2 + id: selected_name color: "black" @@ -259,9 +272,9 @@ Item { } Text { - anchors.bottom: selected_name.bottom + anchors.verticalCenter: selected_name.verticalCenter anchors.left: selected_name.right - anchors.leftMargin: metricsUnit * 1 + anchors.leftMargin: metricsUnit * 1.2 id: selected_type @@ -273,17 +286,17 @@ Item { Text { anchors.top: selected_name.bottom anchors.left: selected_name.left - anchors.topMargin: metricsUnit / 2 + anchors.topMargin: metricsUnit - id: selected_owner + id: selected_hp color: "black" text: root.actionMode.selection_hp } Text { - anchors.top: selected_owner.bottom - anchors.left: selected_owner.left + anchors.top: selected_hp.bottom + anchors.left: selected_icon.left anchors.topMargin: metricsUnit * 2 color: "black" From 524aa35495cd7dcb2425f9b6402a81e13ec2b963 Mon Sep 17 00:00:00 2001 From: MaanooAk Date: Sat, 21 Sep 2019 00:16:48 +0300 Subject: [PATCH 08/11] Improved the unit info format --- libopenage/gui/game_control_link.cpp | 45 ++++++++++++++++++++++------ libopenage/gui/game_control_link.h | 2 ++ 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/libopenage/gui/game_control_link.cpp b/libopenage/gui/game_control_link.cpp index 45334606b7..71601d44cc 100644 --- a/libopenage/gui/game_control_link.cpp +++ b/libopenage/gui/game_control_link.cpp @@ -157,9 +157,13 @@ void ActionModeLink::on_selection_changed(UnitSelection *unit_selection) { if (u->has_attribute(attr_type::owner)) { auto &own_attr = u->get_attribute(); - this->selection_owner = QString::fromStdString( - own_attr.player.name + "\n" + own_attr.player.civ->civ_name); - // TODO find the team status of the player + if (own_attr.player.civ->civ_id != 0) { // not gaia + this->selection_owner = QString::fromStdString( + own_attr.player.name + "\n" + own_attr.player.civ->civ_name); + // TODO find the team status of the player + } else { + this->selection_owner = QString::fromStdString(" "); + } } if (u->has_attribute(attr_type::hitpoints) && u->has_attribute(attr_type::damaged)) { @@ -167,26 +171,40 @@ void ActionModeLink::on_selection_changed(UnitSelection *unit_selection) { auto &dm = u->get_attribute(); // TODO replace ascii health bar with real one if (hp.hp >= 200) { - this->selection_hp = QString::fromStdString("[========] "+std::to_string(dm.hp)+"/"+std::to_string(hp.hp)); + this->selection_hp = QString::fromStdString(progress(dm.hp*1.0f/hp.hp, 8)+" "+std::to_string(dm.hp)+"/"+std::to_string(hp.hp)); } else { - this->selection_hp = QString::fromStdString("[====] "+std::to_string(dm.hp)+"/"+std::to_string(hp.hp)); + this->selection_hp = QString::fromStdString(progress(dm.hp*1.0f/hp.hp, 4)+" "+std::to_string(dm.hp)+"/"+std::to_string(hp.hp)); } } else { - this->selection_hp = QString::fromStdString("-"); + this->selection_hp = QString::fromStdString(" "); } std::string lines; if (u->has_attribute(attr_type::resource)) { auto &res_attr = u->get_attribute(); - lines += ("resource: "+std::to_string(res_attr.amount)+" "+std::to_string(res_attr.resource_type)) + "\n"; + lines += std::to_string((int) res_attr.amount)+" "+std::to_string(res_attr.resource_type) + "\n"; } if (u->has_attribute(attr_type::building)) { auto &build_attr = u->get_attribute(); - lines += ("built: "+std::to_string(build_attr.completed)) + "\n"; + if (build_attr.completed < 1) { + lines += "Building: " + progress(build_attr.completed, 16)+ " "+std::to_string((int) (100 * build_attr.completed)) + "%\n"; + } } if (u->has_attribute(attr_type::garrison)) { auto &garrison_attr = u->get_attribute(); - lines += ("garrison: "+std::to_string(garrison_attr.content.size())) + "\n"; + if (garrison_attr.content.size() > 0) { + lines += "Garrison: "+std::to_string(garrison_attr.content.size()) + " units\n"; + } + } + lines += "\n"; + if (u->has_attribute(attr_type::population)) { + auto &population_attr = u->get_attribute(); + if (population_attr.demand > 1) { + lines += "Population demand: "+std::to_string(population_attr.demand) + " units\n"; + } + if (population_attr.capacity > 0) { + lines += "Population capacity: "+std::to_string(population_attr.capacity) + " units\n"; + } } this->selection_attrs = QString::fromStdString(lines); @@ -202,6 +220,15 @@ void ActionModeLink::on_selection_changed(UnitSelection *unit_selection) { emit this->selection_changed(); } +// TODO remove +std::string ActionModeLink::progress(float progress, int size) { + std::string bar = "["; + for (int i = 0; i < size; i++) { + bar += (i < progress * size ? "=" : " "); + } + return bar + "]"; +} + void ActionModeLink::on_core_adopted() { this->Inherits::on_core_adopted(); QObject::connect(&unwrap(this)->gui_signals, diff --git a/libopenage/gui/game_control_link.h b/libopenage/gui/game_control_link.h index dcb92c3159..819f59f577 100644 --- a/libopenage/gui/game_control_link.h +++ b/libopenage/gui/game_control_link.h @@ -164,6 +164,8 @@ private slots: QString selection_owner; QString selection_hp; QString selection_attrs; + + std::string progress(float progress, int size); }; class EditorModeLink; From 0ed8efdab2f4e708ffddf6f2e07591533002aea8 Mon Sep 17 00:00:00 2001 From: MaanooAk Date: Sat, 21 Sep 2019 01:21:42 +0300 Subject: [PATCH 09/11] Moved the health bars behind the gui (#611) --- buildsystem/codecompliance/__main__.py | 4 ++-- libopenage/engine.cpp | 8 ++++++-- libopenage/engine.h | 3 ++- libopenage/game_control.cpp | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/buildsystem/codecompliance/__main__.py b/buildsystem/codecompliance/__main__.py index cea666509f..240ffe1cda 100644 --- a/buildsystem/codecompliance/__main__.py +++ b/buildsystem/codecompliance/__main__.py @@ -1,4 +1,4 @@ -# Copyright 2014-2018 the openage authors. See copying.md for legal info. +# Copyright 2014-2019 the openage authors. See copying.md for legal info. """ Entry point for the code compliance checker. @@ -183,7 +183,7 @@ def main(args): if args.fix and auto_fixes: remainfound = "remain%s" % plural else: - remainfound = ("were" if issues_count > 1 else "was") + "found" + remainfound = ("were" if issues_count > 1 else "was") + " found" print("==> \x1b[33;1m{num} issue{plural}\x1b[m {remainfound}." "".format(num=issues_count, diff --git a/libopenage/engine.cpp b/libopenage/engine.cpp index 0c028f9118..50700f2ec2 100644 --- a/libopenage/engine.cpp +++ b/libopenage/engine.cpp @@ -466,8 +466,12 @@ void Engine::register_tick_action(TickHandler *handler) { this->on_engine_tick.push_back(handler); } -void Engine::register_drawhud_action(HudHandler *handler) { - this->on_drawhud.push_back(handler); +void Engine::register_drawhud_action(HudHandler *handler, int order) { + if (order < 0) { + this->on_drawhud.insert(this->on_drawhud.begin(), handler); + } else { + this->on_drawhud.push_back(handler); + } } void Engine::register_draw_action(DrawHandler *handler) { diff --git a/libopenage/engine.h b/libopenage/engine.h index 77212e9990..c3c37efded 100644 --- a/libopenage/engine.h +++ b/libopenage/engine.h @@ -181,8 +181,9 @@ class Engine : public ResizeHandler, public options::OptionNode { /** * register a hud drawing handler, drawn in hud coordinates. + * order: 1 above, -1 below */ - void register_drawhud_action(HudHandler *handler); + void register_drawhud_action(HudHandler *handler, int order = 1); /** * register a draw handler, run in game coordinates. diff --git a/libopenage/game_control.cpp b/libopenage/game_control.cpp index 5e4b0ba9ac..3760512166 100644 --- a/libopenage/game_control.cpp +++ b/libopenage/game_control.cpp @@ -742,7 +742,7 @@ void GameControl::set_engine(Engine *engine) { this->engine = engine; // add handlers - this->engine->register_drawhud_action(this); + this->engine->register_drawhud_action(this, -1); auto &action = this->engine->get_action_manager(); From e95978f08415e1ecdc689fa9141fd17461f603ea Mon Sep 17 00:00:00 2001 From: MaanooAk Date: Sat, 21 Sep 2019 22:04:59 +0300 Subject: [PATCH 10/11] Export the unit icons to the unit type --- libopenage/gui/game_control_link.cpp | 6 ++++++ libopenage/gui/game_control_link.h | 2 ++ libopenage/unit/producer.cpp | 4 +++- libopenage/unit/unit_type.h | 7 ++++++- openage/convert/gamedata/unit.py | 4 ++-- 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/libopenage/gui/game_control_link.cpp b/libopenage/gui/game_control_link.cpp index 71601d44cc..36e7ab53e6 100644 --- a/libopenage/gui/game_control_link.cpp +++ b/libopenage/gui/game_control_link.cpp @@ -153,6 +153,12 @@ void ActionModeLink::on_selection_changed(UnitSelection *unit_selection) { Unit *u = ref.get(); this->selection_name = QString::fromStdString(u->unit_type->name()); + // the icons are split into two sprites + if (u->unit_type->unit_class == gamedata::unit_classes::BUILDING) { + this->selection_icon = QString::fromStdString("50706.slp.png." + std::to_string(u->unit_type->icon)); + } else { + this->selection_icon = QString::fromStdString("50730.slp.png." + std::to_string(u->unit_type->icon)); + } this->selection_type = QString::fromStdString("(type: " + std::to_string(u->unit_type->id()) + " " + u->top()->name() + ")"); if (u->has_attribute(attr_type::owner)) { diff --git a/libopenage/gui/game_control_link.h b/libopenage/gui/game_control_link.h index 819f59f577..0bfcc16ffb 100644 --- a/libopenage/gui/game_control_link.h +++ b/libopenage/gui/game_control_link.h @@ -122,6 +122,7 @@ class ActionModeLink : public qtsdl::Inherits { Q_PROPERTY(int selection_size READ get_selection_size NOTIFY selection_changed) Q_PROPERTY(QString selection_name MEMBER selection_name NOTIFY selection_changed) + Q_PROPERTY(QString selection_icon MEMBER selection_icon NOTIFY selection_changed) Q_PROPERTY(QString selection_type MEMBER selection_type NOTIFY selection_changed) Q_PROPERTY(QString selection_owner MEMBER selection_owner NOTIFY selection_changed) Q_PROPERTY(QString selection_hp MEMBER selection_hp NOTIFY selection_changed) @@ -160,6 +161,7 @@ private slots: UnitSelection *selection; QString selection_name; + QString selection_icon; QString selection_type; QString selection_owner; QString selection_hp; diff --git a/libopenage/unit/producer.cpp b/libopenage/unit/producer.cpp index a03f31a766..6f441bae20 100644 --- a/libopenage/unit/producer.cpp +++ b/libopenage/unit/producer.cpp @@ -1,4 +1,4 @@ -// Copyright 2014-2018 the openage authors. See copying.md for legal info. +// Copyright 2014-2019 the openage authors. See copying.md for legal info. #include @@ -97,6 +97,7 @@ ObjectProducer::ObjectProducer(const Player &owner, const GameSpec &spec, const // copy the class type this->unit_class = this->unit_data.unit_class; + this->icon = this->unit_data.icon_id; // for now just look for type names ending with "_D" this->decay = unit_data.name.substr(unit_data.name.length() - 2) == "_D"; @@ -531,6 +532,7 @@ BuildingProducer::BuildingProducer(const Player &owner, const GameSpec &spec, co // copy the class type this->unit_class = this->unit_data.unit_class; + this->icon = this->unit_data.icon_id; // find suitable sounds int creation_sound = this->unit_data.train_sound; diff --git a/libopenage/unit/unit_type.h b/libopenage/unit/unit_type.h index 80394bb88e..0eb2521f8b 100644 --- a/libopenage/unit/unit_type.h +++ b/libopenage/unit/unit_type.h @@ -1,4 +1,4 @@ -// Copyright 2015-2018 the openage authors. See copying.md for legal info. +// Copyright 2015-2019 the openage authors. See copying.md for legal info. #pragma once @@ -180,6 +180,11 @@ class UnitType { */ graphic_set graphics; + /** + * The index of the icon representing this unit + */ + int icon; + /** * the square dimensions of the placement */ diff --git a/openage/convert/gamedata/unit.py b/openage/convert/gamedata/unit.py index 0339c8546b..3e0c875b75 100644 --- a/openage/convert/gamedata/unit.py +++ b/openage/convert/gamedata/unit.py @@ -1,4 +1,4 @@ -# Copyright 2013-2017 the openage authors. See copying.md for legal info. +# Copyright 2013-2019 the openage authors. See copying.md for legal info. # TODO pylint: disable=C,R,too-many-lines @@ -560,7 +560,7 @@ class UnitObject(Exportable): (READ_EXPORT, "dead_unit_id", "int16_t"), # unit id to become on death (READ, "placement_mode", "int8_t"), # 0=placable on top of others in scenario editor, 5=can't (READ, "can_be_built_on", "int8_t"), # 1=no footprints - (READ, "icon_id", "int16_t"), # frame id of the icon slp (57029) to place on the creation button + (READ_EXPORT, "icon_id", "int16_t"), # frame id of the icon slp (57029) to place on the creation button (READ, "hidden_in_editor", "int8_t"), (READ, "old_portrait_icon_id", "int16_t"), (READ, "enabled", "int8_t"), # 0=unlocked by research, 1=insta-available From d8a8bdf58a39125eb0a2ad10b1983068488d8afe Mon Sep 17 00:00:00 2001 From: MaanooAk Date: Sat, 21 Sep 2019 22:26:24 +0300 Subject: [PATCH 11/11] Impl the unit info icon and border, and player team --- assets/qml/IngameHud.qml | 13 ++++++++++++- libopenage/game_control.cpp | 3 ++- libopenage/game_control.h | 2 +- libopenage/gui/actions_list_model.cpp | 4 +++- libopenage/gui/game_control_link.cpp | 7 +++++-- libopenage/gui/game_control_link.h | 4 ++-- libopenage/unit/selection.h | 4 ++-- 7 files changed, 27 insertions(+), 10 deletions(-) diff --git a/assets/qml/IngameHud.qml b/assets/qml/IngameHud.qml index 931230339b..35c3863abf 100644 --- a/assets/qml/IngameHud.qml +++ b/assets/qml/IngameHud.qml @@ -24,6 +24,9 @@ Item { readonly property string srcSuffix: ".slp.png" property string hudImageSource: srcPrefix + (pad + civIndex).slice(-pad.length) + srcSuffix + readonly property string iconsPrefix: "image://by-filename/converted/interface/" + readonly property string iconsBorder: "image://by-filename/converted/interface/53003.slp.png.1" + width: 1289 height: 960 @@ -256,7 +259,15 @@ Item { id: selected_icon - source: "image://by-filename/converted/interface/50730.slp.png.2" + source: root.actionMode.selection_icon ? iconsPrefix + root.actionMode.selection_icon : iconsBorder + } + Image { + anchors.centerIn: selected_icon + + width: 50 + height: 50 + + source: iconsBorder } Text { diff --git a/libopenage/game_control.cpp b/libopenage/game_control.cpp index 3760512166..eb230b4dfb 100644 --- a/libopenage/game_control.cpp +++ b/libopenage/game_control.cpp @@ -847,7 +847,8 @@ void GameControl::announce_current_player_name() { void ActionMode::announce_current_selection() { - emit this->gui_signals.selection_changed(this->selection); + Player* player = this->game_control->get_current_player(); + emit this->gui_signals.selection_changed(this->selection, player); } bool GameControl::on_drawhud() { diff --git a/libopenage/game_control.h b/libopenage/game_control.h index c671cb1f9e..b6e54f5063 100644 --- a/libopenage/game_control.h +++ b/libopenage/game_control.h @@ -148,7 +148,7 @@ public slots: signals: void resource_changed(game_resource resource, int amount); void population_changed(int demand, int capacity, bool warn); - void selection_changed(UnitSelection *unit_selection); + void selection_changed(const UnitSelection *unit_selection, const Player *player); void ability_changed(const std::string &ability); void buttons_type_changed(const ActionButtonsType type); diff --git a/libopenage/gui/actions_list_model.cpp b/libopenage/gui/actions_list_model.cpp index 0589877647..c5c7885052 100644 --- a/libopenage/gui/actions_list_model.cpp +++ b/libopenage/gui/actions_list_model.cpp @@ -1,4 +1,4 @@ -// Copyright 2016-2017 the openage authors. See copying.md for legal info. +// Copyright 2016-2019 the openage authors. See copying.md for legal info. #include "actions_list_model.h" @@ -91,6 +91,7 @@ void ActionsListModel::set_active_buttons(const ActionButtonsType &active_button this->add_button(32, -1, static_cast(GroupIDs::NoGroup), "BUILDING_UNIV"); this->add_button(28, -1, static_cast(GroupIDs::NoGroup), "BUILDING_RTWC"); this->add_button(37, -1, static_cast(GroupIDs::NoGroup), "BUILDING_WNDR"); + // the go back button is not in this slp (is in hudactions.slp.png) this->endResetModel(); break; @@ -109,6 +110,7 @@ void ActionsListModel::set_active_buttons(const ActionButtonsType &active_button this->add_button(42, -1, static_cast(GroupIDs::NoGroup), "BUILDING_WCTW4"); this->add_button(36, -1, static_cast(GroupIDs::NoGroup), "BUILDING_GTCA2"); this->add_button(7, -1, static_cast(GroupIDs::NoGroup), "BUILDING_CSTL"); + // the go back button is not in this slp (is in hudactions.slp.png) this->endResetModel(); break; diff --git a/libopenage/gui/game_control_link.cpp b/libopenage/gui/game_control_link.cpp index 36e7ab53e6..64c5e9abf1 100644 --- a/libopenage/gui/game_control_link.cpp +++ b/libopenage/gui/game_control_link.cpp @@ -144,7 +144,7 @@ void ActionModeLink::on_population_changed(int demand, int capacity, bool warn) emit this->population_changed(); } -void ActionModeLink::on_selection_changed(UnitSelection *unit_selection) { +void ActionModeLink::on_selection_changed(const UnitSelection *unit_selection, const Player *player) { this->selection = unit_selection; if (this->selection->get_units_count() == 1) { @@ -165,7 +165,10 @@ void ActionModeLink::on_selection_changed(UnitSelection *unit_selection) { auto &own_attr = u->get_attribute(); if (own_attr.player.civ->civ_id != 0) { // not gaia this->selection_owner = QString::fromStdString( - own_attr.player.name + "\n" + own_attr.player.civ->civ_name); + own_attr.player.name + "\n" + own_attr.player.civ->civ_name + "\n" + + (!player || *player == own_attr.player ? "" + : player->is_ally(own_attr.player) ? "Ally" : "Enemy") + ); // TODO find the team status of the player } else { this->selection_owner = QString::fromStdString(" "); diff --git a/libopenage/gui/game_control_link.h b/libopenage/gui/game_control_link.h index 0bfcc16ffb..0aa1baab84 100644 --- a/libopenage/gui/game_control_link.h +++ b/libopenage/gui/game_control_link.h @@ -150,7 +150,7 @@ private slots: void on_ability_changed(const std::string &ability); void on_buttons_type_changed(const ActionButtonsType buttons_type); void on_population_changed(int demand, int capacity, bool warn); - void on_selection_changed(UnitSelection *unit_selection); + void on_selection_changed(const UnitSelection *unit_selection, const Player *player); private: virtual void on_core_adopted() override; @@ -158,7 +158,7 @@ private slots: QString ability; QString population; bool population_warn; - UnitSelection *selection; + const UnitSelection *selection; QString selection_name; QString selection_icon; diff --git a/libopenage/unit/selection.h b/libopenage/unit/selection.h index 4ee7336b69..95d1763cd5 100644 --- a/libopenage/unit/selection.h +++ b/libopenage/unit/selection.h @@ -82,9 +82,9 @@ class UnitSelection: public HudHandler { */ void all_invoke(Command &cmd); - int get_units_count() { return this->units.size(); } + int get_units_count() const { return this->units.size(); } - UnitReference & get_first_unit() { return this->units.begin()->second; } + const UnitReference & get_first_unit() const { return this->units.begin()->second; } private: