Skip to content

(WIP) Editor UI experiment #3287

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 41 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
d8efd1b
Add Play button and grid size change button
tobbi Jun 3, 2025
796038a
Add offset to tilemaps in order to have space for displaying toolbar …
tobbi Jun 3, 2025
cd63904
Fix offset calculations for tilemaps when saving
tobbi Jun 3, 2025
a619be8
Include "Don't show grid" in grid toggle button
tobbi Jun 3, 2025
42d8a84
Add save button
tobbi Jun 3, 2025
00de793
Improve logical statement
tobbi Jun 4, 2025
a57f6da
Add button to switch between tile and object mode
tobbi Jun 15, 2025
4d395db
Add support for help texts for editor buttons
tobbi Jun 15, 2025
7b91ace
Update play and save editor icons
tobbi Jun 15, 2025
f0bc09e
Change font to small font, replace grid button
tobbi Jun 15, 2025
ddfb8c9
Make button icons smaller, add function to ToolIcon class for setting…
tobbi Jun 15, 2025
ae1f3ba
Make mode buttons actually work
tobbi Jun 15, 2025
ba7b357
Change icon for toggling between tile and object mode.
tobbi Jun 20, 2025
a23e3ed
WIP: Add editor controls for objects on mouse click
tobbi Jun 21, 2025
187a755
Change layer for properties panel background, add background for toolbar
tobbi Jun 21, 2025
2d5e37c
Add more edit capabilities to sidebar
tobbi Jun 21, 2025
553df0e
Add "edit script" button for script properties
tobbi Jun 23, 2025
583e027
Move positioning code over to overlay_widget and editor
tobbi Jul 3, 2025
2254450
Fix screen coordinates for new positions
tobbi Jul 3, 2025
3d8e69a
Fix initial camera position
tobbi Jul 3, 2025
3821512
Label and control classes: code style
tobbi Jul 3, 2025
599d672
Base work to support adding descriptions to editor properties to be s…
tobbi Jul 3, 2025
86844e0
Added example descriptions per data type
tobbi Jul 3, 2025
9d1a362
Add WIP code for viewing the text of a level
tobbi Jul 3, 2025
a06c500
Fix bugs in ControlTextbox when binding a value
tobbi Jul 4, 2025
e926d93
Add textbox elements for string properties
tobbi Jul 4, 2025
838cef7
Rudimentary support for making editor buttons invisible on mode change
tobbi Jul 4, 2025
5533630
Add test from here button to sidebar
tobbi Jul 4, 2025
c180d53
First support for enum options
tobbi Jul 5, 2025
3f0fed5
Try to update object after changing e.g. crusher size
tobbi Jul 5, 2025
644c6ce
Move `update_properties_panel` method out into own function
tobbi Jul 5, 2025
ff334ed
WIP: Properties for clicked layer items
tobbi Jul 5, 2025
039d972
Fix Checkbox position and dimensions
tobbi Jul 5, 2025
745b923
Fix tooltip z position and use normal font for better readability
tobbi Jul 5, 2025
0208773
WIP: Direction property left sidebar control
tobbi Jul 5, 2025
483d7b5
Delete properties when object is deleted
tobbi Jul 5, 2025
7ed9eda
Add mouse "select" button
tobbi Jul 5, 2025
08627fa
Add object selection modes to top menu bar
tobbi Jul 5, 2025
32d2f18
Move duplicated objects down by half a tile, change overlay texts
tobbi Jul 5, 2025
466a466
Small code style
tobbi Jul 5, 2025
776185b
Set most buttons invisible, only show them on mode select
tobbi Jul 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added data/images/engine/editor/grid_button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/engine/editor/play_button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified data/images/engine/editor/redo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/engine/editor/save.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified data/images/engine/editor/undo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 42 additions & 9 deletions src/editor/button_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#include "supertux/gameconfig.hpp"
#include "supertux/globals.hpp"
#include "supertux/resources.hpp"
#include "util/log.hpp"
#include "video/viewport.hpp"
#include "video/video_system.hpp"

Expand All @@ -28,7 +30,9 @@ ButtonWidget::ButtonWidget(SpritePtr sprite, const Vector& pos,
static_cast<float>(m_sprite->get_height()))),
m_grab(false),
m_hover(false),
m_sig_click(std::move(sig_click))
m_sig_click(std::move(sig_click)),
m_mouse_pos(),
m_help_text()
{
}

Expand All @@ -39,7 +43,7 @@ ButtonWidget::draw(DrawingContext& context)
LAYER_GUI-5);

if (m_sprite) {
m_sprite->draw(context.color(), m_rect.p1(), LAYER_GUI-5);
m_sprite->draw_scaled(context.color(), m_rect.grown(-4.0f), LAYER_GUI - 5);
}

if (m_grab) {
Expand All @@ -49,6 +53,16 @@ ButtonWidget::draw(DrawingContext& context)
context.color().draw_filled_rect(m_rect, g_config->editorhovercolor, 4.0f,
LAYER_GUI-5);
}

if (m_hover && !m_help_text.empty())
{
const auto& font = Resources::control_font;
const auto text_height = font->get_text_height(m_help_text);
const auto text_width = font->get_text_width(m_help_text);
const auto text_rect = Rectf(m_mouse_pos + Vector(32, 32), m_mouse_pos + Vector(32, 32) + Vector(text_width, text_height));
context.color().draw_filled_rect(text_rect, Color::BLACK, INT_MAX);
context.color().draw_text(font, m_help_text, m_mouse_pos + Vector(32, 32), FontAlignment::ALIGN_LEFT, INT_MAX);
}
}

