Update naar godot 4.0

Nog steeds geen nieuwe features ofzo. kopie van bestaande gridmap.
This commit is contained in:
2022-01-23 17:09:52 +01:00
parent ebf2a30bf3
commit 8121b21329
6 changed files with 222 additions and 158 deletions
+95 -61
View File
@@ -5,8 +5,8 @@
/* GODOT ENGINE */ /* GODOT ENGINE */
/* https://godotengine.org */ /* https://godotengine.org */
/*************************************************************************/ /*************************************************************************/
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* */ /* */
/* Permission is hereby granted, free of charge, to any person obtaining */ /* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */ /* a copy of this software and associated documentation files (the */
@@ -34,6 +34,8 @@
#include "core/object/message_queue.h" #include "core/object/message_queue.h"
#include "scene/3d/light_3d.h" #include "scene/3d/light_3d.h"
#include "scene/resources/mesh_library.h" #include "scene/resources/mesh_library.h"
#include "scene/resources/physics_material.h"
#include "scene/resources/primitive_meshes.h"
#include "scene/resources/surface_tool.h" #include "scene/resources/surface_tool.h"
#include "scene/scene_string_names.h" #include "scene/scene_string_names.h"
#include "servers/navigation_server_3d.h" #include "servers/navigation_server_3d.h"
@@ -181,12 +183,39 @@ void HexMap::set_collision_mask_value(int p_layer_number, bool p_value) {
set_collision_mask(mask); set_collision_mask(mask);
} }
void HexMap::set_physics_material(Ref<PhysicsMaterial> p_material) {
physics_material = p_material;
_recreate_octant_data();
}
Ref<PhysicsMaterial> HexMap::get_physics_material() const {
return physics_material;
}
bool HexMap::get_collision_mask_value(int p_layer_number) const { bool HexMap::get_collision_mask_value(int p_layer_number) const {
ERR_FAIL_COND_V_MSG(p_layer_number < 1, false, "Collision layer number must be between 1 and 32 inclusive."); ERR_FAIL_COND_V_MSG(p_layer_number < 1, false, "Collision layer number must be between 1 and 32 inclusive.");
ERR_FAIL_COND_V_MSG(p_layer_number > 32, false, "Collision layer number must be between 1 and 32 inclusive."); ERR_FAIL_COND_V_MSG(p_layer_number > 32, false, "Collision layer number must be between 1 and 32 inclusive.");
return get_collision_mask() & (1 << (p_layer_number - 1)); return get_collision_mask() & (1 << (p_layer_number - 1));
} }
Array HexMap::get_collision_shapes() const {
Array shapes;
for (const KeyValue<OctantKey, Octant *> &E : octant_map) {
Octant *g = E.value;
RID body = g->static_body;
Transform3D body_xform = PhysicsServer3D::get_singleton()->body_get_state(body, PhysicsServer3D::BODY_STATE_TRANSFORM);
int nshapes = PhysicsServer3D::get_singleton()->body_get_shape_count(body);
for (int i = 0; i < nshapes; i++) {
RID shape = PhysicsServer3D::get_singleton()->body_get_shape(body, i);
Transform3D xform = PhysicsServer3D::get_singleton()->body_get_shape_transform(body, i);
shapes.push_back(body_xform * xform);
shapes.push_back(shape);
}
}
return shapes;
}
void HexMap::set_bake_navigation(bool p_bake_navigation) { void HexMap::set_bake_navigation(bool p_bake_navigation) {
bake_navigation = p_bake_navigation; bake_navigation = p_bake_navigation;
_recreate_octant_data(); _recreate_octant_data();
@@ -316,6 +345,10 @@ void HexMap::set_cell_item(const Vector3i &p_position, int p_item, int p_rot) {
PhysicsServer3D::get_singleton()->body_attach_object_instance_id(g->static_body, get_instance_id()); PhysicsServer3D::get_singleton()->body_attach_object_instance_id(g->static_body, get_instance_id());
PhysicsServer3D::get_singleton()->body_set_collision_layer(g->static_body, collision_layer); PhysicsServer3D::get_singleton()->body_set_collision_layer(g->static_body, collision_layer);
PhysicsServer3D::get_singleton()->body_set_collision_mask(g->static_body, collision_mask); PhysicsServer3D::get_singleton()->body_set_collision_mask(g->static_body, collision_mask);
if (physics_material.is_valid()) {
PhysicsServer3D::get_singleton()->body_set_param(g->static_body, PhysicsServer3D::BODY_PARAM_FRICTION, physics_material->get_friction());
PhysicsServer3D::get_singleton()->body_set_param(g->static_body, PhysicsServer3D::BODY_PARAM_BOUNCE, physics_material->get_bounce());
}
SceneTree *st = SceneTree::get_singleton(); SceneTree *st = SceneTree::get_singleton();
if (st && st->is_debugging_collisions_hint()) { if (st && st->is_debugging_collisions_hint()) {
@@ -377,10 +410,7 @@ int HexMap::get_cell_item_orientation(const Vector3i &p_position) const {
} }
Vector3i HexMap::world_to_map(const Vector3 &p_world_position) const { Vector3i HexMap::world_to_map(const Vector3 &p_world_position) const {
Vector3 map_position = p_world_position / cell_size; Vector3 map_position = (p_world_position / cell_size).floor();
map_position.x = floor(map_position.x);
map_position.y = floor(map_position.y);
map_position.z = floor(map_position.z);
return Vector3i(map_position); return Vector3i(map_position);
} }
@@ -423,8 +453,8 @@ bool HexMap::_octant_update(const OctantKey &p_key) {
} }
//erase navigation //erase navigation
for (Map<IndexKey, Octant::NavMesh>::Element *E = g.navmesh_ids.front(); E; E = E->next()) { for (const KeyValue<IndexKey, Octant::NavMesh> &E : g.navmesh_ids) {
NavigationServer3D::get_singleton()->free(E->get().region); NavigationServer3D::get_singleton()->free(E.value.region);
} }
g.navmesh_ids.clear(); g.navmesh_ids.clear();
@@ -475,7 +505,7 @@ bool HexMap::_octant_update(const OctantKey &p_key) {
} }
Pair<Transform3D, IndexKey> p; Pair<Transform3D, IndexKey> p;
p.first = xform; p.first = xform * mesh_library->get_item_mesh_transform(c.item);
p.second = E->get(); p.second = E->get();
multimesh_items[c.item].push_back(p); multimesh_items[c.item].push_back(p);
} }
@@ -494,7 +524,7 @@ bool HexMap::_octant_update(const OctantKey &p_key) {
} }
} }
// add the item's navmesh at given xform to GridMap's Navigation ancestor // add the item's navmesh at given xform to HexMap's Navigation ancestor
Ref<NavigationMesh> navmesh = mesh_library->get_item_navmesh(c.item); Ref<NavigationMesh> navmesh = mesh_library->get_item_navmesh(c.item);
if (navmesh.is_valid()) { if (navmesh.is_valid()) {
Octant::NavMesh nm; Octant::NavMesh nm;
@@ -515,15 +545,15 @@ bool HexMap::_octant_update(const OctantKey &p_key) {
//update multimeshes, only if not baked //update multimeshes, only if not baked
if (baked_meshes.size() == 0) { if (baked_meshes.size() == 0) {
for (Map<int, List<Pair<Transform3D, IndexKey>>>::Element *E = multimesh_items.front(); E; E = E->next()) { for (const KeyValue<int, List<Pair<Transform3D, IndexKey>>> &E : multimesh_items) {
Octant::MultimeshInstance mmi; Octant::MultimeshInstance mmi;
RID mm = RS::get_singleton()->multimesh_create(); RID mm = RS::get_singleton()->multimesh_create();
RS::get_singleton()->multimesh_allocate_data(mm, E->get().size(), RS::MULTIMESH_TRANSFORM_3D); RS::get_singleton()->multimesh_allocate_data(mm, E.value.size(), RS::MULTIMESH_TRANSFORM_3D);
RS::get_singleton()->multimesh_set_mesh(mm, mesh_library->get_item_mesh(E->key())->get_rid()); RS::get_singleton()->multimesh_set_mesh(mm, mesh_library->get_item_mesh(E.key)->get_rid());
int idx = 0; int idx = 0;
for (const Pair<Transform3D, IndexKey> &F : E->get()) { for (const Pair<Transform3D, IndexKey> &F : E.value) {
RS::get_singleton()->multimesh_instance_set_transform(mm, idx, F.first); RS::get_singleton()->multimesh_instance_set_transform(mm, idx, F.first);
#ifdef TOOLS_ENABLED #ifdef TOOLS_ENABLED
@@ -570,9 +600,9 @@ bool HexMap::_octant_update(const OctantKey &p_key) {
} }
void HexMap::_reset_physic_bodies_collision_filters() { void HexMap::_reset_physic_bodies_collision_filters() {
for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) { for (const KeyValue<OctantKey, Octant *> &E : octant_map) {
PhysicsServer3D::get_singleton()->body_set_collision_layer(E->get()->static_body, collision_layer); PhysicsServer3D::get_singleton()->body_set_collision_layer(E.value->static_body, collision_layer);
PhysicsServer3D::get_singleton()->body_set_collision_mask(E->get()->static_body, collision_mask); PhysicsServer3D::get_singleton()->body_set_collision_mask(E.value->static_body, collision_mask);
} }
} }
@@ -593,17 +623,17 @@ void HexMap::_octant_enter_world(const OctantKey &p_key) {
} }
if (bake_navigation && mesh_library.is_valid()) { if (bake_navigation && mesh_library.is_valid()) {
for (Map<IndexKey, Octant::NavMesh>::Element *F = g.navmesh_ids.front(); F; F = F->next()) { for (KeyValue<IndexKey, Octant::NavMesh> &F : g.navmesh_ids) {
if (cell_map.has(F->key()) && F->get().region.is_valid() == false) { if (cell_map.has(F.key) && F.value.region.is_valid() == false) {
Ref<NavigationMesh> nm = mesh_library->get_item_navmesh(cell_map[F->key()].item); Ref<NavigationMesh> nm = mesh_library->get_item_navmesh(cell_map[F.key].item);
if (nm.is_valid()) { if (nm.is_valid()) {
RID region = NavigationServer3D::get_singleton()->region_create(); RID region = NavigationServer3D::get_singleton()->region_create();
NavigationServer3D::get_singleton()->region_set_layers(region, navigation_layers); NavigationServer3D::get_singleton()->region_set_layers(region, navigation_layers);
NavigationServer3D::get_singleton()->region_set_navmesh(region, nm); NavigationServer3D::get_singleton()->region_set_navmesh(region, nm);
NavigationServer3D::get_singleton()->region_set_transform(region, get_global_transform() * F->get().xform); NavigationServer3D::get_singleton()->region_set_transform(region, get_global_transform() * F.value.xform);
NavigationServer3D::get_singleton()->region_set_map(region, get_world_3d()->get_navigation_map()); NavigationServer3D::get_singleton()->region_set_map(region, get_world_3d()->get_navigation_map());
F->get().region = region; F.value.region = region;
} }
} }
} }
@@ -624,10 +654,10 @@ void HexMap::_octant_exit_world(const OctantKey &p_key) {
RS::get_singleton()->instance_set_scenario(g.multimesh_instances[i].instance, RID()); RS::get_singleton()->instance_set_scenario(g.multimesh_instances[i].instance, RID());
} }
for (Map<IndexKey, Octant::NavMesh>::Element *F = g.navmesh_ids.front(); F; F = F->next()) { for (KeyValue<IndexKey, Octant::NavMesh> &F : g.navmesh_ids) {
if (F->get().region.is_valid()) { if (F.value.region.is_valid()) {
NavigationServer3D::get_singleton()->free(F->get().region); NavigationServer3D::get_singleton()->free(F.value.region);
F->get().region = RID(); F.value.region = RID();
} }
} }
} }
@@ -646,8 +676,8 @@ void HexMap::_octant_clean_up(const OctantKey &p_key) {
PhysicsServer3D::get_singleton()->free(g.static_body); PhysicsServer3D::get_singleton()->free(g.static_body);
// Erase navigation // Erase navigation
for (Map<IndexKey, Octant::NavMesh>::Element *E = g.navmesh_ids.front(); E; E = E->next()) { for (const KeyValue<IndexKey, Octant::NavMesh> &E : g.navmesh_ids) {
NavigationServer3D::get_singleton()->free(E->get().region); NavigationServer3D::get_singleton()->free(E.value.region);
} }
g.navmesh_ids.clear(); g.navmesh_ids.clear();
@@ -665,8 +695,8 @@ void HexMap::_notification(int p_what) {
case NOTIFICATION_ENTER_WORLD: { case NOTIFICATION_ENTER_WORLD: {
last_transform = get_global_transform(); last_transform = get_global_transform();
for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) { for (const KeyValue<OctantKey, Octant *> &E : octant_map) {
_octant_enter_world(E->key()); _octant_enter_world(E.key);
} }
for (int i = 0; i < baked_meshes.size(); i++) { for (int i = 0; i < baked_meshes.size(); i++) {
@@ -681,8 +711,8 @@ void HexMap::_notification(int p_what) {
break; break;
} }
//update run //update run
for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) { for (const KeyValue<OctantKey, Octant *> &E : octant_map) {
_octant_transform(E->key()); _octant_transform(E.key);
} }
last_transform = new_xform; last_transform = new_xform;
@@ -692,8 +722,8 @@ void HexMap::_notification(int p_what) {
} }
} break; } break;
case NOTIFICATION_EXIT_WORLD: { case NOTIFICATION_EXIT_WORLD: {
for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) { for (const KeyValue<OctantKey, Octant *> &E : octant_map) {
_octant_exit_world(E->key()); _octant_exit_world(E.key);
} }
//_queue_octants_dirty(MAP_DIRTY_INSTANCES|MAP_DIRTY_TRANSFORMS); //_queue_octants_dirty(MAP_DIRTY_INSTANCES|MAP_DIRTY_TRANSFORMS);
@@ -715,8 +745,8 @@ void HexMap::_update_visibility() {
return; return;
} }
for (Map<OctantKey, Octant *>::Element *e = octant_map.front(); e; e = e->next()) { for (KeyValue<OctantKey, Octant *> &e : octant_map) {
Octant *octant = e->value(); Octant *octant = e.value;
for (int i = 0; i < octant->multimesh_instances.size(); i++) { for (int i = 0; i < octant->multimesh_instances.size(); i++) {
const Octant::MultimeshInstance &mi = octant->multimesh_instances[i]; const Octant::MultimeshInstance &mi = octant->multimesh_instances[i];
RS::get_singleton()->instance_set_visible(mi.instance, is_visible_in_tree()); RS::get_singleton()->instance_set_visible(mi.instance, is_visible_in_tree());
@@ -741,20 +771,20 @@ void HexMap::_recreate_octant_data() {
recreating_octants = true; recreating_octants = true;
Map<IndexKey, Cell> cell_copy = cell_map; Map<IndexKey, Cell> cell_copy = cell_map;
_clear_internal(); _clear_internal();
for (Map<IndexKey, Cell>::Element *E = cell_copy.front(); E; E = E->next()) { for (const KeyValue<IndexKey, Cell> &E : cell_copy) {
set_cell_item(Vector3i(E->key()), E->get().item, E->get().rot); set_cell_item(Vector3i(E.key), E.value.item, E.value.rot);
} }
recreating_octants = false; recreating_octants = false;
} }
void HexMap::_clear_internal() { void HexMap::_clear_internal() {
for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) { for (const KeyValue<OctantKey, Octant *> &E : octant_map) {
if (is_inside_world()) { if (is_inside_world()) {
_octant_exit_world(E->key()); _octant_exit_world(E.key);
} }
_octant_clean_up(E->key()); _octant_clean_up(E.key);
memdelete(E->get()); memdelete(E.value);
} }
octant_map.clear(); octant_map.clear();
@@ -776,9 +806,9 @@ void HexMap::_update_octants_callback() {
} }
List<OctantKey> to_delete; List<OctantKey> to_delete;
for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) { for (const KeyValue<OctantKey, Octant *> &E : octant_map) {
if (_octant_update(E->key())) { if (_octant_update(E.key)) {
to_delete.push_back(E->key()); to_delete.push_back(E.key);
} }
} }
@@ -804,6 +834,9 @@ void HexMap::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_collision_layer_value", "layer_number", "value"), &HexMap::set_collision_layer_value); ClassDB::bind_method(D_METHOD("set_collision_layer_value", "layer_number", "value"), &HexMap::set_collision_layer_value);
ClassDB::bind_method(D_METHOD("get_collision_layer_value", "layer_number"), &HexMap::get_collision_layer_value); ClassDB::bind_method(D_METHOD("get_collision_layer_value", "layer_number"), &HexMap::get_collision_layer_value);
ClassDB::bind_method(D_METHOD("set_physics_material", "material"), &HexMap::set_physics_material);
ClassDB::bind_method(D_METHOD("get_physics_material"), &HexMap::get_physics_material);
ClassDB::bind_method(D_METHOD("set_bake_navigation", "bake_navigation"), &HexMap::set_bake_navigation); ClassDB::bind_method(D_METHOD("set_bake_navigation", "bake_navigation"), &HexMap::set_bake_navigation);
ClassDB::bind_method(D_METHOD("is_baking_navigation"), &HexMap::is_baking_navigation); ClassDB::bind_method(D_METHOD("is_baking_navigation"), &HexMap::is_baking_navigation);
@@ -853,6 +886,7 @@ void HexMap::_bind_methods() {
ClassDB::bind_method(D_METHOD("make_baked_meshes", "gen_lightmap_uv", "lightmap_uv_texel_size"), &HexMap::make_baked_meshes, DEFVAL(false), DEFVAL(0.1)); ClassDB::bind_method(D_METHOD("make_baked_meshes", "gen_lightmap_uv", "lightmap_uv_texel_size"), &HexMap::make_baked_meshes, DEFVAL(false), DEFVAL(0.1));
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "mesh_library", PROPERTY_HINT_RESOURCE_TYPE, "MeshLibrary"), "set_mesh_library", "get_mesh_library"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "mesh_library", PROPERTY_HINT_RESOURCE_TYPE, "MeshLibrary"), "set_mesh_library", "get_mesh_library");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "physics_material", PROPERTY_HINT_RESOURCE_TYPE, "PhysicsMaterial"), "set_physics_material", "get_physics_material");
ADD_GROUP("Cell", "cell_"); ADD_GROUP("Cell", "cell_");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "cell_size"), "set_cell_size", "get_cell_size"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "cell_size"), "set_cell_size", "get_cell_size");
ADD_PROPERTY(PropertyInfo(Variant::INT, "cell_octant_size", PROPERTY_HINT_RANGE, "1,1024,1"), "set_octant_size", "get_octant_size"); ADD_PROPERTY(PropertyInfo(Variant::INT, "cell_octant_size", PROPERTY_HINT_RANGE, "1,1024,1"), "set_octant_size", "get_octant_size");
@@ -886,8 +920,8 @@ void HexMap::set_clip(bool p_enabled, bool p_clip_above, int p_floor, Vector3::A
clip_above = p_clip_above; clip_above = p_clip_above;
//make it all update //make it all update
for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) { for (KeyValue<OctantKey, Octant *> &E : octant_map) {
Octant *g = E->get(); Octant *g = E.value;
g->dirty = true; g->dirty = true;
} }
awaiting_update = true; awaiting_update = true;
@@ -907,15 +941,15 @@ Array HexMap::get_used_cells() const {
Array a; Array a;
a.resize(cell_map.size()); a.resize(cell_map.size());
int i = 0; int i = 0;
for (Map<IndexKey, Cell>::Element *E = cell_map.front(); E; E = E->next()) { for (const KeyValue<IndexKey, Cell> &E : cell_map) {
Vector3 p(E->key().x, E->key().y, E->key().z); Vector3 p(E.key.x, E.key.y, E.key.z);
a[i++] = p; a[i++] = p;
} }
return a; return a;
} }
Array HexMap::get_meshes() { Array HexMap::get_meshes() const {
if (mesh_library.is_null()) { if (mesh_library.is_null()) {
return Array(); return Array();
} }
@@ -923,8 +957,8 @@ Array HexMap::get_meshes() {
Vector3 ofs = _get_offset(); Vector3 ofs = _get_offset();
Array meshes; Array meshes;
for (Map<IndexKey, Cell>::Element *E = cell_map.front(); E; E = E->next()) { for (const KeyValue<IndexKey, Cell> &E : cell_map) {
int id = E->get().item; int id = E.value.item;
if (!mesh_library->has_item(id)) { if (!mesh_library->has_item(id)) {
continue; continue;
} }
@@ -933,13 +967,13 @@ Array HexMap::get_meshes() {
continue; continue;
} }
IndexKey ik = E->key(); IndexKey ik = E.key;
Vector3 cellpos = Vector3(ik.x, ik.y, ik.z); Vector3 cellpos = Vector3(ik.x, ik.y, ik.z);
Transform3D xform; Transform3D xform;
xform.basis.set_orthogonal_index(E->get().rot); xform.basis.set_orthogonal_index(E.value.rot);
xform.set_origin(cellpos * cell_size + ofs); xform.set_origin(cellpos * cell_size + ofs);
xform.basis.scale(Vector3(cell_scale, cell_scale, cell_scale)); xform.basis.scale(Vector3(cell_scale, cell_scale, cell_scale));
@@ -975,10 +1009,10 @@ void HexMap::make_baked_meshes(bool p_gen_lightmap_uv, float p_lightmap_uv_texel
//generate //generate
Map<OctantKey, Map<Ref<Material>, Ref<SurfaceTool>>> surface_map; Map<OctantKey, Map<Ref<Material>, Ref<SurfaceTool>>> surface_map;
for (Map<IndexKey, Cell>::Element *E = cell_map.front(); E; E = E->next()) { for (KeyValue<IndexKey, Cell> &E : cell_map) {
IndexKey key = E->key(); IndexKey key = E.key;
int item = E->get().item; int item = E.value.item;
if (!mesh_library->has_item(item)) { if (!mesh_library->has_item(item)) {
continue; continue;
} }
@@ -993,7 +1027,7 @@ void HexMap::make_baked_meshes(bool p_gen_lightmap_uv, float p_lightmap_uv_texel
Transform3D xform; Transform3D xform;
xform.basis.set_orthogonal_index(E->get().rot); xform.basis.set_orthogonal_index(E.value.rot);
xform.set_origin(cellpos * cell_size + ofs); xform.set_origin(cellpos * cell_size + ofs);
xform.basis.scale(Vector3(cell_scale, cell_scale, cell_scale)); xform.basis.scale(Vector3(cell_scale, cell_scale, cell_scale));
@@ -1026,11 +1060,11 @@ void HexMap::make_baked_meshes(bool p_gen_lightmap_uv, float p_lightmap_uv_texel
} }
} }
for (Map<OctantKey, Map<Ref<Material>, Ref<SurfaceTool>>>::Element *E = surface_map.front(); E; E = E->next()) { for (KeyValue<OctantKey, Map<Ref<Material>, Ref<SurfaceTool>>> &E : surface_map) {
Ref<ArrayMesh> mesh; Ref<ArrayMesh> mesh;
mesh.instantiate(); mesh.instantiate();
for (Map<Ref<Material>, Ref<SurfaceTool>>::Element *F = E->get().front(); F; F = F->next()) { for (KeyValue<Ref<Material>, Ref<SurfaceTool>> &F : E.value) {
F->get()->commit(mesh); F.value->commit(mesh);
} }
BakedMesh bm; BakedMesh bm;
+12 -4
View File
@@ -5,8 +5,8 @@
/* GODOT ENGINE */ /* GODOT ENGINE */
/* https://godotengine.org */ /* https://godotengine.org */
/*************************************************************************/ /*************************************************************************/
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* */ /* */
/* Permission is hereby granted, free of charge, to any person obtaining */ /* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */ /* a copy of this software and associated documentation files (the */
@@ -38,6 +38,8 @@
//heh heh, godotsphir!! this shares no code and the design is completely different with previous projects i've done.. //heh heh, godotsphir!! this shares no code and the design is completely different with previous projects i've done..
//should scale better with hardware that supports instancing //should scale better with hardware that supports instancing
class PhysicsMaterial;
class HexMap : public Node3D { class HexMap : public Node3D {
GDCLASS(HexMap, Node3D); GDCLASS(HexMap, Node3D);
@@ -134,6 +136,7 @@ class HexMap : public Node3D {
uint32_t collision_layer = 1; uint32_t collision_layer = 1;
uint32_t collision_mask = 1; uint32_t collision_mask = 1;
Ref<PhysicsMaterial> physics_material;
bool bake_navigation = false; bool bake_navigation = false;
uint32_t navigation_layers = 1; uint32_t navigation_layers = 1;
@@ -223,6 +226,11 @@ public:
void set_collision_mask_value(int p_layer_number, bool p_value); void set_collision_mask_value(int p_layer_number, bool p_value);
bool get_collision_mask_value(int p_layer_number) const; bool get_collision_mask_value(int p_layer_number) const;
void set_physics_material(Ref<PhysicsMaterial> p_material);
Ref<PhysicsMaterial> get_physics_material() const;
Array get_collision_shapes() const;
void set_bake_navigation(bool p_bake_navigation); void set_bake_navigation(bool p_bake_navigation);
bool is_baking_navigation(); bool is_baking_navigation();
@@ -259,7 +267,7 @@ public:
Array get_used_cells() const; Array get_used_cells() const;
Array get_meshes(); Array get_meshes() const;
void clear_baked_meshes(); void clear_baked_meshes();
void make_baked_meshes(bool p_gen_lightmap_uv = false, float p_lightmap_uv_texel_size = 0.1); void make_baked_meshes(bool p_gen_lightmap_uv = false, float p_lightmap_uv_texel_size = 0.1);
@@ -273,4 +281,4 @@ public:
~HexMap(); ~HexMap();
}; };
#endif // GRID_MAP_H #endif // HEX_MAP_H
+103 -82
View File
@@ -5,8 +5,8 @@
/* GODOT ENGINE */ /* GODOT ENGINE */
/* https://godotengine.org */ /* https://godotengine.org */
/*************************************************************************/ /*************************************************************************/
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* */ /* */
/* Permission is hereby granted, free of charge, to any person obtaining */ /* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */ /* a copy of this software and associated documentation files (the */
@@ -49,7 +49,7 @@ void HexMapEditor::_configure() {
return; return;
} }
update(); update_grid();
} }
void HexMapEditor::_menu_option(int p_option) { void HexMapEditor::_menu_option(int p_option) {
@@ -255,6 +255,12 @@ void HexMapEditor::_update_cursor_transform() {
cursor_transform.basis *= node->get_cell_scale(); cursor_transform.basis *= node->get_cell_scale();
cursor_transform = node->get_global_transform() * cursor_transform; cursor_transform = node->get_global_transform() * cursor_transform;
if (selected_palette >= 0) {
if (node && !node->get_mesh_library().is_null()) {
cursor_transform *= node->get_mesh_library()->get_item_mesh_transform(selected_palette);
}
}
if (cursor_instance.is_valid()) { if (cursor_instance.is_valid()) {
RenderingServer::get_singleton()->instance_set_transform(cursor_instance, cursor_transform); RenderingServer::get_singleton()->instance_set_transform(cursor_instance, cursor_transform);
RenderingServer::get_singleton()->instance_set_visible(cursor_instance, cursor_visible); RenderingServer::get_singleton()->instance_set_visible(cursor_instance, cursor_visible);
@@ -461,7 +467,7 @@ void HexMapEditor::_delete_selection() {
return; return;
} }
undo_redo->create_action(TTR("GridMap Delete Selection")); undo_redo->create_action(TTR("HexMap Delete Selection"));
for (int i = selection.begin.x; i <= selection.end.x; i++) { for (int i = selection.begin.x; i <= selection.end.x; i++) {
for (int j = selection.begin.y; j <= selection.end.y; j++) { for (int j = selection.begin.y; j <= selection.end.y; j++) {
for (int k = selection.begin.z; k <= selection.end.z; k++) { for (int k = selection.begin.z; k <= selection.end.z; k++) {
@@ -481,7 +487,7 @@ void HexMapEditor::_fill_selection() {
return; return;
} }
undo_redo->create_action(TTR("GridMap Fill Selection")); undo_redo->create_action(TTR("HexMap Fill Selection"));
for (int i = selection.begin.x; i <= selection.end.x; i++) { for (int i = selection.begin.x; i <= selection.end.x; i++) {
for (int j = selection.begin.y; j <= selection.end.y; j++) { for (int j = selection.begin.y; j <= selection.end.y; j++) {
for (int k = selection.begin.z; k <= selection.end.z; k++) { for (int k = selection.begin.z; k <= selection.end.z; k++) {
@@ -574,7 +580,7 @@ void HexMapEditor::_do_paste() {
rot.set_orthogonal_index(paste_indicator.orientation); rot.set_orthogonal_index(paste_indicator.orientation);
Vector3 ofs = paste_indicator.current - paste_indicator.click; Vector3 ofs = paste_indicator.current - paste_indicator.click;
undo_redo->create_action(TTR("GridMap Paste Selection")); undo_redo->create_action(TTR("HexMap Paste Selection"));
for (const ClipboardItem &item : clipboard_items) { for (const ClipboardItem &item : clipboard_items) {
Vector3 position = rot.xform(item.grid_offset) + paste_indicator.begin + ofs; Vector3 position = rot.xform(item.grid_offset) + paste_indicator.begin + ofs;
@@ -597,32 +603,32 @@ void HexMapEditor::_do_paste() {
_clear_clipboard_data(); _clear_clipboard_data();
} }
bool HexMapEditor::forward_spatial_input_event(Camera3D *p_camera, const Ref<InputEvent> &p_event) { EditorPlugin::AfterGUIInput HexMapEditor::forward_spatial_input_event(Camera3D *p_camera, const Ref<InputEvent> &p_event) {
if (!node) { if (!node) {
return false; return EditorPlugin::AFTER_GUI_INPUT_PASS;
} }
Ref<InputEventMouseButton> mb = p_event; Ref<InputEventMouseButton> mb = p_event;
if (mb.is_valid()) { if (mb.is_valid()) {
if (mb->get_button_index() == MOUSE_BUTTON_WHEEL_UP && (mb->is_command_pressed() || mb->is_shift_pressed())) { if (mb->get_button_index() == MouseButton::WHEEL_UP && (mb->is_command_pressed() || mb->is_shift_pressed())) {
if (mb->is_pressed()) { if (mb->is_pressed()) {
floor->set_value(floor->get_value() + mb->get_factor()); floor->set_value(floor->get_value() + mb->get_factor());
} }
return true; // Eaten. return EditorPlugin::AFTER_GUI_INPUT_STOP; // Eaten.
} else if (mb->get_button_index() == MOUSE_BUTTON_WHEEL_DOWN && (mb->is_command_pressed() || mb->is_shift_pressed())) { } else if (mb->get_button_index() == MouseButton::WHEEL_DOWN && (mb->is_command_pressed() || mb->is_shift_pressed())) {
if (mb->is_pressed()) { if (mb->is_pressed()) {
floor->set_value(floor->get_value() - mb->get_factor()); floor->set_value(floor->get_value() - mb->get_factor());
} }
return true; return EditorPlugin::AFTER_GUI_INPUT_STOP;
} }
if (mb->is_pressed()) { if (mb->is_pressed()) {
Node3DEditorViewport::NavigationScheme nav_scheme = (Node3DEditorViewport::NavigationScheme)EditorSettings::get_singleton()->get("editors/3d/navigation/navigation_scheme").operator int(); Node3DEditorViewport::NavigationScheme nav_scheme = (Node3DEditorViewport::NavigationScheme)EditorSettings::get_singleton()->get("editors/3d/navigation/navigation_scheme").operator int();
if ((nav_scheme == Node3DEditorViewport::NAVIGATION_MAYA || nav_scheme == Node3DEditorViewport::NAVIGATION_MODO) && mb->is_alt_pressed()) { if ((nav_scheme == Node3DEditorViewport::NAVIGATION_MAYA || nav_scheme == Node3DEditorViewport::NAVIGATION_MODO) && mb->is_alt_pressed()) {
input_action = INPUT_NONE; input_action = INPUT_NONE;
} else if (mb->get_button_index() == MOUSE_BUTTON_LEFT) { } else if (mb->get_button_index() == MouseButton::LEFT) {
bool can_edit = (node && node->get_mesh_library().is_valid()); bool can_edit = (node && node->get_mesh_library().is_valid());
if (input_action == INPUT_PASTE) { if (input_action == INPUT_PASTE) {
_do_paste(); _do_paste();
@@ -637,28 +643,31 @@ bool HexMapEditor::forward_spatial_input_event(Camera3D *p_camera, const Ref<Inp
input_action = INPUT_PAINT; input_action = INPUT_PAINT;
set_items.clear(); set_items.clear();
} }
} else if (mb->get_button_index() == MOUSE_BUTTON_RIGHT) { } else if (mb->get_button_index() == MouseButton::RIGHT) {
if (input_action == INPUT_PASTE) { if (input_action == INPUT_PASTE) {
_clear_clipboard_data(); _clear_clipboard_data();
input_action = INPUT_NONE; input_action = INPUT_NONE;
_update_paste_indicator(); _update_paste_indicator();
return true; return EditorPlugin::AFTER_GUI_INPUT_STOP;
} else if (selection.active) { } else if (selection.active) {
_set_selection(false); _set_selection(false);
return true; return EditorPlugin::AFTER_GUI_INPUT_STOP;
} else { } else {
input_action = INPUT_ERASE; input_action = INPUT_ERASE;
set_items.clear(); set_items.clear();
} }
} else { } else {
return false; return EditorPlugin::AFTER_GUI_INPUT_PASS;
} }
return do_input_action(p_camera, Point2(mb->get_position().x, mb->get_position().y), true); if (do_input_action(p_camera, Point2(mb->get_position().x, mb->get_position().y), true)) {
return EditorPlugin::AFTER_GUI_INPUT_STOP;
}
return EditorPlugin::AFTER_GUI_INPUT_PASS;
} else { } else {
if ((mb->get_button_index() == MOUSE_BUTTON_RIGHT && input_action == INPUT_ERASE) || (mb->get_button_index() == MOUSE_BUTTON_LEFT && input_action == INPUT_PAINT)) { if ((mb->get_button_index() == MouseButton::RIGHT && input_action == INPUT_ERASE) || (mb->get_button_index() == MouseButton::LEFT && input_action == INPUT_PAINT)) {
if (set_items.size()) { if (set_items.size()) {
undo_redo->create_action(TTR("GridMap Paint")); undo_redo->create_action(TTR("HexMap Paint"));
for (const SetItem &si : set_items) { for (const SetItem &si : set_items) {
undo_redo->add_do_method(node, "set_cell_item", si.position, si.new_value, si.new_orientation); undo_redo->add_do_method(node, "set_cell_item", si.position, si.new_value, si.new_orientation);
} }
@@ -671,24 +680,28 @@ bool HexMapEditor::forward_spatial_input_event(Camera3D *p_camera, const Ref<Inp
} }
set_items.clear(); set_items.clear();
input_action = INPUT_NONE; input_action = INPUT_NONE;
return set_items.size() > 0;
if (set_items.size() > 0) {
return EditorPlugin::AFTER_GUI_INPUT_STOP;
}
return EditorPlugin::AFTER_GUI_INPUT_PASS;
} }
if (mb->get_button_index() == MOUSE_BUTTON_LEFT && input_action == INPUT_SELECT) { if (mb->get_button_index() == MouseButton::LEFT && input_action == INPUT_SELECT) {
undo_redo->create_action(TTR("GridMap Selection")); undo_redo->create_action(TTR("HexMap Selection"));
undo_redo->add_do_method(this, "_set_selection", selection.active, selection.begin, selection.end); undo_redo->add_do_method(this, "_set_selection", selection.active, selection.begin, selection.end);
undo_redo->add_undo_method(this, "_set_selection", last_selection.active, last_selection.begin, last_selection.end); undo_redo->add_undo_method(this, "_set_selection", last_selection.active, last_selection.begin, last_selection.end);
undo_redo->commit_action(); undo_redo->commit_action();
} }
if (mb->get_button_index() == MOUSE_BUTTON_LEFT && input_action != INPUT_NONE) { if (mb->get_button_index() == MouseButton::LEFT && input_action != INPUT_NONE) {
set_items.clear(); set_items.clear();
input_action = INPUT_NONE; input_action = INPUT_NONE;
return true; return EditorPlugin::AFTER_GUI_INPUT_STOP;
} }
if (mb->get_button_index() == MOUSE_BUTTON_RIGHT && (input_action == INPUT_ERASE || input_action == INPUT_PASTE)) { if (mb->get_button_index() == MouseButton::RIGHT && (input_action == INPUT_ERASE || input_action == INPUT_PASTE)) {
input_action = INPUT_NONE; input_action = INPUT_NONE;
return true; return EditorPlugin::AFTER_GUI_INPUT_STOP;
} }
} }
} }
@@ -696,41 +709,44 @@ bool HexMapEditor::forward_spatial_input_event(Camera3D *p_camera, const Ref<Inp
Ref<InputEventMouseMotion> mm = p_event; Ref<InputEventMouseMotion> mm = p_event;
if (mm.is_valid()) { if (mm.is_valid()) {
return do_input_action(p_camera, mm->get_position(), false); if (do_input_action(p_camera, mm->get_position(), false)) {
return EditorPlugin::AFTER_GUI_INPUT_STOP;
}
return EditorPlugin::AFTER_GUI_INPUT_PASS;
} }
Ref<InputEventKey> k = p_event; Ref<InputEventKey> k = p_event;
if (k.is_valid()) { if (k.is_valid()) {
if (k->is_pressed()) { if (k->is_pressed()) {
if (k->get_keycode() == KEY_ESCAPE) { if (k->get_keycode() == Key::ESCAPE) {
if (input_action == INPUT_PASTE) { if (input_action == INPUT_PASTE) {
_clear_clipboard_data(); _clear_clipboard_data();
input_action = INPUT_NONE; input_action = INPUT_NONE;
_update_paste_indicator(); _update_paste_indicator();
return true; return EditorPlugin::AFTER_GUI_INPUT_STOP;
} else if (selection.active) { } else if (selection.active) {
_set_selection(false); _set_selection(false);
return true; return EditorPlugin::AFTER_GUI_INPUT_STOP;
} else { } else {
selected_palette = -1; selected_palette = -1;
mesh_library_palette->deselect_all(); mesh_library_palette->deselect_all();
update_palette(); update_palette();
_update_cursor_instance(); _update_cursor_instance();
return true; return EditorPlugin::AFTER_GUI_INPUT_STOP;
} }
} }
if (k->is_shift_pressed() && selection.active && input_action != INPUT_PASTE) { if (k->is_shift_pressed() && selection.active && input_action != INPUT_PASTE) {
if (k->get_keycode() == options->get_popup()->get_item_accelerator(options->get_popup()->get_item_index(MENU_OPTION_PREV_LEVEL))) { if (k->get_keycode() == (Key)options->get_popup()->get_item_accelerator(options->get_popup()->get_item_index(MENU_OPTION_PREV_LEVEL))) {
selection.click[edit_axis]--; selection.click[edit_axis]--;
_validate_selection(); _validate_selection();
return true; return EditorPlugin::AFTER_GUI_INPUT_STOP;
} }
if (k->get_keycode() == options->get_popup()->get_item_accelerator(options->get_popup()->get_item_index(MENU_OPTION_NEXT_LEVEL))) { if (k->get_keycode() == (Key)options->get_popup()->get_item_accelerator(options->get_popup()->get_item_index(MENU_OPTION_NEXT_LEVEL))) {
selection.click[edit_axis]++; selection.click[edit_axis]++;
_validate_selection(); _validate_selection();
return true; return EditorPlugin::AFTER_GUI_INPUT_STOP;
} }
} }
} }
@@ -743,18 +759,18 @@ bool HexMapEditor::forward_spatial_input_event(Camera3D *p_camera, const Ref<Inp
accumulated_floor_delta += delta; accumulated_floor_delta += delta;
int step = 0; int step = 0;
if (ABS(accumulated_floor_delta) > 1.0) { if (ABS(accumulated_floor_delta) > 1.0) {
step = SGN(accumulated_floor_delta); step = SIGN(accumulated_floor_delta);
accumulated_floor_delta -= step; accumulated_floor_delta -= step;
} }
if (step) { if (step) {
floor->set_value(floor->get_value() + step); floor->set_value(floor->get_value() + step);
} }
return true; return EditorPlugin::AFTER_GUI_INPUT_STOP;
} }
} }
accumulated_floor_delta = 0.0; accumulated_floor_delta = 0.0;
return false; return EditorPlugin::AFTER_GUI_INPUT_PASS;
} }
struct _CGMEItemSort { struct _CGMEItemSort {
@@ -788,7 +804,7 @@ void HexMapEditor::_text_changed(const String &p_text) {
void HexMapEditor::_sbox_input(const Ref<InputEvent> &p_ie) { void HexMapEditor::_sbox_input(const Ref<InputEvent> &p_ie) {
const Ref<InputEventKey> k = p_ie; const Ref<InputEventKey> k = p_ie;
if (k.is_valid() && (k->get_keycode() == KEY_UP || k->get_keycode() == KEY_DOWN || k->get_keycode() == KEY_PAGEUP || k->get_keycode() == KEY_PAGEDOWN)) { if (k.is_valid() && (k->get_keycode() == Key::UP || k->get_keycode() == Key::DOWN || k->get_keycode() == Key::PAGEUP || k->get_keycode() == Key::PAGEDOWN)) {
// Forward the key input to the ItemList so it can be scrolled // Forward the key input to the ItemList so it can be scrolled
mesh_library_palette->gui_input(k); mesh_library_palette->gui_input(k);
search_box->accept_event(); search_box->accept_event();
@@ -800,11 +816,11 @@ void HexMapEditor::_mesh_library_palette_input(const Ref<InputEvent> &p_ie) {
// Zoom in/out using Ctrl + mouse wheel // Zoom in/out using Ctrl + mouse wheel
if (mb.is_valid() && mb->is_pressed() && mb->is_command_pressed()) { if (mb.is_valid() && mb->is_pressed() && mb->is_command_pressed()) {
if (mb->is_pressed() && mb->get_button_index() == MOUSE_BUTTON_WHEEL_UP) { if (mb->is_pressed() && mb->get_button_index() == MouseButton::WHEEL_UP) {
size_slider->set_value(size_slider->get_value() + 0.2); size_slider->set_value(size_slider->get_value() + 0.2);
} }
if (mb->is_pressed() && mb->get_button_index() == MOUSE_BUTTON_WHEEL_DOWN) { if (mb->is_pressed() && mb->get_button_index() == MouseButton::WHEEL_DOWN) {
size_slider->set_value(size_slider->get_value() - 0.2); size_slider->set_value(size_slider->get_value() - 0.2);
} }
} }
@@ -818,7 +834,7 @@ void HexMapEditor::_icon_size_changed(float p_value) {
void HexMapEditor::update_palette() { void HexMapEditor::update_palette() {
int selected = mesh_library_palette->get_current(); int selected = mesh_library_palette->get_current();
float min_size = EDITOR_DEF("editors/hex_map/preview_size", 64); float min_size = EDITOR_DEF("editors/grid_map/preview_size", 64);
min_size *= EDSCALE; min_size *= EDSCALE;
mesh_library_palette->clear(); mesh_library_palette->clear();
@@ -869,11 +885,11 @@ void HexMapEditor::update_palette() {
String name = mesh_library->get_item_name(id); String name = mesh_library->get_item_name(id);
Ref<Texture2D> preview = mesh_library->get_item_preview(id); Ref<Texture2D> preview = mesh_library->get_item_preview(id);
if (name == "") { if (name.is_empty()) {
name = "#" + itos(id); name = "#" + itos(id);
} }
if (filter != "" && !filter.is_subsequence_ofi(name)) { if (!filter.is_empty() && !filter.is_subsequence_ofi(name)) {
continue; continue;
} }
@@ -1012,6 +1028,13 @@ void HexMapEditor::_draw_grids(const Vector3 &cell_size) {
} }
} }
void HexMapEditor::_update_theme() {
options->set_icon(get_theme_icon(SNAME("HexMap"), SNAME("EditorIcons")));
search_box->set_right_icon(get_theme_icon(SNAME("Search"), SNAME("EditorIcons")));
mode_thumbnail->set_icon(get_theme_icon(SNAME("FileThumbnail"), SNAME("EditorIcons")));
mode_list->set_icon(get_theme_icon(SNAME("FileList"), SNAME("EditorIcons")));
}
void HexMapEditor::_notification(int p_what) { void HexMapEditor::_notification(int p_what) {
switch (p_what) { switch (p_what) {
case NOTIFICATION_ENTER_TREE: { case NOTIFICATION_ENTER_TREE: {
@@ -1032,6 +1055,7 @@ void HexMapEditor::_notification(int p_what) {
_update_selection_transform(); _update_selection_transform();
_update_paste_indicator(); _update_paste_indicator();
_update_theme();
} break; } break;
case NOTIFICATION_EXIT_TREE: { case NOTIFICATION_EXIT_TREE: {
@@ -1072,8 +1096,7 @@ void HexMapEditor::_notification(int p_what) {
} break; } break;
case NOTIFICATION_THEME_CHANGED: { case NOTIFICATION_THEME_CHANGED: {
options->set_icon(get_theme_icon(SNAME("GridMap"), SNAME("EditorIcons"))); _update_theme();
search_box->set_right_icon(get_theme_icon(SNAME("Search"), SNAME("EditorIcons")));
} break; } break;
case NOTIFICATION_APPLICATION_FOCUS_OUT: { case NOTIFICATION_APPLICATION_FOCUS_OUT: {
@@ -1081,7 +1104,7 @@ void HexMapEditor::_notification(int p_what) {
// Simulate mouse released event to stop drawing when editor focus exists. // Simulate mouse released event to stop drawing when editor focus exists.
Ref<InputEventMouseButton> release; Ref<InputEventMouseButton> release;
release.instantiate(); release.instantiate();
release->set_button_index(MOUSE_BUTTON_LEFT); release->set_button_index(MouseButton::LEFT);
forward_spatial_input_event(nullptr, release); forward_spatial_input_event(nullptr, release);
} }
} break; } break;
@@ -1140,14 +1163,14 @@ HexMapEditor::HexMapEditor(EditorNode *p_editor) {
editor = p_editor; editor = p_editor;
undo_redo = p_editor->get_undo_redo(); undo_redo = p_editor->get_undo_redo();
int mw = EDITOR_DEF("editors/hex_map/palette_min_width", 230); int mw = EDITOR_DEF("editors/grid_map/palette_min_width", 230);
Control *ec = memnew(Control); Control *ec = memnew(Control);
ec->set_custom_minimum_size(Size2(mw, 0) * EDSCALE); ec->set_custom_minimum_size(Size2(mw, 0) * EDSCALE);
add_child(ec); add_child(ec);
spatial_editor_hb = memnew(HBoxContainer); spatial_editor_hb = memnew(HBoxContainer);
spatial_editor_hb->set_h_size_flags(SIZE_EXPAND_FILL); spatial_editor_hb->set_h_size_flags(SIZE_EXPAND_FILL);
spatial_editor_hb->set_alignment(BoxContainer::ALIGN_END); spatial_editor_hb->set_alignment(BoxContainer::ALIGNMENT_END);
Node3DEditor::get_singleton()->add_control_to_menu_panel(spatial_editor_hb); Node3DEditor::get_singleton()->add_control_to_menu_panel(spatial_editor_hb);
spin_box_label = memnew(Label); spin_box_label = memnew(Label);
@@ -1172,39 +1195,39 @@ HexMapEditor::HexMapEditor(EditorNode *p_editor) {
spatial_editor_hb->hide(); spatial_editor_hb->hide();
options->set_text(TTR("Grid Map")); options->set_text(TTR("Grid Map"));
options->get_popup()->add_item(TTR("Previous Floor"), MENU_OPTION_PREV_LEVEL, KEY_Q); options->get_popup()->add_item(TTR("Previous Floor"), MENU_OPTION_PREV_LEVEL, Key::Q);
options->get_popup()->add_item(TTR("Next Floor"), MENU_OPTION_NEXT_LEVEL, KEY_E); options->get_popup()->add_item(TTR("Next Floor"), MENU_OPTION_NEXT_LEVEL, Key::E);
options->get_popup()->add_separator(); options->get_popup()->add_separator();
options->get_popup()->add_radio_check_item(TTR("Clip Disabled"), MENU_OPTION_CLIP_DISABLED); options->get_popup()->add_radio_check_item(TTR("Clip Disabled"), MENU_OPTION_CLIP_DISABLED);
options->get_popup()->set_item_checked(options->get_popup()->get_item_index(MENU_OPTION_CLIP_DISABLED), true); options->get_popup()->set_item_checked(options->get_popup()->get_item_index(MENU_OPTION_CLIP_DISABLED), true);
options->get_popup()->add_radio_check_item(TTR("Clip Above"), MENU_OPTION_CLIP_ABOVE); options->get_popup()->add_radio_check_item(TTR("Clip Above"), MENU_OPTION_CLIP_ABOVE);
options->get_popup()->add_radio_check_item(TTR("Clip Below"), MENU_OPTION_CLIP_BELOW); options->get_popup()->add_radio_check_item(TTR("Clip Below"), MENU_OPTION_CLIP_BELOW);
options->get_popup()->add_separator(); options->get_popup()->add_separator();
options->get_popup()->add_radio_check_item(TTR("Edit X Axis"), MENU_OPTION_X_AXIS, KEY_Z); options->get_popup()->add_radio_check_item(TTR("Edit X Axis"), MENU_OPTION_X_AXIS, Key::Z);
options->get_popup()->add_radio_check_item(TTR("Edit Y Axis"), MENU_OPTION_Y_AXIS, KEY_X); options->get_popup()->add_radio_check_item(TTR("Edit Y Axis"), MENU_OPTION_Y_AXIS, Key::X);
options->get_popup()->add_radio_check_item(TTR("Edit Z Axis"), MENU_OPTION_Z_AXIS, KEY_C); options->get_popup()->add_radio_check_item(TTR("Edit Z Axis"), MENU_OPTION_Z_AXIS, Key::C);
options->get_popup()->set_item_checked(options->get_popup()->get_item_index(MENU_OPTION_Y_AXIS), true); options->get_popup()->set_item_checked(options->get_popup()->get_item_index(MENU_OPTION_Y_AXIS), true);
options->get_popup()->add_separator(); options->get_popup()->add_separator();
options->get_popup()->add_item(TTR("Cursor Rotate X"), MENU_OPTION_CURSOR_ROTATE_X, KEY_A); options->get_popup()->add_item(TTR("Cursor Rotate X"), MENU_OPTION_CURSOR_ROTATE_X, Key::A);
options->get_popup()->add_item(TTR("Cursor Rotate Y"), MENU_OPTION_CURSOR_ROTATE_Y, KEY_S); options->get_popup()->add_item(TTR("Cursor Rotate Y"), MENU_OPTION_CURSOR_ROTATE_Y, Key::S);
options->get_popup()->add_item(TTR("Cursor Rotate Z"), MENU_OPTION_CURSOR_ROTATE_Z, KEY_D); options->get_popup()->add_item(TTR("Cursor Rotate Z"), MENU_OPTION_CURSOR_ROTATE_Z, Key::D);
options->get_popup()->add_item(TTR("Cursor Back Rotate X"), MENU_OPTION_CURSOR_BACK_ROTATE_X, KEY_MASK_SHIFT + KEY_A); options->get_popup()->add_item(TTR("Cursor Back Rotate X"), MENU_OPTION_CURSOR_BACK_ROTATE_X, KeyModifierMask::SHIFT + Key::A);
options->get_popup()->add_item(TTR("Cursor Back Rotate Y"), MENU_OPTION_CURSOR_BACK_ROTATE_Y, KEY_MASK_SHIFT + KEY_S); options->get_popup()->add_item(TTR("Cursor Back Rotate Y"), MENU_OPTION_CURSOR_BACK_ROTATE_Y, KeyModifierMask::SHIFT + Key::S);
options->get_popup()->add_item(TTR("Cursor Back Rotate Z"), MENU_OPTION_CURSOR_BACK_ROTATE_Z, KEY_MASK_SHIFT + KEY_D); options->get_popup()->add_item(TTR("Cursor Back Rotate Z"), MENU_OPTION_CURSOR_BACK_ROTATE_Z, KeyModifierMask::SHIFT + Key::D);
options->get_popup()->add_item(TTR("Cursor Clear Rotation"), MENU_OPTION_CURSOR_CLEAR_ROTATION, KEY_W); options->get_popup()->add_item(TTR("Cursor Clear Rotation"), MENU_OPTION_CURSOR_CLEAR_ROTATION, Key::W);
options->get_popup()->add_separator(); options->get_popup()->add_separator();
options->get_popup()->add_check_item(TTR("Paste Selects"), MENU_OPTION_PASTE_SELECTS); options->get_popup()->add_check_item(TTR("Paste Selects"), MENU_OPTION_PASTE_SELECTS);
options->get_popup()->add_separator(); options->get_popup()->add_separator();
options->get_popup()->add_item(TTR("Duplicate Selection"), MENU_OPTION_SELECTION_DUPLICATE, KEY_MASK_CTRL + KEY_C); options->get_popup()->add_item(TTR("Duplicate Selection"), MENU_OPTION_SELECTION_DUPLICATE, KeyModifierMask::CTRL + Key::C);
options->get_popup()->add_item(TTR("Cut Selection"), MENU_OPTION_SELECTION_CUT, KEY_MASK_CTRL + KEY_X); options->get_popup()->add_item(TTR("Cut Selection"), MENU_OPTION_SELECTION_CUT, KeyModifierMask::CTRL + Key::X);
options->get_popup()->add_item(TTR("Clear Selection"), MENU_OPTION_SELECTION_CLEAR, KEY_DELETE); options->get_popup()->add_item(TTR("Clear Selection"), MENU_OPTION_SELECTION_CLEAR, Key::KEY_DELETE);
options->get_popup()->add_item(TTR("Fill Selection"), MENU_OPTION_SELECTION_FILL, KEY_MASK_CTRL + KEY_F); options->get_popup()->add_item(TTR("Fill Selection"), MENU_OPTION_SELECTION_FILL, KeyModifierMask::CTRL + Key::F);
options->get_popup()->add_separator(); options->get_popup()->add_separator();
options->get_popup()->add_item(TTR("Settings..."), MENU_OPTION_GRIDMAP_SETTINGS); options->get_popup()->add_item(TTR("Settings..."), MENU_OPTION_GRIDMAP_SETTINGS);
settings_dialog = memnew(ConfirmationDialog); settings_dialog = memnew(ConfirmationDialog);
settings_dialog->set_title(TTR("GridMap Settings")); settings_dialog->set_title(TTR("HexMap Settings"));
add_child(settings_dialog); add_child(settings_dialog);
settings_vbc = memnew(VBoxContainer); settings_vbc = memnew(VBoxContainer);
settings_vbc->set_custom_minimum_size(Size2(200, 0) * EDSCALE); settings_vbc->set_custom_minimum_size(Size2(200, 0) * EDSCALE);
@@ -1214,7 +1237,7 @@ HexMapEditor::HexMapEditor(EditorNode *p_editor) {
settings_pick_distance->set_max(10000.0f); settings_pick_distance->set_max(10000.0f);
settings_pick_distance->set_min(500.0f); settings_pick_distance->set_min(500.0f);
settings_pick_distance->set_step(1.0f); settings_pick_distance->set_step(1.0f);
settings_pick_distance->set_value(EDITOR_DEF("editors/hex_map/pick_distance", 5000.0)); settings_pick_distance->set_value(EDITOR_DEF("editors/grid_map/pick_distance", 5000.0));
settings_vbc->add_margin_child(TTR("Pick Distance:"), settings_pick_distance); settings_vbc->add_margin_child(TTR("Pick Distance:"), settings_pick_distance);
options->get_popup()->connect("id_pressed", callable_mp(this, &HexMapEditor::_menu_option)); options->get_popup()->connect("id_pressed", callable_mp(this, &HexMapEditor::_menu_option));
@@ -1234,7 +1257,6 @@ HexMapEditor::HexMapEditor(EditorNode *p_editor) {
mode_thumbnail->set_flat(true); mode_thumbnail->set_flat(true);
mode_thumbnail->set_toggle_mode(true); mode_thumbnail->set_toggle_mode(true);
mode_thumbnail->set_pressed(true); mode_thumbnail->set_pressed(true);
mode_thumbnail->set_icon(p_editor->get_gui_base()->get_theme_icon(SNAME("FileThumbnail"), SNAME("EditorIcons")));
hb->add_child(mode_thumbnail); hb->add_child(mode_thumbnail);
mode_thumbnail->connect("pressed", callable_mp(this, &HexMapEditor::_set_display_mode), varray(DISPLAY_THUMBNAIL)); mode_thumbnail->connect("pressed", callable_mp(this, &HexMapEditor::_set_display_mode), varray(DISPLAY_THUMBNAIL));
@@ -1242,7 +1264,6 @@ HexMapEditor::HexMapEditor(EditorNode *p_editor) {
mode_list->set_flat(true); mode_list->set_flat(true);
mode_list->set_toggle_mode(true); mode_list->set_toggle_mode(true);
mode_list->set_pressed(false); mode_list->set_pressed(false);
mode_list->set_icon(p_editor->get_gui_base()->get_theme_icon(SNAME("FileList"), SNAME("EditorIcons")));
hb->add_child(mode_list); hb->add_child(mode_list);
mode_list->connect("pressed", callable_mp(this, &HexMapEditor::_set_display_mode), varray(DISPLAY_LIST)); mode_list->connect("pressed", callable_mp(this, &HexMapEditor::_set_display_mode), varray(DISPLAY_LIST));
@@ -1255,7 +1276,7 @@ HexMapEditor::HexMapEditor(EditorNode *p_editor) {
size_slider->connect("value_changed", callable_mp(this, &HexMapEditor::_icon_size_changed)); size_slider->connect("value_changed", callable_mp(this, &HexMapEditor::_icon_size_changed));
add_child(size_slider); add_child(size_slider);
EDITOR_DEF("editors/hex_map/preview_size", 64); EDITOR_DEF("editors/grid_map/preview_size", 64);
mesh_library_palette = memnew(ItemList); mesh_library_palette = memnew(ItemList);
add_child(mesh_library_palette); add_child(mesh_library_palette);
@@ -1263,9 +1284,9 @@ HexMapEditor::HexMapEditor(EditorNode *p_editor) {
mesh_library_palette->connect("gui_input", callable_mp(this, &HexMapEditor::_mesh_library_palette_input)); mesh_library_palette->connect("gui_input", callable_mp(this, &HexMapEditor::_mesh_library_palette_input));
info_message = memnew(Label); info_message = memnew(Label);
info_message->set_text(TTR("Give a MeshLibrary resource to this GridMap to use its meshes.")); info_message->set_text(TTR("Give a MeshLibrary resource to this HexMap to use its meshes."));
info_message->set_valign(Label::VALIGN_CENTER); info_message->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER);
info_message->set_align(Label::ALIGN_CENTER); info_message->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
info_message->set_autowrap_mode(Label::AUTOWRAP_WORD_SMART); info_message->set_autowrap_mode(Label::AUTOWRAP_WORD_SMART);
info_message->set_custom_minimum_size(Size2(100 * EDSCALE, 0)); info_message->set_custom_minimum_size(Size2(100 * EDSCALE, 0));
info_message->set_anchors_and_offsets_preset(PRESET_WIDE, PRESET_MODE_KEEP_SIZE, 8 * EDSCALE); info_message->set_anchors_and_offsets_preset(PRESET_WIDE, PRESET_MODE_KEEP_SIZE, 8 * EDSCALE);
@@ -1436,12 +1457,12 @@ HexMapEditor::~HexMapEditor() {
void HexMapEditorPlugin::_notification(int p_what) { void HexMapEditorPlugin::_notification(int p_what) {
if (p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) { if (p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) {
switch ((int)EditorSettings::get_singleton()->get("editors/hex_map/editor_side")) { switch ((int)EditorSettings::get_singleton()->get("editors/grid_map/editor_side")) {
case 0: { // Left. case 0: { // Left.
Node3DEditor::get_singleton()->get_palette_split()->move_child(grid_map_editor, 0); Node3DEditor::get_singleton()->move_control_to_left_panel(grid_map_editor);
} break; } break;
case 1: { // Right. case 1: { // Right.
Node3DEditor::get_singleton()->get_palette_split()->move_child(grid_map_editor, 1); Node3DEditor::get_singleton()->move_control_to_right_panel(grid_map_editor);
} break; } break;
} }
} }
@@ -1471,16 +1492,16 @@ void HexMapEditorPlugin::make_visible(bool p_visible) {
HexMapEditorPlugin::HexMapEditorPlugin(EditorNode *p_node) { HexMapEditorPlugin::HexMapEditorPlugin(EditorNode *p_node) {
editor = p_node; editor = p_node;
EDITOR_DEF("editors/hex_map/editor_side", 1); EDITOR_DEF("editors/grid_map/editor_side", 1);
EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::INT, "editors/hex_map/editor_side", PROPERTY_HINT_ENUM, "Left,Right")); EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::INT, "editors/grid_map/editor_side", PROPERTY_HINT_ENUM, "Left,Right"));
grid_map_editor = memnew(HexMapEditor(editor)); grid_map_editor = memnew(HexMapEditor(editor));
switch ((int)EditorSettings::get_singleton()->get("editors/hex_map/editor_side")) { switch ((int)EditorSettings::get_singleton()->get("editors/grid_map/editor_side")) {
case 0: { // Left. case 0: { // Left.
add_control_to_container(CONTAINER_SPATIAL_EDITOR_SIDE_LEFT, grid_map_editor); Node3DEditor::get_singleton()->add_control_to_left_panel(grid_map_editor);
} break; } break;
case 1: { // Right. case 1: { // Right.
add_control_to_container(CONTAINER_SPATIAL_EDITOR_SIDE_RIGHT, grid_map_editor); Node3DEditor::get_singleton()->add_control_to_right_panel(grid_map_editor);
} break; } break;
} }
grid_map_editor->hide(); grid_map_editor->hide();
+8 -7
View File
@@ -5,8 +5,8 @@
/* GODOT ENGINE */ /* GODOT ENGINE */
/* https://godotengine.org */ /* https://godotengine.org */
/*************************************************************************/ /*************************************************************************/
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* */ /* */
/* Permission is hereby granted, free of charge, to any person obtaining */ /* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */ /* a copy of this software and associated documentation files (the */
@@ -28,8 +28,8 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#ifndef GRID_MAP_EDITOR_PLUGIN_H #ifndef HEX_MAP_EDITOR_PLUGIN_H
#define GRID_MAP_EDITOR_PLUGIN_H #define HEX_MAP_EDITOR_PLUGIN_H
#include "editor/editor_node.h" #include "editor/editor_node.h"
#include "editor/editor_plugin.h" #include "editor/editor_plugin.h"
@@ -201,6 +201,7 @@ class HexMapEditor : public VBoxContainer {
void _update_cursor_transform(); void _update_cursor_transform();
void _update_cursor_instance(); void _update_cursor_instance();
void _update_clip(); void _update_clip();
void _update_theme();
void _text_changed(const String &p_text); void _text_changed(const String &p_text);
void _sbox_input(const Ref<InputEvent> &p_ie); void _sbox_input(const Ref<InputEvent> &p_ie);
@@ -232,7 +233,7 @@ protected:
static void _bind_methods(); static void _bind_methods();
public: public:
bool forward_spatial_input_event(Camera3D *p_camera, const Ref<InputEvent> &p_event); EditorPlugin::AfterGUIInput forward_spatial_input_event(Camera3D *p_camera, const Ref<InputEvent> &p_event);
void edit(HexMap *p_gridmap); void edit(HexMap *p_gridmap);
HexMapEditor() {} HexMapEditor() {}
@@ -250,7 +251,7 @@ protected:
void _notification(int p_what); void _notification(int p_what);
public: public:
virtual bool forward_spatial_gui_input(Camera3D *p_camera, const Ref<InputEvent> &p_event) override { return grid_map_editor->forward_spatial_input_event(p_camera, p_event); } virtual EditorPlugin::AfterGUIInput forward_spatial_gui_input(Camera3D *p_camera, const Ref<InputEvent> &p_event) override { return grid_map_editor->forward_spatial_input_event(p_camera, p_event); }
virtual String get_name() const override { return "HexMap"; } virtual String get_name() const override { return "HexMap"; }
bool has_main_screen() const override { return false; } bool has_main_screen() const override { return false; }
virtual void edit(Object *p_object) override; virtual void edit(Object *p_object) override;
@@ -261,4 +262,4 @@ public:
~HexMapEditorPlugin(); ~HexMapEditorPlugin();
}; };
#endif // CUBE_GRID_MAP_EDITOR_PLUGIN_H #endif // HEX_MAP_EDITOR_PLUGIN_H
+2 -2
View File
@@ -5,8 +5,8 @@
/* GODOT ENGINE */ /* GODOT ENGINE */
/* https://godotengine.org */ /* https://godotengine.org */
/*************************************************************************/ /*************************************************************************/
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* */ /* */
/* Permission is hereby granted, free of charge, to any person obtaining */ /* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */ /* a copy of this software and associated documentation files (the */
+2 -2
View File
@@ -5,8 +5,8 @@
/* GODOT ENGINE */ /* GODOT ENGINE */
/* https://godotengine.org */ /* https://godotengine.org */
/*************************************************************************/ /*************************************************************************/
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* */ /* */
/* Permission is hereby granted, free of charge, to any person obtaining */ /* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */ /* a copy of this software and associated documentation files (the */