Skip to content

Commit 1f82f3c

Browse files
committed
WIP: Add editor controls for objects on mouse click
1 parent a40a5b2 commit 1f82f3c

File tree

4 files changed

+70
-2
lines changed

4 files changed

+70
-2
lines changed

src/editor/editor.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ Editor::Editor() :
120120
m_tileset(nullptr),
121121
m_has_deprecated_tiles(false),
122122
m_widgets(),
123+
m_controls(),
123124
m_undo_widget(),
124125
m_redo_widget(),
125126
m_grid_size_widget(),
@@ -238,6 +239,14 @@ Editor::draw(Compositor& compositor)
238239
widget->draw(context);
239240
}
240241

242+
context.color().draw_filled_rect(Rectf(0, 32.0f, 200.0f, SCREEN_HEIGHT - 32.0f),
243+
Color(0.2f, 0.2f, 0.2f), LAYER_GUI);
244+
245+
for(const auto& control : m_controls)
246+
{
247+
control->draw(context);
248+
}
249+
241250
// If camera scale must be changed, change it here.
242251
if (m_new_scale != 0.f)
243252
{
@@ -367,6 +376,11 @@ Editor::update(float dt_sec, const Controller& controller)
367376
widget->update(dt_sec);
368377
}
369378

379+
for(const auto& control : m_controls)
380+
{
381+
control->update(dt_sec);
382+
}
383+
370384
// Now that all widgets have been updated, which should have relinquished
371385
// pointers to objects marked for deletion, we can actually delete them.
372386
for (auto& sector : m_level->get_sectors())
@@ -1257,4 +1271,26 @@ Editor::pack_addon()
12571271
*zip.Add_File(id + ".nfo") << ss.rdbuf();
12581272
}
12591273

1274+
void
1275+
Editor::addControl(const std::string& name, std::unique_ptr<InterfaceControl> new_control)
1276+
{
1277+
float height = 35.f;
1278+
for (const auto& control : m_controls) {
1279+
height = std::max(height, control->get_rect().get_bottom() + 5.f);
1280+
}
1281+
1282+
if (new_control.get()->get_rect().get_width() == 0.f || new_control.get()->get_rect().get_height() == 0.f) {
1283+
new_control.get()->set_rect(Rectf(100.f, height, 200.f - 1.0f, height + 20.f));
1284+
} else {
1285+
new_control.get()->set_rect(Rectf(new_control.get()->get_rect().get_left(),
1286+
height,
1287+
new_control.get()->get_rect().get_right(),
1288+
height + new_control.get()->get_rect().get_height()));
1289+
}
1290+
1291+
new_control.get()->m_label = std::make_unique<InterfaceLabel>(Rectf(3.f, height, 100.f, height + 20.f), std::move(name));
1292+
//new_control.get()->m_on_change = std::function<void()>([this](){ this->push_version(); });
1293+
m_controls.push_back(std::move(new_control));
1294+
}
1295+
12601296
/* EOF */

src/editor/editor.hpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "editor/toolbox_widget.hpp"
2929
#include "editor/layers_widget.hpp"
3030
#include "editor/scroller_widget.hpp"
31+
#include "interface/control.hpp"
3132
#include "supertux/screen.hpp"
3233
#include "supertux/world.hpp"
3334
#include "util/currenton.hpp"
@@ -81,6 +82,11 @@ class Editor final : public Screen,
8182
void event(const SDL_Event& ev) override;
8283
void on_window_resize() override;
8384

85+
std::vector<std::unique_ptr<InterfaceControl>>& get_controls()
86+
{
87+
return m_controls;
88+
}
89+
8490
void disable_keyboard() { m_enabled = false; }
8591

8692
inline Level* get_level() const { return m_level.get(); }
@@ -158,6 +164,7 @@ class Editor final : public Screen,
158164

159165
inline Sector* get_sector() { return m_sector; }
160166

167+
void addControl(const std::string& name, std::unique_ptr<InterfaceControl> new_control);
161168
void retoggle_undo_tracking();
162169
void undo_stack_cleanup();
163170

@@ -182,7 +189,6 @@ class Editor final : public Screen,
182189
void save_level(const std::string& filename = "", bool switch_file = false);
183190
void test_level(const std::optional<std::pair<std::string, Vector>>& test_pos);
184191
void update_keyboard(const Controller& controller);
185-
186192
void keep_camera_in_bounds();
187193

188194
protected:
@@ -220,6 +226,8 @@ class Editor final : public Screen,
220226
bool m_has_deprecated_tiles;
221227

222228
std::vector<std::unique_ptr<Widget> > m_widgets;
229+
std::vector<std::unique_ptr<InterfaceControl>> m_controls;
230+
223231
ButtonWidget* m_undo_widget;
224232
ButtonWidget* m_redo_widget;
225233
ButtonWidget* m_grid_size_widget;

src/editor/overlay_widget.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@
2222
#include "editor/node_marker.hpp"
2323
#include "editor/object_menu.hpp"
2424
#include "editor/object_info.hpp"
25+
#include "editor/object_option.hpp"
2526
#include "editor/tile_selection.hpp"
2627
#include "editor/tip.hpp"
2728
#include "gui/menu.hpp"
2829
#include "gui/menu_manager.hpp"
30+
#include "interface/control_textbox.hpp"
2931
#include "math/bezier.hpp"
3032
#include "object/camera.hpp"
3133
#include "object/path_gameobject.hpp"
@@ -878,6 +880,28 @@ EditorOverlayWidget::process_left_click()
878880

879881
case EditorTilebox::InputType::NONE:
880882
case EditorTilebox::InputType::OBJECT:
883+
884+
if (m_hovered_object.get() != nullptr)
885+
{
886+
// WIP:
887+
auto& controls = m_editor.get_controls();
888+
controls.clear();
889+
ObjectSettings os = m_hovered_object.get()->get_settings();
890+
for(const auto& option : os.get_options())
891+
{
892+
if (dynamic_cast<LabelObjectOption*>(option.get()))
893+
{
894+
m_editor.addControl(option.get()->get_text(), nullptr);
895+
}
896+
else
897+
{
898+
auto textbox = std::make_unique<ControlTextbox>();
899+
textbox.get()->set_rect(Rectf(0, 32, 200, 32));
900+
textbox.get()->put_text(option.get()->to_string());
901+
m_editor.addControl(option.get()->get_text(), std::move(textbox));
902+
}
903+
}
904+
}
881905
switch (m_editor.get_tileselect_move_mode())
882906
{
883907
case 0:

src/object/tilemap.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ TileMap::get_offset() const
632632
// Apply custom offset for tilemap to fit buttons at the top of the editor.
633633
// This extra offset isn't saved.
634634
if (Editor::is_active() && !Level::current()->is_saving_in_progress())
635-
return m_offset + Vector(0, 32);
635+
return m_offset + Vector(200, 32);
636636

637637
return m_offset;
638638
}

0 commit comments

Comments
 (0)