summaryrefslogtreecommitdiff
path: root/modules/gridmap
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2017-08-26 00:40:45 -0300
committerJuan Linietsky <reduzio@gmail.com>2017-08-26 00:47:28 -0300
commit1894157c9fab05984428d83a743b0fe1d720c80c (patch)
tree817530eb75258c3dc6c73d4eb276af7b61761b06 /modules/gridmap
parentd9e94fa0c308f8f157e71fb03bab5834308b56ee (diff)
-Massive clean up to gizmos
-Make sure handles are always visible (on top) -Fixed instanced scene selection (should work properly now) -Added interpolated camera -Customizable gizmo colors in editor settings
Diffstat (limited to 'modules/gridmap')
-rw-r--r--modules/gridmap/grid_map.cpp427
-rw-r--r--modules/gridmap/grid_map.h48
-rw-r--r--modules/gridmap/grid_map_editor_plugin.cpp360
-rw-r--r--modules/gridmap/grid_map_editor_plugin.h13
4 files changed, 71 insertions, 777 deletions
diff --git a/modules/gridmap/grid_map.cpp b/modules/gridmap/grid_map.cpp
index fe5936b715..b444664878 100644
--- a/modules/gridmap/grid_map.cpp
+++ b/modules/gridmap/grid_map.cpp
@@ -96,25 +96,6 @@ bool GridMap::_set(const StringName &p_name, const Variant &p_value) {
}
_recreate_octant_data();
- } else if (name.begins_with("areas/")) {
- int which = name.get_slicec('/', 1).to_int();
- String what = name.get_slicec('/', 2);
- if (what == "bounds") {
- ERR_FAIL_COND_V(area_map.has(which), false);
- create_area(which, p_value);
- return true;
- }
-
- ERR_FAIL_COND_V(!area_map.has(which), false);
-
- if (what == "name")
- area_set_name(which, p_value);
- else if (what == "disable_distance")
- area_set_portal_disable_distance(which, p_value);
- else if (what == "exterior_portal")
- area_set_portal_disable_color(which, p_value);
- else
- return false;
} else
return false;
@@ -158,19 +139,6 @@ bool GridMap::_get(const StringName &p_name, Variant &r_ret) const {
d["cells"] = cells;
r_ret = d;
- } else if (name.begins_with("areas/")) {
- int which = name.get_slicec('/', 1).to_int();
- String what = name.get_slicec('/', 2);
- if (what == "bounds")
- r_ret = area_get_bounds(which);
- else if (what == "name")
- r_ret = area_get_name(which);
- else if (what == "disable_distance")
- r_ret = area_get_portal_disable_distance(which);
- else if (what == "exterior_portal")
- r_ret = area_is_exterior_portal(which);
- else
- return false;
} else
return false;
@@ -189,16 +157,6 @@ void GridMap::_get_property_list(List<PropertyInfo> *p_list) const {
p_list->push_back(PropertyInfo(Variant::REAL, "cell_scale"));
p_list->push_back(PropertyInfo(Variant::DICTIONARY, "data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE));
-
- for (const Map<int, Area *>::Element *E = area_map.front(); E; E = E->next()) {
-
- String base = "areas/" + itos(E->key()) + "/";
- p_list->push_back(PropertyInfo(Variant::RECT3, base + "bounds", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE));
- p_list->push_back(PropertyInfo(Variant::STRING, base + "name", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE));
- p_list->push_back(PropertyInfo(Variant::REAL, base + "disable_distance", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE));
- p_list->push_back(PropertyInfo(Variant::COLOR, base + "disable_color", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE));
- p_list->push_back(PropertyInfo(Variant::BOOL, base + "exterior_portal", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE));
- }
}
void GridMap::set_theme(const Ref<MeshLibrary> &p_theme) {
@@ -268,20 +226,6 @@ bool GridMap::get_center_z() const {
return center_z;
}
-int GridMap::_find_area(const IndexKey &p_pos) const {
-
- for (const Map<int, Area *>::Element *E = area_map.front(); E; E = E->next()) {
- //this should somehow be faster...
- const Area &a = *E->get();
- if (p_pos.x >= a.from.x && p_pos.x < a.to.x &&
- p_pos.y >= a.from.y && p_pos.y < a.to.y &&
- p_pos.z >= a.from.z && p_pos.z < a.to.z) {
- return E->key();
- }
- }
-
- return 0;
-}
void GridMap::set_cell_item(int p_x, int p_y, int p_z, int p_item, int p_rot) {
ERR_FAIL_INDEX(ABS(p_x), 1 << 20);
@@ -297,7 +241,6 @@ void GridMap::set_cell_item(int p_x, int p_y, int p_z, int p_item, int p_rot) {
ok.x = p_x / octant_size;
ok.y = p_y / octant_size;
ok.z = p_z / octant_size;
- ok.area = _find_area(key);
if (cell_map.has(key)) {
@@ -485,19 +428,12 @@ void GridMap::_octant_enter_world(const OctantKey &p_key) {
if (g.collision_debug_instance.is_valid()) {
VS::get_singleton()->instance_set_scenario(g.collision_debug_instance, get_world()->get_scenario());
VS::get_singleton()->instance_set_transform(g.collision_debug_instance, get_global_transform());
- if (area_map.has(p_key.area)) {
- VS::get_singleton()->instance_set_room(g.collision_debug_instance, area_map[p_key.area]->instance);
- }
}
for (Map<int, Octant::ItemInstances>::Element *E = g.items.front(); E; E = E->next()) {
VS::get_singleton()->instance_set_scenario(E->get().multimesh_instance, get_world()->get_scenario());
VS::get_singleton()->instance_set_transform(E->get().multimesh_instance, get_global_transform());
//print_line("INSTANCEPOS: "+get_global_transform());
-
- if (area_map.has(p_key.area)) {
- VS::get_singleton()->instance_set_room(E->get().multimesh_instance, area_map[p_key.area]->instance);
- }
}
}
@@ -655,7 +591,6 @@ void GridMap::_octant_exit_world(const OctantKey &p_key) {
if (g.collision_debug_instance.is_valid()) {
- VS::get_singleton()->instance_set_room(g.collision_debug_instance, RID());
VS::get_singleton()->instance_set_scenario(g.collision_debug_instance, RID());
}
@@ -663,7 +598,6 @@ void GridMap::_octant_exit_world(const OctantKey &p_key) {
VS::get_singleton()->instance_set_scenario(E->get().multimesh_instance, RID());
//VS::get_singleton()->instance_set_transform(E->get().multimesh_instance,get_global_transform());
- VS::get_singleton()->instance_set_room(E->get().multimesh_instance, RID());
}
}
@@ -673,8 +607,6 @@ void GridMap::_notification(int p_what) {
case NOTIFICATION_ENTER_WORLD: {
- _update_area_instances();
-
for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) {
//IndexKey ik;
//ik.key = E->key().indexkey;
@@ -761,14 +693,14 @@ void GridMap::_queue_dirty_map() {
void GridMap::_recreate_octant_data() {
Map<IndexKey, Cell> cell_copy = cell_map;
- _clear_internal(true);
+ _clear_internal();
for (Map<IndexKey, Cell>::Element *E = cell_copy.front(); E; E = E->next()) {
set_cell_item(E->key().x, E->key().y, E->key().z, E->get().item, E->get().rot);
}
}
-void GridMap::_clear_internal(bool p_keep_areas) {
+void GridMap::_clear_internal() {
for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) {
if (is_inside_world())
@@ -790,20 +722,6 @@ void GridMap::_clear_internal(bool p_keep_areas) {
octant_map.clear();
cell_map.clear();
-
- if (p_keep_areas)
- return;
-
- for (Map<int, Area *>::Element *E = area_map.front(); E; E = E->next()) {
-
- VS::get_singleton()->free(E->get()->base_portal);
- VS::get_singleton()->free(E->get()->instance);
- for (int i = 0; i < E->get()->portals.size(); i++) {
- VS::get_singleton()->free(E->get()->portals[i].instance);
- }
-
- memdelete(E->get());
- }
}
void GridMap::clear() {
@@ -856,19 +774,6 @@ void GridMap::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_clip", "enabled", "clipabove", "floor", "axis"), &GridMap::set_clip, DEFVAL(true), DEFVAL(0), DEFVAL(Vector3::AXIS_X));
- ClassDB::bind_method(D_METHOD("create_area", "id", "area"), &GridMap::create_area);
- ClassDB::bind_method(D_METHOD("area_get_bounds", "area"), &GridMap::area_get_bounds);
- ClassDB::bind_method(D_METHOD("area_set_exterior_portal", "area", "enable"), &GridMap::area_set_exterior_portal);
- ClassDB::bind_method(D_METHOD("area_set_name", "area", "name"), &GridMap::area_set_name);
- ClassDB::bind_method(D_METHOD("area_get_name", "area"), &GridMap::area_get_name);
- ClassDB::bind_method(D_METHOD("area_is_exterior_portal", "area"), &GridMap::area_is_exterior_portal);
- ClassDB::bind_method(D_METHOD("area_set_portal_disable_distance", "area", "distance"), &GridMap::area_set_portal_disable_distance);
- ClassDB::bind_method(D_METHOD("area_get_portal_disable_distance", "area"), &GridMap::area_get_portal_disable_distance);
- ClassDB::bind_method(D_METHOD("area_set_portal_disable_color", "area", "color"), &GridMap::area_set_portal_disable_color);
- ClassDB::bind_method(D_METHOD("area_get_portal_disable_color", "area"), &GridMap::area_get_portal_disable_color);
- ClassDB::bind_method(D_METHOD("erase_area", "area"), &GridMap::erase_area);
- ClassDB::bind_method(D_METHOD("get_unused_area_id"), &GridMap::get_unused_area_id);
-
ClassDB::bind_method(D_METHOD("clear"), &GridMap::clear);
ClassDB::bind_method(D_METHOD("get_meshes"), &GridMap::get_meshes);
@@ -898,334 +803,6 @@ void GridMap::set_clip(bool p_enabled, bool p_clip_above, int p_floor, Vector3::
_update_dirty_map_callback();
}
-void GridMap::_update_areas() {
-
- //clear the portals
- for (Map<int, Area *>::Element *E = area_map.front(); E; E = E->next()) {
- //this should somehow be faster...
- Area &a = *E->get();
- a.portals.clear();
- if (a.instance.is_valid()) {
- VisualServer::get_singleton()->free(a.instance);
- a.instance = RID();
- }
- }
-
- //test all areas against all areas and create portals - this sucks (slow :( )
- for (Map<int, Area *>::Element *E = area_map.front(); E; E = E->next()) {
- Area &a = *E->get();
- if (a.exterior_portal) //that's pretty much all it does... yes it is
- continue;
- Vector3 from_a(a.from.x, a.from.y, a.from.z);
- Vector3 to_a(a.to.x, a.to.y, a.to.z);
-
- for (Map<int, Area *>::Element *F = area_map.front(); F; F = F->next()) {
-
- Area &b = *F->get();
- Vector3 from_b(b.from.x, b.from.y, b.from.z);
- Vector3 to_b(b.to.x, b.to.y, b.to.z);
-
- // initially test intersection and discards
- int axis = -1;
- float sign = 0;
- bool valid = true;
- Vector3 axmin, axmax;
-
- for (int i = 0; i < 3; i++) {
-
- if (from_a[i] == to_b[i]) {
-
- if (axis != -1) {
- valid = false;
- break;
- }
-
- axis = i;
- sign = -1;
- } else if (from_b[i] == to_a[i]) {
-
- if (axis != -1) {
- valid = false;
- break;
- }
- axis = i;
- sign = +1;
- }
-
- if (from_a[i] > to_b[i] || to_a[i] < from_b[i]) {
- valid = false;
- break;
- } else {
-
- axmin[i] = (from_a[i] > from_b[i]) ? from_a[i] : from_b[i];
- axmax[i] = (to_a[i] < to_b[i]) ? to_a[i] : to_b[i];
- }
- }
-
- if (axis == -1 || !valid)
- continue;
-
- Transform xf;
-
- for (int i = 0; i < 3; i++) {
-
- int ax = (axis + i) % 3;
- Vector3 axis_vec;
- float scale = (i == 0) ? sign : ((axmax[ax] - axmin[ax]) * cell_size);
- axis_vec[ax] = scale;
- xf.basis.set_axis((2 + i) % 3, axis_vec);
- xf.origin[i] = axmin[i] * cell_size;
- }
-
- Area::Portal portal;
- portal.xform = xf;
- a.portals.push_back(portal);
- }
- }
-
- _update_area_instances();
-}
-
-void GridMap::_update_area_instances() {
-
- Transform base_xform;
- if (_in_tree)
- base_xform = get_global_transform();
-
- for (Map<int, Area *>::Element *E = area_map.front(); E; E = E->next()) {
- //this should somehow be faster...
- Area &a = *E->get();
- if (a.instance.is_valid() != _in_tree) {
-
- if (!_in_tree) {
-
- for (int i = 0; i < a.portals.size(); i++) {
-
- Area::Portal &p = a.portals[i];
- ERR_CONTINUE(!p.instance.is_valid());
- VisualServer::get_singleton()->free(p.instance);
- p.instance = RID();
- }
-
- VisualServer::get_singleton()->free(a.instance);
- a.instance = RID();
-
- } else {
-
- //a.instance = VisualServer::get_singleton()->instance_create2(base_room,get_world()->get_scenario());
- for (int i = 0; i < a.portals.size(); i++) {
-
- Area::Portal &p = a.portals[i];
- ERR_CONTINUE(p.instance.is_valid());
- p.instance = VisualServer::get_singleton()->instance_create2(a.base_portal, get_world()->get_scenario());
- VisualServer::get_singleton()->instance_set_room(p.instance, a.instance);
- }
- }
- }
-
- if (a.instance.is_valid()) {
- Transform xform;
-
- Vector3 from_a(a.from.x, a.from.y, a.from.z);
- Vector3 to_a(a.to.x, a.to.y, a.to.z);
-
- for (int i = 0; i < 3; i++) {
- xform.origin[i] = from_a[i] * cell_size;
- Vector3 s;
- s[i] = (to_a[i] - from_a[i]) * cell_size;
- xform.basis.set_axis(i, s);
- }
-
- VisualServer::get_singleton()->instance_set_transform(a.instance, base_xform * xform);
-
- for (int i = 0; i < a.portals.size(); i++) {
-
- Area::Portal &p = a.portals[i];
- ERR_CONTINUE(!p.instance.is_valid());
-
- VisualServer::get_singleton()->instance_set_transform(p.instance, base_xform * xform);
- }
- }
- }
-}
-
-Error GridMap::create_area(int p_id, const Rect3 &p_area) {
-
- ERR_FAIL_COND_V(area_map.has(p_id), ERR_ALREADY_EXISTS);
- ERR_EXPLAIN("ID 0 is taken as global area, start from 1");
- ERR_FAIL_COND_V(p_id == 0, ERR_INVALID_PARAMETER);
- ERR_FAIL_COND_V(p_area.has_no_area(), ERR_INVALID_PARAMETER);
-
- // FIRST VALIDATE AREA
- IndexKey from, to;
- from.x = p_area.position.x;
- from.y = p_area.position.y;
- from.z = p_area.position.z;
- to.x = p_area.position.x + p_area.size.x;
- to.y = p_area.position.y + p_area.size.y;
- to.z = p_area.position.z + p_area.size.z;
-
- for (Map<int, Area *>::Element *E = area_map.front(); E; E = E->next()) {
- //this should somehow be faster...
- Area &a = *E->get();
-
- //does it interset with anything else?
-
- if (from.x >= a.to.x ||
- to.x <= a.from.x ||
- from.y >= a.to.y ||
- to.y <= a.from.y ||
- from.z >= a.to.z ||
- to.z <= a.from.z) {
-
- // all good
- } else {
-
- return ERR_INVALID_PARAMETER;
- }
- }
-
- Area *area = memnew(Area);
- area->from = from;
- area->to = to;
- area->portal_disable_distance = 0;
- area->exterior_portal = false;
- area->name = "Area " + itos(p_id);
- area_map[p_id] = area;
- _recreate_octant_data();
- return OK;
-}
-
-Rect3 GridMap::area_get_bounds(int p_area) const {
-
- ERR_FAIL_COND_V(!area_map.has(p_area), Rect3());
-
- const Area *a = area_map[p_area];
- Rect3 aabb;
- aabb.position = Vector3(a->from.x, a->from.y, a->from.z);
- aabb.size = Vector3(a->to.x, a->to.y, a->to.z) - aabb.position;
-
- return aabb;
-}
-
-void GridMap::area_set_name(int p_area, const String &p_name) {
-
- ERR_FAIL_COND(!area_map.has(p_area));
-
- Area *a = area_map[p_area];
- a->name = p_name;
-}
-
-String GridMap::area_get_name(int p_area) const {
-
- ERR_FAIL_COND_V(!area_map.has(p_area), "");
-
- const Area *a = area_map[p_area];
- return a->name;
-}
-
-void GridMap::area_set_exterior_portal(int p_area, bool p_enable) {
-
- ERR_FAIL_COND(!area_map.has(p_area));
-
- Area *a = area_map[p_area];
- if (a->exterior_portal == p_enable)
- return;
- a->exterior_portal = p_enable;
-
- _recreate_octant_data();
-}
-
-bool GridMap::area_is_exterior_portal(int p_area) const {
-
- ERR_FAIL_COND_V(!area_map.has(p_area), false);
-
- const Area *a = area_map[p_area];
- return a->exterior_portal;
-}
-
-void GridMap::area_set_portal_disable_distance(int p_area, float p_distance) {
-
- ERR_FAIL_COND(!area_map.has(p_area));
-
- Area *a = area_map[p_area];
- a->portal_disable_distance = p_distance;
-}
-
-float GridMap::area_get_portal_disable_distance(int p_area) const {
-
- ERR_FAIL_COND_V(!area_map.has(p_area), 0);
-
- const Area *a = area_map[p_area];
- return a->portal_disable_distance;
-}
-
-void GridMap::area_set_portal_disable_color(int p_area, Color p_color) {
-
- ERR_FAIL_COND(!area_map.has(p_area));
-
- Area *a = area_map[p_area];
- a->portal_disable_color = p_color;
-}
-
-Color GridMap::area_get_portal_disable_color(int p_area) const {
-
- ERR_FAIL_COND_V(!area_map.has(p_area), Color());
-
- const Area *a = area_map[p_area];
- return a->portal_disable_color;
-}
-
-void GridMap::get_area_list(List<int> *p_areas) const {
-
- for (const Map<int, Area *>::Element *E = area_map.front(); E; E = E->next()) {
-
- p_areas->push_back(E->key());
- }
-}
-
-GridMap::Area::Portal::~Portal() {
-
- if (instance.is_valid())
- VisualServer::get_singleton()->free(instance);
-}
-
-GridMap::Area::Area() {
-
- base_portal = VisualServer::get_singleton()->portal_create();
- Vector<Point2> points;
- points.push_back(Point2(0, 1));
- points.push_back(Point2(1, 1));
- points.push_back(Point2(1, 0));
- points.push_back(Point2(0, 0));
- VisualServer::get_singleton()->portal_set_shape(base_portal, points);
-}
-
-GridMap::Area::~Area() {
-
- if (instance.is_valid())
- VisualServer::get_singleton()->free(instance);
- VisualServer::get_singleton()->free(base_portal);
-}
-
-void GridMap::erase_area(int p_area) {
-
- ERR_FAIL_COND(!area_map.has(p_area));
-
- Area *a = area_map[p_area];
- memdelete(a);
- area_map.erase(p_area);
- _recreate_octant_data();
-}
-
-int GridMap::get_unused_area_id() const {
-
- if (area_map.empty())
- return 1;
- else
- return area_map.back()->key() + 1;
-}
-
void GridMap::set_cell_scale(float p_scale) {
cell_scale = p_scale;
diff --git a/modules/gridmap/grid_map.h b/modules/gridmap/grid_map.h
index 106bf82dc2..7af1e08eb2 100644
--- a/modules/gridmap/grid_map.h
+++ b/modules/gridmap/grid_map.h
@@ -120,7 +120,7 @@ class GridMap : public Spatial {
int16_t x;
int16_t y;
int16_t z;
- int16_t area;
+ int16_t empty;
};
uint64_t key;
@@ -148,35 +148,10 @@ class GridMap : public Spatial {
int clip_floor;
Vector3::Axis clip_axis;
- /**
- * @brief An Area is something like a room: it has doors, and Octants can choose to belong to it.
- */
- struct Area {
-
- String name;
- RID base_portal;
- RID instance;
- IndexKey from;
- IndexKey to;
- struct Portal {
- Transform xform;
- RID instance;
- ~Portal();
- };
- Vector<Portal> portals;
- float portal_disable_distance;
- Color portal_disable_color;
- bool exterior_portal;
-
- Area();
- ~Area();
- };
-
Ref<MeshLibrary> theme;
Map<OctantKey, Octant *> octant_map;
Map<IndexKey, Cell> cell_map;
- Map<int, Area *> area_map;
void _recreate_octant_data();
@@ -188,8 +163,6 @@ class GridMap : public Spatial {
float param[VS::LIGHT_PARAM_MAX];
};
- _FORCE_INLINE_ int _find_area(const IndexKey &p_pos) const;
-
_FORCE_INLINE_ Vector3 _octant_get_offset(const OctantKey &p_key) const {
return Vector3(p_key.x, p_key.y, p_key.z) * cell_size * octant_size;
@@ -208,10 +181,7 @@ class GridMap : public Spatial {
void resource_changed(const RES &p_res);
- void _update_areas();
- void _update_area_instances();
-
- void _clear_internal(bool p_keep_areas = false);
+ void _clear_internal();
protected:
bool _set(const StringName &p_name, const Variant &p_value);
@@ -248,20 +218,6 @@ public:
void set_clip(bool p_enabled, bool p_clip_above = true, int p_floor = 0, Vector3::Axis p_axis = Vector3::AXIS_X);
- Error create_area(int p_id, const Rect3 &p_area);
- Rect3 area_get_bounds(int p_area) const;
- void area_set_exterior_portal(int p_area, bool p_enable);
- void area_set_name(int p_area, const String &p_name);
- String area_get_name(int p_area) const;
- bool area_is_exterior_portal(int p_area) const;
- void area_set_portal_disable_distance(int p_area, float p_distance);
- float area_get_portal_disable_distance(int p_area) const;
- void area_set_portal_disable_color(int p_area, Color p_color);
- Color area_get_portal_disable_color(int p_area) const;
- void get_area_list(List<int> *p_areas) const;
- void erase_area(int p_area);
- int get_unused_area_id() const;
-
void set_cell_scale(float p_scale);
float get_cell_scale() const;
diff --git a/modules/gridmap/grid_map_editor_plugin.cpp b/modules/gridmap/grid_map_editor_plugin.cpp
index 5d98b0f7a7..561efb9d0f 100644
--- a/modules/gridmap/grid_map_editor_plugin.cpp
+++ b/modules/gridmap/grid_map_editor_plugin.cpp
@@ -178,30 +178,6 @@ void GridMapEditor::_menu_option(int p_option) {
int idx = options->get_popup()->get_item_index(MENU_OPTION_DUPLICATE_SELECTS);
options->get_popup()->set_item_checked(idx, !options->get_popup()->is_item_checked(idx));
} break;
- case MENU_OPTION_SELECTION_MAKE_AREA:
- case MENU_OPTION_SELECTION_MAKE_EXTERIOR_CONNECTOR: {
-
- if (!selection.active)
- break;
- int area = node->get_unused_area_id();
- Error err = node->create_area(area, Rect3(selection.begin, selection.end - selection.begin + Vector3(1, 1, 1)));
- if (err != OK) {
- }
- if (p_option == MENU_OPTION_SELECTION_MAKE_EXTERIOR_CONNECTOR) {
-
- node->area_set_exterior_portal(area, true);
- }
- _update_areas_display();
- update_areas();
-
- } break;
- case MENU_OPTION_REMOVE_AREA: {
- if (selected_area < 1)
- return;
- node->erase_area(selected_area);
- _update_areas_display();
- update_areas();
- } break;
case MENU_OPTION_SELECTION_DUPLICATE:
if (!(selection.active && input_action == INPUT_NONE))
return;
@@ -513,146 +489,96 @@ bool GridMapEditor::forward_spatial_input_event(Camera *p_camera, const Ref<Inpu
return false;
}
- if (edit_mode->get_selected() == 0) { // regular click
-
- Ref<InputEventMouseButton> mb = p_event;
-
- if (mb.is_valid()) {
-
- if (mb->get_button_index() == BUTTON_WHEEL_UP && (mb->get_command() || mb->get_shift())) {
- if (mb->is_pressed())
- floor->set_value(floor->get_value() + mb->get_factor());
-
- return true; //eaten
- } else if (mb->get_button_index() == BUTTON_WHEEL_DOWN && (mb->get_command() || mb->get_shift())) {
- if (mb->is_pressed())
- floor->set_value(floor->get_value() - mb->get_factor());
- return true;
- }
-
- if (mb->is_pressed()) {
-
- if (mb->get_button_index() == BUTTON_LEFT) {
+ Ref<InputEventMouseButton> mb = p_event;
- if (input_action == INPUT_DUPLICATE) {
-
- //paste
- _duplicate_paste();
- input_action = INPUT_NONE;
- _update_duplicate_indicator();
- } else if (mb->get_shift()) {
- input_action = INPUT_SELECT;
- } else if (mb->get_command())
- input_action = INPUT_COPY;
- else {
- input_action = INPUT_PAINT;
- set_items.clear();
- }
- } else if (mb->get_button_index() == BUTTON_RIGHT)
- if (input_action == INPUT_DUPLICATE) {
-
- input_action = INPUT_NONE;
- _update_duplicate_indicator();
- } else {
- input_action = INPUT_ERASE;
- set_items.clear();
- }
- else
- return false;
+ if (mb.is_valid()) {
- return do_input_action(p_camera, Point2(mb->get_position().x, mb->get_position().y), true);
- } else {
+ if (mb->get_button_index() == BUTTON_WHEEL_UP && (mb->get_command() || mb->get_shift())) {
+ if (mb->is_pressed())
+ floor->set_value(floor->get_value() + mb->get_factor());
- if (
- (mb->get_button_index() == BUTTON_RIGHT && input_action == INPUT_ERASE) ||
- (mb->get_button_index() == BUTTON_LEFT && input_action == INPUT_PAINT)) {
+ return true; //eaten
+ } else if (mb->get_button_index() == BUTTON_WHEEL_DOWN && (mb->get_command() || mb->get_shift())) {
+ if (mb->is_pressed())
+ floor->set_value(floor->get_value() - mb->get_factor());
+ return true;
+ }
- if (set_items.size()) {
- undo_redo->create_action(TTR("GridMap Paint"));
- for (List<SetItem>::Element *E = set_items.front(); E; E = E->next()) {
+ if (mb->is_pressed()) {
- const SetItem &si = E->get();
- undo_redo->add_do_method(node, "set_cell_item", si.pos.x, si.pos.y, si.pos.z, si.new_value, si.new_orientation);
- }
- for (List<SetItem>::Element *E = set_items.back(); E; E = E->prev()) {
+ if (mb->get_button_index() == BUTTON_LEFT) {
- const SetItem &si = E->get();
- undo_redo->add_undo_method(node, "set_cell_item", si.pos.x, si.pos.y, si.pos.z, si.old_value, si.old_orientation);
- }
+ if (input_action == INPUT_DUPLICATE) {
- undo_redo->commit_action();
- }
- set_items.clear();
+ //paste
+ _duplicate_paste();
input_action = INPUT_NONE;
- return true;
- }
-
- if (mb->get_button_index() == BUTTON_LEFT && input_action != INPUT_NONE) {
-
+ _update_duplicate_indicator();
+ } else if (mb->get_shift()) {
+ input_action = INPUT_SELECT;
+ } else if (mb->get_command())
+ input_action = INPUT_COPY;
+ else {
+ input_action = INPUT_PAINT;
set_items.clear();
- input_action = INPUT_NONE;
- return true;
}
- if (mb->get_button_index() == BUTTON_RIGHT && (input_action == INPUT_ERASE || input_action == INPUT_DUPLICATE)) {
+ } else if (mb->get_button_index() == BUTTON_RIGHT)
+ if (input_action == INPUT_DUPLICATE) {
+
input_action = INPUT_NONE;
- return true;
+ _update_duplicate_indicator();
+ } else {
+ input_action = INPUT_ERASE;
+ set_items.clear();
}
- }
- }
-
- Ref<InputEventMouseMotion> mm = p_event;
-
- if (mm.is_valid()) {
-
- return do_input_action(p_camera, mm->get_position(), false);
- }
-
- } else if (edit_mode->get_selected() == 1) {
- //area mode, select an area
+ else
+ return false;
- Ref<InputEventMouseButton> mb = p_event;
+ return do_input_action(p_camera, Point2(mb->get_position().x, mb->get_position().y), true);
+ } else {
- if (mb.is_valid()) {
+ if (
+ (mb->get_button_index() == BUTTON_RIGHT && input_action == INPUT_ERASE) ||
+ (mb->get_button_index() == BUTTON_LEFT && input_action == INPUT_PAINT)) {
- if (mb->get_button_index() == BUTTON_LEFT && mb->is_pressed()) {
+ if (set_items.size()) {
+ undo_redo->create_action("GridMap Paint");
+ for (List<SetItem>::Element *E = set_items.front(); E; E = E->next()) {
- Point2 point = mb->get_position();
-
- Camera *camera = p_camera;
- Vector3 from = camera->project_ray_origin(point);
- Vector3 normal = camera->project_ray_normal(point);
- Transform local_xform = node->get_global_transform().affine_inverse();
- from = local_xform.xform(from);
- normal = local_xform.basis.xform(normal).normalized();
+ const SetItem &si = E->get();
+ undo_redo->add_do_method(node, "set_cell_item", si.pos.x, si.pos.y, si.pos.z, si.new_value, si.new_orientation);
+ }
+ for (List<SetItem>::Element *E = set_items.back(); E; E = E->prev()) {
- List<int> areas;
- node->get_area_list(&areas);
+ const SetItem &si = E->get();
+ undo_redo->add_undo_method(node, "set_cell_item", si.pos.x, si.pos.y, si.pos.z, si.old_value, si.old_orientation);
+ }
- float min_d = 1e10;
- int min_area = -1;
+ undo_redo->commit_action();
+ }
+ set_items.clear();
+ input_action = INPUT_NONE;
+ return true;
+ }
- for (List<int>::Element *E = areas.front(); E; E = E->next()) {
+ if (mb->get_button_index() == BUTTON_LEFT && input_action != INPUT_NONE) {
- int area = E->get();
- Rect3 aabb = node->area_get_bounds(area);
- aabb.position *= node->get_cell_size();
- aabb.size *= node->get_cell_size();
+ set_items.clear();
+ input_action = INPUT_NONE;
+ return true;
+ }
+ if (mb->get_button_index() == BUTTON_RIGHT && (input_action == INPUT_ERASE || input_action == INPUT_DUPLICATE)) {
+ input_action = INPUT_NONE;
+ return true;
+ }
+ }
+ }
- Vector3 rclip, rnormal;
- if (!aabb.intersects_segment(from, from + normal * 10000, &rclip, &rnormal))
- continue;
+ Ref<InputEventMouseMotion> mm = p_event;
- float d = normal.dot(rclip);
- if (d < min_d) {
- min_d = d;
- min_area = area;
- }
- }
+ if (mm.is_valid()) {
- selected_area = min_area;
- update_areas();
- }
- }
+ return do_input_action(p_camera, mm->get_position(), false);
}
return false;
@@ -749,52 +675,6 @@ void GridMapEditor::update_pallete() {
last_theme = theme.operator->();
}
-void GridMapEditor::_area_renamed() {
-
- TreeItem *it = area_list->get_selected();
- int area = it->get_metadata(0);
- if (area < 1)
- return;
- node->area_set_name(area, it->get_text(0));
-}
-
-void GridMapEditor::_area_selected() {
-
- TreeItem *it = area_list->get_selected();
- int area = it->get_metadata(0);
- if (area < 1)
- return;
- selected_area = area;
-}
-
-void GridMapEditor::update_areas() {
-
- area_list->clear();
-
- List<int> areas;
- node->get_area_list(&areas);
-
- TreeItem *root = area_list->create_item(NULL);
- area_list->set_hide_root(true);
- TreeItem *selected = NULL;
-
- for (List<int>::Element *E = areas.front(); E; E = E->next()) {
-
- int area = E->get();
- TreeItem *ti = area_list->create_item(root);
- String name = node->area_get_name(area);
-
- ti->set_metadata(0, area);
- ti->set_text(0, name);
- ti->set_editable(0, true);
- if (area == selected_area)
- selected = ti;
- }
-
- if (selected)
- selected->select(0);
-}
-
void GridMapEditor::edit(GridMap *p_gridmap) {
node = p_gridmap;
@@ -816,13 +696,10 @@ void GridMapEditor::edit(GridMap *p_gridmap) {
VisualServer::get_singleton()->instance_set_visible(cursor_instance, false);
- _clear_areas();
-
return;
}
update_pallete();
- update_areas();
set_process(true);
@@ -894,7 +771,6 @@ void GridMapEditor::edit(GridMap *p_gridmap) {
update_grid();
_update_clip();
- _update_areas_display();
}
void GridMapEditor::_update_clip() {
@@ -931,9 +807,6 @@ void GridMapEditor::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE) {
theme_pallete->connect("item_selected", this, "_item_selected_cbk");
- edit_mode->connect("item_selected", this, "_edit_mode_changed");
- area_list->connect("item_edited", this, "_area_renamed");
- area_list->connect("item_selected", this, "_area_selected");
for (int i = 0; i < 3; i++) {
grid[i] = VS::get_singleton()->mesh_create();
@@ -1021,85 +894,6 @@ void GridMapEditor::_item_selected_cbk(int idx) {
_update_cursor_instance();
}
-void GridMapEditor::_clear_areas() {
-
- for (int i = 0; i < areas.size(); i++) {
-
- VisualServer::get_singleton()->free(areas[i].instance);
- VisualServer::get_singleton()->free(areas[i].mesh);
- }
-
- areas.clear();
-}
-
-void GridMapEditor::_update_areas_display() {
- if (!node) {
- return;
- }
-#if 0
- _clear_areas();
- List<int> areas;
- node->get_area_list(&areas);
-
- Transform global_xf = node->get_global_transform();
-
- for(List<int>::Element *E=areas.front();E;E=E->next()) {
-
- int area = E->get();
- Color color;
- if (node->area_is_exterior_portal(area))
- color=Color(1,1,1,0.2);
- else
- color.set_hsv(Math::fmod(area*0.37,1),Math::fmod(area*0.75,1),1.0,0.2);
-
-
- RID material = VisualServer::get_singleton()->fixed_material_create();
- VisualServer::get_singleton()->fixed_material_set_param( material, VS::FIXED_MATERIAL_PARAM_DIFFUSE,color );
- VisualServer::get_singleton()->fixed_material_set_param( material, VS::FIXED_MATERIAL_PARAM_EMISSION,0.5 );
- VisualServer::get_singleton()->fixed_material_set_flag( material, VisualServer::FIXED_MATERIAL_FLAG_USE_ALPHA, true );
-
-
- RID mesh = VisualServer::get_singleton()->mesh_create();
-
- PoolVector<Plane> planes;
- for(int i=0;i<3;i++) {
-
- Vector3 axis;
- axis[i]=1.0;
- planes.push_back(Plane(axis,1));
- planes.push_back(Plane(-axis,0));
- }
-
- VisualServer::get_singleton()->mesh_add_surface_from_planes(mesh,planes);
- VisualServer::get_singleton()->mesh_surface_set_material(mesh,0,material,true);
-
- AreaDisplay ad;
- ad.mesh=mesh;
- ad.instance = VisualServer::get_singleton()->instance_create2(mesh,node->get_world()->get_scenario());
- Transform xform;
- Rect3 aabb = node->area_get_bounds(area);
- xform.origin=aabb.pos * node->get_cell_size();
- xform.basis.scale(aabb.size * node->get_cell_size());
- VisualServer::get_singleton()->instance_set_transform(ad.instance,global_xf * xform);
- this->areas.push_back(ad);
-
- }
-#endif
-}
-
-void GridMapEditor::_edit_mode_changed(int p_what) {
-
- if (p_what == 0) {
-
- theme_pallete->show();
- area_list->hide();
- } else {
-
- theme_pallete->hide();
- area_list->show();
- }
-}
-
void GridMapEditor::_floor_changed(float p_value) {
if (updating)
@@ -1116,9 +910,6 @@ void GridMapEditor::_bind_methods() {
ClassDB::bind_method("_menu_option", &GridMapEditor::_menu_option);
ClassDB::bind_method("_configure", &GridMapEditor::_configure);
ClassDB::bind_method("_item_selected_cbk", &GridMapEditor::_item_selected_cbk);
- ClassDB::bind_method("_edit_mode_changed", &GridMapEditor::_edit_mode_changed);
- ClassDB::bind_method("_area_renamed", &GridMapEditor::_area_renamed);
- ClassDB::bind_method("_area_selected", &GridMapEditor::_area_selected);
ClassDB::bind_method("_floor_changed", &GridMapEditor::_floor_changed);
ClassDB::bind_method(D_METHOD("_set_display_mode", "mode"), &GridMapEditor::_set_display_mode);
@@ -1198,15 +989,6 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) {
add_child(hb);
hb->set_h_size_flags(SIZE_EXPAND_FILL);
- edit_mode = memnew(OptionButton);
- edit_mode->set_area_as_parent_rect();
- edit_mode->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_BEGIN, 24);
- edit_mode->set_margin(MARGIN_RIGHT, -14);
- edit_mode->add_item(TTR("Tiles"));
- edit_mode->add_item(TTR("Areas"));
- hb->add_child(edit_mode);
- edit_mode->set_h_size_flags(SIZE_EXPAND_FILL);
-
mode_thumbnail = memnew(ToolButton);
mode_thumbnail->set_toggle_mode(true);
mode_thumbnail->set_pressed(true);
@@ -1224,17 +1006,11 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) {
EDITOR_DEF("editors/grid_map/preview_size", 64);
display_mode = DISPLAY_THUMBNAIL;
- selected_area = -1;
theme_pallete = memnew(ItemList);
add_child(theme_pallete);
theme_pallete->set_v_size_flags(SIZE_EXPAND_FILL);
- area_list = memnew(Tree);
- add_child(area_list);
- area_list->set_v_size_flags(SIZE_EXPAND_FILL);
- area_list->hide();
-
spatial_editor_hb->add_child(memnew(VSeparator));
Label *fl = memnew(Label);
fl->set_text(" Floor: ");
@@ -1363,8 +1139,6 @@ GridMapEditor::~GridMapEditor() {
VisualServer::get_singleton()->free(duplicate_mesh);
if (duplicate_instance.is_valid())
VisualServer::get_singleton()->free(duplicate_instance);
-
- _clear_areas();
}
void GridMapEditorPlugin::edit(Object *p_object) {
diff --git a/modules/gridmap/grid_map_editor_plugin.h b/modules/gridmap/grid_map_editor_plugin.h
index a1b2c96ccd..6c7c0ab331 100644
--- a/modules/gridmap/grid_map_editor_plugin.h
+++ b/modules/gridmap/grid_map_editor_plugin.h
@@ -75,7 +75,6 @@ class GridMapEditor : public VBoxContainer {
Panel *panel;
MenuButton *options;
SpinBox *floor;
- OptionButton *edit_mode;
ToolButton *mode_thumbnail;
ToolButton *mode_list;
HBoxContainer *spatial_editor_hb;
@@ -137,7 +136,6 @@ class GridMapEditor : public VBoxContainer {
int display_mode;
int selected_pallete;
- int selected_area;
int cursor_rot;
enum Menu {
@@ -177,18 +175,12 @@ class GridMapEditor : public VBoxContainer {
RID instance;
};
- Vector<AreaDisplay> areas;
-
- void _update_areas_display();
- void _clear_areas();
-
void update_grid();
void _configure();
void _menu_option(int);
void update_pallete();
void _set_display_mode(int p_mode);
ItemList *theme_pallete;
- Tree *area_list;
void _item_selected_cbk(int idx);
void _update_cursor_transform();
void _update_cursor_instance();
@@ -199,14 +191,9 @@ class GridMapEditor : public VBoxContainer {
void _update_selection_transform();
void _validate_selection();
- void _edit_mode_changed(int p_what);
- void _area_renamed();
- void _area_selected();
-
void _floor_changed(float p_value);
void _delete_selection();
- void update_areas();
EditorNode *editor;
bool do_input_action(Camera *p_camera, const Point2 &p_point, bool p_click);