|
| 1 | +// SuperTux |
| 2 | +// Copyright (C) 2025 MatusGuy <[email protected]> |
| 3 | +// |
| 4 | +// This program is free software: you can redistribute it and/or modify |
| 5 | +// it under the terms of the GNU General Public License as published by |
| 6 | +// the Free Software Foundation, either version 3 of the License, or |
| 7 | +// (at your option) any later version. |
| 8 | +// |
| 9 | +// This program is distributed in the hope that it will be useful, |
| 10 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +// GNU General Public License for more details. |
| 13 | +// |
| 14 | +// You should have received a copy of the GNU General Public License |
| 15 | +// along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + |
| 17 | +#include "editor_comment.hpp" |
| 18 | + |
| 19 | +#include "editor/editor.hpp" |
| 20 | +#include "supertux/info_box_line.hpp" |
| 21 | +#include "util/reader_mapping.hpp" |
| 22 | +#include "video/drawing_context.hpp" |
| 23 | + |
| 24 | +EditorComment::EditorComment(const ReaderMapping& reader): |
| 25 | + MovingObject(reader), |
| 26 | + m_comment(""), |
| 27 | + m_lines() |
| 28 | +{ |
| 29 | + parse_type(reader); |
| 30 | + |
| 31 | + float w,h; |
| 32 | + reader.get("width", w, 32.f * 3); |
| 33 | + reader.get("height", h, 32.f * 3); |
| 34 | + m_col.m_bbox.set_size(w, h); |
| 35 | + |
| 36 | + reader.get("comment", m_comment); |
| 37 | + refresh_comment(); |
| 38 | +} |
| 39 | + |
| 40 | +void |
| 41 | +EditorComment::draw(DrawingContext& context) |
| 42 | +{ |
| 43 | + // TODO: There should be an object factory param |
| 44 | + // for objects that only exist when testing in editor. |
| 45 | + if (!Editor::current()) |
| 46 | + return; |
| 47 | + |
| 48 | + float y = get_y(); |
| 49 | + for (std::unique_ptr<InfoBoxLine>& line : m_lines) |
| 50 | + { |
| 51 | + if (y >= get_bbox().get_bottom()) |
| 52 | + break; |
| 53 | + |
| 54 | + line->draw(context, Rectf(Vector(get_x(), y), Sizef(get_width() / 2, y)), get_layer() + 1, InfoBoxLine::LEFT); |
| 55 | + y += line->get_height(); |
| 56 | + } |
| 57 | + |
| 58 | + context.color().draw_filled_rect(get_bbox(), get_color(), 0.f, get_layer()); |
| 59 | +} |
| 60 | + |
| 61 | +void |
| 62 | +EditorComment::check_state() |
| 63 | +{ |
| 64 | + refresh_comment(); |
| 65 | +} |
| 66 | + |
| 67 | +GameObjectTypes |
| 68 | +EditorComment::get_types() const |
| 69 | +{ |
| 70 | + return { |
| 71 | + /* l10n: A note refers to a reminder left for future |
| 72 | + level designers to read in order to better understand |
| 73 | + the usage of certain features in a level, for example. */ |
| 74 | + { "note", _("Note") }, |
| 75 | + |
| 76 | + /* l10n: A to-do refers to a reminder left for the |
| 77 | + author of the comment to finish designing something in |
| 78 | + a level. */ |
| 79 | + { "todo", _("To-do") }, |
| 80 | + |
| 81 | + /* l10n: A fix-me refers to a reminder left for the |
| 82 | + author of the comment to fix a flaw with the level |
| 83 | + design. */ |
| 84 | + { "fixme", _("Fix-me") }, |
| 85 | + |
| 86 | + /* l10n: A hack refers to usage of an unintended or |
| 87 | + non-ideal way of implementing a level design idea. */ |
| 88 | + { "hack", _("Hack") } |
| 89 | + }; |
| 90 | +} |
| 91 | + |
| 92 | +ObjectSettings |
| 93 | +EditorComment::get_settings() |
| 94 | +{ |
| 95 | + ObjectSettings result = MovingObject::get_settings(); |
| 96 | + |
| 97 | + result.add_multiline_text(_("Comment"), &m_comment, "comment"); |
| 98 | + |
| 99 | + return result; |
| 100 | +} |
| 101 | + |
| 102 | +void |
| 103 | +EditorComment::refresh_comment() |
| 104 | +{ |
| 105 | + m_lines = InfoBoxLine::split(m_comment, get_width(), true); |
| 106 | +} |
| 107 | + |
| 108 | +Color |
| 109 | +EditorComment::get_color() const |
| 110 | +{ |
| 111 | + switch (m_type) |
| 112 | + { |
| 113 | + case NOTE: return Color(0.19f, 0.65f, 0.32f, 0.6f); |
| 114 | + case TODO: return Color(0.26f, 0.53f, 0.96f, 0.6f); |
| 115 | + case FIXME: return Color(1.f, 0.44f, 0.11f, 0.6f); |
| 116 | + case HACK: return Color(0.96f, 0.23f, 0.23f, 0.6f); |
| 117 | + default: return Color(); |
| 118 | + } |
| 119 | +} |
| 120 | + |
| 121 | +/* EOF */ |
0 commit comments