Преглед изворни кода

tools: add mass and lock_rotation options in sprite importer

Raphael de Vasconcelos Nascimento пре 6 година
родитељ
комит
9fbf140746
2 измењених фајлова са 24 додато и 6 уклоњено
  1. 6 4
      tools/level_editor/project.vala
  2. 18 2
      tools/level_editor/sprite_import_dialog.vala

+ 6 - 4
tools/level_editor/project.vala

@@ -330,6 +330,8 @@ end
 			int collision_w                = (int)sid.collision_w.value;
 			int collision_h                = (int)sid.collision_h.value;
 			string actor_class             = (string)sid.actor_class.value;
+			bool lock_rotation_y           = sid.lock_rotation_y.active;
+			double mass					   = (double)sid.mass.value;
 
 			sid.destroy();
 
@@ -577,12 +579,12 @@ end
 							db.set_property_string(id, "data.class", actor_class);
 							db.set_property_string(id, "data.collision_filter", "default");
 							db.set_property_bool  (id, "data.lock_rotation_x", true);
-							db.set_property_bool  (id, "data.lock_rotation_y", true);
+							db.set_property_bool  (id, "data.lock_rotation_y", lock_rotation_y);
 							db.set_property_bool  (id, "data.lock_rotation_z", true);
 							db.set_property_bool  (id, "data.lock_translation_x", false);
 							db.set_property_bool  (id, "data.lock_translation_y", true);
 							db.set_property_bool  (id, "data.lock_translation_z", false);
-							db.set_property_double(id, "data.mass", 10);
+							db.set_property_double(id, "data.mass", mass);
 							db.set_property_string(id, "data.material", "default");
 							db.set_property_string(id, "type", "actor");
 
@@ -593,12 +595,12 @@ end
 							unit.set_component_property_string(id, "data.class", actor_class);
 							unit.set_component_property_string(id, "data.collision_filter", "default");
 							unit.set_component_property_bool  (id, "data.lock_rotation_x", true);
-							unit.set_component_property_bool  (id, "data.lock_rotation_y", true);
+							unit.set_component_property_bool  (id, "data.lock_rotation_y", lock_rotation_y);
 							unit.set_component_property_bool  (id, "data.lock_rotation_z", true);
 							unit.set_component_property_bool  (id, "data.lock_translation_x", false);
 							unit.set_component_property_bool  (id, "data.lock_translation_y", true);
 							unit.set_component_property_bool  (id, "data.lock_translation_z", false);
-							unit.set_component_property_double(id, "data.mass", 10);
+							unit.set_component_property_double(id, "data.mass", mass);
 							unit.set_component_property_string(id, "data.material", "default");
 							unit.set_component_property_string(id, "type", "actor");
 						}

+ 18 - 2
tools/level_editor/sprite_import_dialog.vala

@@ -137,6 +137,8 @@ public class SpriteImportDialog : Gtk.Dialog
 	public Gtk.SpinButton collision_w;
 	public Gtk.SpinButton collision_h;
 	public ComboBoxMap actor_class;
+	public Gtk.SpinButton mass;
+	public Gtk.CheckButton lock_rotation_y;
 
 	// Widgets
 	public SpriteImportDialog(string png)
@@ -347,6 +349,11 @@ public class SpriteImportDialog : Gtk.Dialog
 		actor_class.append("keyframed", "keyframed");
 		actor_class.append("trigger", "trigger");
 		actor_class.value = "static";
+		lock_rotation_y = new Gtk.CheckButton();
+		lock_rotation_y.active = true;
+		mass = new Gtk.SpinButton.with_range(0, double.MAX, 1.0);
+		mass.value = 10;
+
 
 		circle_collision_center_x = new Gtk.SpinButton.with_range(-double.MAX, double.MAX, 1.0);
 		circle_collision_center_x.value = cell_w.value/2.0;
@@ -523,6 +530,9 @@ public class SpriteImportDialog : Gtk.Dialog
 		grid.attach(label_with_alignment("Depth", Gtk.Align.END),        0, 12, 1, 1);
 
 		grid.attach(label_with_alignment("Collision", Gtk.Align.END),    0, 13, 1, 1);
+		grid.attach(label_with_alignment("Class", Gtk.Align.END),    0, 14, 1, 1);
+		grid.attach(label_with_alignment("Mass", Gtk.Align.END),    0, 15, 1, 1);
+		grid.attach(label_with_alignment("Lock Rotation", Gtk.Align.END),    0, 16, 1, 1);
 
 		grid.attach(resolution,   1,  0, 1, 1);
 		grid.attach(cells_h,      1,  1, 1, 1);
@@ -540,6 +550,8 @@ public class SpriteImportDialog : Gtk.Dialog
 
 		grid.attach(collision_enabled, 1, 13, 1, 1);
 		grid.attach(actor_class,       1, 14, 1, 1);
+		grid.attach(mass,              1, 15, 1, 1);
+		grid.attach(lock_rotation_y,   1, 16, 1, 1);
 		shape = new Gtk.Stack();
 		Gtk.Grid square_grid = new Gtk.Grid();
 		square_grid.attach(label_with_alignment("Collision X", Gtk.Align.END),  0, 0, 1, 1);
@@ -580,8 +592,8 @@ public class SpriteImportDialog : Gtk.Dialog
 		shape.add_titled(capsule_grid, "capsule_collider", "Capsule Collider");
 		shape_switcher = new Gtk.StackSwitcher();
 		shape_switcher.set_stack(shape);
-		grid.attach(shape_switcher, 1, 15, 1, 1);
-		grid.attach(shape, 1, 16, 1, 5);
+		grid.attach(shape_switcher, 1, 17, 1, 1);
+		grid.attach(shape, 1, 18, 1, 5);
 
 		grid.row_spacing = 6;
 		grid.column_spacing = 12;
@@ -645,6 +657,8 @@ public class SpriteImportDialog : Gtk.Dialog
 
 		shape.visible_child_name         = importer_settings.has_key("shape_active_name") ? (string)importer_settings["shape_active_name"] : "square_collider";
 		actor_class.value                = importer_settings.has_key("actor_class") ? (string)importer_settings["actor_class"] : "static";
+		lock_rotation_y.active			 = importer_settings.has_key("lock_rotation_y") ? (bool)importer_settings["lock_rotation_y"] : true;
+		mass.value						 = importer_settings.has_key("mass") ? (double)importer_settings["mass"] : 10.0;
 	}
 
 	public void save(Hashtable importer_settings)
@@ -674,6 +688,8 @@ public class SpriteImportDialog : Gtk.Dialog
 		importer_settings["capsule_collision_height"]   = capsule_collision_height.value;
 		importer_settings["shape_active_name"]          = shape.visible_child_name;
 		importer_settings["actor_class"]                = actor_class.value;
+		importer_settings["lock_rotation_y"]            = lock_rotation_y.active;
+		importer_settings["mass"]						= mass.value;
 	}
 }