summaryrefslogtreecommitdiff
path: root/editor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor.cpp')
-rw-r--r--editor.cpp78
1 files changed, 70 insertions, 8 deletions
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("<null>");
+ editor.ent_version->set_text("<null>");
+ editor.ent_index->set_text("<null>");
+ editor.ent_mask->set_text("<null>");
+ }
+}
+
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<UI::Modal>(
+ 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<UI::Table>(
+ editor.ent_win->contents,
+ rows
+ );
+ ui->create_element<UI::Label>(tab, "Handle");
+ editor.ent_handle = ui->create_element<UI::Label>(tab, "");
+ ui->create_element<UI::Label>(tab, "Index");
+ editor.ent_index = ui->create_element<UI::Label>(tab, "");
+ ui->create_element<UI::Label>(tab, "Version");
+ editor.ent_version = ui->create_element<UI::Label>(tab, "");
+ ui->create_element<UI::Label>(tab, "Mask");
+ editor.ent_mask = ui->create_element<UI::Label>(tab, "");
+ setup_ent_debug();
+ }
+ return 0;
+}
+
+void init_editor(UI* ui, World* world) {
editor.ui = ui;
editor.toolbar = ui->create_element<UI::Toolbar>(ui->root);
editor.mat_btn = ui->create_element<UI::Button>(
editor.toolbar,
"Edit Material"
);
- editor.mat_win = 0;
editor.mat_btn->handler = mat_btn_handler;
+ editor.ent_btn = ui->create_element<UI::Button>(
+ 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<C_Model>(e)) {
- auto& cm = w.get<C_Model>(e);
+ if (e && editor.world->has<C_Model>(e)) {
+ auto& cm = editor.world->get<C_Model>(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();
+ }
}
}