<NME> hud.h
<BEF> //
// open horizon -- undefined_darkness@outlook.com
//

#pragma once

#include "ui.h"
#include "circle_mesh.h"

namespace gui
{
//------------------------------------------------------------

class hud
{
public:
    void load(const char *aircraft_name, const char *location_name);
    void draw(const render &r);
    void update(int dt);

    void set_location(const char *location_name);
    void set_hide(bool value);
    void set_project_pos(const nya_math::vec3 &pos) { m_project_pos = pos; }
    void set_pos(const nya_math::vec3 &pos) { m_pos = pos; }
    void set_angles(float pitch, float yaw, float roll) { m_pitch = pitch, m_yaw = yaw, m_roll = roll; }
    void set_speed(int value) { m_speed = value; }
    void set_ab(bool value) { m_ab = value; }
    void set_pitch_ladder(bool visible) { m_pitch_ladder = visible; }
    void set_alt(int value) { m_alt = value; }
    void set_missiles(const char *id, int icon);
    void set_missiles_count(int count) { m_missiles_count = count; }
    void set_missile_reload(int idx, float value);
    void set_locks(int count, int icon);
    void set_lock(int idx, bool locked, bool active);
    void set_mgun(bool visible) { m_mgun = visible; }
    void set_jammed(bool active) { m_jammed = active; }
    void change_radar() { m_show_map = !m_show_map; }

    void clear_alerts() { m_alerts.clear(); }
    void add_alert(float v) { m_alerts.push_back(v); }


    bool is_special_selected() const { return m_missiles_icon > 0; }

    void clear_scores();
    void set_team_score(int allies, int enemies);
    void set_score(int line, int place, const std::wstring &name, const std::wstring &value);
    void remove_score(int line);

    void clear_alerts() { m_alerts.clear(); }
    void add_alert(float v) { m_alerts.push_back(v); }

public:
    typedef nya_math::vec4 color;
    const static color white;
    const static color green;
    const static color red;
    const static color blue;

    void clear_ecm() { m_ecms.clear(); }
    void add_ecm(const nya_math::vec3 &pos) { m_ecms.push_back(pos); }

    hud(): m_common_loaded(false), m_hide(false) {}

private:
    nya_math::vec3 m_project_pos;
    nya_math::vec3 m_pos;
    };

    void clear_targets() { m_targets.clear(); }
    void add_target(const nya_math::vec3 &pos, float yaw, target_type target, select_type select);
    void add_target(const std::wstring &name, const std::wstring &player_name, const nya_math::vec3 &pos, float yaw, target_type target, select_type select, bool tgt);

    void set_bomb_target(const nya_math::vec3 &pos, float radius, const color &c);
    void clear_bomb_marks() { m_bomb_marks.clear(); }
    void add_bomb_mark(const nya_math::vec3 &pos, float radius, const color &c);

    void clear_ecm() { m_ecms.clear(); }
    void add_ecm(const nya_math::vec3 &pos) { m_ecms.push_back(pos); }

    void clear_texts() { m_texts.clear(); }
    void add_text(int idx, const std::wstring &text, const std::string &font, int x, int y, const color &c);

    enum { popup_priority_mission_result = 200 };
    void popup(const std::wstring &text, int priority, const color &c = green, int time = 2000);

    void set_radio(std::wstring name, std::wstring message, int time, const color &c = white);

    hud(): m_common_loaded(false), m_hide(false) {}

private:
    typedef nya_math::vec2 vec2;
    nya_math::vec3 m_project_pos;
    nya_math::vec3 m_pos;
    ivalue m_speed;
    bvalue m_ab;
    fvalue m_pitch;
    fvalue m_yaw;
    fvalue m_roll;
    ivalue m_alt;
    ivalue m_missiles_icon;

    std::vector<nya_math::vec2> m_saam_mesh;

private:
    bool m_common_loaded;
    bool m_hide;
    std::vector<nya_math::vec3> m_ecms;

    struct zone
    {
        nya_math::vec3 pos;
        circle_mesh mesh;
        bvalue mode_point;
    };

