From b2392cf01e6fd0c15bc52941177fbe4b8a5d1a69 Mon Sep 17 00:00:00 2001 From: quou Date: Sat, 18 Jan 2025 17:05:58 +1100 Subject: entity debugger --- editor.cpp | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 70 insertions(+), 8 deletions(-) (limited to 'editor.cpp') diff --git a/editor.cpp b/editor.cpp index a7f3b31..5b96db6 100644 --- a/editor.cpp +++ b/editor.cpp @@ -8,12 +8,14 @@ static struct { UI* ui; UI::Toolbar* toolbar; - UI::Button* mat_btn; - UI::Modal* mat_win; + UI::Button* mat_btn, * ent_btn; + UI::Modal* mat_win, * ent_win; UI::Label* mat_name; UI::Slider* metalness_input; UI::Slider* roughness_input; UI::Slider* ao_input; + UI::Label* ent_handle, * ent_index, * ent_version, * ent_mask; + World* world; Entity_Id selected; Model_Instance* selected_inst; int selected_mesh; @@ -48,6 +50,21 @@ static void setup_mat_edit() { } } +void setup_ent_debug() { + if (editor.selected) { + int ind = entity_index(editor.selected); + editor.ent_handle->set_hex(editor.selected); + editor.ent_version->set_int(entity_version(editor.selected)); + editor.ent_index->set_int(ind); + editor.ent_mask->set_hex(editor.world->masks[ind]); + } else { + editor.ent_handle->set_text(""); + editor.ent_version->set_text(""); + editor.ent_index->set_text(""); + editor.ent_mask->set_text(""); + } +} + static int mat_btn_handler(UI::Element* e, const UI::Message& m) { (void)e; if (m.type == UI::Message::Type::click) { @@ -114,26 +131,68 @@ static int mat_btn_handler(UI::Element* e, const UI::Message& m) { return 0; } -void init_editor(UI* ui) { +static int ent_win_handler(UI::Element* e, const UI::Message& m) { + (void)e; + if (m.type == UI::Message::Type::destroy) { + editor.ent_btn->enable(); + editor.ent_win = 0; + } + return 0; +} + +static int ent_btn_handler(UI::Element* e, const UI::Message& m) { + if (m.type == UI::Message::Type::click) { + auto ui = editor.ui; + editor.ent_win = ui->create_element( + editor.ui->root, + "Entity Debugger" + ); + editor.ent_win->handler = ent_win_handler; + editor.ent_btn->disable(); + int rows[] = { 100, 50, 0 }; + auto tab = ui->create_element( + editor.ent_win->contents, + rows + ); + ui->create_element(tab, "Handle"); + editor.ent_handle = ui->create_element(tab, ""); + ui->create_element(tab, "Index"); + editor.ent_index = ui->create_element(tab, ""); + ui->create_element(tab, "Version"); + editor.ent_version = ui->create_element(tab, ""); + ui->create_element(tab, "Mask"); + editor.ent_mask = ui->create_element(tab, ""); + setup_ent_debug(); + } + return 0; +} + +void init_editor(UI* ui, World* world) { editor.ui = ui; editor.toolbar = ui->create_element(ui->root); editor.mat_btn = ui->create_element( editor.toolbar, "Edit Material" ); - editor.mat_win = 0; editor.mat_btn->handler = mat_btn_handler; + editor.ent_btn = ui->create_element( + editor.toolbar, + "Entity Debugger" + ); + editor.ent_btn->handler = ent_btn_handler; + editor.mat_win = 0; + editor.ent_win = 0; + editor.world = world; } void deinit_editor() { - } -void editor_on_select(World& w, Entity_Id e, int m) { +void editor_on_select(Entity_Id e, int m) { if (!editor.ui->hovered) { editor.selected = e; - if (e && w.has(e)) { - auto& cm = w.get(e); + if (e && editor.world->has(e)) { + auto& cm = editor.world->get(e); editor.selected_inst = cm.i; editor.selected_mesh = m; } else { @@ -143,6 +202,9 @@ void editor_on_select(World& w, Entity_Id e, int m) { if (editor.mat_win) { setup_mat_edit(); } + if (editor.ent_win) { + setup_ent_debug(); + } } } -- cgit v1.2.3-54-g00ecf