void
Expand All @@ -71,10 +85,10 @@ ButtonWidget::on_mouse_button_up(const SDL_MouseButtonEvent& button)
{
if (button.button != SDL_BUTTON_LEFT) return false;

Vector mouse_pos = VideoSystem::current()->get_viewport().to_logical(button.x, button.y);
m_mouse_pos = VideoSystem::current()->get_viewport().to_logical(button.x, button.y);

if (m_grab) {
if (m_rect.contains(mouse_pos)) {
if (m_rect.contains(m_mouse_pos)) {
if (m_sig_click) {
m_sig_click();
}
Expand All @@ -92,9 +106,9 @@ ButtonWidget::on_mouse_button_down(const SDL_MouseButtonEvent& button)
{
if (button.button != SDL_BUTTON_LEFT) return false;

Vector mouse_pos = VideoSystem::current()->get_viewport().to_logical(button.x, button.y);
m_mouse_pos = VideoSystem::current()->get_viewport().to_logical(button.x, button.y);

if (m_rect.contains(mouse_pos)) {
if (m_rect.contains(m_mouse_pos)) {
m_hover = true;
m_grab = true;
return true;
Expand All @@ -107,16 +121,35 @@ ButtonWidget::on_mouse_button_down(const SDL_MouseButtonEvent& button)
bool
ButtonWidget::on_mouse_motion(const SDL_MouseMotionEvent& motion)
{
Vector mouse_pos = VideoSystem::current()->get_viewport().to_logical(motion.x, motion.y);
m_mouse_pos = VideoSystem::current()->get_viewport().to_logical(motion.x, motion.y);

if (m_grab) {
m_hover = m_rect.contains(mouse_pos);
m_hover = m_rect.contains(m_mouse_pos);
return true;
} else if (m_rect.contains(mouse_pos)) {
} else if (m_rect.contains(m_mouse_pos)) {
m_hover = true;
return false;
} else {
m_hover = false;
return false;
}
}

void
ButtonWidget::set_sprite(SpritePtr sprite)
{
m_sprite = std::move(sprite);
m_rect.set_size(sprite->get_width() * 1.0f, sprite->get_height() * 1.0f);
}

void
ButtonWidget::set_sprite(const std::string& path)
{
set_sprite(SpriteManager::current()->create(path));
}

void
ButtonWidget::set_help_text(const std::string& help_text)
{
m_help_text = help_text;
}
85 changes: 85 additions & 0 deletions src/editor/button_widget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,99 @@ class ButtonWidget : public Widget
virtual bool on_mouse_button_down(const SDL_MouseButtonEvent& button) override;
virtual bool on_mouse_motion(const SDL_MouseMotionEvent& motion) override;

void set_sprite(const std::string& path);
void set_sprite(SpritePtr sprite);

void set_help_text(const std::string& help_text);

private:
SpritePtr m_sprite;
Rectf m_rect;
bool m_grab;
bool m_hover;
std::function<void()> m_sig_click;
Vector m_mouse_pos;
std::string m_help_text;

private:
ButtonWidget(const ButtonWidget&) = delete;
ButtonWidget& operator=(const ButtonWidget&) = delete;
};

class EditorToolbarButtonWidget : public ButtonWidget
{
public:
EditorToolbarButtonWidget(SpritePtr sprite, const Vector& pos, std::function<void()> m_sig_click = {}) :
ButtonWidget(std::move(sprite), pos, m_sig_click),
m_tile_mode_visible(true),
m_object_mode_visible(true),
m_visible(true)
{
}

EditorToolbarButtonWidget(const std::string& path, const Vector& pos, std::function<void()> callback = {}) :
ButtonWidget(SpriteManager::current()->create(path), pos, std::move(callback)),
m_tile_mode_visible(true),
m_object_mode_visible(true),
m_visible(true)
{
}

virtual void draw(DrawingContext& context) override
{
if (!get_visible())
return;

ButtonWidget::draw(context);
}

virtual void update(float dt_sec) override
{
if (!get_visible())
return;

ButtonWidget::update(dt_sec);
}

virtual bool on_mouse_button_up(const SDL_MouseButtonEvent& button) override
{
if (!get_visible())
return false;

return ButtonWidget::on_mouse_button_up(button);
}

virtual bool on_mouse_button_down(const SDL_MouseButtonEvent& button) override
{
if (!get_visible())
return false;

return ButtonWidget::on_mouse_button_down(button);
}

virtual bool on_mouse_motion(const SDL_MouseMotionEvent& motion) override
{
if (!get_visible())
return false;

return ButtonWidget::on_mouse_motion(motion);
}

void set_visible_in_tile_mode(bool visible) { m_tile_mode_visible = visible; }
bool get_visible_in_tile_mode() const { return m_tile_mode_visible; }

void set_visible_in_object_mode(bool visible) { m_object_mode_visible = visible; }
bool get_visible_in_object_mode() const { return m_object_mode_visible; }

void set_visible(bool visible) { m_visible = visible; }
bool get_visible() const { return m_visible; }

private:
bool m_tile_mode_visible;
bool m_object_mode_visible;
bool m_visible;

private:
EditorToolbarButtonWidget(const EditorToolbarButtonWidget&) = delete;
EditorToolbarButtonWidget& operator=(const EditorToolbarButtonWidget&) = delete;
};
Loading
Loading