diff options
105 files changed, 1721 insertions, 694 deletions
diff --git a/core/class_db.h b/core/class_db.h index f73e082c52..4287c5990f 100644 --- a/core/class_db.h +++ b/core/class_db.h @@ -45,7 +45,7 @@ struct ParamHint { String hint_text; Variant default_val; - ParamHint(const String &p_name = "", PropertyHint p_hint = PROPERTY_HINT_NONE, const String &p_hint_text = "", Variant p_default_val = Variant()) + ParamHint(const String &p_name = "", PropertyHint p_hint = PROPERTY_HINT_NONE, const String &p_hint_text = "", const Variant &p_default_val = Variant()) : name(p_name), hint(p_hint), hint_text(p_hint_text), diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp index 75dfd563dd..8eb40b61d7 100644 --- a/core/io/marshalls.cpp +++ b/core/io/marshalls.cpp @@ -30,12 +30,40 @@ #include "marshalls.h" #include "os/keyboard.h" #include "print_string.h" +#include "reference.h" #include <stdio.h> #define ENCODE_MASK 0xFF #define ENCODE_FLAG_64 1 << 16 -Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int *r_len) { +static Error _decode_string(const uint8_t *&buf, int &len, int *r_len, String &r_string) { + ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); + + uint32_t strlen = decode_uint32(buf); + buf += 4; + len -= 4; + ERR_FAIL_COND_V((int)strlen > len, ERR_FILE_EOF); + + String str; + str.parse_utf8((const char *)buf, strlen); + r_string = str; + + //handle padding + if (strlen % 4) { + strlen += 4 - strlen % 4; + } + + buf += strlen; + len -= strlen; + + if (r_len) { + (*r_len) += 4 + strlen; + } + + return OK; +} + +Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int *r_len, bool p_allow_objects) { const uint8_t *buf = p_buffer; int len = p_len; @@ -104,22 +132,12 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::STRING: { - ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); - uint32_t strlen = decode_uint32(buf); - buf += 4; - len -= 4; - ERR_FAIL_COND_V((int)strlen > len, ERR_INVALID_DATA); - String str; - str.parse_utf8((const char *)buf, strlen); + Error err = _decode_string(buf, len, r_len, str); + if (err) + return err; r_variant = str; - if (r_len) { - if (strlen % 4) - (*r_len) += 4 - strlen % 4; - (*r_len) += 4 + strlen; - } - } break; // math types @@ -363,7 +381,59 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::OBJECT: { - r_variant = (Object *)NULL; + ERR_FAIL_COND_V(!p_allow_objects, ERR_UNAUTHORIZED); + + String str; + Error err = _decode_string(buf, len, r_len, str); + if (err) + return err; + + if (str == String()) { + r_variant = (Object *)NULL; + } else { + + Object *obj = ClassDB::instance(str); + + ERR_FAIL_COND_V(!obj, ERR_UNAVAILABLE); + ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); + + int32_t count = decode_uint32(buf); + buf += 4; + len -= 4; + if (r_len) { + (*r_len) += 4; + } + + for (int i = 0; i < count; i++) { + + str = String(); + err = _decode_string(buf, len, r_len, str); + if (err) + return err; + + Variant value; + int used; + err = decode_variant(value, buf, len, &used, p_allow_objects); + if (err) + return err; + + buf += used; + len -= used; + if (r_len) { + (*r_len) += used; + } + + obj->set(str, value); + } + + if (obj->cast_to<Reference>()) { + REF ref = REF(obj->cast_to<Reference>()); + r_variant = ref; + } else { + r_variant = obj; + } + } + } break; case Variant::DICTIONARY: { @@ -386,7 +456,7 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int Variant key, value; int used; - Error err = decode_variant(key, buf, len, &used); + Error err = decode_variant(key, buf, len, &used, p_allow_objects); ERR_FAIL_COND_V(err, err); buf += used; @@ -395,7 +465,7 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int (*r_len) += used; } - err = decode_variant(value, buf, len, &used); + err = decode_variant(value, buf, len, &used, p_allow_objects); ERR_FAIL_COND_V(err, err); buf += used; @@ -430,7 +500,7 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int int used = 0; Variant v; - Error err = decode_variant(v, buf, len, &used); + Error err = decode_variant(v, buf, len, &used, p_allow_objects); ERR_FAIL_COND_V(err, err); buf += used; len -= used; @@ -691,6 +761,21 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int return OK; } +static void _encode_string(const String &p_string, uint8_t *&buf, int &r_len) { + + CharString utf8 = p_string.utf8(); + + if (buf) { + encode_uint32(utf8.length(), buf); + buf += 4; + copymem(buf, utf8.get_data(), utf8.length()); + } + + r_len += 4 + utf8.length(); + while (r_len % 4) + r_len++; //pad +} + Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len) { uint8_t *buf = r_buffer; @@ -831,17 +916,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len) { } break; case Variant::STRING: { - CharString utf8 = p_variant.operator String().utf8(); - - if (buf) { - encode_uint32(utf8.length(), buf); - buf += 4; - copymem(buf, utf8.get_data(), utf8.length()); - } - - r_len += 4 + utf8.length(); - while (r_len % 4) - r_len++; //pad + _encode_string(p_variant, buf, r_len); } break; // math types @@ -991,9 +1066,57 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len) { ERR_EXPLAIN("Can't marshallize resources"); ERR_FAIL_V(ERR_INVALID_DATA); //no, i'm sorry, no go } break;*/ - case Variant::_RID: + case Variant::_RID: { + + } break; case Variant::OBJECT: { + Object *obj = p_variant; + if (!obj) { + if (buf) { + encode_uint32(0, buf); + buf += 4; + r_len += 4; + } + } else { + _encode_string(obj->get_class(), buf, r_len); + + List<PropertyInfo> props; + obj->get_property_list(&props); + + int pc = 0; + for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { + + if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) + continue; + pc++; + } + + if (buf) { + encode_uint32(pc, buf); + buf += 4; + } + + r_len += 4; + + for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { + + if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) + continue; + + _encode_string(E->get().name, buf, r_len); + + int len; + Error err = encode_variant(obj->get(E->get().name), buf, len); + if (err) + return err; + ERR_FAIL_COND_V(len % 4, ERR_BUG); + r_len += len; + if (buf) + buf += len; + } + } + } break; case Variant::DICTIONARY: { diff --git a/core/io/marshalls.h b/core/io/marshalls.h index eb2785aa4e..a6cc72b691 100644 --- a/core/io/marshalls.h +++ b/core/io/marshalls.h @@ -183,7 +183,7 @@ static inline double decode_double(const uint8_t *p_arr) { return md.d; } -Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int *r_len = NULL); +Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int *r_len = NULL, bool p_allow_objects=true); Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len); #endif diff --git a/core/io/packet_peer.cpp b/core/io/packet_peer.cpp index c028d7d197..f62ffd7183 100644 --- a/core/io/packet_peer.cpp +++ b/core/io/packet_peer.cpp @@ -35,9 +35,20 @@ PacketPeer::PacketPeer() { + allow_object_decoding = false; last_get_error = OK; } +void PacketPeer::set_allow_object_decoding(bool p_enable) { + + allow_object_decoding = p_enable; +} + +bool PacketPeer::is_object_decoding_allowed() const { + + return allow_object_decoding; +} + Error PacketPeer::get_packet_buffer(PoolVector<uint8_t> &r_buffer) const { const uint8_t *buffer; @@ -75,7 +86,7 @@ Error PacketPeer::get_var(Variant &r_variant) const { if (err) return err; - return decode_variant(r_variant, buffer, buffer_size); + return decode_variant(r_variant, buffer, buffer_size, NULL, allow_object_decoding); } Error PacketPeer::put_var(const Variant &p_packet) { @@ -126,6 +137,9 @@ void PacketPeer::_bind_methods() { ClassDB::bind_method(D_METHOD("put_packet", "buffer"), &PacketPeer::_put_packet); ClassDB::bind_method(D_METHOD("get_packet_error"), &PacketPeer::_get_packet_error); ClassDB::bind_method(D_METHOD("get_available_packet_count"), &PacketPeer::get_available_packet_count); + + ClassDB::bind_method(D_METHOD("set_allow_object_decoding", "enable"), &PacketPeer::set_allow_object_decoding); + ClassDB::bind_method(D_METHOD("is_object_decoding_allowed"), &PacketPeer::is_object_decoding_allowed); }; /***************/ diff --git a/core/io/packet_peer.h b/core/io/packet_peer.h index ed6b252d80..3bd6876aa7 100644 --- a/core/io/packet_peer.h +++ b/core/io/packet_peer.h @@ -48,6 +48,8 @@ class PacketPeer : public Reference { mutable Error last_get_error; + bool allow_object_decoding; + public: virtual int get_available_packet_count() const = 0; virtual Error get_packet(const uint8_t **r_buffer, int &r_buffer_size) const = 0; ///< buffer is GONE after next get_packet @@ -63,6 +65,9 @@ public: virtual Error get_var(Variant &r_variant) const; virtual Error put_var(const Variant &p_packet); + void set_allow_object_decoding(bool p_enable); + bool is_object_decoding_allowed() const; + PacketPeer(); ~PacketPeer() {} }; diff --git a/core/io/packet_peer_udp.h b/core/io/packet_peer_udp.h index a39eb6bcfd..007b810b67 100644 --- a/core/io/packet_peer_udp.h +++ b/core/io/packet_peer_udp.h @@ -49,7 +49,7 @@ protected: public: void set_blocking_mode(bool p_enable); - virtual Error listen(int p_port, IP_Address p_bind_address = IP_Address("*"), int p_recv_buffer_size = 65536) = 0; + virtual Error listen(int p_port, const IP_Address &p_bind_address = IP_Address("*"), int p_recv_buffer_size = 65536) = 0; virtual void close() = 0; virtual Error wait() = 0; virtual bool is_listening() const = 0; diff --git a/core/io/resource_import.cpp b/core/io/resource_import.cpp index 61da4f3350..7033dbe5fb 100644 --- a/core/io/resource_import.cpp +++ b/core/io/resource_import.cpp @@ -199,6 +199,52 @@ String ResourceFormatImporter::get_internal_resource_path(const String &p_path) return pat.path; } +void ResourceFormatImporter::get_internal_resource_path_list(const String &p_path, List<String> *r_paths) { + + Error err; + FileAccess *f = FileAccess::open(p_path + ".import", FileAccess::READ, &err); + + if (!f) + return; + + VariantParser::StreamFile stream; + stream.f = f; + + String assign; + Variant value; + VariantParser::Tag next_tag; + + int lines = 0; + String error_text; + while (true) { + + assign = Variant(); + next_tag.fields.clear(); + next_tag.name = String(); + + err = VariantParser::parse_tag_assign_eof(&stream, lines, error_text, next_tag, assign, value, NULL, true); + if (err == ERR_FILE_EOF) { + memdelete(f); + return; + } else if (err != OK) { + ERR_PRINTS("ResourceFormatImporter::get_internal_resource_path_list - " + p_path + ".import:" + itos(lines) + " error: " + error_text); + memdelete(f); + return; + } + + if (assign != String()) { + if (assign.begins_with("path.")) { + r_paths->push_back(value); + } else if (assign == "path") { + r_paths->push_back(value); + } + } else if (next_tag.name != "remap") { + break; + } + } + memdelete(f); +} + String ResourceFormatImporter::get_resource_type(const String &p_path) const { PathAndType pat; diff --git a/core/io/resource_import.h b/core/io/resource_import.h index d3f98cbc07..67fd870178 100644 --- a/core/io/resource_import.h +++ b/core/io/resource_import.h @@ -59,6 +59,7 @@ public: virtual bool can_be_imported(const String &p_path) const; String get_internal_resource_path(const String &p_path) const; + void get_internal_resource_path_list(const String &p_path, List<String> *r_paths); void add_importer(const Ref<ResourceImporter> &p_importer) { importers.insert(p_importer); } void remove_importer(const Ref<ResourceImporter> &p_importer) { importers.erase(p_importer); } diff --git a/core/io/stream_peer.cpp b/core/io/stream_peer.cpp index fdad7c7bdf..7042700d92 100644 --- a/core/io/stream_peer.cpp +++ b/core/io/stream_peer.cpp @@ -210,7 +210,7 @@ void StreamPeer::put_double(double p_val) { void StreamPeer::put_utf8_string(const String &p_string) { CharString cs = p_string.utf8(); - put_u32(p_string.length()); + put_u32(cs.length()); put_data((const uint8_t *)cs.get_data(), cs.length()); } void StreamPeer::put_var(const Variant &p_variant) { @@ -459,8 +459,9 @@ Error StreamPeerBuffer::get_partial_data(uint8_t *p_buffer, int p_bytes, int &r_ } PoolVector<uint8_t>::Read r = data.read(); - copymem(p_buffer, r.ptr(), r_received); + copymem(p_buffer, r.ptr() + pointer, r_received); + pointer += r_received; // FIXME: return what? OK or ERR_* } diff --git a/core/io/tcp_server.h b/core/io/tcp_server.h index 4e7fa7cf3e..b4ff3246ad 100644 --- a/core/io/tcp_server.h +++ b/core/io/tcp_server.h @@ -45,7 +45,7 @@ protected: static void _bind_methods(); public: - virtual Error listen(uint16_t p_port, const IP_Address p_bind_address = IP_Address("*")) = 0; + virtual Error listen(uint16_t p_port, const IP_Address &p_bind_address = IP_Address("*")) = 0; virtual bool is_connection_available() const = 0; virtual Ref<StreamPeerTCP> take_connection() = 0; diff --git a/core/math/octree.h b/core/math/octree.h index 010c1b18f7..2e37056030 100644 --- a/core/math/octree.h +++ b/core/math/octree.h @@ -351,7 +351,7 @@ private: }; void _cull_convex(Octant *p_octant, _CullConvexData *p_cull); - void _cull_AABB(Octant *p_octant, const Rect3 &p_aabb, T **p_result_array, int *p_result_idx, int p_result_max, int *p_subindex_array, uint32_t p_mask); + void _cull_aabb(Octant *p_octant, const Rect3 &p_aabb, T **p_result_array, int *p_result_idx, int p_result_max, int *p_subindex_array, uint32_t p_mask); void _cull_segment(Octant *p_octant, const Vector3 &p_from, const Vector3 &p_to, T **p_result_array, int *p_result_idx, int p_result_max, int *p_subindex_array, uint32_t p_mask); void _cull_point(Octant *p_octant, const Vector3 &p_point, T **p_result_array, int *p_result_idx, int p_result_max, int *p_subindex_array, uint32_t p_mask); @@ -380,7 +380,7 @@ public: int get_subindex(OctreeElementID p_id) const; int cull_convex(const Vector<Plane> &p_convex, T **p_result_array, int p_result_max, uint32_t p_mask = 0xFFFFFFFF); - int cull_AABB(const Rect3 &p_aabb, T **p_result_array, int p_result_max, int *p_subindex_array = NULL, uint32_t p_mask = 0xFFFFFFFF); + int cull_aabb(const Rect3 &p_aabb, T **p_result_array, int p_result_max, int *p_subindex_array = NULL, uint32_t p_mask = 0xFFFFFFFF); int cull_segment(const Vector3 &p_from, const Vector3 &p_to, T **p_result_array, int p_result_max, int *p_subindex_array = NULL, uint32_t p_mask = 0xFFFFFFFF); int cull_point(const Vector3 &p_point, T **p_result_array, int p_result_max, int *p_subindex_array = NULL, uint32_t p_mask = 0xFFFFFFFF); @@ -1095,7 +1095,7 @@ void Octree<T, use_pairs, AL>::_cull_convex(Octant *p_octant, _CullConvexData *p } template <class T, bool use_pairs, class AL> -void Octree<T, use_pairs, AL>::_cull_AABB(Octant *p_octant, const Rect3 &p_aabb, T **p_result_array, int *p_result_idx, int p_result_max, int *p_subindex_array, uint32_t p_mask) { +void Octree<T, use_pairs, AL>::_cull_aabb(Octant *p_octant, const Rect3 &p_aabb, T **p_result_array, int *p_result_idx, int p_result_max, int *p_subindex_array, uint32_t p_mask) { if (*p_result_idx == p_result_max) return; //pointless @@ -1160,7 +1160,7 @@ void Octree<T, use_pairs, AL>::_cull_AABB(Octant *p_octant, const Rect3 &p_aabb, for (int i = 0; i < 8; i++) { if (p_octant->children[i] && p_octant->children[i]->aabb.intersects_inclusive(p_aabb)) { - _cull_AABB(p_octant->children[i], p_aabb, p_result_array, p_result_idx, p_result_max, p_subindex_array, p_mask); + _cull_aabb(p_octant->children[i], p_aabb, p_result_array, p_result_idx, p_result_max, p_subindex_array, p_mask); } } } @@ -1336,14 +1336,14 @@ int Octree<T, use_pairs, AL>::cull_convex(const Vector<Plane> &p_convex, T **p_r } template <class T, bool use_pairs, class AL> -int Octree<T, use_pairs, AL>::cull_AABB(const Rect3 &p_aabb, T **p_result_array, int p_result_max, int *p_subindex_array, uint32_t p_mask) { +int Octree<T, use_pairs, AL>::cull_aabb(const Rect3 &p_aabb, T **p_result_array, int p_result_max, int *p_subindex_array, uint32_t p_mask) { if (!root) return 0; int result_count = 0; pass++; - _cull_AABB(root, p_aabb, p_result_array, &result_count, p_result_max, p_subindex_array, p_mask); + _cull_aabb(root, p_aabb, p_result_array, &result_count, p_result_max, p_subindex_array, p_mask); return result_count; } diff --git a/core/math/plane.cpp b/core/math/plane.cpp index f5e92866c4..17928d07c3 100644 --- a/core/math/plane.cpp +++ b/core/math/plane.cpp @@ -103,7 +103,7 @@ bool Plane::intersect_3(const Plane &p_plane1, const Plane &p_plane2, Vector3 *r return true; } -bool Plane::intersects_ray(Vector3 p_from, Vector3 p_dir, Vector3 *p_intersection) const { +bool Plane::intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *p_intersection) const { Vector3 segment = p_dir; real_t den = normal.dot(segment); @@ -128,7 +128,7 @@ bool Plane::intersects_ray(Vector3 p_from, Vector3 p_dir, Vector3 *p_intersectio return true; } -bool Plane::intersects_segment(Vector3 p_begin, Vector3 p_end, Vector3 *p_intersection) const { +bool Plane::intersects_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 *p_intersection) const { Vector3 segment = p_begin - p_end; real_t den = normal.dot(segment); diff --git a/core/math/plane.h b/core/math/plane.h index 92ebcd8024..73d584e553 100644 --- a/core/math/plane.h +++ b/core/math/plane.h @@ -56,8 +56,8 @@ public: /* intersections */ bool intersect_3(const Plane &p_plane1, const Plane &p_plane2, Vector3 *r_result = 0) const; - bool intersects_ray(Vector3 p_from, Vector3 p_dir, Vector3 *p_intersection) const; - bool intersects_segment(Vector3 p_begin, Vector3 p_end, Vector3 *p_intersection) const; + bool intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *p_intersection) const; + bool intersects_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 *p_intersection) const; _FORCE_INLINE_ Vector3 project(const Vector3 &p_point) const { diff --git a/core/method_ptrcall.h b/core/method_ptrcall.h index ead58c23c8..d8755fd98b 100644 --- a/core/method_ptrcall.h +++ b/core/method_ptrcall.h @@ -80,6 +80,26 @@ struct PtrToArg { } \ } +#define MAKE_PTRARG_BY_REFERENCE(m_type) \ + template <> \ + struct PtrToArg<m_type> { \ + _FORCE_INLINE_ static m_type convert(const void *p_ptr) { \ + return *reinterpret_cast<const m_type *>(p_ptr); \ + } \ + _FORCE_INLINE_ static void encode(const m_type &p_val, void *p_ptr) { \ + *((m_type *)p_ptr) = p_val; \ + } \ + }; \ + template <> \ + struct PtrToArg<const m_type &> { \ + _FORCE_INLINE_ static m_type convert(const void *p_ptr) { \ + return *reinterpret_cast<const m_type *>(p_ptr); \ + } \ + _FORCE_INLINE_ static void encode(const m_type &p_val, void *p_ptr) { \ + *((m_type *)p_ptr) = p_val; \ + } \ + } + MAKE_PTRARG(bool); MAKE_PTRARGCONV(uint8_t, int64_t); MAKE_PTRARGCONV(int8_t, int64_t); @@ -95,14 +115,14 @@ MAKE_PTRARG(double); MAKE_PTRARG(String); MAKE_PTRARG(Vector2); MAKE_PTRARG(Rect2); -MAKE_PTRARG(Vector3); +MAKE_PTRARG_BY_REFERENCE(Vector3); MAKE_PTRARG(Transform2D); -MAKE_PTRARG(Plane); +MAKE_PTRARG_BY_REFERENCE(Plane); MAKE_PTRARG(Quat); -MAKE_PTRARG(Rect3); -MAKE_PTRARG(Basis); -MAKE_PTRARG(Transform); -MAKE_PTRARG(Color); +MAKE_PTRARG_BY_REFERENCE(Rect3); +MAKE_PTRARG_BY_REFERENCE(Basis); +MAKE_PTRARG_BY_REFERENCE(Transform); +MAKE_PTRARG_BY_REFERENCE(Color); MAKE_PTRARG(NodePath); MAKE_PTRARG(RID); MAKE_PTRARG(Dictionary); @@ -114,7 +134,7 @@ MAKE_PTRARG(PoolStringArray); MAKE_PTRARG(PoolVector2Array); MAKE_PTRARG(PoolVector3Array); MAKE_PTRARG(PoolColorArray); -MAKE_PTRARG(Variant); +MAKE_PTRARG_BY_REFERENCE(Variant); //this is for Object @@ -311,8 +331,29 @@ MAKE_DVECARR(Plane); } \ } +#define MAKE_STRINGCONV_BY_REFERENCE(m_type) \ + template <> \ + struct PtrToArg<m_type> { \ + _FORCE_INLINE_ static m_type convert(const void *p_ptr) { \ + m_type s = *reinterpret_cast<const String *>(p_ptr); \ + return s; \ + } \ + _FORCE_INLINE_ static void encode(const m_type &p_vec, void *p_ptr) { \ + String *arr = reinterpret_cast<String *>(p_ptr); \ + *arr = p_vec; \ + } \ + }; \ + \ + template <> \ + struct PtrToArg<const m_type &> { \ + _FORCE_INLINE_ static m_type convert(const void *p_ptr) { \ + m_type s = *reinterpret_cast<const String *>(p_ptr); \ + return s; \ + } \ + } + MAKE_STRINGCONV(StringName); -MAKE_STRINGCONV(IP_Address); +MAKE_STRINGCONV_BY_REFERENCE(IP_Address); template <> struct PtrToArg<PoolVector<Face3> > { diff --git a/core/pair.h b/core/pair.h index d4b1897537..d517339ddf 100644 --- a/core/pair.h +++ b/core/pair.h @@ -37,7 +37,7 @@ struct Pair { S second; Pair() {} - Pair(F p_first, S p_second) + Pair(F p_first, const S &p_second) : first(p_first), second(p_second) { } diff --git a/core/vector.h b/core/vector.h index 5eed8dce96..9f523c567c 100644 --- a/core/vector.h +++ b/core/vector.h @@ -117,7 +117,7 @@ public: } _FORCE_INLINE_ bool empty() const { return _ptr == 0; } Error resize(int p_size); - bool push_back(T p_elem); + bool push_back(const T &p_elem); void remove(int p_index); void erase(const T &p_val) { @@ -129,7 +129,7 @@ public: template <class T_val> int find(const T_val &p_val, int p_from = 0) const; - void set(int p_index, T p_elem); + void set(int p_index, const T &p_elem); T get(int p_index) const; inline T &operator[](int p_index) { @@ -336,7 +336,7 @@ void Vector<T>::invert() { } template <class T> -void Vector<T>::set(int p_index, T p_elem) { +void Vector<T>::set(int p_index, const T &p_elem) { operator[](p_index) = p_elem; } @@ -348,7 +348,7 @@ T Vector<T>::get(int p_index) const { } template <class T> -bool Vector<T>::push_back(T p_elem) { +bool Vector<T>::push_back(const T &p_elem) { Error err = resize(size() + 1); ERR_FAIL_COND_V(err, true) diff --git a/drivers/gles3/rasterizer_canvas_gles3.h b/drivers/gles3/rasterizer_canvas_gles3.h index 26003f543f..29f889cc88 100644 --- a/drivers/gles3/rasterizer_canvas_gles3.h +++ b/drivers/gles3/rasterizer_canvas_gles3.h @@ -42,6 +42,7 @@ public: float projection_matrix[16]; float time; + uint8_t padding[12]; }; RasterizerSceneGLES3 *scene_render; @@ -102,6 +103,7 @@ public: float light_height; float light_outside_alpha; float shadow_distance_mult; + uint8_t padding[4]; } ubo_data; GLuint ubo; diff --git a/drivers/gles3/rasterizer_scene_gles3.h b/drivers/gles3/rasterizer_scene_gles3.h index f6509e0041..0cdaef44a9 100644 --- a/drivers/gles3/rasterizer_scene_gles3.h +++ b/drivers/gles3/rasterizer_scene_gles3.h @@ -141,6 +141,7 @@ public: float fog_height_min; float fog_height_max; float fog_height_curve; + uint8_t padding[8]; } ubo_data; @@ -150,6 +151,7 @@ public: float transform[16]; float ambient_contribution; + uint8_t padding[12]; } env_radiance_data; diff --git a/drivers/gles3/shader_gles3.cpp b/drivers/gles3/shader_gles3.cpp index f1077e2d20..e7a26c0354 100644 --- a/drivers/gles3/shader_gles3.cpp +++ b/drivers/gles3/shader_gles3.cpp @@ -273,6 +273,11 @@ ShaderGLES3::Version *ShaderGLES3::get_current_version() { //vertex precision is high strings.push_back("precision highp float;\n"); strings.push_back("precision highp int;\n"); +#ifndef GLES_OVER_GL + strings.push_back("precision highp sampler2D;\n"); + strings.push_back("precision highp samplerCube;\n"); + strings.push_back("precision highp sampler2DArray;\n"); +#endif #if 0 if (cc) { @@ -371,6 +376,11 @@ ShaderGLES3::Version *ShaderGLES3::get_current_version() { //fragment precision is medium strings.push_back("precision highp float;\n"); strings.push_back("precision highp int;\n"); +#ifndef GLES_OVER_GL + strings.push_back("precision highp sampler2D;\n"); + strings.push_back("precision highp samplerCube;\n"); + strings.push_back("precision highp sampler2DArray;\n"); +#endif #if 0 if (cc) { diff --git a/drivers/gles3/shaders/canvas.glsl b/drivers/gles3/shaders/canvas.glsl index 1c950c82d9..f0dc14c35a 100644 --- a/drivers/gles3/shaders/canvas.glsl +++ b/drivers/gles3/shaders/canvas.glsl @@ -532,11 +532,11 @@ FRAGMENT_SHADER_CODE #ifdef USE_RGBA_SHADOWS -#define SHADOW_DEPTH(m_tex,m_uv) dot(texture2D((m_tex),(m_uv)),vec4(1.0 / (256.0 * 256.0 * 256.0),1.0 / (256.0 * 256.0),1.0 / 256.0,1) ) +#define SHADOW_DEPTH(m_tex,m_uv) dot(texture((m_tex),(m_uv)),vec4(1.0 / (256.0 * 256.0 * 256.0),1.0 / (256.0 * 256.0),1.0 / 256.0,1) ) #else -#define SHADOW_DEPTH(m_tex,m_uv) (texture2D((m_tex),(m_uv)).r) +#define SHADOW_DEPTH(m_tex,m_uv) (texture((m_tex),(m_uv)).r) #endif diff --git a/drivers/unix/ip_unix.cpp b/drivers/unix/ip_unix.cpp index 30d2377a04..f55b75c1d9 100644 --- a/drivers/unix/ip_unix.cpp +++ b/drivers/unix/ip_unix.cpp @@ -100,6 +100,7 @@ IP_Address IP_Unix::_resolve_hostname(const String &p_hostname, Type p_type) { hints.ai_family = AF_UNSPEC; hints.ai_flags = AI_ADDRCONFIG; }; + hints.ai_flags &= !AI_NUMERICHOST; int s = getaddrinfo(p_hostname.utf8().get_data(), NULL, &hints, &result); if (s != 0) { diff --git a/drivers/unix/packet_peer_udp_posix.cpp b/drivers/unix/packet_peer_udp_posix.cpp index 74ceb3946a..3170b121b9 100644 --- a/drivers/unix/packet_peer_udp_posix.cpp +++ b/drivers/unix/packet_peer_udp_posix.cpp @@ -127,7 +127,7 @@ int PacketPeerUDPPosix::get_max_packet_size() const { return 512; // uhm maybe not } -Error PacketPeerUDPPosix::listen(int p_port, IP_Address p_bind_address, int p_recv_buffer_size) { +Error PacketPeerUDPPosix::listen(int p_port, const IP_Address &p_bind_address, int p_recv_buffer_size) { ERR_FAIL_COND_V(sockfd != -1, ERR_ALREADY_IN_USE); ERR_FAIL_COND_V(!p_bind_address.is_valid() && !p_bind_address.is_wildcard(), ERR_INVALID_PARAMETER); diff --git a/drivers/unix/packet_peer_udp_posix.h b/drivers/unix/packet_peer_udp_posix.h index a52b8b8e95..d8b08818b0 100644 --- a/drivers/unix/packet_peer_udp_posix.h +++ b/drivers/unix/packet_peer_udp_posix.h @@ -67,7 +67,7 @@ public: virtual int get_max_packet_size() const; - virtual Error listen(int p_port, IP_Address p_bind_address = IP_Address("*"), int p_recv_buffer_size = 65536); + virtual Error listen(int p_port, const IP_Address &p_bind_address = IP_Address("*"), int p_recv_buffer_size = 65536); virtual void close(); virtual Error wait(); virtual bool is_listening() const; diff --git a/drivers/unix/tcp_server_posix.cpp b/drivers/unix/tcp_server_posix.cpp index 865e9aa1d6..a8554d07a3 100644 --- a/drivers/unix/tcp_server_posix.cpp +++ b/drivers/unix/tcp_server_posix.cpp @@ -69,7 +69,7 @@ void TCPServerPosix::make_default() { TCP_Server::_create = TCPServerPosix::_create; }; -Error TCPServerPosix::listen(uint16_t p_port, const IP_Address p_bind_address) { +Error TCPServerPosix::listen(uint16_t p_port, const IP_Address &p_bind_address) { ERR_FAIL_COND_V(listen_sockfd != -1, ERR_ALREADY_IN_USE); ERR_FAIL_COND_V(!p_bind_address.is_valid() && !p_bind_address.is_wildcard(), ERR_INVALID_PARAMETER); diff --git a/drivers/unix/tcp_server_posix.h b/drivers/unix/tcp_server_posix.h index 659b389fe2..947050ab8a 100644 --- a/drivers/unix/tcp_server_posix.h +++ b/drivers/unix/tcp_server_posix.h @@ -41,7 +41,7 @@ class TCPServerPosix : public TCP_Server { static TCP_Server *_create(); public: - virtual Error listen(uint16_t p_port, IP_Address p_bind_address = IP_Address("*")); + virtual Error listen(uint16_t p_port, const IP_Address &p_bind_address = IP_Address("*")); virtual bool is_connection_available() const; virtual Ref<StreamPeerTCP> take_connection(); diff --git a/editor/animation_editor.cpp b/editor/animation_editor.cpp index 3675948b1d..1571131aee 100644 --- a/editor/animation_editor.cpp +++ b/editor/animation_editor.cpp @@ -1299,7 +1299,7 @@ void AnimationKeyEditor::_track_editor_draw() { Object *obj = NULL; RES res; - Node *node = root->get_node_and_resource(animation->track_get_path(idx), res); + Node *node = root ? root->get_node_and_resource(animation->track_get_path(idx), res) : (Node *)NULL; if (res.is_valid()) { obj = res.ptr(); @@ -1324,7 +1324,7 @@ void AnimationKeyEditor::_track_editor_draw() { te->draw_texture(type_icon[animation->track_get_type(idx)], ofs + Point2(0, y + (h - type_icon[0]->get_height()) / 2).floor()); NodePath np = animation->track_get_path(idx); - Node *n = root->get_node(np); + Node *n = root ? root->get_node(np) : (Node *)NULL; Color ncol = color; if (n && editor_selection->is_selected(n)) ncol = track_select_color; diff --git a/editor/asset_library_editor_plugin.cpp b/editor/asset_library_editor_plugin.cpp index 2a22cde2fb..0a2799c51f 100644 --- a/editor/asset_library_editor_plugin.cpp +++ b/editor/asset_library_editor_plugin.cpp @@ -189,7 +189,14 @@ void EditorAssetLibraryItemDescription::set_image(int p_type, int p_index, const } break; } } - +void EditorAssetLibraryItemDescription::_notification(int p_what) { + switch (p_what) { + case NOTIFICATION_ENTER_TREE: { + previews_bg->add_style_override("panel", get_stylebox("normal", "TextEdit")); + desc_bg->add_style_override("panel", get_stylebox("normal", "TextEdit")); + } break; + } +} void EditorAssetLibraryItemDescription::_bind_methods() { ClassDB::bind_method(D_METHOD("set_image"), &EditorAssetLibraryItemDescription::set_image); ClassDB::bind_method(D_METHOD("_link_click"), &EditorAssetLibraryItemDescription::_link_click); @@ -274,23 +281,21 @@ EditorAssetLibraryItemDescription::EditorAssetLibraryItemDescription() { desc_vbox->add_child(item); desc_vbox->set_custom_minimum_size(Size2(300, 0)); - PanelContainer *desc_bg = memnew(PanelContainer); + desc_bg = memnew(PanelContainer); desc_vbox->add_child(desc_bg); desc_bg->set_v_size_flags(SIZE_EXPAND_FILL); description = memnew(RichTextLabel); description->connect("meta_clicked", this, "_link_click"); desc_bg->add_child(description); - desc_bg->add_style_override("panel", get_stylebox("normal", "TextEdit")); preview = memnew(TextureRect); preview->set_custom_minimum_size(Size2(640, 345)); hbox->add_child(preview); - PanelContainer *previews_bg = memnew(PanelContainer); + previews_bg = memnew(PanelContainer); vbox->add_child(previews_bg); previews_bg->set_custom_minimum_size(Size2(0, 85)); - previews_bg->add_style_override("panel", get_stylebox("normal", "TextEdit")); previews = memnew(ScrollContainer); previews_bg->add_child(previews); @@ -525,53 +530,62 @@ EditorAssetLibraryItemDownload::EditorAssetLibraryItemDownload() { //////////////////////////////////////////////////////////////////////////////// void EditorAssetLibrary::_notification(int p_what) { - if (p_what == NOTIFICATION_READY) { - TextureRect *tf = memnew(TextureRect); - tf->set_texture(get_icon("Error", "EditorIcons")); - reverse->set_icon(get_icon("Updown", "EditorIcons")); + switch (p_what) { + case NOTIFICATION_READY: { - error_hb->add_child(tf); - error_label->raise(); - } + TextureRect *tf = memnew(TextureRect); + tf->set_texture(get_icon("Error", "EditorIcons")); + reverse->set_icon(get_icon("Updown", "EditorIcons")); - if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { - if (is_visible()) { - _repository_changed(0); // Update when shown for the first time - } - } + error_hb->add_child(tf); + error_label->raise(); + } break; - if (p_what == NOTIFICATION_PROCESS) { + case NOTIFICATION_VISIBILITY_CHANGED: { - HTTPClient::Status s = request->get_http_client_status(); - bool visible = s != HTTPClient::STATUS_DISCONNECTED; + if (is_visible()) { + _repository_changed(0); // Update when shown for the first time + } + } break; - if (visible != load_status->is_visible()) { - load_status->set_visible(visible); - } + case NOTIFICATION_PROCESS: { - if (visible) { - switch (s) { + HTTPClient::Status s = request->get_http_client_status(); + bool visible = s != HTTPClient::STATUS_DISCONNECTED; - case HTTPClient::STATUS_RESOLVING: { - load_status->set_value(0.1); - } break; - case HTTPClient::STATUS_CONNECTING: { - load_status->set_value(0.2); - } break; - case HTTPClient::STATUS_REQUESTING: { - load_status->set_value(0.3); - } break; - case HTTPClient::STATUS_BODY: { - load_status->set_value(0.4); - } break; - default: {} + if (visible != load_status->is_visible()) { + load_status->set_visible(visible); } - } - bool no_downloads = downloads_hb->get_child_count() == 0; - if (no_downloads == downloads_scroll->is_visible()) { - downloads_scroll->set_visible(!no_downloads); - } + if (visible) { + switch (s) { + + case HTTPClient::STATUS_RESOLVING: { + load_status->set_value(0.1); + } break; + case HTTPClient::STATUS_CONNECTING: { + load_status->set_value(0.2); + } break; + case HTTPClient::STATUS_REQUESTING: { + load_status->set_value(0.3); + } break; + case HTTPClient::STATUS_BODY: { + load_status->set_value(0.4); + } break; + default: {} + } + } + + bool no_downloads = downloads_hb->get_child_count() == 0; + if (no_downloads == downloads_scroll->is_visible()) { + downloads_scroll->set_visible(!no_downloads); + } + + } break; + case NOTIFICATION_THEME_CHANGED: { + + library_scroll_bg->add_style_override("panel", get_stylebox("bg", "Tree")); + } break; } } @@ -1360,9 +1374,8 @@ EditorAssetLibrary::EditorAssetLibrary(bool p_templates_only) { ///////// - PanelContainer *library_scroll_bg = memnew(PanelContainer); + library_scroll_bg = memnew(PanelContainer); library_main->add_child(library_scroll_bg); - library_scroll_bg->add_style_override("panel", get_stylebox("normal", "TextEdit")); library_scroll_bg->set_v_size_flags(SIZE_EXPAND_FILL); library_scroll = memnew(ScrollContainer); diff --git a/editor/asset_library_editor_plugin.h b/editor/asset_library_editor_plugin.h index 1cc0f22adf..fa768ec96a 100644 --- a/editor/asset_library_editor_plugin.h +++ b/editor/asset_library_editor_plugin.h @@ -89,6 +89,8 @@ class EditorAssetLibraryItemDescription : public ConfirmationDialog { RichTextLabel *description; ScrollContainer *previews; HBoxContainer *preview_hb; + PanelContainer *previews_bg; + PanelContainer *desc_bg; struct Preview { int id; @@ -113,6 +115,7 @@ class EditorAssetLibraryItemDescription : public ConfirmationDialog { void _preview_click(int p_id); protected: + void _notification(int p_what); static void _bind_methods(); public: @@ -179,6 +182,7 @@ class EditorAssetLibrary : public PanelContainer { void _asset_open(); void _asset_file_selected(const String &p_file); + PanelContainer *library_scroll_bg; ScrollContainer *library_scroll; VBoxContainer *library_vb; LineEdit *filter; diff --git a/editor/call_dialog.cpp b/editor/call_dialog.cpp index 8cf9ed6ef4..32b9fc1254 100644 --- a/editor/call_dialog.cpp +++ b/editor/call_dialog.cpp @@ -253,8 +253,8 @@ CallDialog::CallDialog() { call->set_anchor( MARGIN_TOP, ANCHOR_END ); call->set_anchor( MARGIN_RIGHT, ANCHOR_END ); call->set_anchor( MARGIN_BOTTOM, ANCHOR_END ); - call->set_begin( Point2( 70, 29 ) ); - call->set_end( Point2( 15, 15 ) ); + call->set_begin( Point2( -70, -29 ) ); + call->set_end( Point2( -15, -15 ) ); call->set_text(TTR("Call")); add_child(call); @@ -262,8 +262,8 @@ CallDialog::CallDialog() { cancel = memnew( Button ); cancel->set_anchor( MARGIN_TOP, ANCHOR_END ); cancel->set_anchor( MARGIN_BOTTOM, ANCHOR_END ); - cancel->set_begin( Point2( 15, 29 ) ); - cancel->set_end( Point2( 70, 15 ) ); + cancel->set_begin( Point2( -15, 29 ) ); + cancel->set_end( Point2( 70, -15 ) ); cancel->set_text(TTR("Close")); add_child(cancel); @@ -272,7 +272,7 @@ CallDialog::CallDialog() { tree->set_anchor( MARGIN_BOTTOM, ANCHOR_END ); tree->set_begin( Point2( 20,50 ) ); - tree->set_margin(MARGIN_BOTTOM, 44 ); + tree->set_margin(MARGIN_BOTTOM, -44 ); tree->set_margin(MARGIN_RIGHT, 0.5 ); tree->set_select_mode( Tree::SELECT_ROW ); add_child(tree); @@ -282,10 +282,10 @@ CallDialog::CallDialog() { property_editor = memnew( PropertyEditor ); - property_editor->set_anchor_and_margin( MARGIN_RIGHT, ANCHOR_END, 15 ); + property_editor->set_anchor_and_margin( MARGIN_RIGHT, ANCHOR_END, -15 ); property_editor->set_anchor_and_margin( MARGIN_TOP, ANCHOR_BEGIN, 50 ); //property_editor->set_anchor_and_margin( MARGIN_LEFT, ANCHOR_RATIO, 0.55 ); - property_editor->set_anchor_and_margin( MARGIN_BOTTOM, ANCHOR_END, 90 ); + property_editor->set_anchor_and_margin( MARGIN_BOTTOM, ANCHOR_END, -90 ); property_editor->get_scene_tree()->set_hide_root( true ); property_editor->hide_top_label(); @@ -305,15 +305,15 @@ CallDialog::CallDialog() { return_label = memnew( Label ); //return_label->set_anchor_and_margin( MARGIN_LEFT, ANCHOR_RATIO, 0.53 ); - return_label->set_anchor_and_margin( MARGIN_TOP, ANCHOR_END, 85 ); + return_label->set_anchor_and_margin( MARGIN_TOP, ANCHOR_END, -85 ); return_label->set_text(TTR("Return:")); add_child(return_label); return_value = memnew( LineEdit ); //return_value->set_anchor_and_margin( MARGIN_LEFT, ANCHOR_RATIO, 0.55 ); - return_value->set_anchor_and_margin( MARGIN_RIGHT, ANCHOR_END, 15 ); - return_value->set_anchor_and_margin( MARGIN_TOP, ANCHOR_END, 65 ); + return_value->set_anchor_and_margin( MARGIN_RIGHT, ANCHOR_END, -15 ); + return_value->set_anchor_and_margin( MARGIN_TOP, ANCHOR_END, -65 ); add_child(return_value); diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp index 2e406fb23d..07c0945114 100644 --- a/editor/code_editor.cpp +++ b/editor/code_editor.cpp @@ -70,7 +70,7 @@ GotoLineDialog::GotoLineDialog() { line = memnew(LineEdit); line->set_anchor(MARGIN_RIGHT, ANCHOR_END); line->set_begin(Point2(15, 22)); - line->set_end(Point2(15, 35)); + line->set_end(Point2(-15, 35)); add_child(line); register_text_enter(line); text_editor = NULL; @@ -887,7 +887,7 @@ FindReplaceDialog::FindReplaceDialog() { replace_text = memnew(LineEdit); replace_text->set_anchor(MARGIN_RIGHT, ANCHOR_END); replace_text->set_begin(Point2(15, 132)); - replace_text->set_end(Point2(15, 135)); + replace_text->set_end(Point2(-15, 135)); //replace_text->set_self_opacity(0.7); replace_mc->add_child(replace_text); @@ -937,8 +937,8 @@ FindReplaceDialog::FindReplaceDialog() { skip->set_anchor(MARGIN_TOP, ANCHOR_END); skip->set_anchor(MARGIN_RIGHT, ANCHOR_END); skip->set_anchor(MARGIN_BOTTOM, ANCHOR_END); - skip->set_begin(Point2(70, button_margin)); - skip->set_end(Point2(10, margin)); + skip->set_begin(Point2(-70, -button_margin)); + skip->set_end(Point2(-10, -margin)); skip->set_text(TTR("Skip")); add_child(skip); skip->connect("pressed", this, "_skip_pressed"); diff --git a/editor/editor_export.cpp b/editor/editor_export.cpp index 36fd86d88f..fe1dfa281c 100644 --- a/editor/editor_export.cpp +++ b/editor/editor_export.cpp @@ -37,7 +37,6 @@ #include "io/resource_loader.h" #include "io/resource_saver.h" #include "io/zip_io.h" -#include "os/dir_access.h" #include "os/file_access.h" #include "project_settings.h" #include "script_language.h" @@ -420,6 +419,63 @@ void EditorExportPlatform::_export_find_dependencies(const String &p_path, Set<S } } +void EditorExportPlatform::_edit_files_with_filter(DirAccess *da, const Vector<String> &p_filters, Set<String> &r_list, bool exclude) { + + da->list_dir_begin(); + String cur_dir = da->get_current_dir().replace("\\", "/"); + if (!cur_dir.ends_with("/")) + cur_dir += "/"; + + Vector<String> dirs; + String f; + while ((f = da->get_next()) != "") { + if (da->current_is_dir()) + dirs.push_back(f); + else { + String fullpath = cur_dir + f; + for (int i = 0; i < p_filters.size(); ++i) { + if (fullpath.matchn(p_filters[i])) { + if (!exclude) { + r_list.insert(fullpath); + } else { + r_list.erase(fullpath); + } + } + } + } + } + + da->list_dir_end(); + + for (int i = 0; i < dirs.size(); ++i) { + String dir = dirs[i]; + if (dir.begins_with(".")) + continue; + da->change_dir(dir); + _edit_files_with_filter(da, p_filters, r_list, exclude); + da->change_dir(".."); + } +} + +void EditorExportPlatform::_edit_filter_list(Set<String> &r_list, const String &p_filter, bool exclude) { + + if (p_filter == "") + return; + Vector<String> split = p_filter.split(","); + Vector<String> filters; + for (int i = 0; i < split.size(); i++) { + String f = split[i].strip_edges(); + if (f.empty()) + continue; + filters.push_back(f); + } + + DirAccess *da = DirAccess::open("res://"); + ERR_FAIL_NULL(da); + _edit_files_with_filter(da, filters, r_list, exclude); + memdelete(da); +} + Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &p_preset, EditorExportSaveFunction p_func, void *p_udata) { Ref<EditorExportPlatform> platform = p_preset->get_platform(); @@ -449,6 +505,9 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> & } } + _edit_filter_list(paths, p_preset->get_include_filter(), false); + _edit_filter_list(paths, p_preset->get_exclude_filter(), true); + //store everything in the export medium int idx = 0; int total = paths.size(); diff --git a/editor/editor_export.h b/editor/editor_export.h index 3b6e76a547..df42b0d95d 100644 --- a/editor/editor_export.h +++ b/editor/editor_export.h @@ -30,6 +30,7 @@ #ifndef EDITOR_EXPORT_H #define EDITOR_EXPORT_H +#include "os/dir_access.h" #include "resource.h" #include "scene/main/node.h" #include "scene/main/timer.h" @@ -157,6 +158,9 @@ private: static Error _save_pack_file(void *p_userdata, const String &p_path, const Vector<uint8_t> &p_data, int p_file, int p_total); static Error _save_zip_file(void *p_userdata, const String &p_path, const Vector<uint8_t> &p_data, int p_file, int p_total); + void _edit_files_with_filter(DirAccess *da, const Vector<String> &p_filters, Set<String> &r_list, bool exclude); + void _edit_filter_list(Set<String> &r_list, const String &p_filter, bool exclude); + protected: bool exists_export_template(String template_file_name, String *err) const; String find_export_template(String template_file_name, String *err = NULL) const; diff --git a/editor/editor_file_system.cpp b/editor/editor_file_system.cpp index eeb2f5ae8a..2f4ac02703 100644 --- a/editor/editor_file_system.cpp +++ b/editor/editor_file_system.cpp @@ -339,6 +339,7 @@ bool EditorFileSystem::_update_scan_actions() { int idx = ia.dir->find_file_index(ia.file); ERR_CONTINUE(idx == -1); + _delete_internal_files(ia.dir->files[idx]->file); memdelete(ia.dir->files[idx]); ia.dir->files.remove(idx); @@ -598,6 +599,10 @@ void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir, DirAccess fi->type = fc->type; fi->modified_time = fc->modification_time; fi->import_modified_time = fc->import_modification_time; + if (fc->type == String()) { + fi->type = ResourceLoader::get_resource_type(path); + //there is also the chance that file type changed due to reimport, must probably check this somehow here (or kind of note it for next time in another file?) + } } else { @@ -615,6 +620,7 @@ void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir, DirAccess } fi->type = ResourceFormatImporter::get_singleton()->get_resource_type(path); + print_line("import extension tried resource type for " + path + " and its " + fi->type); fi->modified_time = 0; fi->import_modified_time = 0; @@ -633,6 +639,7 @@ void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir, DirAccess fi->import_modified_time = 0; } else { fi->type = ResourceLoader::get_resource_type(path); + print_line("regular import tried resource type for " + path + " and its " + fi->type); fi->modified_time = mt; fi->import_modified_time = 0; } @@ -832,6 +839,19 @@ void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir, const } } +void EditorFileSystem::_delete_internal_files(String p_file) { + if (FileAccess::exists(p_file + ".import")) { + List<String> paths; + ResourceFormatImporter::get_singleton()->get_internal_resource_path_list(p_file, &paths); + DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES); + for (List<String>::Element *E = paths.front(); E; E = E->next()) { + da->remove(E->get()); + } + da->remove(p_file + ".import"); + memdelete(da); + } +} + void EditorFileSystem::_thread_func_sources(void *_userdata) { EditorFileSystem *efs = (EditorFileSystem *)_userdata; @@ -1186,6 +1206,7 @@ void EditorFileSystem::update_file(const String &p_file) { if (!FileAccess::exists(p_file)) { //was removed + _delete_internal_files(p_file); memdelete(fs->files[cpos]); fs->files.remove(cpos); call_deferred("emit_signal", "filesystem_changed"); //update later diff --git a/editor/editor_file_system.h b/editor/editor_file_system.h index 3522a1ab1d..f98758fd03 100644 --- a/editor/editor_file_system.h +++ b/editor/editor_file_system.h @@ -168,6 +168,8 @@ class EditorFileSystem : public Node { void _scan_fs_changes(EditorFileSystemDirectory *p_dir, const ScanProgress &p_progress); + void _delete_internal_files(String p_file); + Set<String> valid_extensions; Set<String> import_extensions; diff --git a/editor/editor_help.cpp b/editor/editor_help.cpp index f80c4ee0e2..8b1f558c0a 100644 --- a/editor/editor_help.cpp +++ b/editor/editor_help.cpp @@ -1788,7 +1788,7 @@ void EditorHelpBit::_bind_methods() { void EditorHelpBit::_notification(int p_what) { if (p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) { - add_style_override("panel", EditorNode::get_singleton()->get_gui_base()->get_stylebox("ScriptPanel", "EditorStyles")); + add_style_override("panel", get_stylebox("ScriptPanel", "EditorStyles")); } } diff --git a/editor/editor_name_dialog.cpp b/editor/editor_name_dialog.cpp index 6ebfcbf313..74bb526ccc 100644 --- a/editor/editor_name_dialog.cpp +++ b/editor/editor_name_dialog.cpp @@ -87,6 +87,6 @@ EditorNameDialog::EditorNameDialog() { makevb->add_child(name); name->set_margin(MARGIN_TOP, 5); name->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_BEGIN, 5); - name->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, 5); + name->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, -5); name->connect("gui_input", this, "_line_gui_input"); } diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index eae44f86f3..242648d4a9 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -364,10 +364,28 @@ void EditorNode::_fs_changed() { E->get()->invalidate(); } - if (export_defer.platform != "") { + if (export_defer.preset != "") { + Ref<EditorExportPreset> preset; + for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); ++i) { + preset = EditorExport::get_singleton()->get_export_preset(i); + if (preset->get_name() == export_defer.preset) { + break; + } + } + if (preset.is_null()) { + String err = "Unknown export preset: " + export_defer.preset; + ERR_PRINT(err.utf8().get_data()); + } else { + Ref<EditorExportPlatform> platform = preset->get_platform(); + if (platform.is_null()) { + String err = "Preset \"" + export_defer.preset + "\" doesn't have a platform."; + ERR_PRINT(err.utf8().get_data()); + } else { + platform->export_project(preset, export_defer.debug, export_defer.path, /*p_flags*/ 0); + } + } - //project_export_settings->export_platform(export_defer.platform,export_defer.path,export_defer.debug,export_defer.password,true); - export_defer.platform = ""; + export_defer.preset = ""; } { @@ -1214,7 +1232,7 @@ void EditorNode::_dialog_action(String p_file) { ml = Ref<MeshLibrary>(memnew(MeshLibrary)); } - //MeshLibraryEditor::update_library_file(editor_data.get_edited_scene_root(),ml,true); + MeshLibraryEditor::update_library_file(editor_data.get_edited_scene_root(), ml, true); Error err = ResourceSaver::save(p_file, ml); if (err) { @@ -1285,7 +1303,7 @@ void EditorNode::_dialog_action(String p_file) { Ref<ConfigFile> config; config.instance(); - Error err = config->load(EditorSettings::get_singleton()->get_settings_path().plus_file("editor_layouts.cfg")); + Error err = config->load(EditorSettings::get_singleton()->get_settings_path().plus_file("editor_layouts-3.cfg")); if (err == ERR_CANT_OPEN) { config.instance(); // new config @@ -1296,7 +1314,7 @@ void EditorNode::_dialog_action(String p_file) { _save_docks_to_config(config, p_file); - config->save(EditorSettings::get_singleton()->get_settings_path().plus_file("editor_layouts.cfg")); + config->save(EditorSettings::get_singleton()->get_settings_path().plus_file("editor_layouts-3.cfg")); layout_dialog->hide(); _update_layouts_menu(); @@ -1313,7 +1331,7 @@ void EditorNode::_dialog_action(String p_file) { Ref<ConfigFile> config; config.instance(); - Error err = config->load(EditorSettings::get_singleton()->get_settings_path().plus_file("editor_layouts.cfg")); + Error err = config->load(EditorSettings::get_singleton()->get_settings_path().plus_file("editor_layouts-3.cfg")); if (err != OK || !config->has_section(p_file)) { show_warning(TTR("Layout name not found!")); @@ -1327,7 +1345,7 @@ void EditorNode::_dialog_action(String p_file) { config->set_value(p_file, E->get(), Variant()); } - config->save(EditorSettings::get_singleton()->get_settings_path().plus_file("editor_layouts.cfg")); + config->save(EditorSettings::get_singleton()->get_settings_path().plus_file("editor_layouts-3.cfg")); layout_dialog->hide(); _update_layouts_menu(); @@ -3844,9 +3862,9 @@ void EditorNode::_editor_file_dialog_unregister(EditorFileDialog *p_dialog) { Vector<EditorNodeInitCallback> EditorNode::_init_callbacks; -Error EditorNode::export_platform(const String &p_platform, const String &p_path, bool p_debug, const String &p_password, bool p_quit_after) { +Error EditorNode::export_preset(const String &preset, const String &p_path, bool p_debug, const String &p_password, bool p_quit_after) { - export_defer.platform = p_platform; + export_defer.preset = preset; export_defer.path = p_path; export_defer.debug = p_debug; export_defer.password = p_password; @@ -4313,7 +4331,7 @@ void EditorNode::_update_layouts_menu() { Ref<ConfigFile> config; config.instance(); - Error err = config->load(EditorSettings::get_singleton()->get_settings_path().plus_file("editor_layouts.cfg")); + Error err = config->load(EditorSettings::get_singleton()->get_settings_path().plus_file("editor_layouts-3.cfg")); if (err != OK) { return; //no config } @@ -4361,7 +4379,7 @@ void EditorNode::_layout_menu_option(int p_id) { Ref<ConfigFile> config; config.instance(); - Error err = config->load(EditorSettings::get_singleton()->get_settings_path().plus_file("editor_layouts.cfg")); + Error err = config->load(EditorSettings::get_singleton()->get_settings_path().plus_file("editor_layouts-3.cfg")); if (err != OK) { return; //no config } @@ -4907,13 +4925,19 @@ void EditorNode::dim_editor(bool p_dimming) { static int dim_count = 0; bool dim_ui = EditorSettings::get_singleton()->get("interface/dim_editor_on_dialog_popup"); if (p_dimming) { - if (dim_ui && dim_count == 0) - _start_dimming(true); - dim_count++; + if (dim_ui) { + if (dim_count == 0) { + _start_dimming(true); + } + dim_count++; + } } else { - dim_count--; - if (dim_count < 1) + if (dim_count == 1) { _start_dimming(false); + dim_count = 0; + } else if (dim_ui && dim_count > 0) { + dim_count--; + } } } @@ -6058,7 +6082,7 @@ EditorNode::EditorNode() { add_editor_plugin(memnew(MultiMeshEditorPlugin(this))); add_editor_plugin(memnew(MeshInstanceEditorPlugin(this))); add_editor_plugin(memnew(AnimationTreeEditorPlugin(this))); - //add_editor_plugin( memnew( MeshLibraryEditorPlugin(this) ) ); + add_editor_plugin(memnew(MeshLibraryEditorPlugin(this))); add_editor_plugin(memnew(StyleBoxEditorPlugin(this))); add_editor_plugin(memnew(ParticlesEditorPlugin(this))); add_editor_plugin(memnew(ResourcePreloaderEditorPlugin(this))); diff --git a/editor/editor_node.h b/editor/editor_node.h index a46f09c254..cf6ef33325 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -539,7 +539,7 @@ private: } struct ExportDefer { - String platform; + String preset; String path; bool debug; String password; @@ -742,7 +742,7 @@ public: void show_warning(const String &p_text, const String &p_title = "Warning!"); - Error export_platform(const String &p_platform, const String &p_path, bool p_debug, const String &p_password, bool p_quit_after = false); + Error export_preset(const String &p_platform, const String &p_path, bool p_debug, const String &p_password, bool p_quit_after = false); static void register_editor_types(); static void unregister_editor_types(); diff --git a/editor/editor_themes.cpp b/editor/editor_themes.cpp index 7b1a6a8e27..7c422eb26e 100644 --- a/editor/editor_themes.cpp +++ b/editor/editor_themes.cpp @@ -455,6 +455,7 @@ Ref<Theme> create_editor_theme() { theme->set_stylebox("scroll_focus", "HScrollBar", make_stylebox(theme->get_icon("GuiScrollBg", "EditorIcons"), 5, 5, 5, 5, 0, 0, 0, 0)); theme->set_stylebox("grabber", "HScrollBar", make_stylebox(theme->get_icon("GuiScrollGrabber", "EditorIcons"), 6, 6, 6, 6, 2, 2, 2, 2)); theme->set_stylebox("grabber_highlight", "HScrollBar", make_stylebox(theme->get_icon("GuiScrollGrabberHl", "EditorIcons"), 5, 5, 5, 5, 2, 2, 2, 2)); + theme->set_stylebox("grabber_pressed", "HScrollBar", make_stylebox(theme->get_icon("GuiScrollGrabberPressed", "EditorIcons"), 6, 6, 6, 6, 2, 2, 2, 2)); theme->set_icon("increment", "HScrollBar", empty_icon); theme->set_icon("increment_highlight", "HScrollBar", empty_icon); @@ -466,6 +467,7 @@ Ref<Theme> create_editor_theme() { theme->set_stylebox("scroll_focus", "VScrollBar", make_stylebox(theme->get_icon("GuiScrollBg", "EditorIcons"), 5, 5, 5, 5, 0, 0, 0, 0)); theme->set_stylebox("grabber", "VScrollBar", make_stylebox(theme->get_icon("GuiScrollGrabber", "EditorIcons"), 6, 6, 6, 6, 2, 2, 2, 2)); theme->set_stylebox("grabber_highlight", "VScrollBar", make_stylebox(theme->get_icon("GuiScrollGrabberHl", "EditorIcons"), 5, 5, 5, 5, 2, 2, 2, 2)); + theme->set_stylebox("grabber_pressed", "VScrollBar", make_stylebox(theme->get_icon("GuiScrollGrabberPressed", "EditorIcons"), 6, 6, 6, 6, 2, 2, 2, 2)); theme->set_icon("increment", "VScrollBar", empty_icon); theme->set_icon("increment_highlight", "VScrollBar", empty_icon); diff --git a/editor/icons/2x/icon_editor_control_anchor.png b/editor/icons/2x/icon_editor_control_anchor.png Binary files differnew file mode 100644 index 0000000000..838f85b763 --- /dev/null +++ b/editor/icons/2x/icon_editor_control_anchor.png diff --git a/editor/icons/icon_GUI_scroll_grabber_pressed.png b/editor/icons/icon_GUI_scroll_grabber_pressed.png Binary files differnew file mode 100644 index 0000000000..a46d242ddd --- /dev/null +++ b/editor/icons/icon_GUI_scroll_grabber_pressed.png diff --git a/editor/icons/icon_editor_control_anchor.png b/editor/icons/icon_editor_control_anchor.png Binary files differnew file mode 100644 index 0000000000..158dd62a7b --- /dev/null +++ b/editor/icons/icon_editor_control_anchor.png diff --git a/editor/icons/source/icon_GUI_scroll_grabber_pressed.svg b/editor/icons/source/icon_GUI_scroll_grabber_pressed.svg new file mode 100644 index 0000000000..852e985c4c --- /dev/null +++ b/editor/icons/source/icon_GUI_scroll_grabber_pressed.svg @@ -0,0 +1,83 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> + +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + width="12" + height="12" + viewBox="0 0 12 11.999999" + id="svg2" + version="1.1" + inkscape:version="0.48.4 r9939" + sodipodi:docname="icon_GUI_scroll_grabber_pressed.svg" + inkscape:export-filename="D:\HDD Documents\Other Projects\godot\editor\icons\icon_GUI_scroll_grabber_pressed.png" + inkscape:export-xdpi="90" + inkscape:export-ydpi="90"> + <defs + id="defs4" /> + <sodipodi:namedview + id="base" + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1.0" + inkscape:pageopacity="0.0" + inkscape:pageshadow="2" + inkscape:zoom="69.166667" + inkscape:cx="3.7445783" + inkscape:cy="6" + inkscape:document-units="px" + inkscape:current-layer="layer1" + showgrid="true" + units="px" + inkscape:object-paths="true" + inkscape:snap-intersection-paths="true" + inkscape:snap-bbox="true" + inkscape:bbox-paths="true" + inkscape:bbox-nodes="true" + inkscape:snap-bbox-edge-midpoints="true" + inkscape:window-width="1920" + inkscape:window-height="1017" + inkscape:window-x="-8" + inkscape:window-y="-8" + inkscape:window-maximized="1" + inkscape:snap-nodes="false"> + <inkscape:grid + type="xygrid" + id="grid4136" + empspacing="4" /> + </sodipodi:namedview> + <metadata + id="metadata7"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + <dc:title></dc:title> + </cc:Work> + </rdf:RDF> + </metadata> + <g + inkscape:label="Layer 1" + inkscape:groupmode="layer" + id="layer1" + transform="translate(0,-1040.3623)"> + <circle + style="opacity:1;fill:#afafaf;fill-opacity:0.72941178;stroke:none;stroke-width:2.24999642000000000;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + id="path4239" + cx="6" + cy="1046.3623" + r="2.9999952" + inkscape:export-filename="/mnt/2TB/Development/godot_dev/editor/icons/icon_scroll_grabber_hl.png" + inkscape:export-xdpi="96" + inkscape:export-ydpi="96" + d="m 8.9999952,1046.3623 c 0,1.6569 -1.3431436,3 -2.9999952,3 -1.6568516,0 -2.9999952,-1.3431 -2.9999952,-3 0,-1.6568 1.3431436,-3 2.9999952,-3 1.6568516,0 2.9999952,1.3432 2.9999952,3 z" /> + </g> +</svg> diff --git a/editor/icons/source/icon_editor_control_anchor.svg b/editor/icons/source/icon_editor_control_anchor.svg new file mode 100644 index 0000000000..473b69d060 --- /dev/null +++ b/editor/icons/source/icon_editor_control_anchor.svg @@ -0,0 +1,98 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> + +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + width="16" + height="16" + viewBox="0 0 16 16" + id="svg2" + version="1.1" + inkscape:version="0.92.1 r" + inkscape:export-filename="/home/gilles/godot/editor/icons/icon_editor_control_anchor.png" + inkscape:export-xdpi="96" + inkscape:export-ydpi="96" + sodipodi:docname="icon_editor_control_anchor.svg"> + <defs + id="defs4" /> + <sodipodi:namedview + id="base" + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1.0" + inkscape:pageopacity="0.0" + inkscape:pageshadow="2" + inkscape:zoom="22.627416" + inkscape:cx="0.71312079" + inkscape:cy="11.175116" + inkscape:document-units="px" + inkscape:current-layer="layer1" + showgrid="true" + units="px" + inkscape:snap-bbox="true" + inkscape:bbox-paths="true" + inkscape:bbox-nodes="true" + inkscape:snap-bbox-edge-midpoints="true" + inkscape:snap-bbox-midpoints="true" + inkscape:snap-object-midpoints="true" + inkscape:snap-center="true" + inkscape:window-width="1356" + inkscape:window-height="742" + inkscape:window-x="4" + inkscape:window-y="20" + inkscape:window-maximized="0" + inkscape:pagecheckerboard="true" + showguides="false"> + <inkscape:grid + type="xygrid" + id="grid3336" /> + </sodipodi:namedview> + <metadata + id="metadata7"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + <dc:title /> + </cc:Work> + </rdf:RDF> + </metadata> + <g + inkscape:label="Layer 1" + inkscape:groupmode="layer" + id="layer1" + transform="translate(0,-1036.3622)"> + <path + style="fill:#a5efac;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;fill-opacity:1" + d="M 8.8320312 6.1445312 A 4 4.0000234 0 0 1 6.140625 8.8300781 L 16 16 L 8.8320312 6.1445312 z " + transform="translate(0,1036.3622)" + id="path7188" /> + <ellipse + r="2" + style="opacity:1;fill:#6e6e6e;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" + id="ellipse4152" + cx="3" + cy="1039.3622" /> + <ellipse + style="fill:#a5efac;fill-opacity:1;stroke:none;stroke-width:0.53333384;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;paint-order:fill markers stroke" + id="path31" + cx="4" + cy="1040.3622" + rx="4" + ry="4.0000091" /> + <circle + style="fill:#a5efac;fill-opacity:1;stroke:none;stroke-width:0.5333333;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;paint-order:fill markers stroke" + id="path31-3" + cx="5" + cy="1041.3622" + r="0" /> + </g> +</svg> diff --git a/editor/import/editor_import_collada.cpp b/editor/import/editor_import_collada.cpp index 2a077e2627..a75147a3a9 100644 --- a/editor/import/editor_import_collada.cpp +++ b/editor/import/editor_import_collada.cpp @@ -390,7 +390,7 @@ Error ColladaImport::_create_material(const String &p_target) { } } } else { - //material->set_parameter(SpatialMaterial::PARAM_DIFFUSE,effect.diffuse.color); + material->set_albedo(effect.diffuse.color); } // SPECULAR diff --git a/editor/io_plugins/editor_scene_import_plugin.cpp b/editor/io_plugins/editor_scene_import_plugin.cpp index aa96f731ce..1890ca906a 100644 --- a/editor/io_plugins/editor_scene_import_plugin.cpp +++ b/editor/io_plugins/editor_scene_import_plugin.cpp @@ -1307,7 +1307,7 @@ EditorSceneImportDialog::EditorSceneImportDialog(EditorNode *p_editor, EditorSce //confirm_import->set_child_rect(cvb); PanelContainer *pc = memnew( PanelContainer ); - pc->add_style_override("panel",get_stylebox("normal","TextEdit")); + pc->add_style_override("panel", EditorNode::get_singleton()->get_gui_base()->get_stylebox("normal","TextEdit")); //ec->add_child(pc); missing_files = memnew( RichTextLabel ); cvb->add_margin_child(TTR("The Following Files are Missing:"),pc,true); diff --git a/editor/output_strings.cpp b/editor/output_strings.cpp index eb2fc62f03..8c9f8386ef 100644 --- a/editor/output_strings.cpp +++ b/editor/output_strings.cpp @@ -38,15 +38,15 @@ void OutputStrings::update_scrollbars() { v_scroll->set_anchor(MARGIN_RIGHT, ANCHOR_END); v_scroll->set_anchor(MARGIN_BOTTOM, ANCHOR_END); - v_scroll->set_begin(Point2(vmin.width, 0)); + v_scroll->set_begin(Point2(-vmin.width, 0)); v_scroll->set_end(Point2(0, 0)); h_scroll->set_anchor(MARGIN_RIGHT, ANCHOR_END); h_scroll->set_anchor(MARGIN_TOP, ANCHOR_END); h_scroll->set_anchor(MARGIN_BOTTOM, ANCHOR_END); - h_scroll->set_begin(Point2(0, hmin.y)); - h_scroll->set_end(Point2(vmin.x, 0)); + h_scroll->set_begin(Point2(0, -hmin.y)); + h_scroll->set_end(Point2(-vmin.x, 0)); margin.y = hmin.y; margin.x = vmin.x; diff --git a/editor/plugins/animation_player_editor_plugin.cpp b/editor/plugins/animation_player_editor_plugin.cpp index c4e79bf263..ecae272b6d 100644 --- a/editor/plugins/animation_player_editor_plugin.cpp +++ b/editor/plugins/animation_player_editor_plugin.cpp @@ -1246,7 +1246,7 @@ AnimationPlayerEditor::AnimationPlayerEditor(EditorNode *p_editor) { set_focus_mode(FOCUS_ALL); player = NULL; - add_style_override("panel", get_stylebox("panel", "Panel")); + add_style_override("panel", editor->get_gui_base()->get_stylebox("panel", "Panel")); Label *l; diff --git a/editor/plugins/animation_tree_editor_plugin.cpp b/editor/plugins/animation_tree_editor_plugin.cpp index a66e4cb561..6e24d4d2cb 100644 --- a/editor/plugins/animation_tree_editor_plugin.cpp +++ b/editor/plugins/animation_tree_editor_plugin.cpp @@ -1371,7 +1371,7 @@ AnimationTreeEditor::AnimationTreeEditor() { edit_option = memnew(OptionButton); edit_option->set_anchor(MARGIN_RIGHT, ANCHOR_END); - edit_option->set_margin(MARGIN_RIGHT, 10); + edit_option->set_margin(MARGIN_RIGHT, -10); edit_dialog->add_child(edit_option); edit_option->connect("item_selected", this, "_edit_dialog_changedf"); edit_option->hide(); @@ -1379,7 +1379,7 @@ AnimationTreeEditor::AnimationTreeEditor() { for (int i = 0; i < 2; i++) { edit_scroll[i] = memnew(HSlider); edit_scroll[i]->set_anchor(MARGIN_RIGHT, ANCHOR_END); - edit_scroll[i]->set_margin(MARGIN_RIGHT, 10); + edit_scroll[i]->set_margin(MARGIN_RIGHT, -10); edit_dialog->add_child(edit_scroll[i]); edit_scroll[i]->hide(); edit_scroll[i]->connect("value_changed", this, "_edit_dialog_changedf"); @@ -1387,7 +1387,7 @@ AnimationTreeEditor::AnimationTreeEditor() { for (int i = 0; i < 4; i++) { edit_line[i] = memnew(LineEdit); edit_line[i]->set_anchor(MARGIN_RIGHT, ANCHOR_END); - edit_line[i]->set_margin(MARGIN_RIGHT, 10); + edit_line[i]->set_margin(MARGIN_RIGHT, -10); edit_dialog->add_child(edit_line[i]); edit_line[i]->hide(); edit_line[i]->connect("text_changed", this, "_edit_dialog_changeds"); @@ -1399,14 +1399,14 @@ AnimationTreeEditor::AnimationTreeEditor() { edit_button = memnew(Button); edit_button->set_anchor(MARGIN_RIGHT, ANCHOR_END); - edit_button->set_margin(MARGIN_RIGHT, 10); + edit_button->set_margin(MARGIN_RIGHT, -10); edit_dialog->add_child(edit_button); edit_button->hide(); edit_button->connect("pressed", this, "_edit_oneshot_start"); edit_check = memnew(CheckButton); edit_check->set_anchor(MARGIN_RIGHT, ANCHOR_END); - edit_check->set_margin(MARGIN_RIGHT, 10); + edit_check->set_margin(MARGIN_RIGHT, -10); edit_dialog->add_child(edit_check); edit_check->hide(); edit_check->connect("pressed", this, "_edit_dialog_changed"); @@ -1428,7 +1428,7 @@ AnimationTreeEditor::AnimationTreeEditor() { filter_button = memnew(Button); filter_button->set_anchor(MARGIN_RIGHT, ANCHOR_END); - filter_button->set_margin(MARGIN_RIGHT, 10); + filter_button->set_margin(MARGIN_RIGHT, -10); edit_dialog->add_child(filter_button); filter_button->hide(); filter_button->set_text(TTR("Filters..")); diff --git a/editor/plugins/camera_editor_plugin.cpp b/editor/plugins/camera_editor_plugin.cpp index b8f8464bae..8e625c4a73 100644 --- a/editor/plugins/camera_editor_plugin.cpp +++ b/editor/plugins/camera_editor_plugin.cpp @@ -88,7 +88,7 @@ CameraEditor::CameraEditor() { preview->set_toggle_mode(true); preview->set_anchor(MARGIN_LEFT, Control::ANCHOR_END); preview->set_anchor(MARGIN_RIGHT, Control::ANCHOR_END); - preview->set_margin(MARGIN_LEFT, 60); + preview->set_margin(MARGIN_LEFT, -60); preview->set_margin(MARGIN_RIGHT, 0); preview->set_margin(MARGIN_TOP, 0); preview->set_margin(MARGIN_BOTTOM, 10); diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index a6ef5e08bc..322c3ae86a 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -709,8 +709,8 @@ CanvasItem *CanvasItemEditor::get_single_item() { return single_item; } -CanvasItemEditor::DragType CanvasItemEditor::_find_drag_type(const Point2 &p_click, Vector2 &r_point) { - +CanvasItemEditor::DragType CanvasItemEditor::_get_resize_handle_drag_type(const Point2 &p_click, Vector2 &r_point) { + // Returns a drag type if a resize handle is clicked CanvasItem *canvas_item = get_single_item(); ERR_FAIL_COND_V(!canvas_item, DRAG_NONE); @@ -775,6 +775,90 @@ CanvasItemEditor::DragType CanvasItemEditor::_find_drag_type(const Point2 &p_cli return DRAG_NONE; } +float CanvasItemEditor::_anchor_snap(float p_anchor, bool *p_snapped, float p_opposite_anchor) { + bool snapped = false; + float dist, dist_min = 0.0; + float radius = 0.05 / zoom; + float basic_anchors[3] = { 0.0, 0.5, 1.0 }; + for (int i = 0; i < 3; i++) { + if ((dist = fabs(p_anchor - basic_anchors[i])) < radius) { + if (!snapped || dist <= dist_min) { + p_anchor = basic_anchors[i]; + dist_min = dist; + snapped = true; + } + } + } + if (p_opposite_anchor >= 0 && (dist = fabs(p_anchor - p_opposite_anchor)) < radius) { + if (!snapped || dist <= dist_min) { + p_anchor = p_opposite_anchor; + dist_min = dist; + snapped = true; + } + } + if (p_snapped) + *p_snapped = snapped; + return p_anchor; +} + +Vector2 CanvasItemEditor::_anchor_to_position(Control *p_control, Vector2 anchor) { + ERR_FAIL_COND_V(!p_control, Vector2()); + + Transform2D parent_transform = p_control->get_transform().affine_inverse(); + Size2 parent_size = p_control->get_parent_area_size(); + + return parent_transform.xform(Vector2(parent_size.x * anchor.x, parent_size.y * anchor.y)); +} + +Vector2 CanvasItemEditor::_position_to_anchor(Control *p_control, Vector2 position) { + ERR_FAIL_COND_V(!p_control, Vector2()); + Size2 parent_size = p_control->get_parent_area_size(); + + return p_control->get_transform().xform(position) / parent_size; +} + +CanvasItemEditor::DragType CanvasItemEditor::_get_anchor_handle_drag_type(const Point2 &p_click, Vector2 &r_point) { + // Returns a drag type if an anchor handle is clicked + CanvasItem *canvas_item = get_single_item(); + ERR_FAIL_COND_V(!canvas_item, DRAG_NONE); + + Control *control = canvas_item->cast_to<Control>(); + ERR_FAIL_COND_V(!control, DRAG_NONE); + + Vector2 anchor_pos[4]; + anchor_pos[0] = Vector2(control->get_anchor(MARGIN_LEFT), control->get_anchor(MARGIN_TOP)); + anchor_pos[1] = Vector2(control->get_anchor(MARGIN_RIGHT), control->get_anchor(MARGIN_TOP)); + anchor_pos[2] = Vector2(control->get_anchor(MARGIN_RIGHT), control->get_anchor(MARGIN_BOTTOM)); + anchor_pos[3] = Vector2(control->get_anchor(MARGIN_LEFT), control->get_anchor(MARGIN_BOTTOM)); + + Rect2 anchor_rects[4]; + for (int i = 0; i < 4; i++) { + anchor_pos[i] = (transform * control->get_global_transform_with_canvas()).xform(_anchor_to_position(control, anchor_pos[i])); + anchor_rects[i] = Rect2(anchor_pos[i], anchor_handle->get_size()); + anchor_rects[i].position -= anchor_handle->get_size() * Vector2(i == 0 || i == 3, i <= 1); + } + + DragType dragger[] = { + DRAG_ANCHOR_TOP_LEFT, + DRAG_ANCHOR_TOP_RIGHT, + DRAG_ANCHOR_BOTTOM_RIGHT, + DRAG_ANCHOR_BOTTOM_LEFT, + }; + + for (int i = 0; i < 4; i++) { + if (anchor_rects[i].has_point(p_click)) { + r_point = transform.affine_inverse().xform(anchor_pos[i]); + if ((anchor_pos[0] == anchor_pos[2]) && (anchor_pos[0].distance_to(p_click) < anchor_handle->get_size().length() / 3.0)) { + return DRAG_ANCHOR_ALL; + } else { + return dragger[i]; + } + } + } + + return DRAG_NONE; +} + void CanvasItemEditor::_prepare_drag(const Point2 &p_click_pos) { List<Node *> &selection = editor_selection->get_selected_node_list(); @@ -1265,6 +1349,7 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) { if (b) { bool ik_found = false; + bool first = true; while (b) { @@ -1336,8 +1421,8 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) { } } - // Drag - drag = _find_drag_type(click, drag_point_from); + // Drag resize handles + drag = _get_resize_handle_drag_type(click, drag_point_from); if (drag != DRAG_NONE) { drag_from = transform.affine_inverse().xform(click); se->undo_state = canvas_item->edit_get_state(); @@ -1347,6 +1432,16 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) { se->undo_pivot = canvas_item->cast_to<Control>()->get_pivot_offset(); return; } + + // Drag anchor handles + if (canvas_item->cast_to<Control>()) { + drag = _get_anchor_handle_drag_type(click, drag_point_from); + if (drag != DRAG_NONE) { + drag_from = transform.affine_inverse().xform(click); + se->undo_state = canvas_item->edit_get_state(); + return; + } + } } } @@ -1423,9 +1518,8 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) { } if (drag == DRAG_NONE) { - if ((m->get_button_mask() & BUTTON_MASK_LEFT && tool == TOOL_PAN) || m->get_button_mask() & BUTTON_MASK_MIDDLE || (m->get_button_mask() & BUTTON_MASK_LEFT && Input::get_singleton()->is_key_pressed(KEY_SPACE))) { - + // Pan the viewport Point2i relative; if (bool(EditorSettings::get_singleton()->get("editors/2d/warped_mouse_panning"))) { relative = Input::get_singleton()->warp_mouse_motion(m, viewport->get_global_rect()); @@ -1441,7 +1535,6 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) { } List<Node *> &selection = editor_selection->get_selected_node_list(); - for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { CanvasItem *canvas_item = E->get()->cast_to<CanvasItem>(); @@ -1470,7 +1563,7 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) { continue; if (drag == DRAG_ROTATE) { - + // Rotate the node Vector2 center = canvas_item->get_global_transform_with_canvas().get_origin(); { Node2D *node = canvas_item->cast_to<Node2D>(); @@ -1499,10 +1592,47 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) { continue; } + Control *control = canvas_item->cast_to<Control>(); + if (control) { + // Drag and snap the anchor + Vector2 anchor = _position_to_anchor(control, canvas_item->get_global_transform_with_canvas().affine_inverse().xform(dto - drag_from + drag_point_from)); + + switch (drag) { + case DRAG_ANCHOR_TOP_LEFT: + control->set_anchor(MARGIN_LEFT, _anchor_snap(anchor.x, NULL, control->get_anchor(MARGIN_RIGHT)), false, false); + control->set_anchor(MARGIN_TOP, _anchor_snap(anchor.y, NULL, control->get_anchor(MARGIN_BOTTOM)), false, false); + continue; + break; + case DRAG_ANCHOR_TOP_RIGHT: + control->set_anchor(MARGIN_RIGHT, _anchor_snap(anchor.x, NULL, control->get_anchor(MARGIN_LEFT)), false, false); + control->set_anchor(MARGIN_TOP, _anchor_snap(anchor.y, NULL, control->get_anchor(MARGIN_BOTTOM)), false, false); + continue; + break; + case DRAG_ANCHOR_BOTTOM_RIGHT: + control->set_anchor(MARGIN_RIGHT, _anchor_snap(anchor.x, NULL, control->get_anchor(MARGIN_LEFT)), false, false); + control->set_anchor(MARGIN_BOTTOM, _anchor_snap(anchor.y, NULL, control->get_anchor(MARGIN_TOP)), false, false); + continue; + break; + case DRAG_ANCHOR_BOTTOM_LEFT: + control->set_anchor(MARGIN_LEFT, _anchor_snap(anchor.x, NULL, control->get_anchor(MARGIN_RIGHT)), false, false); + control->set_anchor(MARGIN_BOTTOM, _anchor_snap(anchor.y, NULL, control->get_anchor(MARGIN_TOP)), false, false); + continue; + break; + case DRAG_ANCHOR_ALL: + control->set_anchor(MARGIN_LEFT, _anchor_snap(anchor.x)); + control->set_anchor(MARGIN_RIGHT, _anchor_snap(anchor.x)); + control->set_anchor(MARGIN_TOP, _anchor_snap(anchor.y)); + control->set_anchor(MARGIN_BOTTOM, _anchor_snap(anchor.y)); + continue; + break; + } + } + bool uniform = m->get_shift(); bool symmetric = m->get_alt(); - dto = dto - (drag == DRAG_ALL || drag == DRAG_NODE_2D ? drag_from - drag_point_from : Vector2(0, 0)); + if (drag == DRAG_ALL || drag == DRAG_NODE_2D) + dto -= drag_from - drag_point_from; if (uniform && (drag == DRAG_ALL || drag == DRAG_NODE_2D)) { if (ABS(dto.x - drag_point_from.x) > ABS(dto.y - drag_point_from.y)) { @@ -1528,76 +1658,75 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) { // Keep the height/width ratio of the item float aspect = local_rect.size.aspect(); switch (drag) { - case DRAG_LEFT: { + case DRAG_LEFT: drag_vector.y = -drag_vector.x / aspect; - } break; - case DRAG_RIGHT: { + break; + case DRAG_RIGHT: drag_vector.y = drag_vector.x / aspect; - } break; - case DRAG_TOP: { + break; + case DRAG_TOP: drag_vector.x = -drag_vector.y * aspect; - } break; - case DRAG_BOTTOM: { + break; + case DRAG_BOTTOM: drag_vector.x = drag_vector.y * aspect; - } break; + break; case DRAG_BOTTOM_LEFT: - case DRAG_TOP_RIGHT: { + case DRAG_TOP_RIGHT: if (aspect > 1.0) { // width > height, take x as reference drag_vector.y = -drag_vector.x / aspect; } else { // height > width, take y as reference drag_vector.x = -drag_vector.y * aspect; } - } break; + break; case DRAG_BOTTOM_RIGHT: - case DRAG_TOP_LEFT: { + case DRAG_TOP_LEFT: if (aspect > 1.0) { // width > height, take x as reference drag_vector.y = drag_vector.x / aspect; } else { // height > width, take y as reference drag_vector.x = drag_vector.y * aspect; } - } break; + break; } } else { switch (drag) { case DRAG_RIGHT: - case DRAG_LEFT: { + case DRAG_LEFT: drag_vector.y = 0; - } break; + break; case DRAG_TOP: - case DRAG_BOTTOM: { + case DRAG_BOTTOM: drag_vector.x = 0; - } break; + break; } } switch (drag) { - case DRAG_ALL: { + case DRAG_ALL: begin += drag_vector; end += drag_vector; - } break; + break; case DRAG_RIGHT: case DRAG_BOTTOM: - case DRAG_BOTTOM_RIGHT: { + case DRAG_BOTTOM_RIGHT: incend(begin.x, end.x, drag_vector.x, minsize.x, symmetric); incend(begin.y, end.y, drag_vector.y, minsize.y, symmetric); - } break; - - case DRAG_TOP_LEFT: { + break; + case DRAG_TOP_LEFT: incbeg(begin.x, end.x, drag_vector.x, minsize.x, symmetric); incbeg(begin.y, end.y, drag_vector.y, minsize.y, symmetric); - } break; - + break; case DRAG_TOP: - case DRAG_TOP_RIGHT: { + case DRAG_TOP_RIGHT: incbeg(begin.y, end.y, drag_vector.y, minsize.y, symmetric); incend(begin.x, end.x, drag_vector.x, minsize.x, symmetric); - } break; + break; case DRAG_LEFT: - case DRAG_BOTTOM_LEFT: { + case DRAG_BOTTOM_LEFT: incbeg(begin.x, end.x, drag_vector.x, minsize.x, symmetric); incend(begin.y, end.y, drag_vector.y, minsize.y, symmetric); - } break; - case DRAG_PIVOT: { + break; + + case DRAG_PIVOT: if (canvas_item->cast_to<Node2D>()) { Node2D *n2d = canvas_item->cast_to<Node2D>(); @@ -1607,15 +1736,13 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) { canvas_item->cast_to<Control>()->set_pivot_offset(se->undo_pivot + drag_vector); } continue; - } break; - case DRAG_NODE_2D: { + break; + case DRAG_NODE_2D: ERR_FAIL_COND(!canvas_item->cast_to<Node2D>()); canvas_item->cast_to<Node2D>()->set_global_position(dto); continue; - } break; - - default: {} + break; } if (!dragging_bone) { @@ -1768,6 +1895,30 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) { } } +void CanvasItemEditor::_draw_percentage_at_position(float p_value, Point2 p_position, Margin p_side) { + if (p_value != 0) { + Color color = Color(0.8, 0.8, 0.8, 0.5); + Ref<Font> font = get_font("font", "Label"); + String str = vformat("%.1f %%", p_value * 100.0); + Size2 text_size = font->get_string_size(str); + switch (p_side) { + case MARGIN_LEFT: + p_position += Vector2(-text_size.x - 5, text_size.y / 2); + break; + case MARGIN_TOP: + p_position += Vector2(-text_size.x / 2, -5); + break; + case MARGIN_RIGHT: + p_position += Vector2(5, text_size.y / 2); + break; + case MARGIN_BOTTOM: + p_position += Vector2(-text_size.x / 2, text_size.y + 5); + break; + } + viewport->draw_string(font, p_position, str, color); + } +} + void CanvasItemEditor::_viewport_draw() { // TODO fetch the viewport? @@ -1870,13 +2021,99 @@ void CanvasItemEditor::_viewport_draw() { pivot_found = true; } } - if (canvas_item->cast_to<Control>()) { - Vector2 pivot_ofs = canvas_item->cast_to<Control>()->get_pivot_offset(); + + Control *control = canvas_item->cast_to<Control>(); + if (control) { + Vector2 pivot_ofs = control->get_pivot_offset(); if (pivot_ofs != Vector2()) { viewport->draw_texture(pivot, xform.xform(pivot_ofs) + (-pivot->get_size() / 2).floor()); } can_move_pivot = true; pivot_found = true; + + if (tool == TOOL_SELECT) { + float anchors_values[4]; + anchors_values[0] = control->get_anchor(MARGIN_LEFT); + anchors_values[1] = control->get_anchor(MARGIN_TOP); + anchors_values[2] = control->get_anchor(MARGIN_RIGHT); + anchors_values[3] = control->get_anchor(MARGIN_BOTTOM); + + // Draw the anchors + Vector2 anchors[4]; + Vector2 anchors_pos[4]; + for (int i = 0; i < 4; i++) { + anchors[i] = Vector2((i % 2 == 0) ? anchors_values[i] : anchors_values[(i + 1) % 4], (i % 2 == 1) ? anchors_values[i] : anchors_values[(i + 1) % 4]); + anchors_pos[i] = xform.xform(_anchor_to_position(control, anchors[i])); + } + + // Get which anchor is dragged + int dragged_anchor = -1; + switch (drag) { + case DRAG_ANCHOR_ALL: + case DRAG_ANCHOR_TOP_LEFT: + dragged_anchor = 0; + break; + case DRAG_ANCHOR_TOP_RIGHT: + dragged_anchor = 1; + break; + case DRAG_ANCHOR_BOTTOM_RIGHT: + dragged_anchor = 2; + break; + case DRAG_ANCHOR_BOTTOM_LEFT: + dragged_anchor = 3; + break; + } + + if (dragged_anchor >= 0) { + // Draw the 4 lines when dragged + bool snapped; + Color color_snapped = Color(0.64, 0.93, 0.67, 0.5); + Color color_base = Color(0.8, 0.8, 0.8, 0.5); + + Vector2 corners_pos[4]; + for (int i = 0; i < 4; i++) { + corners_pos[i] = xform.xform(_anchor_to_position(control, Vector2((i == 0 || i == 3) ? ANCHOR_BEGIN : ANCHOR_END, (i <= 1) ? ANCHOR_BEGIN : ANCHOR_END))); + } + + Vector2 line_starts[4]; + Vector2 line_ends[4]; + for (int i = 0; i < 4; i++) { + float anchor_val = (i >= 2) ? ANCHOR_END - anchors_values[i] : anchors_values[i]; + line_starts[i] = Vector2::linear_interpolate(corners_pos[i], corners_pos[(i + 1) % 4], anchor_val); + line_ends[i] = Vector2::linear_interpolate(corners_pos[(i + 3) % 4], corners_pos[(i + 2) % 4], anchor_val); + _anchor_snap(anchors_values[i], &snapped); + viewport->draw_line(line_starts[i], line_ends[i], snapped ? color_snapped : color_base, (i == dragged_anchor || (i + 3) % 4 == dragged_anchor) ? 2 : 1); + } + + // Display the percentages next to the lines + float percent_val; + percent_val = anchors_values[(dragged_anchor + 2) % 4] - anchors_values[dragged_anchor]; + percent_val = (dragged_anchor >= 2) ? -percent_val : percent_val; + _draw_percentage_at_position(percent_val, (anchors_pos[dragged_anchor] + anchors_pos[(dragged_anchor + 1) % 4]) / 2, (Margin)((dragged_anchor + 1) % 4)); + + percent_val = anchors_values[(dragged_anchor + 3) % 4] - anchors_values[(dragged_anchor + 1) % 4]; + percent_val = ((dragged_anchor + 1) % 4 >= 2) ? -percent_val : percent_val; + _draw_percentage_at_position(percent_val, (anchors_pos[dragged_anchor] + anchors_pos[(dragged_anchor + 3) % 4]) / 2, (Margin)(dragged_anchor)); + + percent_val = anchors_values[(dragged_anchor + 1) % 4]; + percent_val = ((dragged_anchor + 1) % 4 >= 2) ? ANCHOR_END - percent_val : percent_val; + _draw_percentage_at_position(percent_val, (line_starts[dragged_anchor] + anchors_pos[dragged_anchor]) / 2, (Margin)(dragged_anchor)); + + percent_val = anchors_values[dragged_anchor]; + percent_val = (dragged_anchor >= 2) ? ANCHOR_END - percent_val : percent_val; + _draw_percentage_at_position(percent_val, (line_ends[(dragged_anchor + 1) % 4] + anchors_pos[dragged_anchor]) / 2, (Margin)((dragged_anchor + 1) % 4)); + } + + Rect2 anchor_rects[4]; + anchor_rects[0] = Rect2(anchors_pos[0] - anchor_handle->get_size(), anchor_handle->get_size()); + anchor_rects[1] = Rect2(anchors_pos[1] - Vector2(0.0, anchor_handle->get_size().y), Point2(-anchor_handle->get_size().x, anchor_handle->get_size().y)); + anchor_rects[2] = Rect2(anchors_pos[2], -anchor_handle->get_size()); + anchor_rects[3] = Rect2(anchors_pos[3] - Vector2(anchor_handle->get_size().x, 0.0), Point2(anchor_handle->get_size().x, -anchor_handle->get_size().y)); + + for (int i = 0; i < 4; i++) { + anchor_handle->draw_rect(ci, anchor_rects[i]); + } + } } if (tool == TOOL_SELECT) { @@ -2063,19 +2300,27 @@ void CanvasItemEditor::_notification(int p_what) { continue; Rect2 r = canvas_item->get_item_rect(); - Transform2D xform = canvas_item->get_transform(); + float anchors[4]; Vector2 pivot; if (canvas_item->cast_to<Control>()) { pivot = canvas_item->cast_to<Control>()->get_pivot_offset(); + anchors[MARGIN_LEFT] = canvas_item->cast_to<Control>()->get_anchor(MARGIN_LEFT); + anchors[MARGIN_RIGHT] = canvas_item->cast_to<Control>()->get_anchor(MARGIN_RIGHT); + anchors[MARGIN_TOP] = canvas_item->cast_to<Control>()->get_anchor(MARGIN_TOP); + anchors[MARGIN_BOTTOM] = canvas_item->cast_to<Control>()->get_anchor(MARGIN_BOTTOM); } - if (r != se->prev_rect || xform != se->prev_xform || pivot != se->prev_pivot) { + if (r != se->prev_rect || xform != se->prev_xform || pivot != se->prev_pivot || anchors[MARGIN_LEFT] != se->prev_anchors[MARGIN_LEFT] || anchors[MARGIN_RIGHT] != se->prev_anchors[MARGIN_RIGHT] || anchors[MARGIN_TOP] != se->prev_anchors[MARGIN_TOP] || anchors[MARGIN_BOTTOM] != se->prev_anchors[MARGIN_BOTTOM]) { viewport->update(); se->prev_rect = r; se->prev_xform = xform; se->prev_pivot = pivot; + se->prev_anchors[MARGIN_LEFT] = anchors[MARGIN_LEFT]; + se->prev_anchors[MARGIN_RIGHT] = anchors[MARGIN_RIGHT]; + se->prev_anchors[MARGIN_TOP] = anchors[MARGIN_TOP]; + se->prev_anchors[MARGIN_BOTTOM] = anchors[MARGIN_BOTTOM]; } } @@ -2124,6 +2369,7 @@ void CanvasItemEditor::_notification(int p_what) { pan_button->set_icon(get_icon("ToolPan", "EditorIcons")); pivot_button->set_icon(get_icon("EditPivot", "EditorIcons")); select_handle = get_icon("EditorHandle", "EditorIcons"); + anchor_handle = get_icon("EditorControlAnchor", "EditorIcons"); lock_button->set_icon(get_icon("Lock", "EditorIcons")); unlock_button->set_icon(get_icon("Unlock", "EditorIcons")); group_button->set_icon(get_icon("Group", "EditorIcons")); @@ -2338,7 +2584,7 @@ void CanvasItemEditor::_update_scroll(float) { viewport->update(); } -void CanvasItemEditor::_set_anchor(Control::AnchorType p_left, Control::AnchorType p_top, Control::AnchorType p_right, Control::AnchorType p_bottom) { +void CanvasItemEditor::_set_anchors_preset(Control::LayoutPreset p_preset) { List<Node *> &selection = editor_selection->get_selected_node_list(); undo_redo->create_action(TTR("Change Anchors")); @@ -2346,10 +2592,7 @@ void CanvasItemEditor::_set_anchor(Control::AnchorType p_left, Control::AnchorTy Control *c = E->get()->cast_to<Control>(); - undo_redo->add_do_method(c, "set_anchor", MARGIN_LEFT, p_left); - undo_redo->add_do_method(c, "set_anchor", MARGIN_TOP, p_top); - undo_redo->add_do_method(c, "set_anchor", MARGIN_RIGHT, p_right); - undo_redo->add_do_method(c, "set_anchor", MARGIN_BOTTOM, p_bottom); + undo_redo->add_do_method(c, "set_anchors_preset", p_preset); undo_redo->add_undo_method(c, "set_anchor", MARGIN_LEFT, c->get_anchor(MARGIN_LEFT)); undo_redo->add_undo_method(c, "set_anchor", MARGIN_TOP, c->get_anchor(MARGIN_TOP)); undo_redo->add_undo_method(c, "set_anchor", MARGIN_RIGHT, c->get_anchor(MARGIN_RIGHT)); @@ -2367,10 +2610,7 @@ void CanvasItemEditor::_set_full_rect() { Control *c = E->get()->cast_to<Control>(); - undo_redo->add_do_method(c, "set_anchor", MARGIN_LEFT, ANCHOR_BEGIN); - undo_redo->add_do_method(c, "set_anchor", MARGIN_TOP, ANCHOR_BEGIN); - undo_redo->add_do_method(c, "set_anchor", MARGIN_RIGHT, ANCHOR_END); - undo_redo->add_do_method(c, "set_anchor", MARGIN_BOTTOM, ANCHOR_END); + undo_redo->add_do_method(c, "set_anchors_preset", PRESET_WIDE); undo_redo->add_do_method(c, "set_margin", MARGIN_LEFT, 0); undo_redo->add_do_method(c, "set_margin", MARGIN_TOP, 0); undo_redo->add_do_method(c, "set_margin", MARGIN_RIGHT, 0); @@ -2591,53 +2831,52 @@ void CanvasItemEditor::_popup_callback(int p_op) { //space_selected_items< proj_vector2_y, compare_items_y >(); } break; case ANCHOR_ALIGN_TOP_LEFT: { - _set_anchor(ANCHOR_BEGIN, ANCHOR_BEGIN, ANCHOR_BEGIN, ANCHOR_BEGIN); + _set_anchors_preset(PRESET_TOP_LEFT); } break; case ANCHOR_ALIGN_TOP_RIGHT: { - _set_anchor(ANCHOR_END, ANCHOR_BEGIN, ANCHOR_END, ANCHOR_BEGIN); + _set_anchors_preset(PRESET_TOP_RIGHT); } break; case ANCHOR_ALIGN_BOTTOM_LEFT: { - _set_anchor(ANCHOR_BEGIN, ANCHOR_END, ANCHOR_BEGIN, ANCHOR_END); + _set_anchors_preset(PRESET_BOTTOM_LEFT); } break; case ANCHOR_ALIGN_BOTTOM_RIGHT: { - _set_anchor(ANCHOR_END, ANCHOR_END, ANCHOR_END, ANCHOR_END); + _set_anchors_preset(PRESET_BOTTOM_RIGHT); } break; case ANCHOR_ALIGN_CENTER_LEFT: { - _set_anchor(ANCHOR_BEGIN, ANCHOR_CENTER, ANCHOR_BEGIN, ANCHOR_CENTER); + _set_anchors_preset(PRESET_CENTER_LEFT); } break; case ANCHOR_ALIGN_CENTER_RIGHT: { - - _set_anchor(ANCHOR_END, ANCHOR_CENTER, ANCHOR_END, ANCHOR_CENTER); + _set_anchors_preset(PRESET_CENTER_RIGHT); } break; case ANCHOR_ALIGN_CENTER_TOP: { - _set_anchor(ANCHOR_CENTER, ANCHOR_BEGIN, ANCHOR_CENTER, ANCHOR_BEGIN); + _set_anchors_preset(PRESET_CENTER_TOP); } break; case ANCHOR_ALIGN_CENTER_BOTTOM: { - _set_anchor(ANCHOR_CENTER, ANCHOR_END, ANCHOR_CENTER, ANCHOR_END); + _set_anchors_preset(PRESET_CENTER_BOTTOM); } break; case ANCHOR_ALIGN_CENTER: { - _set_anchor(ANCHOR_CENTER, ANCHOR_CENTER, ANCHOR_CENTER, ANCHOR_CENTER); + _set_anchors_preset(PRESET_CENTER); } break; case ANCHOR_ALIGN_TOP_WIDE: { - _set_anchor(ANCHOR_BEGIN, ANCHOR_BEGIN, ANCHOR_END, ANCHOR_BEGIN); + _set_anchors_preset(PRESET_TOP_WIDE); } break; case ANCHOR_ALIGN_LEFT_WIDE: { - _set_anchor(ANCHOR_BEGIN, ANCHOR_BEGIN, ANCHOR_BEGIN, ANCHOR_END); + _set_anchors_preset(PRESET_LEFT_WIDE); } break; case ANCHOR_ALIGN_RIGHT_WIDE: { - _set_anchor(ANCHOR_END, ANCHOR_BEGIN, ANCHOR_END, ANCHOR_END); + _set_anchors_preset(PRESET_RIGHT_WIDE); } break; case ANCHOR_ALIGN_BOTTOM_WIDE: { - _set_anchor(ANCHOR_BEGIN, ANCHOR_END, ANCHOR_END, ANCHOR_END); + _set_anchors_preset(PRESET_BOTTOM_WIDE); } break; case ANCHOR_ALIGN_VCENTER_WIDE: { - _set_anchor(ANCHOR_CENTER, ANCHOR_BEGIN, ANCHOR_CENTER, ANCHOR_END); + _set_anchors_preset(PRESET_VCENTER_WIDE); } break; case ANCHOR_ALIGN_HCENTER_WIDE: { - _set_anchor(ANCHOR_BEGIN, ANCHOR_CENTER, ANCHOR_END, ANCHOR_CENTER); + _set_anchors_preset(PRESET_HCENTER_WIDE); } break; case ANCHOR_ALIGN_WIDE: { - _set_anchor(ANCHOR_BEGIN, ANCHOR_BEGIN, ANCHOR_END, ANCHOR_END); + _set_anchors_preset(PRESET_WIDE); } break; case ANCHOR_ALIGN_WIDE_FIT: { _set_full_rect(); @@ -3372,7 +3611,7 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { dialog_val = memnew(SpinBox); dialog_val->set_anchor(MARGIN_RIGHT, ANCHOR_END); dialog_val->set_begin(Point2(15, 25)); - dialog_val->set_end(Point2(10, 25)); + dialog_val->set_end(Point2(-10, 25)); value_dialog->add_child(dialog_val); dialog_val->connect("value_changed", this, "_dialog_value_changed"); select_sb = Ref<StyleBoxTexture>(memnew(StyleBoxTexture)); diff --git a/editor/plugins/canvas_item_editor_plugin.h b/editor/plugins/canvas_item_editor_plugin.h index 4383be251c..9b027fda60 100644 --- a/editor/plugins/canvas_item_editor_plugin.h +++ b/editor/plugins/canvas_item_editor_plugin.h @@ -57,6 +57,7 @@ public: float prev_rot; Rect2 prev_rect; Vector2 prev_pivot; + float prev_anchors[4]; CanvasItemEditorSelectedItem() { prev_rot = 0; } }; @@ -143,11 +144,15 @@ class CanvasItemEditor : public VBoxContainer { DRAG_BOTTOM_RIGHT, DRAG_BOTTOM, DRAG_BOTTOM_LEFT, + DRAG_ANCHOR_TOP_LEFT, + DRAG_ANCHOR_TOP_RIGHT, + DRAG_ANCHOR_BOTTOM_RIGHT, + DRAG_ANCHOR_BOTTOM_LEFT, + DRAG_ANCHOR_ALL, DRAG_ALL, DRAG_ROTATE, DRAG_PIVOT, DRAG_NODE_2D, - }; enum KeyMoveMODE { @@ -300,6 +305,7 @@ class CanvasItemEditor : public VBoxContainer { #endif Ref<StyleBoxTexture> select_sb; Ref<Texture> select_handle; + Ref<Texture> anchor_handle; int handle_len; bool _is_part_of_subscene(CanvasItem *p_item); @@ -325,8 +331,13 @@ class CanvasItemEditor : public VBoxContainer { void _key_move(const Vector2 &p_dir, bool p_snap, KeyMoveMODE p_move_mode); void _list_select(const Ref<InputEventMouseButton> &b); - DragType _find_drag_type(const Point2 &p_click, Vector2 &r_point); + DragType _get_resize_handle_drag_type(const Point2 &p_click, Vector2 &r_point); void _prepare_drag(const Point2 &p_click_pos); + DragType _get_anchor_handle_drag_type(const Point2 &p_click, Vector2 &r_point); + + float _anchor_snap(float anchor, bool *snapped = NULL, float p_opposite_anchor = -1); + Vector2 _anchor_to_position(Control *p_control, Vector2 anchor); + Vector2 _position_to_anchor(Control *p_control, Vector2 position); void _popup_callback(int p_op); bool updating_scroll; @@ -355,12 +366,14 @@ class CanvasItemEditor : public VBoxContainer { void _unhandled_key_input(const Ref<InputEvent> &p_ev); + void _draw_percentage_at_position(float p_value, Point2 p_position, Margin p_side); + void _viewport_gui_input(const Ref<InputEvent> &p_event); void _viewport_draw(); void _focus_selection(int p_op); - void _set_anchor(Control::AnchorType p_left, Control::AnchorType p_top, Control::AnchorType p_right, Control::AnchorType p_bottom); + void _set_anchors_preset(Control::LayoutPreset p_preset); void _set_full_rect(); HSplitContainer *palette_split; diff --git a/editor/plugins/cube_grid_theme_editor_plugin.cpp b/editor/plugins/cube_grid_theme_editor_plugin.cpp index 17149ef868..b26b2aec4f 100644 --- a/editor/plugins/cube_grid_theme_editor_plugin.cpp +++ b/editor/plugins/cube_grid_theme_editor_plugin.cpp @@ -29,7 +29,6 @@ /*************************************************************************/ #include "cube_grid_theme_editor_plugin.h" -#if 0 #include "editor/editor_node.h" #include "editor/editor_settings.h" #include "main/main.h" @@ -39,214 +38,236 @@ #include "scene/main/viewport.h" #include "scene/resources/packed_scene.h" -void MeshLibraryEditor::edit(const Ref<MeshLibrary>& p_theme) { +void MeshLibraryEditor::edit(const Ref<MeshLibrary> &p_theme) { - theme=p_theme; + theme = p_theme; if (theme.is_valid()) - menu->get_popup()->set_item_disabled(menu->get_popup()->get_item_index(MENU_OPTION_UPDATE_FROM_SCENE),!theme->has_meta("_editor_source_scene")); - + menu->get_popup()->set_item_disabled(menu->get_popup()->get_item_index(MENU_OPTION_UPDATE_FROM_SCENE), !theme->has_meta("_editor_source_scene")); } void MeshLibraryEditor::_menu_confirm() { + switch (option) { - switch(option) { - - case MENU_OPTION_REMOVE_ITEM: { + case MENU_OPTION_REMOVE_ITEM: { - theme->remove_item(to_erase); - } break; - case MENU_OPTION_UPDATE_FROM_SCENE: { + theme->remove_item(to_erase); + } break; + case MENU_OPTION_UPDATE_FROM_SCENE: { String existing = theme->get_meta("_editor_source_scene"); - ERR_FAIL_COND(existing==""); + ERR_FAIL_COND(existing == ""); _import_scene_cbk(existing); - } break; - default: {}; + } break; + default: {}; } - } - void MeshLibraryEditor::_import_scene(Node *p_scene, Ref<MeshLibrary> p_library, bool p_merge) { if (!p_merge) p_library->clear(); - - for(int i=0;i<p_scene->get_child_count();i++) { - + for (int i = 0; i < p_scene->get_child_count(); i++) { Node *child = p_scene->get_child(i); if (!child->cast_to<MeshInstance>()) { - if (child->get_child_count()>0) { - child=child->get_child(0); + if (child->get_child_count() > 0) { + child = child->get_child(0); if (!child->cast_to<MeshInstance>()) { continue; } } else continue; - - } MeshInstance *mi = child->cast_to<MeshInstance>(); - Ref<Mesh> mesh=mi->get_mesh(); + Ref<Mesh> mesh = mi->get_mesh(); if (mesh.is_null()) - continue; + continue; int id = p_library->find_item_name(mi->get_name()); - if (id<0) { + if (id < 0) { - id=p_library->get_last_unused_item_id(); + id = p_library->get_last_unused_item_id(); p_library->create_item(id); - p_library->set_item_name(id,mi->get_name()); + p_library->set_item_name(id, mi->get_name()); } - - p_library->set_item_mesh(id,mesh); + p_library->set_item_mesh(id, mesh); Ref<Shape> collision; + for (int j = 0; j < mi->get_child_count(); j++) { - for(int j=0;j<mi->get_child_count();j++) { -#if 1 Node *child2 = mi->get_child(j); if (!child2->cast_to<StaticBody>()) continue; + StaticBody *sb = child2->cast_to<StaticBody>(); - if (sb->get_shape_count()==0) - continue; - collision=sb->get_shape(0); - if (!collision.is_null()) - break; -#endif + List<uint32_t> shapes; + sb->get_shape_owners(&shapes); + + for (List<uint32_t>::Element *E = shapes.front(); E; E = E->next()) { + if (sb->is_shape_owner_disabled(E->get())) continue; + + //Transform shape_transform = sb->shape_owner_get_transform(E->get()); + + //shape_transform.set_origin(shape_transform.get_origin() - phys_offset); + + for (int k = 0; k < sb->shape_owner_get_shape_count(E->get()); k++) { + + collision = sb->shape_owner_get_shape(E->get(), k); + if (collision.is_valid()) + break; + /* TileSet::ShapeData shape_data; + shape_data.shape = shape; + shape_data.shape_transform = shape_transform; + shape_data.one_way_collision = one_way; + collisions.push_back(shape_data);*/ + } + if (collision.is_valid()) + break; + } } if (!collision.is_null()) { - p_library->set_item_shape(id,collision); + p_library->set_item_shape(id, collision); } Ref<NavigationMesh> navmesh; - for(int j=0;j<mi->get_child_count();j++) { - Node *child2 = mi->get_child(j); - if (!child2->cast_to<NavigationMeshInstance>()) - continue; - NavigationMeshInstance *sb = child2->cast_to<NavigationMeshInstance>(); - navmesh=sb->get_navigation_mesh(); - if (!navmesh.is_null()) - break; + for (int j = 0; j < mi->get_child_count(); j++) { + Node *child2 = mi->get_child(j); + if (!child2->cast_to<NavigationMeshInstance>()) + continue; + NavigationMeshInstance *sb = child2->cast_to<NavigationMeshInstance>(); + navmesh = sb->get_navigation_mesh(); + if (!navmesh.is_null()) + break; } - if(!navmesh.is_null()){ + if (!navmesh.is_null()) { p_library->set_item_navmesh(id, navmesh); } - } - - //generate previews! - - if (1) { - Vector<int> ids = p_library->get_item_list(); - RID vp = VS::get_singleton()->viewport_create(); - VS::ViewportRect vr; - vr.x=0; - vr.y=0; - vr.width=EditorSettings::get_singleton()->get("editors/grid_map/preview_size"); - vr.height=EditorSettings::get_singleton()->get("editors/grid_map/preview_size"); - VS::get_singleton()->viewport_set_rect(vp,vr); - VS::get_singleton()->viewport_set_as_render_target(vp,true); - VS::get_singleton()->viewport_set_render_target_update_mode(vp,VS::RENDER_TARGET_UPDATE_ALWAYS); - RID scen = VS::get_singleton()->scenario_create(); - VS::get_singleton()->viewport_set_scenario(vp,scen); - RID cam = VS::get_singleton()->camera_create(); - VS::get_singleton()->camera_set_transform(cam, Transform() ); - VS::get_singleton()->viewport_attach_camera(vp,cam); - RID light = VS::get_singleton()->light_create(VS::LIGHT_DIRECTIONAL); - RID lightinst = VS::get_singleton()->instance_create2(light,scen); - VS::get_singleton()->camera_set_orthogonal(cam,1.0,0.01,1000.0); - - - EditorProgress ep("mlib",TTR("Creating Mesh Library"),ids.size()); - - for(int i=0;i<ids.size();i++) { - - int id=ids[i]; + } + + //generate previews! + + if (1) { + Vector<int> ids = p_library->get_item_list(); + RID vp = VS::get_singleton()->viewport_create(); + int size = EditorSettings::get_singleton()->get("editors/grid_map/preview_size"); + + RID scenario = VS::get_singleton()->scenario_create(); + + RID viewport = VS::get_singleton()->viewport_create(); + VS::get_singleton()->viewport_set_update_mode(viewport, VS::VIEWPORT_UPDATE_ALWAYS); + VS::get_singleton()->viewport_set_vflip(viewport, true); + VS::get_singleton()->viewport_set_scenario(viewport, scenario); + VS::get_singleton()->viewport_set_size(viewport, size, size); + VS::get_singleton()->viewport_set_transparent_background(viewport, true); + VS::get_singleton()->viewport_set_active(viewport, true); + RID viewport_texture = VS::get_singleton()->viewport_get_texture(viewport); + + RID camera = VS::get_singleton()->camera_create(); + VS::get_singleton()->viewport_attach_camera(viewport, camera); + VS::get_singleton()->camera_set_transform(camera, Transform(Basis(), Vector3(0, 0, 3))); + //VS::get_singleton()->camera_set_perspective(camera,45,0.1,10); + VS::get_singleton()->camera_set_orthogonal(camera, 1.0, 0.01, 1000.0); + + RID light = VS::get_singleton()->light_create(VS::LIGHT_DIRECTIONAL); + RID light_instance = VS::get_singleton()->instance_create2(light, scenario); + VS::get_singleton()->instance_set_transform(light_instance, Transform().looking_at(Vector3(-1, -1, -1), Vector3(0, 1, 0))); + + RID light2 = VS::get_singleton()->light_create(VS::LIGHT_DIRECTIONAL); + VS::get_singleton()->light_set_color(light2, Color(0.7, 0.7, 0.7)); + //VS::get_singleton()->light_set_color(light2, VS::LIGHT_COLOR_SPECULAR, Color(0.0, 0.0, 0.0)); + RID light_instance2 = VS::get_singleton()->instance_create2(light2, scenario); + + VS::get_singleton()->instance_set_transform(light_instance2, Transform().looking_at(Vector3(0, 1, 0), Vector3(0, 0, 1))); + + //sphere = VS::get_singleton()->mesh_create(); + RID mesh_instance = VS::get_singleton()->instance_create(); + VS::get_singleton()->instance_set_scenario(mesh_instance, scenario); + + EditorProgress ep("mlib", TTR("Creating Mesh Library"), ids.size()); + + for (int i = 0; i < ids.size(); i++) { + + int id = ids[i]; Ref<Mesh> mesh = p_library->get_item_mesh(id); if (!mesh.is_valid()) continue; - AABB aabb= mesh->get_aabb(); - print_line("aabb: "+aabb); - Vector3 ofs = aabb.pos + aabb.size*0.5; - aabb.pos-=ofs; + Rect3 aabb = mesh->get_aabb(); + print_line("aabb: " + aabb); + Vector3 ofs = aabb.position + aabb.size * 0.5; + aabb.position -= ofs; Transform xform; - xform.basis=Matrix3().rotated(Vector3(0,1,0),-Math_PI*0.25); - xform.basis = Matrix3().rotated(Vector3(1,0,0),Math_PI*0.25)*xform.basis; - AABB rot_aabb = xform.xform(aabb); - print_line("rot_aabb: "+rot_aabb); - float m = MAX(rot_aabb.size.x,rot_aabb.size.y)*0.5; - if (m==0) + xform.basis = Basis().rotated(Vector3(0, 1, 0), -Math_PI * 0.25); + xform.basis = Basis().rotated(Vector3(1, 0, 0), Math_PI * 0.25) * xform.basis; + Rect3 rot_aabb = xform.xform(aabb); + print_line("rot_aabb: " + rot_aabb); + float m = MAX(rot_aabb.size.x, rot_aabb.size.y) * 0.5; + if (m == 0) continue; - m=1.0/m; - m*=0.5; - print_line("scale: "+rtos(m)); - xform.basis.scale(Vector3(m,m,m)); - xform.origin=-xform.basis.xform(ofs); //-ofs*m; - xform.origin.z-=rot_aabb.size.z*2; - RID inst = VS::get_singleton()->instance_create2(mesh->get_rid(),scen); - VS::get_singleton()->instance_set_transform(inst,xform); - ep.step(TTR("Thumbnail.."),i); - VS::get_singleton()->viewport_queue_screen_capture(vp); + m = 1.0 / m; + m *= 0.5; + print_line("scale: " + rtos(m)); + xform.basis.scale(Vector3(m, m, m)); + xform.origin = -xform.basis.xform(ofs); //-ofs*m; + xform.origin.z -= rot_aabb.size.z * 2; + RID inst = VS::get_singleton()->instance_create2(mesh->get_rid(), scenario); + VS::get_singleton()->instance_set_transform(inst, xform); + ep.step(TTR("Thumbnail.."), i); + Main::iteration(); Main::iteration(); - Image img = VS::get_singleton()->viewport_get_screen_capture(vp); - ERR_CONTINUE(img.empty()); - Ref<ImageTexture> it( memnew( ImageTexture )); + Ref<Image> img = VS::get_singleton()->texture_get_data(viewport_texture); + ERR_CONTINUE(!img.is_valid() || img->empty()); + Ref<ImageTexture> it(memnew(ImageTexture)); it->create_from_image(img); - p_library->set_item_preview(id,it); + p_library->set_item_preview(id, it); //print_line("loaded image, size: "+rtos(m)+" dist: "+rtos(dist)+" empty?"+itos(img.empty())+" w: "+itos(it->get_width())+" h: "+itos(it->get_height())); VS::get_singleton()->free(inst); - } + } - VS::get_singleton()->free(lightinst); - VS::get_singleton()->free(light); - VS::get_singleton()->free(vp); - VS::get_singleton()->free(cam); - VS::get_singleton()->free(scen); + VS::get_singleton()->free(mesh_instance); + VS::get_singleton()->free(viewport); + VS::get_singleton()->free(light); + VS::get_singleton()->free(light_instance); + VS::get_singleton()->free(light2); + VS::get_singleton()->free(light_instance2); + VS::get_singleton()->free(camera); + VS::get_singleton()->free(scenario); } - - } - -void MeshLibraryEditor::_import_scene_cbk(const String& p_str) { - +void MeshLibraryEditor::_import_scene_cbk(const String &p_str) { print_line("Impot Callback!"); - Ref<PackedScene> ps = ResourceLoader::load(p_str,"PackedScene"); + Ref<PackedScene> ps = ResourceLoader::load(p_str, "PackedScene"); ERR_FAIL_COND(ps.is_null()); Node *scene = ps->instance(); - _import_scene(scene,theme,option==MENU_OPTION_UPDATE_FROM_SCENE); + _import_scene(scene, theme, option == MENU_OPTION_UPDATE_FROM_SCENE); memdelete(scene); - theme->set_meta("_editor_source_scene",p_str); - menu->get_popup()->set_item_disabled(menu->get_popup()->get_item_index(MENU_OPTION_UPDATE_FROM_SCENE),false); - + theme->set_meta("_editor_source_scene", p_str); + menu->get_popup()->set_item_disabled(menu->get_popup()->get_item_index(MENU_OPTION_UPDATE_FROM_SCENE), false); } -Error MeshLibraryEditor::update_library_file(Node *p_base_scene, Ref<MeshLibrary> ml,bool p_merge) { +Error MeshLibraryEditor::update_library_file(Node *p_base_scene, Ref<MeshLibrary> ml, bool p_merge) { - _import_scene(p_base_scene,ml,p_merge); + _import_scene(p_base_scene, ml, p_merge); return OK; } - void MeshLibraryEditor::_menu_cbk(int p_option) { - option=p_option; - switch(p_option) { + option = p_option; + switch (p_option) { case MENU_OPTION_ADD_ITEM: { @@ -255,86 +276,84 @@ void MeshLibraryEditor::_menu_cbk(int p_option) { case MENU_OPTION_REMOVE_ITEM: { String p = editor->get_property_editor()->get_selected_path(); - if (p.begins_with("/MeshLibrary/item") && p.get_slice_count("/")>=3) { + if (p.begins_with("/MeshLibrary/item") && p.get_slice_count("/") >= 3) { - to_erase = p.get_slice("/",3).to_int(); - cd->set_text(vformat(TTR("Remove item %d?"),to_erase)); - cd->popup_centered(Size2(300,60)); + to_erase = p.get_slice("/", 3).to_int(); + cd->set_text(vformat(TTR("Remove item %d?"), to_erase)); + cd->popup_centered(Size2(300, 60)); } } break; case MENU_OPTION_IMPORT_FROM_SCENE: { file->popup_centered_ratio(); } break; - case MENU_OPTION_UPDATE_FROM_SCENE: { + case MENU_OPTION_UPDATE_FROM_SCENE: { - cd->set_text("Update from existing scene?:\n"+String(theme->get_meta("_editor_source_scene"))); - cd->popup_centered(Size2(500,60)); - } break; + cd->set_text("Update from existing scene?:\n" + String(theme->get_meta("_editor_source_scene"))); + cd->popup_centered(Size2(500, 60)); + } break; } } - void MeshLibraryEditor::_bind_methods() { - ClassDB::bind_method("_menu_cbk",&MeshLibraryEditor::_menu_cbk); - ClassDB::bind_method("_menu_confirm",&MeshLibraryEditor::_menu_confirm); - ClassDB::bind_method("_import_scene_cbk",&MeshLibraryEditor::_import_scene_cbk); + ClassDB::bind_method("_menu_cbk", &MeshLibraryEditor::_menu_cbk); + ClassDB::bind_method("_menu_confirm", &MeshLibraryEditor::_menu_confirm); + ClassDB::bind_method("_import_scene_cbk", &MeshLibraryEditor::_import_scene_cbk); } MeshLibraryEditor::MeshLibraryEditor(EditorNode *p_editor) { - file = memnew( EditorFileDialog ); + file = memnew(EditorFileDialog); file->set_mode(EditorFileDialog::MODE_OPEN_FILE); //not for now? List<String> extensions; - ResourceLoader::get_recognized_extensions_for_type("PackedScene",&extensions); + ResourceLoader::get_recognized_extensions_for_type("PackedScene", &extensions); file->clear_filters(); file->set_title(TTR("Import Scene")); - for(int i=0;i<extensions.size();i++) { + for (int i = 0; i < extensions.size(); i++) { - file->add_filter("*."+extensions[i]+" ; "+extensions[i].to_upper()); + file->add_filter("*." + extensions[i] + " ; " + extensions[i].to_upper()); } add_child(file); - file->connect("file_selected",this,"_import_scene_cbk"); + file->connect("file_selected", this, "_import_scene_cbk"); - Panel *panel = memnew( Panel ); + Panel *panel = memnew(Panel); panel->set_area_as_parent_rect(); add_child(panel); - MenuButton * options = memnew( MenuButton ); + MenuButton *options = memnew(MenuButton); panel->add_child(options); - options->set_position(Point2(1,1)); + options->set_position(Point2(1, 1)); options->set_text("Theme"); - options->get_popup()->add_item(TTR("Add Item"),MENU_OPTION_ADD_ITEM); - options->get_popup()->add_item(TTR("Remove Selected Item"),MENU_OPTION_REMOVE_ITEM); + options->get_popup()->add_item(TTR("Add Item"), MENU_OPTION_ADD_ITEM); + options->get_popup()->add_item(TTR("Remove Selected Item"), MENU_OPTION_REMOVE_ITEM); options->get_popup()->add_separator(); - options->get_popup()->add_item(TTR("Import from Scene"),MENU_OPTION_IMPORT_FROM_SCENE); - options->get_popup()->add_item(TTR("Update from Scene"),MENU_OPTION_UPDATE_FROM_SCENE); - options->get_popup()->set_item_disabled(options->get_popup()->get_item_index(MENU_OPTION_UPDATE_FROM_SCENE),true); - options->get_popup()->connect("id_pressed", this,"_menu_cbk"); - menu=options; - editor=p_editor; + options->get_popup()->add_item(TTR("Import from Scene"), MENU_OPTION_IMPORT_FROM_SCENE); + options->get_popup()->add_item(TTR("Update from Scene"), MENU_OPTION_UPDATE_FROM_SCENE); + options->get_popup()->set_item_disabled(options->get_popup()->get_item_index(MENU_OPTION_UPDATE_FROM_SCENE), true); + options->get_popup()->connect("id_pressed", this, "_menu_cbk"); + menu = options; + editor = p_editor; cd = memnew(ConfirmationDialog); add_child(cd); - cd->get_ok()->connect("pressed", this,"_menu_confirm"); - + cd->get_ok()->connect("pressed", this, "_menu_confirm"); } void MeshLibraryEditorPlugin::edit(Object *p_node) { if (p_node && p_node->cast_to<MeshLibrary>()) { - theme_editor->edit( p_node->cast_to<MeshLibrary>() ); + theme_editor->edit(p_node->cast_to<MeshLibrary>()); theme_editor->show(); } else theme_editor->hide(); } -bool MeshLibraryEditorPlugin::handles(Object *p_node) const{ +bool MeshLibraryEditorPlugin::handles(Object *p_node) const { - return p_node->is_type("MeshLibrary"); + return p_node->is_class("MeshLibrary"); } -void MeshLibraryEditorPlugin::make_visible(bool p_visible){ +void MeshLibraryEditorPlugin::make_visible(bool p_visible) { if (p_visible) theme_editor->show(); @@ -344,15 +363,13 @@ void MeshLibraryEditorPlugin::make_visible(bool p_visible){ MeshLibraryEditorPlugin::MeshLibraryEditorPlugin(EditorNode *p_node) { - EDITOR_DEF("editors/grid_map/preview_size",64); - theme_editor = memnew( MeshLibraryEditor(p_node) ); + EDITOR_DEF("editors/grid_map/preview_size", 64); + theme_editor = memnew(MeshLibraryEditor(p_node)); p_node->get_viewport()->add_child(theme_editor); theme_editor->set_area_as_parent_rect(); - theme_editor->set_anchor( MARGIN_RIGHT, Control::ANCHOR_END ); - theme_editor->set_anchor( MARGIN_BOTTOM, Control::ANCHOR_BEGIN ); - theme_editor->set_end( Point2(0,22) ); + theme_editor->set_anchor(MARGIN_RIGHT, Control::ANCHOR_END); + theme_editor->set_anchor(MARGIN_BOTTOM, Control::ANCHOR_BEGIN); + theme_editor->set_end(Point2(0, 22)); theme_editor->hide(); - } -#endif diff --git a/editor/plugins/cube_grid_theme_editor_plugin.h b/editor/plugins/cube_grid_theme_editor_plugin.h index ed5875a999..6fe5fc4235 100644 --- a/editor/plugins/cube_grid_theme_editor_plugin.h +++ b/editor/plugins/cube_grid_theme_editor_plugin.h @@ -33,10 +33,9 @@ #include "editor/editor_node.h" #include "scene/resources/mesh_library.h" -#if 0 class MeshLibraryEditor : public Control { - GDCLASS( MeshLibraryEditor, Control ); + GDCLASS(MeshLibraryEditor, Control); Ref<MeshLibrary> theme; @@ -55,7 +54,7 @@ class MeshLibraryEditor : public Control { }; int option; - void _import_scene_cbk(const String& p_str); + void _import_scene_cbk(const String &p_str); void _menu_cbk(int p_option); void _menu_confirm(); @@ -63,25 +62,22 @@ class MeshLibraryEditor : public Control { protected: static void _bind_methods(); -public: - void edit(const Ref<MeshLibrary>& p_theme); - static Error update_library_file(Node *p_base_scene, Ref<MeshLibrary> ml,bool p_merge=true); +public: + void edit(const Ref<MeshLibrary> &p_theme); + static Error update_library_file(Node *p_base_scene, Ref<MeshLibrary> ml, bool p_merge = true); MeshLibraryEditor(EditorNode *p_editor); }; - - class MeshLibraryEditorPlugin : public EditorPlugin { - GDCLASS( MeshLibraryEditorPlugin, EditorPlugin ); + GDCLASS(MeshLibraryEditorPlugin, EditorPlugin); MeshLibraryEditor *theme_editor; EditorNode *editor; public: - virtual String get_name() const { return "MeshLibrary"; } bool has_main_screen() const { return false; } virtual void edit(Object *p_node); @@ -89,8 +85,6 @@ public: virtual void make_visible(bool p_visible); MeshLibraryEditorPlugin(EditorNode *p_node); - }; #endif // CUBE_GRID_THEME_EDITOR_PLUGIN_H -#endif diff --git a/editor/plugins/multimesh_editor_plugin.cpp b/editor/plugins/multimesh_editor_plugin.cpp index 9520cc5297..a9689cce56 100644 --- a/editor/plugins/multimesh_editor_plugin.cpp +++ b/editor/plugins/multimesh_editor_plugin.cpp @@ -381,7 +381,7 @@ MultiMeshEditor::MultiMeshEditor() { populate_amount = memnew(SpinBox); populate_amount->set_anchor(MARGIN_RIGHT, ANCHOR_END); populate_amount->set_begin(Point2(20, 232)); - populate_amount->set_end(Point2(5, 237)); + populate_amount->set_end(Point2(-5, 237)); populate_amount->set_min(1); populate_amount->set_max(65536); populate_amount->set_value(128); diff --git a/editor/plugins/resource_preloader_editor_plugin.cpp b/editor/plugins/resource_preloader_editor_plugin.cpp index 2703da12fe..ccefbc1843 100644 --- a/editor/plugins/resource_preloader_editor_plugin.cpp +++ b/editor/plugins/resource_preloader_editor_plugin.cpp @@ -362,7 +362,7 @@ void ResourcePreloaderEditor::_bind_methods() { ResourcePreloaderEditor::ResourcePreloaderEditor() { - //add_style_override("panel", get_stylebox("panel","Panel")); + //add_style_override("panel", EditorNode::get_singleton()->get_gui_base()->get_stylebox("panel","Panel")); VBoxContainer *vbc = memnew(VBoxContainer); add_child(vbc); diff --git a/editor/plugins/sample_editor_plugin.cpp b/editor/plugins/sample_editor_plugin.cpp index 739a8abb53..1d6417e2d5 100644 --- a/editor/plugins/sample_editor_plugin.cpp +++ b/editor/plugins/sample_editor_plugin.cpp @@ -360,20 +360,20 @@ SampleEditor::SampleEditor() { player = memnew(SamplePlayer); add_child(player); - add_style_override("panel", get_stylebox("panel","Panel")); + add_style_override("panel", EditorNode::get_singleton()->get_gui_base()->get_stylebox("panel","Panel")); library = Ref<SampleLibrary>(memnew(SampleLibrary)); player->set_sample_library(library); sample_texframe = memnew( TextureRect ); add_child(sample_texframe); sample_texframe->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_BEGIN,5); - sample_texframe->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_END,5); + sample_texframe->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_END,-5); sample_texframe->set_anchor_and_margin(MARGIN_TOP,ANCHOR_BEGIN,30); - sample_texframe->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_END,5); + sample_texframe->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_END,-5); info_label = memnew( Label ); sample_texframe->add_child(info_label); info_label->set_area_as_parent_rect(); - info_label->set_anchor_and_margin(MARGIN_TOP,ANCHOR_END,15); + info_label->set_anchor_and_margin(MARGIN_TOP,ANCHOR_END,-15); info_label->set_margin(MARGIN_BOTTOM,4); info_label->set_margin(MARGIN_RIGHT,4); info_label->set_align(Label::ALIGN_RIGHT); diff --git a/editor/plugins/sample_library_editor_plugin.cpp b/editor/plugins/sample_library_editor_plugin.cpp index 5ccfde15ff..3deb634491 100644 --- a/editor/plugins/sample_library_editor_plugin.cpp +++ b/editor/plugins/sample_library_editor_plugin.cpp @@ -432,7 +432,7 @@ SampleLibraryEditor::SampleLibraryEditor() { player = memnew(SamplePlayer); add_child(player); - add_style_override("panel", get_stylebox("panel","Panel")); + add_style_override("panel", EditorNode::get_singleton()->get_gui_base()->get_stylebox("panel","Panel")); load = memnew( Button ); @@ -452,9 +452,9 @@ SampleLibraryEditor::SampleLibraryEditor() { tree->set_columns(6); add_child(tree); tree->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_BEGIN,5); - tree->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_END,5); + tree->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_END,-5); tree->set_anchor_and_margin(MARGIN_TOP,ANCHOR_BEGIN,30); - tree->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_END,5); + tree->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_END,-5); tree->set_column_titles_visible(true); tree->set_column_title(0,TTR("Name")); tree->set_column_title(1,TTR("Preview")); diff --git a/editor/plugins/sample_player_editor_plugin.cpp b/editor/plugins/sample_player_editor_plugin.cpp index 25f1fe9e17..ea9b646a9b 100644 --- a/editor/plugins/sample_player_editor_plugin.cpp +++ b/editor/plugins/sample_player_editor_plugin.cpp @@ -120,8 +120,8 @@ SamplePlayerEditor::SamplePlayerEditor() { play->set_position(Point2( 5, 5 )); play->set_toggle_mode(true); - play->set_anchor_and_margin(MARGIN_LEFT,Control::ANCHOR_END,250); - play->set_anchor_and_margin(MARGIN_RIGHT,Control::ANCHOR_END,230); + play->set_anchor_and_margin(MARGIN_LEFT,Control::ANCHOR_END,-250); + play->set_anchor_and_margin(MARGIN_RIGHT,Control::ANCHOR_END,-230); play->set_anchor_and_margin(MARGIN_TOP,Control::ANCHOR_BEGIN,0); play->set_anchor_and_margin(MARGIN_BOTTOM,Control::ANCHOR_BEGIN,0); @@ -131,15 +131,15 @@ SamplePlayerEditor::SamplePlayerEditor() { stop->set_position(Point2( 35, 5 )); stop->set_toggle_mode(true); - stop->set_anchor_and_margin(MARGIN_LEFT,Control::ANCHOR_END,220); - stop->set_anchor_and_margin(MARGIN_RIGHT,Control::ANCHOR_END,200); + stop->set_anchor_and_margin(MARGIN_LEFT,Control::ANCHOR_END,-220); + stop->set_anchor_and_margin(MARGIN_RIGHT,Control::ANCHOR_END,-200); stop->set_anchor_and_margin(MARGIN_TOP,Control::ANCHOR_BEGIN,0); stop->set_anchor_and_margin(MARGIN_BOTTOM,Control::ANCHOR_BEGIN,0); add_child(stop); samples = memnew( OptionButton ); - samples->set_anchor_and_margin(MARGIN_LEFT,Control::ANCHOR_END,190); - samples->set_anchor_and_margin(MARGIN_RIGHT,Control::ANCHOR_END,5); + samples->set_anchor_and_margin(MARGIN_LEFT,Control::ANCHOR_END,-190); + samples->set_anchor_and_margin(MARGIN_RIGHT,Control::ANCHOR_END,-5); samples->set_anchor_and_margin(MARGIN_TOP,Control::ANCHOR_BEGIN,0); samples->set_anchor_and_margin(MARGIN_BOTTOM,Control::ANCHOR_BEGIN,0); add_child(samples); @@ -182,7 +182,7 @@ SamplePlayerEditorPlugin::SamplePlayerEditorPlugin(EditorNode *p_node) { sample_player_editor->set_anchor(MARGIN_LEFT,Control::ANCHOR_END); sample_player_editor->set_anchor(MARGIN_RIGHT,Control::ANCHOR_END); - sample_player_editor->set_margin(MARGIN_LEFT,250); + sample_player_editor->set_margin(MARGIN_LEFT,-250); sample_player_editor->set_margin(MARGIN_RIGHT,0); sample_player_editor->set_margin(MARGIN_TOP,0); sample_player_editor->set_margin(MARGIN_BOTTOM,10); diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp index 65e997f9c0..5faacf7a67 100644 --- a/editor/plugins/spatial_editor_plugin.cpp +++ b/editor/plugins/spatial_editor_plugin.cpp @@ -267,6 +267,7 @@ ObjectID SpatialEditorViewport::_select_ray(const Point2 &p_pos, bool p_append, int selected_handle = -1; Vector<Spatial *> subscenes = Vector<Spatial *>(); + Vector<Vector3> subscenes_positions = Vector<Vector3>(); for (int i = 0; i < instances.size(); i++) { @@ -284,13 +285,16 @@ ObjectID SpatialEditorViewport::_select_ray(const Point2 &p_pos, bool p_append, if ((!seg.is_valid()) || found_gizmos.has(seg)) { Node *subscene_candidate = spat; + Vector3 source_click_spatial_pos = spat->get_global_transform().origin; - while (subscene_candidate->get_owner() != editor->get_edited_scene()) + while ((subscene_candidate->get_owner() != NULL) && (subscene_candidate->get_owner() != editor->get_edited_scene())) subscene_candidate = subscene_candidate->get_owner(); spat = subscene_candidate->cast_to<Spatial>(); - if (spat && (spat->get_filename() != "")) + if (spat && (spat->get_filename() != "") && (subscene_candidate->get_owner() != NULL)) { subscenes.push_back(spat); + subscenes_positions.push_back(source_click_spatial_pos); + } continue; } @@ -324,7 +328,7 @@ ObjectID SpatialEditorViewport::_select_ray(const Point2 &p_pos, bool p_append, for (int idx_subscene = 0; idx_subscene < subscenes.size(); idx_subscene++) { Spatial *subscene = subscenes.get(idx_subscene); - float dist = ray.cross(subscene->get_global_transform().origin - pos).length(); + float dist = ray.cross(subscenes_positions.get(idx_subscene) - pos).length(); if ((dist < 0) || (dist > 1.2)) continue; @@ -2485,7 +2489,7 @@ SpatialEditorViewport::SpatialEditorViewport(SpatialEditor *p_spatial_editor, Ed preview_camera = memnew(Button); preview_camera->set_toggle_mode(true); - preview_camera->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_END, 90 * EDSCALE); + preview_camera->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_END, -90 * EDSCALE); preview_camera->set_anchor_and_margin(MARGIN_TOP, ANCHOR_BEGIN, 10 * EDSCALE); preview_camera->set_text("preview"); surface->add_child(preview_camera); diff --git a/editor/plugins/sprite_frames_editor_plugin.cpp b/editor/plugins/sprite_frames_editor_plugin.cpp index 6a010062f2..0f008552d0 100644 --- a/editor/plugins/sprite_frames_editor_plugin.cpp +++ b/editor/plugins/sprite_frames_editor_plugin.cpp @@ -714,7 +714,7 @@ void SpriteFramesEditor::_bind_methods() { SpriteFramesEditor::SpriteFramesEditor() { - //add_style_override("panel", get_stylebox("panel","Panel")); + //add_style_override("panel", EditorNode::get_singleton()->get_gui_base()->get_stylebox("panel","Panel")); split = memnew(HSplitContainer); add_child(split); diff --git a/editor/project_manager.cpp b/editor/project_manager.cpp index b77544befa..dc0c888eea 100644 --- a/editor/project_manager.cpp +++ b/editor/project_manager.cpp @@ -848,6 +848,7 @@ void ProjectManager::_load_recent_projects() { VBoxContainer *vb = memnew(VBoxContainer); vb->set_name("project"); + vb->set_h_size_flags(SIZE_EXPAND_FILL); hb->add_child(vb); Control *ec = memnew(Control); ec->set_custom_minimum_size(Size2(0, 1)); @@ -855,12 +856,14 @@ void ProjectManager::_load_recent_projects() { Label *title = memnew(Label(project_name)); title->add_font_override("font", gui_base->get_font("large", "Fonts")); title->add_color_override("font_color", font_color); + title->set_clip_text(true); vb->add_child(title); Label *fpath = memnew(Label(path)); fpath->set_name("path"); vb->add_child(fpath); fpath->set_modulate(Color(1, 1, 1, 0.5)); fpath->add_color_override("font_color", font_color); + fpath->set_clip_text(true); scroll_childs->add_child(hb); } diff --git a/editor/property_editor.cpp b/editor/property_editor.cpp index a262d8cd01..d6c1407b62 100644 --- a/editor/property_editor.cpp +++ b/editor/property_editor.cpp @@ -434,13 +434,13 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant:: } else if (hint == PROPERTY_HINT_EXP_EASING) { easing_draw->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_BEGIN, 5 * EDSCALE); - easing_draw->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, 5 * EDSCALE); + easing_draw->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, -5 * EDSCALE); easing_draw->set_anchor_and_margin(MARGIN_TOP, ANCHOR_BEGIN, 5 * EDSCALE); - easing_draw->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, 30 * EDSCALE); + easing_draw->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, -30 * EDSCALE); type_button->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_BEGIN, 3 * EDSCALE); - type_button->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, 3 * EDSCALE); - type_button->set_anchor_and_margin(MARGIN_TOP, ANCHOR_END, 25 * EDSCALE); - type_button->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, 7 * EDSCALE); + type_button->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, -3 * EDSCALE); + type_button->set_anchor_and_margin(MARGIN_TOP, ANCHOR_END, -25 * EDSCALE); + type_button->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, -7 * EDSCALE); type_button->set_text(TTR("Preset..")); type_button->get_popup()->clear(); type_button->get_popup()->add_item(TTR("Linear"), EASING_LINEAR); @@ -523,8 +523,8 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant:: action_buttons[0]->set_anchor(MARGIN_TOP, ANCHOR_END); action_buttons[0]->set_anchor(MARGIN_RIGHT, ANCHOR_END); action_buttons[0]->set_anchor(MARGIN_BOTTOM, ANCHOR_END); - action_buttons[0]->set_begin(Point2(70 * EDSCALE, button_margin - 5 * EDSCALE)); - action_buttons[0]->set_end(Point2(margin, margin)); + action_buttons[0]->set_begin(Point2(-70 * EDSCALE, -button_margin + 5 * EDSCALE)); + action_buttons[0]->set_end(Point2(-margin, -margin)); action_buttons[0]->set_text(TTR("Close")); action_buttons[0]->show(); @@ -2474,11 +2474,14 @@ bool PropertyEditor::_is_drop_valid(const Dictionary &p_drag_data, const Diction String allowed_type = d["hint_text"]; + print_line("allowed type " + allowed_type); + Dictionary drag_data = p_drag_data; if (drag_data.has("type") && String(drag_data["type"]) == "resource") { Ref<Resource> res = drag_data["resource"]; for (int i = 0; i < allowed_type.get_slice_count(","); i++) { String at = allowed_type.get_slice(",", i).strip_edges(); + print_line("RES vs " + at); if (res.is_valid() && ClassDB::is_parent_class(res->get_class(), at)) { return true; } @@ -2489,13 +2492,18 @@ bool PropertyEditor::_is_drop_valid(const Dictionary &p_drag_data, const Diction Vector<String> files = drag_data["files"]; + print_line("fileS: " + String(Variant(files))); if (files.size() == 1) { String file = files[0]; String ftype = EditorFileSystem::get_singleton()->get_file_type(file); + + print_line("file: " + file); + print_line("type: " + ftype); if (ftype != "") { for (int i = 0; i < allowed_type.get_slice_count(","); i++) { String at = allowed_type.get_slice(",", i).strip_edges(); + print_line("FILE vs " + at); if (ClassDB::is_parent_class(ftype, at)) { return true; } @@ -4766,12 +4774,11 @@ double PropertyValueEvaluator::eval(const String &p_text) { return _default_eval(p_text); } - ScriptInstance *script_instance = script->instance_create(this); + ScriptInstance *script_instance = script->instance_create(obj); if (!script_instance) return _default_eval(p_text); Variant::CallError call_err; - script_instance->call("set_this", obj); double result = script_instance->call("e", NULL, 0, call_err); if (call_err.error == Variant::CallError::CALL_OK) { return result; @@ -4788,7 +4795,7 @@ void PropertyValueEvaluator::edit(Object *p_obj) { } String PropertyValueEvaluator::_build_script(const String &p_text) { - String script_text = "tool\nvar this\nfunc set_this(p_this):\n\tthis=p_this\nfunc e():\n\treturn "; + String script_text = "tool\nextends Object\nfunc e():\n\treturn "; script_text += p_text.strip_edges(); script_text += "\n"; return script_text; diff --git a/main/input_default.cpp b/main/input_default.cpp index 4e2fd6f9d4..e7dc9d4b70 100644 --- a/main/input_default.cpp +++ b/main/input_default.cpp @@ -899,8 +899,14 @@ void InputDefault::joy_axis(int p_device, int p_axis, const JoyAxis &p_value) { return; } - if (ABS(joy.last_axis[p_axis]) > 0.5 && joy.last_axis[p_axis] * p_value.value < 0) { - //changed direction quickly, insert fake event to release pending inputmap actions + //when changing direction quickly, insert fake event to release pending inputmap actions + float last = joy.last_axis[p_axis]; + if (p_value.min == 0 && (last < 0.25 || last > 0.75) && (last - 0.5) * (p_value.value - 0.5) < 0) { + JoyAxis jx; + jx.min = p_value.min; + jx.value = p_value.value < 0.5 ? 0.6 : 0.4; + joy_axis(p_device, p_axis, jx); + } else if (ABS(last) > 0.5 && last * p_value.value < 0) { JoyAxis jx; jx.min = p_value.min; jx.value = p_value.value < 0 ? 0.1 : -0.1; diff --git a/main/main.cpp b/main/main.cpp index f23da57185..e00a482bde 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -1048,7 +1048,7 @@ bool Main::start() { String script; String test; String screen; - String _export_platform; + String _export_preset; String _import; String _import_script; bool noquit = false; @@ -1083,10 +1083,10 @@ bool Main::start() { test = args[i + 1]; } else if (args[i] == "-export") { editor = true; //needs editor - _export_platform = args[i + 1]; + _export_preset = args[i + 1]; } else if (args[i] == "-export_debug") { editor = true; //needs editor - _export_platform = args[i + 1]; + _export_preset = args[i + 1]; export_debug = true; } else if (args[i] == "-import") { editor = true; //needs editor @@ -1136,7 +1136,7 @@ bool Main::start() { #endif - if (_export_platform != "") { + if (_export_preset != "") { if (game_path == "") { String err = "Command line param "; err += export_debug ? "-export_debug" : "-export"; @@ -1243,9 +1243,9 @@ bool Main::start() { //root_node->set_editor(editor); //startup editor - if (_export_platform != "") { + if (_export_preset != "") { - editor_node->export_platform(_export_platform, game_path, export_debug, "", true); + editor_node->export_preset(_export_preset, game_path, export_debug, "", true); game_path = ""; //no load anything } } @@ -1466,6 +1466,7 @@ bool Main::start() { String iconpath = GLOBAL_DEF("application/config/icon", "Variant()"); if (iconpath != "") { Ref<Image> icon; + icon.instance(); if (icon->load(iconpath) == OK) OS::get_singleton()->set_icon(icon); } diff --git a/main/tests/test_gui.cpp b/main/tests/test_gui.cpp index 3c6a708cd8..44d4464aac 100644 --- a/main/tests/test_gui.cpp +++ b/main/tests/test_gui.cpp @@ -278,7 +278,7 @@ public: richtext->set_position(Point2(600, 210)); richtext->set_size(Point2(180, 250)); - richtext->set_anchor_and_margin(MARGIN_RIGHT, Control::ANCHOR_END, 20); + richtext->set_anchor_and_margin(MARGIN_RIGHT, Control::ANCHOR_END, -20); frame->add_child(richtext); @@ -319,8 +319,6 @@ public: ///richtext->add_text("Hello!\n"); //richtext->pop(); - richtext->set_anchor(MARGIN_RIGHT, Control::ANCHOR_END); - TabContainer *tabc = memnew(TabContainer); Control *ctl = memnew(Control); diff --git a/modules/gdnative/godot/dictionary.cpp b/modules/gdnative/godot/dictionary.cpp index b92c8125bb..c538456432 100644 --- a/modules/gdnative/godot/dictionary.cpp +++ b/modules/gdnative/godot/dictionary.cpp @@ -30,7 +30,7 @@ #include <godot/dictionary.h> #include "core/variant.h" - +// core/variant.h before to avoid compile errors with MSVC #include "core/dictionary.h" #include "core/io/json.h" diff --git a/modules/gdscript/gd_script.cpp b/modules/gdscript/gd_script.cpp index 9d304c6d34..2d06c0f5d2 100644 --- a/modules/gdscript/gd_script.cpp +++ b/modules/gdscript/gd_script.cpp @@ -615,7 +615,7 @@ Error GDScript::reload(bool p_keep_state) { if (basedir != "") basedir = basedir.get_base_dir(); - if (basedir.find("res://") == -1 && basedir.find("user://") == -1) { + if (basedir != "" && basedir.find("res://") == -1 && basedir.find("user://") == -1) { //loading a template, don't parse return OK; } diff --git a/modules/gridmap/grid_map_editor_plugin.cpp b/modules/gridmap/grid_map_editor_plugin.cpp index 954e865bcd..38f58799df 100644 --- a/modules/gridmap/grid_map_editor_plugin.cpp +++ b/modules/gridmap/grid_map_editor_plugin.cpp @@ -1203,7 +1203,7 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { 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_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, 14); + edit_mode->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, -14); edit_mode->add_item("Tiles"); edit_mode->add_item("Areas"); hb->add_child(edit_mode); diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp index 0192fe33f4..0f6b47c56d 100644 --- a/modules/visual_script/visual_script_editor.cpp +++ b/modules/visual_script/visual_script_editor.cpp @@ -3271,7 +3271,7 @@ VisualScriptEditor::VisualScriptEditor() { graph->set_area_as_parent_rect(); hint_text = memnew(Label); - hint_text->set_anchor_and_margin(MARGIN_TOP, ANCHOR_END, 100); + hint_text->set_anchor_and_margin(MARGIN_TOP, ANCHOR_END, -100); hint_text->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, 0); hint_text->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, 0); hint_text->set_align(Label::ALIGN_CENTER); diff --git a/platform/uwp/export/export.cpp b/platform/uwp/export/export.cpp index a1aa58a5e7..39717196aa 100644 --- a/platform/uwp/export/export.cpp +++ b/platform/uwp/export/export.cpp @@ -171,7 +171,7 @@ class AppxPackager { } Vector<uint8_t> make_file_header(FileMeta p_file_meta); - void store_central_dir_header(const FileMeta p_file, bool p_do_hash = true); + void store_central_dir_header(const FileMeta &p_file, bool p_do_hash = true); Vector<uint8_t> make_end_of_central_record(); String content_type(String p_extension); @@ -329,7 +329,7 @@ Vector<uint8_t> AppxPackager::make_file_header(FileMeta p_file_meta) { return buf; } -void AppxPackager::store_central_dir_header(const FileMeta p_file, bool p_do_hash) { +void AppxPackager::store_central_dir_header(const FileMeta &p_file, bool p_do_hash) { Vector<uint8_t> &buf = central_dir_data; int offs = buf.size(); diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index f72e5ef595..779f909a15 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -889,23 +889,6 @@ static int QueryDpiForMonitor(HMONITOR hmon, _MonitorDpiType dpiType = MDT_Defau return (dpiX + dpiY) / 2; } -BOOL CALLBACK OS_Windows::MonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) { - OS_Windows *self = (OS_Windows *)OS::get_singleton(); - MonitorInfo minfo; - minfo.hMonitor = hMonitor; - minfo.hdcMonitor = hdcMonitor; - minfo.rect.position.x = lprcMonitor->left; - minfo.rect.position.y = lprcMonitor->top; - minfo.rect.size.x = lprcMonitor->right - lprcMonitor->left; - minfo.rect.size.y = lprcMonitor->bottom - lprcMonitor->top; - - minfo.dpi = QueryDpiForMonitor(hMonitor); - - self->monitor_info.push_back(minfo); - - return TRUE; -} - void OS_Windows::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) { main_loop = NULL; @@ -941,9 +924,6 @@ void OS_Windows::initialize(const VideoMode &p_desired, int p_video_driver, int return; // Return } - EnumDisplayMonitors(NULL, NULL, MonitorEnumProc, 0); - - print_line("DETECTED MONITORS: " + itos(monitor_info.size())); pre_fs_valid = true; if (video_mode.fullscreen) { @@ -1217,8 +1197,6 @@ void OS_Windows::finalize() { physics_2d_server->finish(); memdelete(physics_2d_server); - - monitor_info.clear(); } void OS_Windows::finalize_core() { @@ -1344,51 +1322,131 @@ OS::VideoMode OS_Windows::get_video_mode(int p_screen) const { void OS_Windows::get_fullscreen_mode_list(List<VideoMode> *p_list, int p_screen) const { } +static BOOL CALLBACK _MonitorEnumProcCount(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) { + + int *data = (int *)dwData; + (*data)++; + return TRUE; +} + int OS_Windows::get_screen_count() const { - return monitor_info.size(); + int data = 0; + EnumDisplayMonitors(NULL, NULL, _MonitorEnumProcCount, (LPARAM)&data); + return data; } -int OS_Windows::get_current_screen() const { - HMONITOR monitor = MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST); - for (int i = 0; i < monitor_info.size(); i++) { - if (monitor_info[i].hMonitor == monitor) - return i; +typedef struct { + int count; + int screen; + HMONITOR monitor; +} EnumScreenData; + +static BOOL CALLBACK _MonitorEnumProcScreen(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) { + + EnumScreenData *data = (EnumScreenData *)dwData; + if (data->monitor == hMonitor) { + data->screen = data->count; } - return 0; + data->count++; + return TRUE; } -void OS_Windows::set_current_screen(int p_screen) { - ERR_FAIL_INDEX(p_screen, monitor_info.size()); +int OS_Windows::get_current_screen() const { + + EnumScreenData data = { 0, 0, MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST) }; + EnumDisplayMonitors(NULL, NULL, _MonitorEnumProcScreen, (LPARAM)&data); + return data.screen; +} + +void OS_Windows::set_current_screen(int p_screen) { Vector2 ofs = get_window_position() - get_screen_position(get_current_screen()); set_window_position(ofs + get_screen_position(p_screen)); } +typedef struct { + int count; + int screen; + Point2 pos; +} EnumPosData; + +static BOOL CALLBACK _MonitorEnumProcPos(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) { + + EnumPosData *data = (EnumPosData *)dwData; + if (data->count == data->screen) { + data->pos.x = lprcMonitor->left; + data->pos.y = lprcMonitor->top; + } + + data->count++; + return TRUE; +} + Point2 OS_Windows::get_screen_position(int p_screen) const { - ERR_FAIL_INDEX_V(p_screen, monitor_info.size(), Point2()); - return Vector2(monitor_info[p_screen].rect.position); + EnumPosData data = { 0, p_screen, Point2() }; + EnumDisplayMonitors(NULL, NULL, _MonitorEnumProcPos, (LPARAM)&data); + return data.pos; } + +typedef struct { + int count; + int screen; + Size2 size; +} EnumSizeData; + +static BOOL CALLBACK _MonitorEnumProcSize(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) { + + EnumSizeData *data = (EnumSizeData *)dwData; + if (data->count == data->screen) { + data->size.x = lprcMonitor->right - lprcMonitor->left; + data->size.y = lprcMonitor->bottom - lprcMonitor->top; + } + + data->count++; + return TRUE; +} + Size2 OS_Windows::get_screen_size(int p_screen) const { - ERR_FAIL_INDEX_V(p_screen, monitor_info.size(), Point2()); - return Vector2(monitor_info[p_screen].rect.size); + EnumSizeData data = { 0, p_screen, Size2() }; + EnumDisplayMonitors(NULL, NULL, _MonitorEnumProcSize, (LPARAM)&data); + return data.size; +} + +typedef struct { + int count; + int screen; + int dpi; +} EnumDpiData; + +static BOOL CALLBACK _MonitorEnumProcDpi(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) { + + EnumDpiData *data = (EnumDpiData *)dwData; + if (data->count == data->screen) { + data->dpi = QueryDpiForMonitor(hMonitor); + } + + data->count++; + return TRUE; } int OS_Windows::get_screen_dpi(int p_screen) const { - ERR_FAIL_INDEX_V(p_screen, monitor_info.size(), 72); - UINT dpix, dpiy; - return monitor_info[p_screen].dpi; + EnumDpiData data = { 0, p_screen, 72 }; + EnumDisplayMonitors(NULL, NULL, _MonitorEnumProcDpi, (LPARAM)&data); + return data.dpi; } + Point2 OS_Windows::get_window_position() const { RECT r; GetWindowRect(hWnd, &r); return Point2(r.left, r.top); } + void OS_Windows::set_window_position(const Point2 &p_position) { if (video_mode.fullscreen) return; diff --git a/platform/windows/os_windows.h b/platform/windows/os_windows.h index beaf5d5e35..e9af14f11c 100644 --- a/platform/windows/os_windows.h +++ b/platform/windows/os_windows.h @@ -164,22 +164,12 @@ protected: }; Map<ProcessID, ProcessInfo> *process_map; - struct MonitorInfo { - HMONITOR hMonitor; - HDC hdcMonitor; - Rect2 rect; - int dpi; - }; - bool pre_fs_valid; RECT pre_fs_rect; - Vector<MonitorInfo> monitor_info; bool maximized; bool minimized; bool borderless; - static BOOL CALLBACK MonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData); - public: LRESULT WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); diff --git a/platform/windows/packet_peer_udp_winsock.cpp b/platform/windows/packet_peer_udp_winsock.cpp index f3b91c1b56..3991a90423 100644 --- a/platform/windows/packet_peer_udp_winsock.cpp +++ b/platform/windows/packet_peer_udp_winsock.cpp @@ -118,7 +118,7 @@ void PacketPeerUDPWinsock::_set_sock_blocking(bool p_blocking) { }; } -Error PacketPeerUDPWinsock::listen(int p_port, IP_Address p_bind_address, int p_recv_buffer_size) { +Error PacketPeerUDPWinsock::listen(int p_port, const IP_Address &p_bind_address, int p_recv_buffer_size) { ERR_FAIL_COND_V(sockfd != -1, ERR_ALREADY_IN_USE); ERR_FAIL_COND_V(!p_bind_address.is_valid() && !p_bind_address.is_wildcard(), ERR_INVALID_PARAMETER); diff --git a/platform/windows/packet_peer_udp_winsock.h b/platform/windows/packet_peer_udp_winsock.h index ceb6df71aa..01f2e5113f 100644 --- a/platform/windows/packet_peer_udp_winsock.h +++ b/platform/windows/packet_peer_udp_winsock.h @@ -67,7 +67,7 @@ public: virtual int get_max_packet_size() const; - virtual Error listen(int p_port, IP_Address p_bind_address = IP_Address("*"), int p_recv_buffer_size = 65536); + virtual Error listen(int p_port, const IP_Address &p_bind_address = IP_Address("*"), int p_recv_buffer_size = 65536); virtual void close(); virtual Error wait(); virtual bool is_listening() const; diff --git a/platform/windows/tcp_server_winsock.cpp b/platform/windows/tcp_server_winsock.cpp index 3292813d4e..cc17c8a631 100644 --- a/platform/windows/tcp_server_winsock.cpp +++ b/platform/windows/tcp_server_winsock.cpp @@ -63,7 +63,7 @@ void TCPServerWinsock::cleanup() { }; }; -Error TCPServerWinsock::listen(uint16_t p_port, const IP_Address p_bind_address) { +Error TCPServerWinsock::listen(uint16_t p_port, const IP_Address &p_bind_address) { ERR_FAIL_COND_V(listen_sockfd != -1, ERR_ALREADY_IN_USE); ERR_FAIL_COND_V(!p_bind_address.is_valid() && !p_bind_address.is_wildcard(), ERR_INVALID_PARAMETER); diff --git a/platform/windows/tcp_server_winsock.h b/platform/windows/tcp_server_winsock.h index 7e5d1e750e..077acb94d7 100644 --- a/platform/windows/tcp_server_winsock.h +++ b/platform/windows/tcp_server_winsock.h @@ -40,7 +40,7 @@ class TCPServerWinsock : public TCP_Server { static TCP_Server *_create(); public: - virtual Error listen(uint16_t p_port, const IP_Address p_bind_address = IP_Address("*")); + virtual Error listen(uint16_t p_port, const IP_Address &p_bind_address = IP_Address("*")); virtual bool is_connection_available() const; virtual Ref<StreamPeerTCP> take_connection(); diff --git a/scene/2d/light_2d.cpp b/scene/2d/light_2d.cpp index e8c2122bd1..ffe69fa93f 100644 --- a/scene/2d/light_2d.cpp +++ b/scene/2d/light_2d.cpp @@ -416,7 +416,7 @@ void Light2D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "editor_only"), "set_editor_only", "is_editor_only"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "offset"), "set_texture_offset", "get_texture_offset"); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "scale", PROPERTY_HINT_RANGE, "0.01,50,0.01"), "set_texture_scale", "get_texture_scale"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "texture_scale", PROPERTY_HINT_RANGE, "0.01,50,0.01"), "set_texture_scale", "get_texture_scale"); ADD_PROPERTY(PropertyInfo(Variant::COLOR, "color"), "set_color", "get_color"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "energy", PROPERTY_HINT_RANGE, "0.01,100,0.01"), "set_energy", "get_energy"); ADD_PROPERTY(PropertyInfo(Variant::INT, "mode", PROPERTY_HINT_ENUM, "Add,Sub,Mix,Mask"), "set_mode", "get_mode"); diff --git a/scene/2d/navigation2d.cpp b/scene/2d/navigation2d.cpp index e579838903..383236b4ca 100644 --- a/scene/2d/navigation2d.cpp +++ b/scene/2d/navigation2d.cpp @@ -646,7 +646,8 @@ debug path break; } - path.push_back(begin_point); + if (path[path.size() - 1].distance_to(begin_point) > CMP_EPSILON) + path.push_back(begin_point); path.invert(); } diff --git a/scene/2d/particles_2d.cpp b/scene/2d/particles_2d.cpp index 4aa841131a..a2ec33f403 100644 --- a/scene/2d/particles_2d.cpp +++ b/scene/2d/particles_2d.cpp @@ -55,6 +55,8 @@ void Particles2D::set_one_shot(bool p_enable) { one_shot = p_enable; VS::get_singleton()->particles_set_one_shot(particles, one_shot); + if (!one_shot && emitting) + VisualServer::get_singleton()->particles_restart(particles); } void Particles2D::set_pre_process_time(float p_time) { diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp index 2f1e8925b8..6ec1642138 100644 --- a/scene/2d/physics_body_2d.cpp +++ b/scene/2d/physics_body_2d.cpp @@ -982,11 +982,12 @@ Dictionary KinematicBody2D::_move(const Vector2 &p_motion) { if (move(p_motion, col)) { Dictionary d; d["position"] = col.collision; - d["normal"] = col.collision; + d["normal"] = col.normal; d["local_shape"] = col.local_shape; d["travel"] = col.travel; d["remainder"] = col.remainder; d["collider_id"] = col.collider; + d["collider_velocity"] = col.collider_vel; if (col.collider) { d["collider"] = ObjectDB::get_instance(col.collider); } else { diff --git a/scene/3d/collision_shape.cpp b/scene/3d/collision_shape.cpp index 4fd215bd1a..2aa6a95718 100644 --- a/scene/3d/collision_shape.cpp +++ b/scene/3d/collision_shape.cpp @@ -89,13 +89,6 @@ void CollisionShape::_notification(int p_what) { parent->shape_owner_set_transform(owner_id, get_transform()); } } break; - case NOTIFICATION_EXIT_TREE: { - if (parent) { - parent->remove_shape_owner(owner_id); - } - owner_id = 0; - parent = NULL; - } break; case NOTIFICATION_UNPARENTED: { if (parent) { parent->remove_shape_owner(owner_id); diff --git a/scene/3d/navigation_mesh.cpp b/scene/3d/navigation_mesh.cpp index 4c93bcfb5e..5d4568f5d3 100644 --- a/scene/3d/navigation_mesh.cpp +++ b/scene/3d/navigation_mesh.cpp @@ -208,6 +208,8 @@ void NavigationMesh::_bind_methods() { ClassDB::bind_method(D_METHOD("get_polygon", "idx"), &NavigationMesh::get_polygon); ClassDB::bind_method(D_METHOD("clear_polygons"), &NavigationMesh::clear_polygons); + ClassDB::bind_method(D_METHOD("create_from_mesh", "mesh"), &NavigationMesh::create_from_mesh); + ClassDB::bind_method(D_METHOD("_set_polygons", "polygons"), &NavigationMesh::_set_polygons); ClassDB::bind_method(D_METHOD("_get_polygons"), &NavigationMesh::_get_polygons); diff --git a/scene/3d/particles.cpp b/scene/3d/particles.cpp index 081caf4419..e88a52c76a 100644 --- a/scene/3d/particles.cpp +++ b/scene/3d/particles.cpp @@ -63,6 +63,8 @@ void Particles::set_one_shot(bool p_one_shot) { one_shot = p_one_shot; VS::get_singleton()->particles_set_one_shot(particles, one_shot); + if (!one_shot && emitting) + VisualServer::get_singleton()->particles_restart(particles); } void Particles::set_pre_process_time(float p_time) { @@ -406,7 +408,7 @@ void ParticlesMaterial::init_shaders() { shader_names->anim_speed = "anim_speed"; shader_names->anim_offset = "anim_offset"; - shader_names->initial_linear_velocity = "initial_linear_velocity_random"; + shader_names->initial_linear_velocity_random = "initial_linear_velocity_random"; shader_names->initial_angle_random = "initial_angle_random"; shader_names->angular_velocity_random = "angular_velocity_random"; shader_names->orbit_velocity_random = "orbit_velocity_random"; @@ -753,18 +755,20 @@ void ParticlesMaterial::_update_shader() { code += " pos.z=0.0; \n"; } code += " //apply linear acceleration\n"; - code += " force+=normalize(VELOCITY) * (linear_accel+tex_linear_accel)*mix(1.0,rand_from_seed(alt_seed),linear_accel_random);\n"; + code += " force+= length(VELOCITY) > 0.0 ? normalize(VELOCITY) * (linear_accel+tex_linear_accel)*mix(1.0,rand_from_seed(alt_seed),linear_accel_random) : vec3(0.0);\n"; code += " //apply radial acceleration\n"; code += " vec3 org = vec3(0.0);\n"; - code += " // if (!p_system->local_coordinates)\n"; - code += " //org=p_transform.origin;\n"; - code += " force+=normalize(pos-org) * (radial_accel+tex_radial_accel)*mix(1.0,rand_from_seed(alt_seed),radial_accel_random);\n"; + code += " // if (!p_system->local_coordinates)\n"; + code += " //org=p_transform.origin;\n"; + code += " vec3 diff = pos-org;\n"; + code += " force+=length(diff) > 0.0 ? normalize(diff) * (radial_accel+tex_radial_accel)*mix(1.0,rand_from_seed(alt_seed),radial_accel_random) : vec3(0.0);\n"; code += " //apply tangential acceleration;\n"; if (flags[FLAG_DISABLE_Z]) { - code += " force+=vec3(normalize((pos-org).yx * vec2(-1.0,1.0)),0.0) * ((tangent_accel+tex_tangent_accel)*mix(1.0,rand_from_seed(alt_seed),radial_accel_random));\n"; + code += " force+=length(diff.yx) > 0.0 ? vec3(normalize(diff.yx * vec2(-1.0,1.0)),0.0) * ((tangent_accel+tex_tangent_accel)*mix(1.0,rand_from_seed(alt_seed),radial_accel_random)) : vec3(0.0);\n"; } else { - code += " force+=normalize(cross(normalize(pos-org),normalize(gravity))) * ((tangent_accel+tex_tangent_accel)*mix(1.0,rand_from_seed(alt_seed),radial_accel_random));\n"; + code += " vec3 crossDiff = cross(normalize(diff),normalize(gravity));\n"; + code += " force+=length(crossDiff) > 0.0 ? normalize(crossDiff) * ((tangent_accel+tex_tangent_accel)*mix(1.0,rand_from_seed(alt_seed),radial_accel_random)) : vec3(0.0);\n"; } code += " //apply attractor forces\n"; code += " VELOCITY+=force * DELTA;\n"; @@ -1264,9 +1268,8 @@ int ParticlesMaterial::get_emission_point_count() const { void ParticlesMaterial::set_trail_divisor(int p_divisor) { - VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->trail_divisor, p_divisor); trail_divisor = p_divisor; - _change_notify(); + VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->trail_divisor, p_divisor); } int ParticlesMaterial::get_trail_divisor() const { diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 01570e28c4..c97426ad42 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -51,6 +51,12 @@ Variant Control::edit_get_state() const { s["rect"] = get_rect(); s["rot"] = get_rotation(); s["scale"] = get_scale(); + Array anchors; + anchors.push_back(get_anchor(MARGIN_LEFT)); + anchors.push_back(get_anchor(MARGIN_TOP)); + anchors.push_back(get_anchor(MARGIN_RIGHT)); + anchors.push_back(get_anchor(MARGIN_BOTTOM)); + s["anchors"] = anchors; return s; } void Control::edit_set_state(const Variant &p_state) { @@ -62,6 +68,11 @@ void Control::edit_set_state(const Variant &p_state) { set_size(state.size); set_rotation(s["rot"]); set_scale(s["scale"]); + Array anchors = s["anchors"]; + set_anchor(MARGIN_LEFT, anchors[0]); + set_anchor(MARGIN_TOP, anchors[1]); + set_anchor(MARGIN_RIGHT, anchors[2]); + set_anchor(MARGIN_BOTTOM, anchors[3]); } void Control::set_custom_minimum_size(const Size2 &p_custom) { @@ -1212,21 +1223,7 @@ void Control::_size_changed() { for (int i = 0; i < 4; i++) { float area = parent_size[i & 1]; - switch (data.anchor[i]) { - - case ANCHOR_BEGIN: { - - margin_pos[i] = data.margin[i]; - } break; - case ANCHOR_END: { - - margin_pos[i] = area - data.margin[i]; - } break; - case ANCHOR_CENTER: { - - margin_pos[i] = (area / 2) - data.margin[i]; - } break; - } + margin_pos[i] = data.margin[i] + (data.anchor[i] * area); } Point2 new_pos_cache = Point2(margin_pos[0], margin_pos[1]); @@ -1299,59 +1296,38 @@ float Control::_get_range(int p_idx) const { return to - from; } -float Control::_s2a(float p_val, AnchorType p_anchor, float p_range) const { - - switch (p_anchor) { - - case ANCHOR_BEGIN: { - return p_val; - } break; - case ANCHOR_END: { - return p_range - p_val; - } break; - case ANCHOR_CENTER: { - return (p_range / 2) - p_val; - } break; - } - - return 0; +float Control::_s2a(float p_val, float p_anchor, float p_range) const { + return p_val - (p_anchor * p_range); } -float Control::_a2s(float p_val, AnchorType p_anchor, float p_range) const { - - switch (p_anchor) { - - case ANCHOR_BEGIN: { - return Math::floor(p_val); - } break; - case ANCHOR_END: { - return Math::floor(p_range - p_val); - } break; - case ANCHOR_CENTER: { - return Math::floor((p_range / 2) - p_val); - } break; - } - return 0; +float Control::_a2s(float p_val, float p_anchor, float p_range) const { + return Math::floor(p_val + (p_anchor * p_range)); } -void Control::set_anchor(Margin p_margin, AnchorType p_anchor, bool p_keep_margin) { +void Control::set_anchor(Margin p_margin, float p_anchor, bool p_keep_margin, bool p_push_opposite_anchor) { + bool pushed = false; + data.anchor[p_margin] = CLAMP(p_anchor, 0.0, 1.0); - if (!is_inside_tree()) { + if (((p_margin == MARGIN_LEFT || p_margin == MARGIN_TOP) && data.anchor[p_margin] > data.anchor[(p_margin + 2) % 4]) || + ((p_margin == MARGIN_RIGHT || p_margin == MARGIN_BOTTOM) && data.anchor[p_margin] < data.anchor[(p_margin + 2) % 4])) { + if (p_push_opposite_anchor) { + data.anchor[(p_margin + 2) % 4] = data.anchor[p_margin]; + pushed = true; + } else { + data.anchor[p_margin] = data.anchor[(p_margin + 2) % 4]; + } + } - data.anchor[p_margin] = p_anchor; - } else if (!p_keep_margin) { - float pr = _get_parent_range(p_margin); - float s = _a2s(data.margin[p_margin], data.anchor[p_margin], pr); - data.anchor[p_margin] = p_anchor; - data.margin[p_margin] = _s2a(s, p_anchor, pr); - } else { - data.anchor[p_margin] = p_anchor; - _size_changed(); + if (is_inside_tree()) { + if (p_keep_margin) { + _size_changed(); + } } + update(); _change_notify(); } -void Control::_set_anchor(Margin p_margin, AnchorType p_anchor) { +void Control::_set_anchor(Margin p_margin, float p_anchor) { #ifdef TOOLS_ENABLED if (is_inside_tree() && get_tree()->is_editor_hint()) { set_anchor(p_margin, p_anchor, EDITOR_DEF("editors/2d/keep_margins_when_changing_anchors", false)); @@ -1363,13 +1339,127 @@ void Control::_set_anchor(Margin p_margin, AnchorType p_anchor) { #endif } -void Control::set_anchor_and_margin(Margin p_margin, AnchorType p_anchor, float p_pos) { +void Control::set_anchor_and_margin(Margin p_margin, float p_anchor, float p_pos, bool p_push_opposite_anchor) { - set_anchor(p_margin, p_anchor); + set_anchor(p_margin, p_anchor, false, p_push_opposite_anchor); set_margin(p_margin, p_pos); } -Control::AnchorType Control::get_anchor(Margin p_margin) const { +void Control::set_anchors_preset(LayoutPreset p_preset, bool p_keep_margin) { + //Left + switch (p_preset) { + case PRESET_TOP_LEFT: + case PRESET_BOTTOM_LEFT: + case PRESET_CENTER_LEFT: + case PRESET_TOP_WIDE: + case PRESET_BOTTOM_WIDE: + case PRESET_LEFT_WIDE: + case PRESET_HCENTER_WIDE: + case PRESET_WIDE: + set_anchor(MARGIN_LEFT, ANCHOR_BEGIN, p_keep_margin); + break; + + case PRESET_CENTER_TOP: + case PRESET_CENTER_BOTTOM: + case PRESET_CENTER: + case PRESET_VCENTER_WIDE: + set_anchor(MARGIN_LEFT, 0.5, p_keep_margin); + break; + + case PRESET_TOP_RIGHT: + case PRESET_BOTTOM_RIGHT: + case PRESET_CENTER_RIGHT: + case PRESET_RIGHT_WIDE: + set_anchor(MARGIN_LEFT, ANCHOR_END, p_keep_margin); + break; + } + + // Top + switch (p_preset) { + case PRESET_TOP_LEFT: + case PRESET_TOP_RIGHT: + case PRESET_CENTER_TOP: + case PRESET_LEFT_WIDE: + case PRESET_RIGHT_WIDE: + case PRESET_TOP_WIDE: + case PRESET_VCENTER_WIDE: + case PRESET_WIDE: + set_anchor(MARGIN_TOP, ANCHOR_BEGIN, p_keep_margin); + break; + + case PRESET_CENTER_LEFT: + case PRESET_CENTER_RIGHT: + case PRESET_CENTER: + case PRESET_HCENTER_WIDE: + set_anchor(MARGIN_TOP, 0.5, p_keep_margin); + break; + + case PRESET_BOTTOM_LEFT: + case PRESET_BOTTOM_RIGHT: + case PRESET_CENTER_BOTTOM: + case PRESET_BOTTOM_WIDE: + set_anchor(MARGIN_TOP, ANCHOR_END, p_keep_margin); + break; + } + + // Right + switch (p_preset) { + case PRESET_TOP_LEFT: + case PRESET_BOTTOM_LEFT: + case PRESET_CENTER_LEFT: + case PRESET_LEFT_WIDE: + set_anchor(MARGIN_RIGHT, ANCHOR_BEGIN, p_keep_margin); + break; + + case PRESET_CENTER_TOP: + case PRESET_CENTER_BOTTOM: + case PRESET_CENTER: + case PRESET_VCENTER_WIDE: + set_anchor(MARGIN_RIGHT, 0.5, p_keep_margin); + break; + + case PRESET_TOP_RIGHT: + case PRESET_BOTTOM_RIGHT: + case PRESET_CENTER_RIGHT: + case PRESET_TOP_WIDE: + case PRESET_RIGHT_WIDE: + case PRESET_BOTTOM_WIDE: + case PRESET_HCENTER_WIDE: + case PRESET_WIDE: + set_anchor(MARGIN_RIGHT, ANCHOR_END, p_keep_margin); + break; + } + + // Bottom + switch (p_preset) { + case PRESET_TOP_LEFT: + case PRESET_TOP_RIGHT: + case PRESET_CENTER_TOP: + case PRESET_TOP_WIDE: + set_anchor(MARGIN_BOTTOM, ANCHOR_BEGIN, p_keep_margin); + break; + + case PRESET_CENTER_LEFT: + case PRESET_CENTER_RIGHT: + case PRESET_CENTER: + case PRESET_HCENTER_WIDE: + set_anchor(MARGIN_BOTTOM, 0.5, p_keep_margin); + break; + + case PRESET_BOTTOM_LEFT: + case PRESET_BOTTOM_RIGHT: + case PRESET_CENTER_BOTTOM: + case PRESET_LEFT_WIDE: + case PRESET_RIGHT_WIDE: + case PRESET_BOTTOM_WIDE: + case PRESET_VCENTER_WIDE: + case PRESET_WIDE: + set_anchor(MARGIN_BOTTOM, ANCHOR_END, p_keep_margin); + break; + } +} + +float Control::get_anchor(Margin p_margin) const { return data.anchor[p_margin]; } @@ -1523,11 +1613,13 @@ Rect2 Control::get_item_rect() const { void Control::set_area_as_parent_rect(int p_margin) { data.anchor[MARGIN_LEFT] = ANCHOR_BEGIN; + data.margin[MARGIN_LEFT] = p_margin; data.anchor[MARGIN_TOP] = ANCHOR_BEGIN; + data.margin[MARGIN_TOP] = p_margin; data.anchor[MARGIN_RIGHT] = ANCHOR_END; + data.margin[MARGIN_RIGHT] = -p_margin; data.anchor[MARGIN_BOTTOM] = ANCHOR_END; - for (int i = 0; i < 4; i++) - data.margin[i] = p_margin; + data.margin[MARGIN_BOTTOM] = -p_margin; _size_changed(); } @@ -2371,11 +2463,12 @@ void Control::_bind_methods() { ClassDB::bind_method(D_METHOD("accept_event"), &Control::accept_event); ClassDB::bind_method(D_METHOD("get_minimum_size"), &Control::get_minimum_size); ClassDB::bind_method(D_METHOD("get_combined_minimum_size"), &Control::get_combined_minimum_size); - ClassDB::bind_method(D_METHOD("set_anchor", "margin", "anchor_mode", "keep_margin"), &Control::set_anchor, DEFVAL(false)); - ClassDB::bind_method(D_METHOD("_set_anchor", "margin", "anchor_mode"), &Control::_set_anchor); + ClassDB::bind_method(D_METHOD("set_anchor", "margin", "anchor", "keep_margin", "push_opposite_anchor"), &Control::set_anchor, DEFVAL(false), DEFVAL(true)); + ClassDB::bind_method(D_METHOD("_set_anchor", "margin", "anchor"), &Control::_set_anchor); + ClassDB::bind_method(D_METHOD("set_anchors_preset", "preset", "keep_margin"), &Control::set_anchors_preset, DEFVAL(false)); ClassDB::bind_method(D_METHOD("get_anchor", "margin"), &Control::get_anchor); ClassDB::bind_method(D_METHOD("set_margin", "margin", "offset"), &Control::set_margin); - ClassDB::bind_method(D_METHOD("set_anchor_and_margin", "margin", "anchor_mode", "offset"), &Control::set_anchor_and_margin); + ClassDB::bind_method(D_METHOD("set_anchor_and_margin", "margin", "anchor", "offset", "push_opposite_anchor"), &Control::set_anchor_and_margin, DEFVAL(false)); ClassDB::bind_method(D_METHOD("set_begin", "pos"), &Control::set_begin); ClassDB::bind_method(D_METHOD("set_end", "pos"), &Control::set_end); ClassDB::bind_method(D_METHOD("set_position", "pos"), &Control::set_position); @@ -2497,10 +2590,10 @@ void Control::_bind_methods() { BIND_VMETHOD(MethodInfo("drop_data", PropertyInfo(Variant::VECTOR2, "pos"), PropertyInfo(Variant::NIL, "data"))); ADD_GROUP("Anchor", "anchor_"); - ADD_PROPERTYINZ(PropertyInfo(Variant::INT, "anchor_left", PROPERTY_HINT_ENUM, "Begin,End,Center"), "_set_anchor", "get_anchor", MARGIN_LEFT); - ADD_PROPERTYINZ(PropertyInfo(Variant::INT, "anchor_top", PROPERTY_HINT_ENUM, "Begin,End,Center"), "_set_anchor", "get_anchor", MARGIN_TOP); - ADD_PROPERTYINZ(PropertyInfo(Variant::INT, "anchor_right", PROPERTY_HINT_ENUM, "Begin,End,Center"), "_set_anchor", "get_anchor", MARGIN_RIGHT); - ADD_PROPERTYINZ(PropertyInfo(Variant::INT, "anchor_bottom", PROPERTY_HINT_ENUM, "Begin,End,Center"), "_set_anchor", "get_anchor", MARGIN_BOTTOM); + ADD_PROPERTYI(PropertyInfo(Variant::REAL, "anchor_left", PROPERTY_HINT_RANGE, "0,1,0.01"), "_set_anchor", "get_anchor", MARGIN_LEFT); + ADD_PROPERTYI(PropertyInfo(Variant::REAL, "anchor_top", PROPERTY_HINT_RANGE, "0,1,0.01"), "_set_anchor", "get_anchor", MARGIN_TOP); + ADD_PROPERTYI(PropertyInfo(Variant::REAL, "anchor_right", PROPERTY_HINT_RANGE, "0,1,0.01"), "_set_anchor", "get_anchor", MARGIN_RIGHT); + ADD_PROPERTYI(PropertyInfo(Variant::REAL, "anchor_bottom", PROPERTY_HINT_RANGE, "0,1,0.01"), "_set_anchor", "get_anchor", MARGIN_BOTTOM); ADD_GROUP("Margin", "margin_"); ADD_PROPERTYINZ(PropertyInfo(Variant::INT, "margin_left", PROPERTY_HINT_RANGE, "-4096,4096"), "set_margin", "get_margin", MARGIN_LEFT); @@ -2541,9 +2634,6 @@ void Control::_bind_methods() { ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "theme", PROPERTY_HINT_RESOURCE_TYPE, "Theme"), "set_theme", "get_theme"); ADD_GROUP("", ""); - BIND_CONSTANT(ANCHOR_BEGIN); - BIND_CONSTANT(ANCHOR_END); - BIND_CONSTANT(ANCHOR_CENTER); BIND_CONSTANT(FOCUS_NONE); BIND_CONSTANT(FOCUS_CLICK); BIND_CONSTANT(FOCUS_ALL); @@ -2574,6 +2664,23 @@ void Control::_bind_methods() { BIND_CONSTANT(CURSOR_HSPLIT); BIND_CONSTANT(CURSOR_HELP); + BIND_CONSTANT(PRESET_TOP_LEFT); + BIND_CONSTANT(PRESET_TOP_RIGHT); + BIND_CONSTANT(PRESET_BOTTOM_LEFT); + BIND_CONSTANT(PRESET_BOTTOM_RIGHT); + BIND_CONSTANT(PRESET_CENTER_LEFT); + BIND_CONSTANT(PRESET_CENTER_TOP); + BIND_CONSTANT(PRESET_CENTER_RIGHT); + BIND_CONSTANT(PRESET_CENTER_BOTTOM); + BIND_CONSTANT(PRESET_CENTER); + BIND_CONSTANT(PRESET_LEFT_WIDE); + BIND_CONSTANT(PRESET_TOP_WIDE); + BIND_CONSTANT(PRESET_RIGHT_WIDE); + BIND_CONSTANT(PRESET_BOTTOM_WIDE); + BIND_CONSTANT(PRESET_VCENTER_WIDE); + BIND_CONSTANT(PRESET_HCENTER_WIDE); + BIND_CONSTANT(PRESET_WIDE); + BIND_CONSTANT(SIZE_EXPAND); BIND_CONSTANT(SIZE_FILL); BIND_CONSTANT(SIZE_EXPAND_FILL); @@ -2587,6 +2694,9 @@ void Control::_bind_methods() { BIND_CONSTANT(GROW_DIRECTION_BEGIN); BIND_CONSTANT(GROW_DIRECTION_END); + BIND_CONSTANT(ANCHOR_BEGIN); + BIND_CONSTANT(ANCHOR_END); + ADD_SIGNAL(MethodInfo("resized")); ADD_SIGNAL(MethodInfo("gui_input", PropertyInfo(Variant::OBJECT, "ev", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent"))); ADD_SIGNAL(MethodInfo("mouse_entered")); diff --git a/scene/gui/control.h b/scene/gui/control.h index 86cf8f6dbd..d73ca3f7c9 100644 --- a/scene/gui/control.h +++ b/scene/gui/control.h @@ -51,10 +51,10 @@ class Control : public CanvasItem { OBJ_CATEGORY("GUI Nodes"); public: - enum AnchorType { - ANCHOR_BEGIN, - ANCHOR_END, - ANCHOR_CENTER, + enum Anchor { + + ANCHOR_BEGIN = 0, + ANCHOR_END = 1 }; enum GrowDirection { @@ -105,6 +105,25 @@ public: CURSOR_MAX }; + enum LayoutPreset { + PRESET_TOP_LEFT, + PRESET_TOP_RIGHT, + PRESET_BOTTOM_LEFT, + PRESET_BOTTOM_RIGHT, + PRESET_CENTER_LEFT, + PRESET_CENTER_TOP, + PRESET_CENTER_RIGHT, + PRESET_CENTER_BOTTOM, + PRESET_CENTER, + PRESET_LEFT_WIDE, + PRESET_TOP_WIDE, + PRESET_RIGHT_WIDE, + PRESET_BOTTOM_WIDE, + PRESET_VCENTER_WIDE, + PRESET_HCENTER_WIDE, + PRESET_WIDE + }; + private: struct CComparator { @@ -122,7 +141,7 @@ private: Size2 size_cache; float margin[4]; - AnchorType anchor[4]; + float anchor[4]; FocusMode focus_mode; GrowDirection h_grow; GrowDirection v_grow; @@ -182,12 +201,12 @@ private: void _window_find_focus_neighbour(const Vector2 &p_dir, Node *p_at, const Point2 *p_points, float p_min, float &r_closest_dist, Control **r_closest); Control *_get_focus_neighbour(Margin p_margin, int p_count = 0); - void _set_anchor(Margin p_margin, AnchorType p_anchor); + void _set_anchor(Margin p_margin, float p_anchor); float _get_parent_range(int p_idx) const; float _get_range(int p_idx) const; - float _s2a(float p_val, AnchorType p_anchor, float p_range) const; - float _a2s(float p_val, AnchorType p_anchor, float p_range) const; + float _s2a(float p_val, float p_anchor, float p_range) const; + float _a2s(float p_val, float p_anchor, float p_range) const; void _propagate_theme_changed(CanvasItem *p_at, Control *p_owner, bool p_assign = true); void _theme_changed(); @@ -275,10 +294,11 @@ public: /* POSITIONING */ - void set_anchor(Margin p_margin, AnchorType p_anchor, bool p_keep_margin = false); - void set_anchor_and_margin(Margin p_margin, AnchorType p_anchor, float p_pos); + void set_anchor(Margin p_margin, float p_anchor, bool p_keep_margin = false, bool p_push_opposite_anchor = true); + void set_anchor_and_margin(Margin p_margin, float p_anchor, float p_pos, bool p_push_opposite_anchor = true); + void set_anchors_preset(LayoutPreset p_preset, bool p_keep_margin = false); - AnchorType get_anchor(Margin p_margin) const; + float get_anchor(Margin p_margin) const; void set_margin(Margin p_margin, float p_value); @@ -425,11 +445,12 @@ public: ~Control(); }; -VARIANT_ENUM_CAST(Control::AnchorType); VARIANT_ENUM_CAST(Control::FocusMode); VARIANT_ENUM_CAST(Control::SizeFlags); VARIANT_ENUM_CAST(Control::CursorShape); +VARIANT_ENUM_CAST(Control::LayoutPreset); VARIANT_ENUM_CAST(Control::MouseFilter); VARIANT_ENUM_CAST(Control::GrowDirection); +VARIANT_ENUM_CAST(Control::Anchor); #endif diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp index dedf44d407..d576ff1dbc 100644 --- a/scene/gui/dialogs.cpp +++ b/scene/gui/dialogs.cpp @@ -215,7 +215,7 @@ void WindowDialog::_notification(int p_what) { close_button->set_pressed_texture(get_icon("close", "WindowDialog")); close_button->set_hover_texture(get_icon("close_highlight", "WindowDialog")); close_button->set_anchor(MARGIN_LEFT, ANCHOR_END); - close_button->set_begin(Point2(get_constant("close_h_ofs", "WindowDialog"), -get_constant("close_v_ofs", "WindowDialog"))); + close_button->set_begin(Point2(-get_constant("close_h_ofs", "WindowDialog"), -get_constant("close_v_ofs", "WindowDialog"))); } break; case NOTIFICATION_MOUSE_EXIT: { @@ -546,7 +546,7 @@ AcceptDialog::AcceptDialog() { label->set_anchor(MARGIN_RIGHT, ANCHOR_END); label->set_anchor(MARGIN_BOTTOM, ANCHOR_END); label->set_begin(Point2(margin, margin)); - label->set_end(Point2(margin, button_margin + 10)); + label->set_end(Point2(-margin, -button_margin - 10)); //label->set_autowrap(true); add_child(label); diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index e85ef73f4e..ec1932ed5a 100644 --- a/scene/gui/graph_edit.cpp +++ b/scene/gui/graph_edit.cpp @@ -269,14 +269,14 @@ void GraphEdit::_notification(int p_what) { Size2 hmin = h_scroll->get_combined_minimum_size(); Size2 vmin = v_scroll->get_combined_minimum_size(); - v_scroll->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_END, vmin.width); + v_scroll->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_END, -vmin.width); v_scroll->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, 0); v_scroll->set_anchor_and_margin(MARGIN_TOP, ANCHOR_BEGIN, 0); v_scroll->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, 0); h_scroll->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_BEGIN, 0); h_scroll->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, 0); - h_scroll->set_anchor_and_margin(MARGIN_TOP, ANCHOR_END, hmin.height); + h_scroll->set_anchor_and_margin(MARGIN_TOP, ANCHOR_END, -hmin.height); h_scroll->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, 0); zoom_minus->set_icon(get_icon("minus")); diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp index 484051f546..d90f0c7898 100644 --- a/scene/gui/item_list.cpp +++ b/scene/gui/item_list.cpp @@ -736,10 +736,10 @@ void ItemList::_notification(int p_what) { Ref<StyleBox> bg = get_stylebox("bg"); int mw = scroll_bar->get_minimum_size().x; - scroll_bar->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_END, mw + bg->get_margin(MARGIN_RIGHT)); - scroll_bar->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, bg->get_margin(MARGIN_RIGHT)); + scroll_bar->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_END, -mw + bg->get_margin(MARGIN_RIGHT)); + scroll_bar->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, -bg->get_margin(MARGIN_RIGHT)); scroll_bar->set_anchor_and_margin(MARGIN_TOP, ANCHOR_BEGIN, bg->get_margin(MARGIN_TOP)); - scroll_bar->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, bg->get_margin(MARGIN_BOTTOM)); + scroll_bar->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, -bg->get_margin(MARGIN_BOTTOM)); Size2 size = get_size(); diff --git a/scene/gui/popup.cpp b/scene/gui/popup.cpp index 8979e0f111..bdd0e8e597 100644 --- a/scene/gui/popup.cpp +++ b/scene/gui/popup.cpp @@ -108,13 +108,10 @@ void Popup::set_as_minsize() { float margin_begin = c->get_margin(m_beg); float margin_end = c->get_margin(m_end); - AnchorType anchor_begin = c->get_anchor(m_beg); - AnchorType anchor_end = c->get_anchor(m_end); + float anchor_begin = c->get_anchor(m_beg); + float anchor_end = c->get_anchor(m_end); - if (anchor_begin == ANCHOR_BEGIN) - minsize[j] += margin_begin; - if (anchor_end == ANCHOR_END) - minsize[j] += margin_end; + minsize[j] += margin_begin * (ANCHOR_END - anchor_begin) + margin_end * anchor_end; } total_minsize.width = MAX(total_minsize.width, minsize.width); @@ -145,13 +142,10 @@ void Popup::popup_centered_minsize(const Size2 &p_minsize) { float margin_begin = c->get_margin(m_beg); float margin_end = c->get_margin(m_end); - AnchorType anchor_begin = c->get_anchor(m_beg); - AnchorType anchor_end = c->get_anchor(m_end); + float anchor_begin = c->get_anchor(m_beg); + float anchor_end = c->get_anchor(m_end); - if (anchor_begin == ANCHOR_BEGIN) - minsize[j] += margin_begin; - if (anchor_end == ANCHOR_END) - minsize[j] += margin_end; + minsize[j] += margin_begin * (ANCHOR_END - anchor_begin) + margin_end * anchor_end; } total_minsize.width = MAX(total_minsize.width, minsize.width); diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index 0e4004c27b..42084ade25 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -594,7 +594,7 @@ void RichTextLabel::_update_scroll() { main->first_invalid_line = 0; scroll_w = vscroll->get_combined_minimum_size().width; vscroll->show(); - vscroll->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_END, scroll_w); + vscroll->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_END, -scroll_w); _validate_line_caches(main); } else { diff --git a/scene/gui/scroll_bar.cpp b/scene/gui/scroll_bar.cpp index bd66cd2745..2ccdbb05a9 100644 --- a/scene/gui/scroll_bar.cpp +++ b/scene/gui/scroll_bar.cpp @@ -233,7 +233,14 @@ void ScrollBar::_notification(int p_what) { Ref<Texture> decr = highlight == HIGHLIGHT_DECR ? get_icon("decrement_highlight") : get_icon("decrement"); Ref<Texture> incr = highlight == HIGHLIGHT_INCR ? get_icon("increment_highlight") : get_icon("increment"); Ref<StyleBox> bg = has_focus() ? get_stylebox("scroll_focus") : get_stylebox("scroll"); - Ref<StyleBox> grabber = (drag.active || highlight == HIGHLIGHT_RANGE) ? get_stylebox("grabber_highlight") : get_stylebox("grabber"); + + Ref<StyleBox> grabber; + if (drag.active) + grabber = get_stylebox("grabber_pressed"); + else if (highlight == HIGHLIGHT_RANGE) + grabber = get_stylebox("grabber_highlight"); + else + grabber = get_stylebox("grabber"); Point2 ofs; diff --git a/scene/gui/scroll_container.cpp b/scene/gui/scroll_container.cpp index cc1a637d2b..939bdd8d0c 100644 --- a/scene/gui/scroll_container.cpp +++ b/scene/gui/scroll_container.cpp @@ -187,14 +187,14 @@ void ScrollContainer::_update_scrollbar_pos() { Size2 hmin = h_scroll->get_combined_minimum_size(); Size2 vmin = v_scroll->get_combined_minimum_size(); - v_scroll->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_END, vmin.width); + v_scroll->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_END, -vmin.width); v_scroll->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, 0); v_scroll->set_anchor_and_margin(MARGIN_TOP, ANCHOR_BEGIN, 0); v_scroll->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, 0); h_scroll->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_BEGIN, 0); h_scroll->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, 0); - h_scroll->set_anchor_and_margin(MARGIN_TOP, ANCHOR_END, hmin.height); + h_scroll->set_anchor_and_margin(MARGIN_TOP, ANCHOR_END, -hmin.height); h_scroll->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, 0); h_scroll->raise(); diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp index 4b8b180b0e..61a409d43e 100644 --- a/scene/gui/tab_container.cpp +++ b/scene/gui/tab_container.cpp @@ -371,8 +371,10 @@ void TabContainer::add_child_notify(Node *p_child) { if (tabs_visible) c->set_margin(MARGIN_TOP, _get_top_margin()); Ref<StyleBox> sb = get_stylebox("panel"); - for (int i = 0; i < 4; i++) - c->set_margin(Margin(i), c->get_margin(Margin(i)) + sb->get_margin(Margin(i))); + c->set_margin(Margin(MARGIN_TOP), c->get_margin(Margin(MARGIN_TOP)) + sb->get_margin(Margin(MARGIN_TOP))); + c->set_margin(Margin(MARGIN_LEFT), c->get_margin(Margin(MARGIN_LEFT)) + sb->get_margin(Margin(MARGIN_LEFT))); + c->set_margin(Margin(MARGIN_RIGHT), c->get_margin(Margin(MARGIN_RIGHT)) - sb->get_margin(Margin(MARGIN_RIGHT))); + c->set_margin(Margin(MARGIN_BOTTOM), c->get_margin(Margin(MARGIN_BOTTOM)) - sb->get_margin(Margin(MARGIN_BOTTOM))); update(); p_child->connect("renamed", this, "_child_renamed_callback"); @@ -402,8 +404,10 @@ void TabContainer::set_current_tab(int p_current) { c->set_area_as_parent_rect(); if (tabs_visible) c->set_margin(MARGIN_TOP, _get_top_margin()); - for (int i = 0; i < 4; i++) - c->set_margin(Margin(i), c->get_margin(Margin(i)) + sb->get_margin(Margin(i))); + c->set_margin(Margin(MARGIN_TOP), c->get_margin(Margin(MARGIN_TOP)) + sb->get_margin(Margin(MARGIN_TOP))); + c->set_margin(Margin(MARGIN_LEFT), c->get_margin(Margin(MARGIN_LEFT)) + sb->get_margin(Margin(MARGIN_LEFT))); + c->set_margin(Margin(MARGIN_RIGHT), c->get_margin(Margin(MARGIN_RIGHT)) - sb->get_margin(Margin(MARGIN_RIGHT))); + c->set_margin(Margin(MARGIN_BOTTOM), c->get_margin(Margin(MARGIN_BOTTOM)) - sb->get_margin(Margin(MARGIN_BOTTOM))); } else c->hide(); diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 0d872d906e..0474c6fd26 100755 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -1301,8 +1301,9 @@ String Node::_generate_serial_child_name(Node *p_child) { } } + int num_places = nums.length(); for (;;) { - String attempt = (name + (num > 0 || explicit_zero ? nnsep + itos(num) : "")).strip_edges(); + String attempt = (name + (num > 0 || explicit_zero ? nnsep + itos(num).pad_zeros(num_places) : "")).strip_edges(); bool found = false; for (int i = 0; i < data.children.size(); i++) { if (data.children[i] == p_child) diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp index 067bcbff3e..66eafa1070 100644 --- a/scene/main/scene_tree.cpp +++ b/scene/main/scene_tree.cpp @@ -801,11 +801,11 @@ Ref<Material> SceneTree::get_debug_navigation_material() { return navigation_material; Ref<SpatialMaterial> line_material = Ref<SpatialMaterial>(memnew(SpatialMaterial)); - /* line_material->set_flag(Material::FLAG_UNSHADED, true); - line_material->set_line_width(3.0); - line_material->set_fixed_flag(SpatialMaterial::FLAG_USE_ALPHA, true); - line_material->set_fixed_flag(SpatialMaterial::FLAG_USE_COLOR_ARRAY, true); - line_material->set_parameter(SpatialMaterial::PARAM_DIFFUSE,get_debug_navigation_color());*/ + line_material->set_flag(SpatialMaterial::FLAG_UNSHADED, true); + line_material->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true); + line_material->set_flag(SpatialMaterial::FLAG_SRGB_VERTEX_COLOR, true); + line_material->set_flag(SpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); + line_material->set_albedo(get_debug_navigation_color()); navigation_material = line_material; @@ -818,11 +818,11 @@ Ref<Material> SceneTree::get_debug_navigation_disabled_material() { return navigation_disabled_material; Ref<SpatialMaterial> line_material = Ref<SpatialMaterial>(memnew(SpatialMaterial)); - /* line_material->set_flag(Material::FLAG_UNSHADED, true); - line_material->set_line_width(3.0); - line_material->set_fixed_flag(SpatialMaterial::FLAG_USE_ALPHA, true); - line_material->set_fixed_flag(SpatialMaterial::FLAG_USE_COLOR_ARRAY, true); - line_material->set_parameter(SpatialMaterial::PARAM_DIFFUSE,get_debug_navigation_disabled_color());*/ + line_material->set_flag(SpatialMaterial::FLAG_UNSHADED, true); + line_material->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true); + line_material->set_flag(SpatialMaterial::FLAG_SRGB_VERTEX_COLOR, true); + line_material->set_flag(SpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); + line_material->set_albedo(get_debug_navigation_disabled_color()); navigation_disabled_material = line_material; @@ -834,11 +834,11 @@ Ref<Material> SceneTree::get_debug_collision_material() { return collision_material; Ref<SpatialMaterial> line_material = Ref<SpatialMaterial>(memnew(SpatialMaterial)); - /*line_material->set_flag(Material::FLAG_UNSHADED, true); - line_material->set_line_width(3.0); - line_material->set_fixed_flag(SpatialMaterial::FLAG_USE_ALPHA, true); - line_material->set_fixed_flag(SpatialMaterial::FLAG_USE_COLOR_ARRAY, true); - line_material->set_parameter(SpatialMaterial::PARAM_DIFFUSE,get_debug_collisions_color());*/ + line_material->set_flag(SpatialMaterial::FLAG_UNSHADED, true); + line_material->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true); + line_material->set_flag(SpatialMaterial::FLAG_SRGB_VERTEX_COLOR, true); + line_material->set_flag(SpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); + line_material->set_albedo(get_debug_collisions_color()); collision_material = line_material; @@ -852,11 +852,12 @@ Ref<ArrayMesh> SceneTree::get_debug_contact_mesh() { debug_contact_mesh = Ref<ArrayMesh>(memnew(ArrayMesh)); - Ref<SpatialMaterial> mat = memnew(SpatialMaterial); - /*mat->set_flag(Material::FLAG_UNSHADED,true); - mat->set_flag(Material::FLAG_DOUBLE_SIDED,true); - mat->set_fixed_flag(SpatialMaterial::FLAG_USE_ALPHA,true); - mat->set_parameter(SpatialMaterial::PARAM_DIFFUSE,get_debug_collision_contact_color());*/ + Ref<SpatialMaterial> mat = Ref<SpatialMaterial>(memnew(SpatialMaterial)); + mat->set_flag(SpatialMaterial::FLAG_UNSHADED, true); + mat->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true); + mat->set_flag(SpatialMaterial::FLAG_SRGB_VERTEX_COLOR, true); + mat->set_flag(SpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); + mat->set_albedo(get_debug_collision_contact_color()); Vector3 diamond[6] = { Vector3(-1, 0, 0), diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 717e76c5fd..a22d897669 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -1473,8 +1473,8 @@ void Viewport::_gui_show_tooltip() { gui.tooltip_label->set_anchor_and_margin(MARGIN_LEFT, Control::ANCHOR_BEGIN, ttp->get_margin(MARGIN_LEFT)); gui.tooltip_label->set_anchor_and_margin(MARGIN_TOP, Control::ANCHOR_BEGIN, ttp->get_margin(MARGIN_TOP)); - gui.tooltip_label->set_anchor_and_margin(MARGIN_RIGHT, Control::ANCHOR_END, ttp->get_margin(MARGIN_RIGHT)); - gui.tooltip_label->set_anchor_and_margin(MARGIN_BOTTOM, Control::ANCHOR_END, ttp->get_margin(MARGIN_BOTTOM)); + gui.tooltip_label->set_anchor_and_margin(MARGIN_RIGHT, Control::ANCHOR_END, -ttp->get_margin(MARGIN_RIGHT)); + gui.tooltip_label->set_anchor_and_margin(MARGIN_BOTTOM, Control::ANCHOR_END, -ttp->get_margin(MARGIN_BOTTOM)); gui.tooltip_label->set_text(tooltip); Rect2 r(gui.tooltip_pos + Point2(10, 10), gui.tooltip_label->get_combined_minimum_size() + ttp->get_minimum_size()); Rect2 vr = gui.tooltip_label->get_viewport_rect(); @@ -1932,8 +1932,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { Control *top = gui.modal_stack.back()->get(); if (over != top && !top->is_a_parent_of(over)) { - - return; // don't send motion event to anything below modal stack top + over = NULL; //nothing can be found outside the modal stack } } diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp index 3e612c745f..d1dff13774 100644 --- a/scene/resources/default_theme/default_theme.cpp +++ b/scene/resources/default_theme/default_theme.cpp @@ -488,6 +488,7 @@ void fill_default_theme(Ref<Theme> &t, const Ref<Font> &default_font, const Ref< t->set_stylebox("scroll_focus", "HScrollBar", make_stylebox(scroll_bg_png, 5, 5, 5, 5, 0, 0, 0, 0)); t->set_stylebox("grabber", "HScrollBar", make_stylebox(scroll_grabber_png, 5, 5, 5, 5, 2, 2, 2, 2)); t->set_stylebox("grabber_highlight", "HScrollBar", make_stylebox(scroll_grabber_hl_png, 5, 5, 5, 5, 2, 2, 2, 2)); + t->set_stylebox("grabber_pressed", "HScrollBar", make_stylebox(scroll_grabber_pressed_png, 5, 5, 5, 5, 2, 2, 2, 2)); t->set_icon("increment", "HScrollBar", empty_icon); t->set_icon("increment_highlight", "HScrollBar", empty_icon); @@ -500,6 +501,7 @@ void fill_default_theme(Ref<Theme> &t, const Ref<Font> &default_font, const Ref< t->set_stylebox("scroll_focus", "VScrollBar", make_stylebox(scroll_bg_png, 5, 5, 5, 5, 0, 0, 0, 0)); t->set_stylebox("grabber", "VScrollBar", make_stylebox(scroll_grabber_png, 5, 5, 5, 5, 2, 2, 2, 2)); t->set_stylebox("grabber_highlight", "VScrollBar", make_stylebox(scroll_grabber_hl_png, 5, 5, 5, 5, 2, 2, 2, 2)); + t->set_stylebox("grabber_pressed", "VScrollBar", make_stylebox(scroll_grabber_pressed_png, 5, 5, 5, 5, 2, 2, 2, 2)); t->set_icon("increment", "VScrollBar", empty_icon); t->set_icon("increment_highlight", "VScrollBar", empty_icon); diff --git a/scene/resources/default_theme/scroll_grabber_pressed.png b/scene/resources/default_theme/scroll_grabber_pressed.png Binary files differnew file mode 100644 index 0000000000..a46d242ddd --- /dev/null +++ b/scene/resources/default_theme/scroll_grabber_pressed.png diff --git a/scene/resources/default_theme/theme_data.h b/scene/resources/default_theme/theme_data.h index 70a8ad12cb..bed4bdb760 100644 --- a/scene/resources/default_theme/theme_data.h +++ b/scene/resources/default_theme/theme_data.h @@ -334,6 +334,10 @@ static const unsigned char scroll_grabber_hl_png[] = { 0x89, 0x50, 0x4e, 0x47, 0xd, 0xa, 0x1a, 0xa, 0x0, 0x0, 0x0, 0xd, 0x49, 0x48, 0x44, 0x52, 0x0, 0x0, 0x0, 0xc, 0x0, 0x0, 0x0, 0xc, 0x8, 0x3, 0x0, 0x0, 0x0, 0x61, 0xab, 0xac, 0xd5, 0x0, 0x0, 0x0, 0x4, 0x67, 0x41, 0x4d, 0x41, 0x0, 0x0, 0xb1, 0x8f, 0xb, 0xfc, 0x61, 0x5, 0x0, 0x0, 0x0, 0x20, 0x63, 0x48, 0x52, 0x4d, 0x0, 0x0, 0x7a, 0x26, 0x0, 0x0, 0x80, 0x84, 0x0, 0x0, 0xfa, 0x0, 0x0, 0x0, 0x80, 0xe8, 0x0, 0x0, 0x75, 0x30, 0x0, 0x0, 0xea, 0x60, 0x0, 0x0, 0x3a, 0x98, 0x0, 0x0, 0x17, 0x70, 0x9c, 0xba, 0x51, 0x3c, 0x0, 0x0, 0x0, 0x6c, 0x50, 0x4c, 0x54, 0x45, 0x0, 0x0, 0x0, 0x97, 0xd0, 0xdf, 0x92, 0xcb, 0xdc, 0x84, 0xbb, 0xd4, 0x92, 0xca, 0xdc, 0x95, 0xd0, 0xdd, 0x83, 0xbb, 0xd3, 0x8b, 0xc8, 0xd7, 0x79, 0xb5, 0xcb, 0x78, 0xb4, 0xca, 0x73, 0xb0, 0xc7, 0x73, 0xb0, 0xc7, 0x7b, 0xc0, 0xcf, 0x79, 0xc5, 0xd1, 0x6b, 0xae, 0xc1, 0x75, 0xc6, 0xcf, 0x70, 0xbc, 0xca, 0x64, 0xa6, 0xbc, 0x71, 0xbc, 0xc9, 0x82, 0xba, 0xd4, 0x6a, 0xa2, 0xc6, 0x62, 0x9a, 0xc2, 0x61, 0x9a, 0xc1, 0x68, 0x9f, 0xc2, 0x5d, 0x92, 0xbb, 0x5c, 0x92, 0xb8, 0x58, 0x8d, 0xb6, 0x59, 0x8e, 0xb3, 0x56, 0x89, 0xb0, 0x5c, 0x91, 0xb2, 0x53, 0x84, 0xa9, 0x58, 0x8f, 0xae, 0x54, 0x83, 0xa4, 0x57, 0x8e, 0xad, 0x64, 0xa5, 0xba, 0xff, 0xff, 0xff, 0xbb, 0x65, 0x65, 0x27, 0x0, 0x0, 0x0, 0x13, 0x74, 0x52, 0x4e, 0x53, 0x0, 0x25, 0xad, 0xf1, 0xad, 0x27, 0xef, 0xad, 0xf1, 0xf3, 0xf1, 0xf3, 0xad, 0x28, 0xef, 0x27, 0xad, 0xf2, 0xad, 0xcd, 0x8a, 0x27, 0xfe, 0x0, 0x0, 0x0, 0x1, 0x62, 0x4b, 0x47, 0x44, 0x23, 0x2a, 0x62, 0x6c, 0x3a, 0x0, 0x0, 0x0, 0x9, 0x70, 0x48, 0x59, 0x73, 0x0, 0x0, 0xb, 0x13, 0x0, 0x0, 0xb, 0x13, 0x1, 0x0, 0x9a, 0x9c, 0x18, 0x0, 0x0, 0x0, 0x7, 0x74, 0x49, 0x4d, 0x45, 0x7, 0xe0, 0x6, 0x16, 0x12, 0x2b, 0x5, 0x39, 0x1a, 0x32, 0x39, 0x0, 0x0, 0x0, 0x50, 0x49, 0x44, 0x41, 0x54, 0x8, 0xd7, 0x63, 0x60, 0xc0, 0x7, 0x18, 0x99, 0x98, 0x85, 0x59, 0x18, 0x21, 0x6c, 0x56, 0x36, 0x11, 0x51, 0x31, 0x11, 0x36, 0x56, 0x30, 0x87, 0x5d, 0x5c, 0x2, 0x8, 0xc4, 0xd9, 0xc1, 0x1c, 0xe, 0x49, 0x29, 0x20, 0x90, 0xe4, 0x4, 0x73, 0xb8, 0xa4, 0x65, 0x80, 0x40, 0x9a, 0x1b, 0xcc, 0xe1, 0x91, 0x95, 0x3, 0x2, 0x59, 0x1e, 0x30, 0x87, 0x97, 0x4f, 0x5e, 0x41, 0x41, 0x91, 0x8f, 0x17, 0x62, 0x1c, 0xbf, 0x80, 0xa0, 0x92, 0x10, 0x3f, 0x5e, 0xdb, 0x1, 0x41, 0x87, 0x4, 0x7d, 0x15, 0xc4, 0xfd, 0x6a, 0x0, 0x0, 0x0, 0x19, 0x74, 0x45, 0x58, 0x74, 0x43, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x0, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x47, 0x49, 0x4d, 0x50, 0x57, 0x81, 0xe, 0x17, 0x0, 0x0, 0x0, 0x25, 0x74, 0x45, 0x58, 0x74, 0x64, 0x61, 0x74, 0x65, 0x3a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x0, 0x32, 0x30, 0x31, 0x36, 0x2d, 0x30, 0x36, 0x2d, 0x32, 0x32, 0x54, 0x32, 0x30, 0x3a, 0x33, 0x39, 0x3a, 0x32, 0x36, 0x2b, 0x30, 0x32, 0x3a, 0x30, 0x30, 0xc9, 0xad, 0xc8, 0x52, 0x0, 0x0, 0x0, 0x25, 0x74, 0x45, 0x58, 0x74, 0x64, 0x61, 0x74, 0x65, 0x3a, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x79, 0x0, 0x32, 0x30, 0x31, 0x36, 0x2d, 0x30, 0x36, 0x2d, 0x32, 0x32, 0x54, 0x32, 0x30, 0x3a, 0x33, 0x39, 0x3a, 0x32, 0x36, 0x2b, 0x30, 0x32, 0x3a, 0x30, 0x30, 0xb8, 0xf0, 0x70, 0xee, 0x0, 0x0, 0x0, 0x0, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82 }; +static const unsigned char scroll_grabber_pressed_png[] = { + 0x89, 0x50, 0x4e, 0x47, 0xd, 0xa, 0x1a, 0xa, 0x0, 0x0, 0x0, 0xd, 0x49, 0x48, 0x44, 0x52, 0x0, 0x0, 0x0, 0xc, 0x0, 0x0, 0x0, 0xc, 0x8, 0x6, 0x0, 0x0, 0x0, 0x56, 0x75, 0x5c, 0xe7, 0x0, 0x0, 0x0, 0x4, 0x73, 0x42, 0x49, 0x54, 0x8, 0x8, 0x8, 0x8, 0x7c, 0x8, 0x64, 0x88, 0x0, 0x0, 0x0, 0x9, 0x70, 0x48, 0x59, 0x73, 0x0, 0x0, 0xd, 0xd7, 0x0, 0x0, 0xd, 0xd7, 0x1, 0x42, 0x28, 0x9b, 0x78, 0x0, 0x0, 0x0, 0x19, 0x74, 0x45, 0x58, 0x74, 0x53, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72, 0x65, 0x0, 0x77, 0x77, 0x77, 0x2e, 0x69, 0x6e, 0x6b, 0x73, 0x63, 0x61, 0x70, 0x65, 0x2e, 0x6f, 0x72, 0x67, 0x9b, 0xee, 0x3c, 0x1a, 0x0, 0x0, 0x0, 0x66, 0x49, 0x44, 0x41, 0x54, 0x28, 0x91, 0xcd, 0x91, 0xb1, 0xa, 0xc0, 0x20, 0x10, 0x43, 0x63, 0x71, 0xbf, 0x5f, 0x12, 0x9c, 0xfd, 0x1a, 0x3f, 0xcd, 0xa9, 0x83, 0xe0, 0x2f, 0x65, 0x2f, 0x9c, 0x8b, 0x83, 0x47, 0xed, 0x60, 0xbb, 0x34, 0xdb, 0x3d, 0x12, 0x48, 0x38, 0xa7, 0xaa, 0xd8, 0xd1, 0xb1, 0xe5, 0x7e, 0x13, 0xf0, 0xf3, 0xd1, 0x5a, 0xf3, 0x24, 0x23, 0x80, 0x34, 0x50, 0x11, 0x91, 0x1a, 0x42, 0xb8, 0x96, 0x1, 0x92, 0x51, 0x55, 0xf3, 0x84, 0x32, 0x49, 0x0, 0x38, 0x9f, 0x2a, 0x25, 0xdc, 0x65, 0xd8, 0xe7, 0xd1, 0x65, 0xe1, 0x31, 0xcc, 0x6c, 0x10, 0x91, 0x3a, 0x3a, 0x9b, 0xd1, 0xb3, 0xc7, 0xfd, 0xef, 0x71, 0x1d, 0x42, 0xe6, 0x21, 0x43, 0xf5, 0x2b, 0xd8, 0x6c, 0x0, 0x0, 0x0, 0x0, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82 +}; + static const unsigned char selection_png[] = { 0x89, 0x50, 0x4e, 0x47, 0xd, 0xa, 0x1a, 0xa, 0x0, 0x0, 0x0, 0xd, 0x49, 0x48, 0x44, 0x52, 0x0, 0x0, 0x0, 0x10, 0x0, 0x0, 0x0, 0x10, 0x4, 0x3, 0x0, 0x0, 0x0, 0xed, 0xdd, 0xe2, 0x52, 0x0, 0x0, 0x0, 0x4, 0x67, 0x41, 0x4d, 0x41, 0x0, 0x0, 0xb1, 0x8f, 0xb, 0xfc, 0x61, 0x5, 0x0, 0x0, 0x0, 0x20, 0x63, 0x48, 0x52, 0x4d, 0x0, 0x0, 0x7a, 0x26, 0x0, 0x0, 0x80, 0x84, 0x0, 0x0, 0xfa, 0x0, 0x0, 0x0, 0x80, 0xe8, 0x0, 0x0, 0x75, 0x30, 0x0, 0x0, 0xea, 0x60, 0x0, 0x0, 0x3a, 0x98, 0x0, 0x0, 0x17, 0x70, 0x9c, 0xba, 0x51, 0x3c, 0x0, 0x0, 0x0, 0x2d, 0x50, 0x4c, 0x54, 0x45, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xfd, 0xfb, 0xff, 0xfd, 0xf7, 0xff, 0xfd, 0xf7, 0xff, 0xfd, 0xf7, 0xff, 0xfd, 0xf6, 0xff, 0xf6, 0xf4, 0xff, 0x15, 0x15, 0x17, 0xff, 0x70, 0xc0, 0x21, 0x0, 0x0, 0x0, 0xe, 0x74, 0x52, 0x4e, 0x53, 0x6, 0xf, 0x16, 0x18, 0x2a, 0x3b, 0x40, 0x3c, 0x6, 0x3d, 0x44, 0x3e, 0x31, 0x25, 0x8, 0x3d, 0x16, 0xb4, 0x0, 0x0, 0x0, 0x1, 0x62, 0x4b, 0x47, 0x44, 0xe, 0x6f, 0xbd, 0x30, 0x4f, 0x0, 0x0, 0x0, 0x9, 0x70, 0x48, 0x59, 0x73, 0x0, 0x0, 0xb, 0x13, 0x0, 0x0, 0xb, 0x13, 0x1, 0x0, 0x9a, 0x9c, 0x18, 0x0, 0x0, 0x0, 0x7, 0x74, 0x49, 0x4d, 0x45, 0x7, 0xe0, 0x6, 0x16, 0x12, 0x2b, 0x5, 0x39, 0x1a, 0x32, 0x39, 0x0, 0x0, 0x0, 0x37, 0x49, 0x44, 0x41, 0x54, 0x8, 0xd7, 0x63, 0x60, 0x54, 0x36, 0x6, 0x2, 0x23, 0x1, 0x6, 0x91, 0xb0, 0x34, 0x20, 0x48, 0x75, 0x64, 0x50, 0xef, 0x5c, 0x5, 0x4, 0x33, 0x8a, 0x18, 0xcc, 0xf6, 0xdc, 0x5, 0x82, 0xd3, 0xc9, 0xc, 0x66, 0x6b, 0x41, 0x8c, 0x5b, 0x94, 0x33, 0x60, 0x6, 0xc2, 0xad, 0x80, 0x5b, 0xa, 0x73, 0x6, 0x0, 0x45, 0x34, 0x48, 0x41, 0xa3, 0xc5, 0x91, 0x23, 0x0, 0x0, 0x0, 0x25, 0x74, 0x45, 0x58, 0x74, 0x64, 0x61, 0x74, 0x65, 0x3a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x0, 0x32, 0x30, 0x31, 0x36, 0x2d, 0x30, 0x36, 0x2d, 0x32, 0x32, 0x54, 0x32, 0x30, 0x3a, 0x33, 0x39, 0x3a, 0x32, 0x36, 0x2b, 0x30, 0x32, 0x3a, 0x30, 0x30, 0xc9, 0xad, 0xc8, 0x52, 0x0, 0x0, 0x0, 0x25, 0x74, 0x45, 0x58, 0x74, 0x64, 0x61, 0x74, 0x65, 0x3a, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x79, 0x0, 0x32, 0x30, 0x31, 0x36, 0x2d, 0x30, 0x36, 0x2d, 0x32, 0x32, 0x54, 0x32, 0x30, 0x3a, 0x33, 0x39, 0x3a, 0x32, 0x36, 0x2b, 0x30, 0x32, 0x3a, 0x30, 0x30, 0xb8, 0xf0, 0x70, 0xee, 0x0, 0x0, 0x0, 0x0, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82 }; diff --git a/scene/resources/environment.cpp b/scene/resources/environment.cpp index c121dae1f1..0bf6a50d93 100644 --- a/scene/resources/environment.cpp +++ b/scene/resources/environment.cpp @@ -1135,6 +1135,8 @@ void Environment::_bind_methods() { Environment::Environment() { + environment = VS::get_singleton()->environment_create(); + bg_mode = BG_CLEAR_COLOR; bg_sky_scale = 1.0; bg_energy = 1.0; @@ -1160,8 +1162,6 @@ Environment::Environment() { set_adjustment_enable(adjustment_enabled); //update - environment = VS::get_singleton()->environment_create(); - ssr_enabled = false; ssr_max_steps = 64; ssr_fade_in = 0.15; diff --git a/servers/physics/broad_phase_octree.cpp b/servers/physics/broad_phase_octree.cpp index 2439fbeae9..e1aaf4e31a 100644 --- a/servers/physics/broad_phase_octree.cpp +++ b/servers/physics/broad_phase_octree.cpp @@ -78,7 +78,7 @@ int BroadPhaseOctree::cull_segment(const Vector3 &p_from, const Vector3 &p_to, C int BroadPhaseOctree::cull_aabb(const Rect3 &p_aabb, CollisionObjectSW **p_results, int p_max_results, int *p_result_indices) { - return octree.cull_AABB(p_aabb, p_results, p_max_results, p_result_indices); + return octree.cull_aabb(p_aabb, p_results, p_max_results, p_result_indices); } void *BroadPhaseOctree::_pair_callback(void *self, OctreeElementID p_A, CollisionObjectSW *p_object_A, int subindex_A, OctreeElementID p_B, CollisionObjectSW *p_object_B, int subindex_B) { diff --git a/servers/physics_2d/space_2d_sw.cpp b/servers/physics_2d/space_2d_sw.cpp index a17d1f6a12..29f879d8e9 100644 --- a/servers/physics_2d/space_2d_sw.cpp +++ b/servers/physics_2d/space_2d_sw.cpp @@ -678,25 +678,21 @@ bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, co } } - if (col_obj->get_type() == CollisionObject2DSW::TYPE_BODY) { + if (col_obj->is_shape_set_as_one_way_collision(j)) { - const Body2DSW *body = static_cast<const Body2DSW *>(col_obj); - if (col_obj->is_shape_set_as_one_way_collision(j)) { + Vector2 cd[2]; + Physics2DServerSW::CollCbkData cbk; + cbk.max = 1; + cbk.amount = 0; + cbk.ptr = cd; + cbk.valid_dir = body_shape_xform.get_axis(1).normalized(); + ; + cbk.valid_depth = 10e20; - Vector2 cd[2]; - Physics2DServerSW::CollCbkData cbk; - cbk.max = 1; - cbk.amount = 0; - cbk.ptr = cd; - cbk.valid_dir = body_shape_xform.get_axis(1).normalized(); - ; - cbk.valid_depth = 10e20; - - Vector2 sep = mnormal; //important optimization for this to work fast enough - bool collided = CollisionSolver2DSW::solve(body_shape, body_shape_xform, p_motion * (hi + contact_max_allowed_penetration), col_obj->get_shape(shape_idx), col_obj_xform, Vector2(), Physics2DServerSW::_shape_col_cbk, &cbk, &sep, 0); - if (!collided || cbk.amount == 0) { - continue; - } + Vector2 sep = mnormal; //important optimization for this to work fast enough + bool collided = CollisionSolver2DSW::solve(body_shape, body_shape_xform, p_motion * (hi + contact_max_allowed_penetration), col_obj->get_shape(shape_idx), col_obj_xform, Vector2(), Physics2DServerSW::_shape_col_cbk, &cbk, &sep, 0); + if (!collided || cbk.amount == 0) { + continue; } } diff --git a/servers/visual/visual_server_raster.cpp b/servers/visual/visual_server_raster.cpp index cc4fe0809d..4f16ae4125 100644 --- a/servers/visual/visual_server_raster.cpp +++ b/servers/visual/visual_server_raster.cpp @@ -2902,7 +2902,7 @@ Vector<RID> VisualServerRaster::instances_cull_aabb(const AABB& p_aabb, RID p_sc int culled=0; Instance *cull[1024]; - culled=scenario->octree.cull_AABB(p_aabb,cull,1024); + culled=scenario->octree.cull_aabb(p_aabb,cull,1024); for (int i=0;i<culled;i++) { diff --git a/servers/visual/visual_server_scene.cpp b/servers/visual/visual_server_scene.cpp index 11a9c8c9c1..d0990f0bc8 100644 --- a/servers/visual/visual_server_scene.cpp +++ b/servers/visual/visual_server_scene.cpp @@ -910,7 +910,7 @@ Vector<ObjectID> VisualServerScene::instances_cull_aabb(const Rect3 &p_aabb, RID int culled = 0; Instance *cull[1024]; - culled = scenario->octree.cull_AABB(p_aabb, cull, 1024); + culled = scenario->octree.cull_aabb(p_aabb, cull, 1024); for (int i = 0; i < culled; i++) { |