    std::vector<zone> m_zones;

    struct lock { bool locked = false, active = false; };
    std::vector<lock> m_locks;
    ivalue m_lock_icon, m_lock_icon_active;

    ivalue m_anim_time;
    std::wstring m_missiles_name;
    ivalue m_missiles_count;
    bvalue m_mgun;
    bvalue m_saam_visible;
    bvalue m_saam_locked;
    bvalue m_saam_tracking;
    bvalue m_mgp_icon;
    bvalue m_mgp;
    bvalue m_jammed;

    std::vector<vec2> m_saam_mesh;

    struct score_line
    {
        int place = -1;
        std::wstring name, value;
    };

    std::vector<score_line> m_scores;
    bvalue m_show_team_score;
    std::wstring m_team_score[2];

    struct text
    {
        std::wstring t;
        std::string f;
        int x = 0, y = 0;
        nya_math::vec4 c;
    };

    std::vector<text> m_texts;

private:
    bool m_common_loaded;
    bool m_hide;
    fonts m_fonts;
    tiles m_common;
    tiles m_aircraft;
    tiles m_location;
    std::string m_location_name;
    vec2 m_map_offset;
    float m_map_scale = 1.0f;

private:
    std::wstring m_popup_text;
    color m_popup_color;
    ivalue m_popup_time;
    ivalue m_popup_priority;

private:
    std::wstring m_radio_name;
    std::vector<std::wstring> m_radio_text;
    color m_radio_color;
    ivalue m_radio_time;
};

//------------------------------------------------------------
}

<MSG> hud scores

<DFF> @@ -36,6 +36,10 @@ public:
     void set_jammed(bool active) { m_jammed = active; }
     void change_radar() { m_show_map = !m_show_map; }
 
+    void clear_scores();
+    void set_team_score(int allies, int enemies);
+    void set_score(int line, int place, const std::wstring &name, const std::wstring &value);
+
     void clear_alerts() { m_alerts.clear(); }
     void add_alert(float v) { m_alerts.push_back(v); }
 
@@ -60,8 +64,17 @@ public:
     void clear_ecm() { m_ecms.clear(); }
     void add_ecm(const nya_math::vec3 &pos) { m_ecms.push_back(pos); }
 
+    void clear_texts() { m_texts.clear(); }
+    void add_text(int idx, const std::wstring &text, const std::string &font, int x, int y, const nya_math::vec4 &color);
+
     hud(): m_common_loaded(false), m_hide(false) {}
 
+public:
+    const static nya_math::vec4 white;
+    const static nya_math::vec4 green;
+    const static nya_math::vec4 red;
+    const static nya_math::vec4 blue;
+
 private:
     nya_math::vec3 m_project_pos;
     nya_math::vec3 m_pos;
@@ -102,6 +115,26 @@ private:
 
     std::vector<nya_math::vec2> m_saam_mesh;
 
+    struct score_line
+    {
+        int place = 0;
+        std::wstring name, value;
+    };
+
+    std::vector<score_line> m_scores;
+    bvalue m_show_team_score;
+    std::wstring m_team_score[2];
+
+    struct text
+    {
+        std::wstring t;
+        std::string f;
+        int x = 0, y = 0;
+        nya_math::vec4 c;
+    };
+
+    std::vector<text> m_texts;
+
 private:
     bool m_common_loaded;
     bool m_hide;

