Begin implementing MessageBox
This commit is contained in:
parent
62c85aeb66
commit
33efea173f
@ -137,6 +137,7 @@ if(BUILD_CLIENT)
|
|||||||
src/game/gui/image_gallery.cpp
|
src/game/gui/image_gallery.cpp
|
||||||
src/game/gui/label.cpp
|
src/game/gui/label.cpp
|
||||||
src/game/gui/layout.cpp
|
src/game/gui/layout.cpp
|
||||||
|
src/game/gui/message_box.cpp
|
||||||
src/game/gui/style_change_listener.cpp
|
src/game/gui/style_change_listener.cpp
|
||||||
src/game/gui/style.cpp
|
src/game/gui/style.cpp
|
||||||
src/game/gui/text_edit.cpp
|
src/game/gui/text_edit.cpp
|
||||||
|
83
src/game/gui/message_box.cpp
Normal file
83
src/game/gui/message_box.cpp
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
/*
|
||||||
|
PolyGun
|
||||||
|
|
||||||
|
Copyright (c) 2023 mrkubax10 <mrkubax10@onet.pl>
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "game/gui/message_box.hpp"
|
||||||
|
|
||||||
|
#include "common/locale/util.hpp"
|
||||||
|
#include "common/xml/reader.hpp"
|
||||||
|
#include "game/engine/engine.hpp"
|
||||||
|
#include "game/gui/style.hpp"
|
||||||
|
#include "game/renderer/texture.hpp"
|
||||||
|
|
||||||
|
using namespace polygun::gui;
|
||||||
|
|
||||||
|
MessageBox::MessageBox(engine::Engine* engine, xml::XMLNode* node) :
|
||||||
|
Container(engine, node),
|
||||||
|
StyleChangeListener(),
|
||||||
|
m_title(),
|
||||||
|
m_title_texture(engine->get_master_renderer()->create_texture())
|
||||||
|
{
|
||||||
|
xml::XMLReader reader(node);
|
||||||
|
std::string val;
|
||||||
|
if(reader.get_attribute("text", m_title))
|
||||||
|
update_title_text_texture();
|
||||||
|
else if(reader.get_attribute("tr_text", val))
|
||||||
|
set_title(_(val));
|
||||||
|
m_left_padding = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageBox::~MessageBox() {
|
||||||
|
delete m_title_texture;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MessageBox::set_title(const std::string& title) {
|
||||||
|
m_title = title;
|
||||||
|
update_title_text_texture();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MessageBox::render(renderer::GUIRenderer* renderer) {
|
||||||
|
renderer->fill_rect(glm::vec2(get_x()-2, get_y()-2), glm::vec2(get_width()+2, get_height()+2), add_to_color(Style::get().m_background_color, glm::vec4ub(100, 100, 100, 0)));
|
||||||
|
renderer->fill_rect(glm::vec2(get_x()+2, get_y()+2), glm::vec2(get_width(), get_height()), subtract_from_color(Style::get().m_background_color, glm::vec4ub(40, 40, 40, 0)));
|
||||||
|
renderer->fill_rect(glm::vec2(get_x(), get_y()), glm::vec2(get_width(), get_height()), Style::get().m_background_color);
|
||||||
|
renderer->render_texture(glm::vec2(get_x()+5, get_y()+5), m_title_texture);
|
||||||
|
Container::render(renderer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MessageBox::on_style_change() {
|
||||||
|
update_title_text_texture();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MessageBox::update_title_text_texture() {
|
||||||
|
std::unique_ptr<renderer::Surface> surf;
|
||||||
|
const float width = get_width();
|
||||||
|
const float height = get_height();
|
||||||
|
const glm::vec4ub& color = m_inactive?Style::get().m_inactive_text_color:Style::get().m_text_color;
|
||||||
|
const unsigned title_size = 14;
|
||||||
|
if(width>0 && height>0)
|
||||||
|
surf = Style::get().m_font.render_text_in_area(glm::vec2(width, height), m_title, title_size, color);
|
||||||
|
else
|
||||||
|
surf = Style::get().m_font.render_text(m_title, title_size, color);
|
||||||
|
m_title_texture->load_from_surface(*surf);
|
||||||
|
m_top_padding = m_title_texture->get_height()+15;
|
||||||
|
}
|
54
src/game/gui/message_box.hpp
Normal file
54
src/game/gui/message_box.hpp
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
PolyGun
|
||||||
|
|
||||||
|
Copyright (c) 2023 mrkubax10 <mrkubax10@onet.pl>
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef POLYGUN_GUI_MESSAGEBOX_HPP
|
||||||
|
#define POLYGUN_GUI_MESSAGEBOX_HPP
|
||||||
|
|
||||||
|
#include "game/gui/container.hpp"
|
||||||
|
#include "game/gui/style_change_listener.hpp"
|
||||||
|
|
||||||
|
namespace polygun::renderer {
|
||||||
|
class Texture;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace polygun::gui {
|
||||||
|
class MessageBox final : public Container, public StyleChangeListener {
|
||||||
|
MessageBox(engine::Engine* engine, xml::XMLNode* node);
|
||||||
|
virtual ~MessageBox() override;
|
||||||
|
|
||||||
|
void set_title(const std::string& title);
|
||||||
|
|
||||||
|
virtual void render(renderer::GUIRenderer* renderer) override;
|
||||||
|
virtual void on_style_change() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string m_title;
|
||||||
|
renderer::Texture* m_title_texture;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void update_title_text_texture();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // POLYGUN_GUI_MESSAGEBOX_HPP
|
21
src/game/hud/kartkowka.html
Normal file
21
src/game/hud/kartkowka.html
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang ="pl">
|
||||||
|
<head>
|
||||||
|
<meta charset ="utf-8">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h2>Szymon Maczuga</h2>
|
||||||
|
<hr>
|
||||||
|
<p>Uczę się i chce uzyskac zawód <u><b>Technik Programista</b></u>.</p>
|
||||||
|
<div> Dzisiaj pójdzie mi super i dostane ocenę <i><mark> pozytywną </mark></i></div>
|
||||||
|
<p>Dostanę <s>niedostateczny</s> czy bardzo dobry</p>
|
||||||
|
<br>
|
||||||
|
<mark>Trzeba sie uczyć systematycznie</mark>
|
||||||
|
<pre>Zmotywuje się do
|
||||||
|
nauki
|
||||||
|
i osiągne sukces.</pre>
|
||||||
|
<code>Logarytmy to jest wyzwanie: log<sub>a</sub>b<sup>n</sup>=n*log<sub>a</sub>b</code>
|
||||||
|
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
x
Reference in New Issue
Block a user