Skip to content

Commit 33fbac5

Browse files
committed
WIP: Add editor controls for objects on mouse click
1 parent 9b539f6 commit 33fbac5

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(),
@@ -245,6 +246,14 @@ Editor::draw(Compositor& compositor)
245246
widget->draw(context);
246247
}
247248

249+
context.color().draw_filled_rect(Rectf(0, 32.0f, 200.0f, SCREEN_HEIGHT - 32.0f),
250+
Color(0.2f, 0.2f, 0.2f), LAYER_GUI);
251+
252+
for(const auto& control : m_controls)
253+
{
254+
control->draw(context);
255+
}
256+
248257
// If camera scale must be changed, change it here.
249258
if (m_new_scale != 0.f)
250259
{
@@ -383,6 +392,11 @@ Editor::update(float dt_sec, const Controller& controller)
383392
widget->update(dt_sec);
384393
}
385394

395+
for(const auto& control : m_controls)
396+
{
397+
control->update(dt_sec);
398+
}
399+
386400
// Now that all widgets have been updated, which should have relinquished
387401
// pointers to objects marked for deletion, we can actually delete them.
388402
for (auto& sector : m_level->get_sectors())
@@ -1273,4 +1287,26 @@ Editor::pack_addon()
12731287
*zip.Add_File(id + ".nfo") << ss.rdbuf();
12741288
}
12751289

1290+
void
1291+
Editor::addControl(const std::string& name, std::unique_ptr<InterfaceControl> new_control)
1292+
{
1293+
float height = 35.f;
1294+
for (const auto& control : m_controls) {
1295+
height = std::max(height, control->get_rect().get_bottom() + 5.f);
1296+
}
1297+
1298+
if (new_control.get()->get_rect().get_width() == 0.f || new_control.get()->get_rect().get_height() == 0.f) {
1299+
new_control.get()->set_rect(Rectf(100.f, height, 200.f - 1.0f, height + 20.f));
1300+
} else {
1301+
new_control.get()->set_rect(Rectf(new_control.get()->get_rect().get_left(),
1302+
height,
1303+
new_control.get()->get_rect().get_right(),
1304+
height + new_control.get()->get_rect().get_height()));
1305+
}
1306+
1307+
new_control.get()->m_label = std::make_unique<InterfaceLabel>(Rectf(3.f, height, 100.f, height + 20.f), std::move(name));
1308+
//new_control.get()->m_on_change = std::function<void()>([this](){ this->push_version(); });
1309+
m_controls.push_back(std::move(new_control));
1310+
}
1311+
12761312
/* 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(); }
@@ -162,6 +168,7 @@ class Editor final : public Screen,
162168

163169
void queue_layers_refresh();
164170

171+
void addControl(const std::string& name, std::unique_ptr<InterfaceControl> new_control);
165172
void retoggle_undo_tracking();
166173
void undo_stack_cleanup();
167174

@@ -186,7 +193,6 @@ class Editor final : public Screen,
186193
void save_level(const std::string& filename = "", bool switch_file = false);
187194
void test_level(const std::optional<std::pair<std::string, Vector>>& test_pos);
188195
void update_keyboard(const Controller& controller);
189-
190196
void keep_camera_in_bounds();
191197

192198
protected:
@@ -224,6 +230,8 @@ class Editor final : public Screen,
224230
bool m_has_deprecated_tiles;
225231

226232
std::vector<std::unique_ptr<Widget> > m_widgets;
233+
std::vector<std::unique_ptr<InterfaceControl>> m_controls;
234+
227235
ButtonWidget* m_undo_widget;
228236
ButtonWidget* m_redo_widget;
229237
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
@@ -689,7 +689,7 @@ TileMap::get_offset() const
689689
// Apply custom offset for tilemap to fit buttons at the top of the editor.
690690
// This extra offset isn't saved.
691691
if (Editor::is_active() && !Level::current()->is_saving_in_progress())
692-
return m_offset + Vector(0, 32);
692+
return m_offset + Vector(200, 32);
693693

694694
return m_offset;
695695
}

0 commit comments

Comments
 (0)