{'commit': 'diff --git a/gui/hud.cpp b/gui/hud.cpp\nindex 2d9addf..3d50bcb 100755\n--- a/gui/hud.cpp\n+++ b/gui/hud.cpp\n@@ -9,6 +9,11 @@\n namespace gui\n {\n \n+const nya_math::vec4 hud::white = nya_math::vec4(255,255,255,255)/255.0;\n+const nya_math::vec4 hud::green = nya_math::vec4(103,223,144,255)/255.0;\n+const nya_math::vec4 hud::red = nya_math::vec4(200,0,0,255)/255.0;\n+const nya_math::vec4 hud::blue = nya_math::vec4(100,200,200,255)/255.0;\n+\n //------------------------------------------------------------\n \n inline bool get_project_pos(const render &r, const nya_math::vec3 &pos, nya_math::vec2 &result)\n@@ -107,11 +112,6 @@ void hud::draw(const render &r)\n \n     const float anim = fabsf(m_anim_time / 500.0f - 1.0);\n \n-    const auto white = nya_math::vec4(255,255,255,255)/255.0;\n-    const auto green = nya_math::vec4(103,223,144,255)/255.0;\n-    const auto red = nya_math::vec4(200,0,0,255)/255.0;\n-    const auto blue = nya_math::vec4(100,200,200,255)/255.0;\n-\n     nya_math::vec2 jam_glitch;\n     if (m_jammed)\n         jam_glitch.set((rand() % 2000 - 1000) * 0.005f, (rand() % 2000 - 1000) * 0.005f);\n@@ -129,7 +129,7 @@ void hud::draw(const render &r)\n     m_fonts.draw_text(r, buf, "OCRB15", r.get_width()/2 + 158, r.get_height()/2 - 8, alert_color);\n \n     swprintf(buf, sizeof(buf), L"pos   %ld   %ld   %ld", long(m_pos.x),long(m_pos.y),long(m_pos.z));\n-    m_fonts.draw_text(r, buf, "Zurich14", 20, 20, green);\n+    m_fonts.draw_text(r, buf, "Zurich14", 20, r.get_height() - 20, green);\n \n     m_common.draw(r, 10, r.get_width()/2 - 150, r.get_height()/2, alert_color);\n     m_common.draw(r, 16, r.get_width()/2 + 150, r.get_height()/2, alert_color);\n@@ -351,11 +351,85 @@ void hud::draw(const render &r)\n             m_common.draw(r, 170, r.get_width()/2, r.get_height()/2, red, ar + a);\n     }\n \n+    if (m_show_team_score)\n+    {\n+        const int h = 0; //r.get_height() - 70\n+        m_fonts.draw_text(r, m_team_score[0].c_str(), "ZurichXCnBT52", r.get_width()/2 - 30 - m_fonts.get_text_width(m_team_score[0].c_str(), "ZurichXCnBT52"), h, blue);\n+        m_fonts.draw_text(r, m_team_score[1].c_str(), "ZurichXCnBT52", r.get_width()/2 + 30, h, red);\n+    }\n+\n+    int scores_y = 5;\n+    for (auto &s: m_scores)\n+    {\n+        int pos = 10;\n+        wchar_t buf[16];\n+        swprintf(buf, sizeof(buf), L"%2d", s.place);\n+        m_fonts.draw_text(r, buf, "Zurich14", pos, scores_y, green);\n+        pos += 30;\n+        m_fonts.draw_text(r, s.name.c_str(), "Zurich14", pos, scores_y, green);\n+        pos += 200 - m_fonts.get_text_width(s.value.c_str(), "Zurich14");\n+        m_fonts.draw_text(r, s.value.c_str(), "Zurich14", pos, scores_y, green);\n+        scores_y += 20;\n+    }\n+\n+    for (auto &t: m_texts)\n+        m_fonts.draw_text(r, t.t.c_str(), t.f.c_str(), t.x, t.y, green);\n+\n     //Zurich12 -23 14 -111 20 -105 30 -96 BD30Outline -113 BD20Outline -26 BD22Outline -18 OCRB15 -33\n }\n \n //------------------------------------------------------------\n \n+void hud::clear_scores()\n+{\n+    m_show_team_score = false;\n+    m_scores.clear();\n+}\n+\n+//------------------------------------------------------------\n+\n+void hud::set_team_score(int allies, int enemies)\n+{\n+    m_show_team_score = true;\n+    m_team_score[0] = std::to_wstring(allies);\n+    m_team_score[1] = std::to_wstring(enemies);\n+}\n+\n+//------------------------------------------------------------\n+\n+void hud::set_score(int line, int place, const std::wstring &name, const std::wstring &value)\n+{\n+    if (line < 0)\n+        return;\n+\n+    if (line >= (int)m_texts.size())\n+        m_scores.resize(line + 1);\n+\n+    auto &s = m_scores[line];\n+    s.place = place;\n+    s.name = name;\n+    s.value = value;\n+}\n+\n+//------------------------------------------------------------\n+\n+void hud::add_text(int idx, const std::wstring &text, const std::string &font, int x, int y, const nya_math::vec4 &color)\n+{\n+    if (idx < 0)\n+        return;\n+\n+    if (idx >= (int)m_texts.size())\n+        m_texts.resize(idx + 1);\n+\n+    auto &t = m_texts[idx];\n+    t.t = text;\n+    t.f = font;\n+    t.x = x, t.y = y;\n+    t.c = color;\n+}\n+\n+//------------------------------------------------------------\n+\n void hud::set_missiles(const char *id, int icon)\n {\n     if (id && id[0] == \'_\')\ndiff --git a/gui/hud.h b/gui/hud.h\nindex 33c7ba8..1882a12 100644\n--- a/gui/hud.h\n+++ b/gui/hud.h\n@@ -36,6 +36,10 @@ public:\n     void set_jammed(bool active) { m_jammed = active; }\n     void change_radar() { m_show_map = !m_show_map; }\n \n+    void clear_scores();\n+    void set_team_score(int allies, int enemies);\n+    void set_score(int line, int place, const std::wstring &name, const std::wstring &value);\n+\n     void clear_alerts() { m_alerts.clear(); }\n     void add_alert(float v) { m_alerts.push_back(v); }\n \n@@ -60,8 +64,17 @@ public:\n     void clear_ecm() { m_ecms.clear(); }\n     void add_ecm(const nya_math::vec3 &pos) { m_ecms.push_back(pos); }\n \n+    void clear_texts() { m_texts.clear(); }\n+    void add_text(int idx, const std::wstring &text, const std::string &font, int x, int y, const nya_math::vec4 &color);\n+\n     hud(): m_common_loaded(false), m_hide(false) {}\n \n+public:\n+    const static nya_math::vec4 white;\n+    const static nya_math::vec4 green;\n+    const static nya_math::vec4 red;\n+    const static nya_math::vec4 blue;\n+\n private:\n     nya_math::vec3 m_project_pos;\n     nya_math::vec3 m_pos;\n@@ -102,6 +115,26 @@ private:\n \n     std::vector<nya_math::vec2> m_saam_mesh;\n \n+    struct score_line\n+    {\n+        int place = 0;\n+        std::wstring name, value;\n+    };\n+\n+    std::vector<score_line> m_scores;\n+    bvalue m_show_team_score;\n+    std::wstring m_team_score[2];\n+\n+    struct text\n+    {\n+        std::wstring t;\n+        std::string f;\n+        int x = 0, y = 0;\n+        nya_math::vec4 c;\n+    };\n+\n+    std::vector<text> m_texts;\n+\n private:\n     bool m_common_loaded;\n     bool m_hide;\n', 'commit_subject': 'hud scores', 'repo_name': 'undefined-darkness/open-horizon', 'committer': {'name': 'Undefined Darkness', 'email': '6097a8eb4b8bba70d1426da0bee4348be7ff02b2@outlook.com', 'time_sec': '1458283442', 'tz_offset': '180', 'date': {'seconds': '1458283442'}}, 'commit_tree': 'c63feefc6f54a018f459b2e6bd3dd9eaaf641a58', 'commit_message': 'hud scores\n', 'language_name': 'C++', 'license': 'mit', 'hunks': '@@ -36,6 +36,10 @@ public:\n     void set_jammed(bool active) { m_jammed = active; }\n     void change_radar() { m_show_map = !m_show_map; }\n \n+    void clear_scores();\n+    void set_team_score(int allies, int enemies);\n+    void set_score(int line, int place, const std::wstring &name, const std::wstring &value);\n+\n     void clear_alerts() { m_alerts.clear(); }\n     void add_alert(float v) { m_alerts.push_back(v); }\n \n@@ -60,8 +64,17 @@ public:\n     void clear_ecm() { m_ecms.clear(); }\n     void add_ecm(const nya_math::vec3 &pos) { m_ecms.push_back(pos); }\n \n+    void clear_texts() { m_texts.clear(); }\n+    void add_text(int idx, const std::wstring &text, const std::string &font, int x, int y, const nya_math::vec4 &color);\n+\n     hud(): m_common_loaded(false), m_hide(false) {}\n \n+public:\n+    const static nya_math::vec4 white;\n+    const static nya_math::vec4 green;\n+    const static nya_math::vec4 red;\n+    const static nya_math::vec4 blue;\n+\n private:\n     nya_math::vec3 m_project_pos;\n     nya_math::vec3 m_pos;\n@@ -102,6 +115,26 @@ private:\n \n     std::vector<nya_math::vec2> m_saam_mesh;\n \n+    struct score_line\n+    {\n+        int place = 0;\n+        std::wstring name, value;\n+    };\n+\n+    std::vector<score_line> m_scores;\n+    bvalue m_show_team_score;\n+    std::wstring m_team_score[2];\n+\n+    struct text\n+    {\n+        std::wstring t;\n+        std::string f;\n+        int x = 0, y = 0;\n+        nya_math::vec4 c;\n+    };\n+\n+    std::vector<text> m_texts;\n+\n private:\n     bool m_common_loaded;\n     bool m_hide;\n', 'addition_count': 33, 'deletion_count': 0, 'src_file': 'a/gui/hud.h', 'tgt_file': 'b/gui/hud.h', 'file_extension': '.h', 'before_file': '//\n// open horizon -- undefined_darkness@outlook.com\n//\n\n#pragma once\n\n#include "ui.h"\n#include "circle_mesh.h"\n\nnamespace gui\n{\n//------------------------------------------------------------\n\nclass hud\n{\npublic:\n    void load(const char *aircraft_name, const char *location_name);\n    void draw(const render &r);\n    void update(int dt);\n\n    void set_location(const char *location_name);\n    void set_hide(bool value);\n    void set_project_pos(const nya_math::vec3 &pos) { m_project_pos = pos; }\n    void set_pos(const nya_math::vec3 &pos) { m_pos = pos; }\n    void set_angles(float pitch, float yaw, float roll) { m_pitch = pitch, m_yaw = yaw, m_roll = roll; }\n    void set_speed(int value) { m_speed = value; }\n    void set_ab(bool value) { m_ab = value; }\n    void set_pitch_ladder(bool visible) { m_pitch_ladder = visible; }\n    void set_alt(int value) { m_alt = value; }\n    void set_missiles(const char *id, int icon);\n    void set_missiles_count(int count) { m_missiles_count = count; }\n    void set_missile_reload(int idx, float value);\n    void set_locks(int count, int icon);\n    void set_lock(int idx, bool locked, bool active);\n    void set_mgun(bool visible) { m_mgun = visible; }\n    void set_jammed(bool active) { m_jammed = active; }\n    void change_radar() { m_show_map = !m_show_map; }\n\n    void clear_alerts() { m_alerts.clear(); }\n    void add_alert(float v) { m_alerts.push_back(v); }\n\n\n    bool is_special_selected() const { return m_missiles_icon > 0; }\n\n    void clear_scores();\n    void set_team_score(int allies, int enemies);\n    void set_score(int line, int place, const std::wstring &name, const std::wstring &value);\n    void remove_score(int line);\n\n    void clear_alerts() { m_alerts.clear(); }\n    void add_alert(float v) { m_alerts.push_back(v); }\n\npublic:\n    typedef nya_math::vec4 color;\n    const static color white;\n    const static color green;\n    const static color red;\n    const static color blue;\n\n    void clear_ecm() { m_ecms.clear(); }\n    void add_ecm(const nya_math::vec3 &pos) { m_ecms.push_back(pos); }\n\n    hud(): m_common_loaded(false), m_hide(false) {}\n\nprivate:\n    nya_math::vec3 m_project_pos;\n    nya_math::vec3 m_pos;\n    };\n\n    void clear_targets() { m_targets.clear(); }\n    void add_target(const nya_math::vec3 &pos, float yaw, target_type target, select_type select);\n    void add_target(const std::wstring &name, const std::wstring &player_name, const nya_math::vec3 &pos, float yaw, target_type target, select_type select, bool tgt);\n\n    void set_bomb_target(const nya_math::vec3 &pos, float radius, const color &c);\n    void clear_bomb_marks() { m_bomb_marks.clear(); }\n    void add_bomb_mark(const nya_math::vec3 &pos, float radius, const color &c);\n\n    void clear_ecm() { m_ecms.clear(); }\n    void add_ecm(const nya_math::vec3 &pos) { m_ecms.push_back(pos); }\n\n    void clear_texts() { m_texts.clear(); }\n    void add_text(int idx, const std::wstring &text, const std::string &font, int x, int y, const color &c);\n\n    enum { popup_priority_mission_result = 200 };\n    void popup(const std::wstring &text, int priority, const color &c = green, int time = 2000);\n\n    void set_radio(std::wstring name, std::wstring message, int time, const color &c = white);\n\n    hud(): m_common_loaded(false), m_hide(false) {}\n\nprivate:\n    typedef nya_math::vec2 vec2;\n    nya_math::vec3 m_project_pos;\n    nya_math::vec3 m_pos;\n    ivalue m_speed;\n    bvalue m_ab;\n    fvalue m_pitch;\n    fvalue m_yaw;\n    fvalue m_roll;\n    ivalue m_alt;\n    ivalue m_missiles_icon;\n\n    std::vector<nya_math::vec2> m_saam_mesh;\n\nprivate:\n    bool m_common_loaded;\n    bool m_hide;\n    std::vector<nya_math::vec3> m_ecms;\n\n    struct zone\n    {\n        nya_math::vec3 pos;\n        circle_mesh mesh;\n        bvalue mode_point;\n    };\n\n    std::vector<zone> m_zones;\n\n    struct lock { bool locked = false, active = false; };\n    std::vector<lock> m_locks;\n    ivalue m_lock_icon, m_lock_icon_active;\n\n    ivalue m_anim_time;\n    std::wstring m_missiles_name;\n    ivalue m_missiles_count;\n    bvalue m_mgun;\n    bvalue m_saam_visible;\n    bvalue m_saam_locked;\n    bvalue m_saam_tracking;\n    bvalue m_mgp_icon;\n    bvalue m_mgp;\n    bvalue m_jammed;\n\n    std::vector<vec2> m_saam_mesh;\n\n    struct score_line\n    {\n        int place = -1;\n        std::wstring name, value;\n    };\n\n    std::vector<score_line> m_scores;\n    bvalue m_show_team_score;\n    std::wstring m_team_score[2];\n\n    struct text\n    {\n        std::wstring t;\n        std::string f;\n        int x = 0, y = 0;\n        nya_math::vec4 c;\n    };\n\n    std::vector<text> m_texts;\n\nprivate:\n    bool m_common_loaded;\n    bool m_hide;\n    fonts m_fonts;\n    tiles m_common;\n    tiles m_aircraft;\n    tiles m_location;\n    std::string m_location_name;\n    vec2 m_map_offset;\n    float m_map_scale = 1.0f;\n\nprivate:\n    std::wstring m_popup_text;\n    color m_popup_color;\n    ivalue m_popup_time;\n    ivalue m_popup_priority;\n\nprivate:\n    std::wstring m_radio_name;\n    std::vector<std::wstring> m_radio_text;\n    color m_radio_color;\n    ivalue m_radio_time;\n};\n\n//------------------------------------------------------------\n}\n', 'message': 'hud scores\n', 'author_name': 'Undefined Darkness', 'lang': 'h'}