diff --git a/addons/gloot/ui/ctrl_dragable.gd b/addons/gloot/ui/ctrl_dragable.gd index bb5b80ef..203429e7 100644 --- a/addons/gloot/ui/ctrl_dragable.gd +++ b/addons/gloot/ui/ctrl_dragable.gd @@ -78,7 +78,7 @@ static func get_grab_offset() -> Vector2: func drag_start() -> void: - if drag_preview == null: + if !is_instance_valid(drag_preview): return drag_preview.mouse_filter = Control.MOUSE_FILTER_IGNORE @@ -94,7 +94,7 @@ func _get_global_preview_position() -> Vector2: func drag_end() -> void: - if drag_preview == null: + if !is_instance_valid(drag_preview): return _preview_canvas_layer.remove_child(drag_preview) @@ -103,12 +103,12 @@ func drag_end() -> void: func _notification(what) -> void: - if what == NOTIFICATION_PREDELETE && _preview_canvas_layer: + if what == NOTIFICATION_PREDELETE && is_instance_valid(_preview_canvas_layer): _preview_canvas_layer.queue_free() func _process(_delta) -> void: - if drag_preview: + if is_instance_valid(drag_preview): drag_preview.global_position = _get_global_preview_position() diff --git a/addons/gloot/ui/ctrl_inventory.gd b/addons/gloot/ui/ctrl_inventory.gd index f999989d..ff8391cf 100644 --- a/addons/gloot/ui/ctrl_inventory.gd +++ b/addons/gloot/ui/ctrl_inventory.gd @@ -17,7 +17,7 @@ signal inventory_item_context_activated(item) if is_inside_tree(): assert(node is Inventory) - self.inventory = node + inventory = node update_configuration_warnings() @@ -50,7 +50,7 @@ func _get_configuration_warnings() -> PackedStringArray: func _ready(): if Engine.is_editor_hint(): # Clean up, in case it is duplicated in the editor - if _vbox_container: + if is_instance_valid(_vbox_container): _vbox_container.queue_free() _vbox_container = VBoxContainer.new() @@ -68,13 +68,13 @@ func _ready(): _vbox_container.add_child(_item_list) if has_node(inventory_path): - self.inventory = get_node(inventory_path) + inventory = get_node(inventory_path) _refresh() func _connect_inventory_signals() -> void: - if !inventory: + if !is_instance_valid(inventory): return if !inventory.contents_changed.is_connected(_refresh): @@ -84,7 +84,7 @@ func _connect_inventory_signals() -> void: func _disconnect_inventory_signals() -> void: - if !inventory: + if !is_instance_valid(inventory): return if inventory.contents_changed.is_connected(_refresh): @@ -113,12 +113,12 @@ func _refresh() -> void: func _clear_list() -> void: - if _item_list: + if is_instance_valid(_item_list): _item_list.clear() func _populate_list() -> void: - if inventory == null: + if !is_instance_valid(inventory): return for item in inventory.get_items(): diff --git a/addons/gloot/ui/ctrl_inventory_grid.gd b/addons/gloot/ui/ctrl_inventory_grid.gd index e9746e01..ec7ac95d 100644 --- a/addons/gloot/ui/ctrl_inventory_grid.gd +++ b/addons/gloot/ui/ctrl_inventory_grid.gd @@ -46,7 +46,7 @@ const CtrlDragable = preload("res://addons/gloot/ui/ctrl_dragable.gd") if is_inside_tree(): assert(node is InventoryGrid) - self.inventory = node + inventory = node update_configuration_warnings() @export var default_item_texture: Texture2D : set(new_default_item_texture): @@ -69,8 +69,8 @@ var inventory: InventoryGrid = null : _connect_inventory_signals() _refresh() -var _ctrl_item_container: WeakRef = weakref(null) -var _ctrl_drop_zone: CtrlDropZone +var _ctrl_item_container: Control = null +var _ctrl_drop_zone: CtrlDropZone = null var _selected_item: InventoryItem = null @@ -85,17 +85,15 @@ func _get_configuration_warnings() -> PackedStringArray: func _ready() -> void: if Engine.is_editor_hint(): # Clean up, in case it is duplicated in the editor - var ctrl_item_container = _ctrl_item_container.get_ref() - if ctrl_item_container: - ctrl_item_container.queue_free() - - var ctrl_item_container = Control.new() - ctrl_item_container.size_flags_horizontal = SIZE_EXPAND_FILL - ctrl_item_container.size_flags_vertical = SIZE_EXPAND_FILL - ctrl_item_container.anchor_right = 1.0 - ctrl_item_container.anchor_bottom = 1.0 - add_child(ctrl_item_container) - _ctrl_item_container = weakref(ctrl_item_container) + if is_instance_valid(_ctrl_item_container): + _ctrl_item_container.queue_free() + + _ctrl_item_container = Control.new() + _ctrl_item_container.size_flags_horizontal = SIZE_EXPAND_FILL + _ctrl_item_container.size_flags_vertical = SIZE_EXPAND_FILL + _ctrl_item_container.anchor_right = 1.0 + _ctrl_item_container.anchor_bottom = 1.0 + add_child(_ctrl_item_container) _ctrl_drop_zone = CtrlDropZone.new() _ctrl_drop_zone.dragable_dropped.connect(_on_dragable_dropped) @@ -112,16 +110,16 @@ func _ready() -> void: add_child(_ctrl_drop_zone) _ctrl_drop_zone.deactivate() - ctrl_item_container.resized.connect(func(): _ctrl_drop_zone.size = ctrl_item_container.size) + _ctrl_item_container.resized.connect(func(): _ctrl_drop_zone.size = _ctrl_item_container.size) if has_node(inventory_path): - self.inventory = get_node_or_null(inventory_path) + inventory = get_node_or_null(inventory_path) _refresh() func _connect_inventory_signals() -> void: - if !inventory: + if !is_instance_valid(inventory): return if !inventory.contents_changed.is_connected(_refresh): @@ -135,7 +133,7 @@ func _connect_inventory_signals() -> void: func _disconnect_inventory_signals() -> void: - if !inventory: + if !is_instance_valid(inventory): return if inventory.contents_changed.is_connected(_refresh): @@ -169,7 +167,7 @@ func _refresh() -> void: func _draw() -> void: - if !inventory: + if !is_instance_valid(inventory): return if draw_grid: _draw_grid(Vector2.ZERO, inventory.size.x, inventory.size.y, field_dimensions, item_spacing) @@ -213,7 +211,7 @@ func _get_inventory_size_px() -> Vector2: func _refresh_grid_container() -> void: - if !inventory: + if !is_instance_valid(inventory): return custom_minimum_size = _get_inventory_size_px() @@ -221,18 +219,16 @@ func _refresh_grid_container() -> void: func _clear_list() -> void: - var ctrl_item_container = _ctrl_item_container.get_ref() - if !ctrl_item_container: + if !is_instance_valid(_ctrl_item_container): return - for ctrl_inventory_item in ctrl_item_container.get_children(): - ctrl_item_container.remove_child(ctrl_inventory_item) + for ctrl_inventory_item in _ctrl_item_container.get_children(): + _ctrl_item_container.remove_child(ctrl_inventory_item) ctrl_inventory_item.queue_free() func _populate_list() -> void: - var ctrl_item_container = _ctrl_item_container.get_ref() - if inventory == null || ctrl_item_container == null: + if !is_instance_valid(inventory) || !is_instance_valid(_ctrl_item_container): return for item in inventory.get_items(): @@ -253,7 +249,7 @@ func _populate_list() -> void: # Position the item centered when it's not streched ctrl_inventory_item.position += _get_unstreched_sprite_offset(item) - ctrl_item_container.add_child(ctrl_inventory_item) + _ctrl_item_container.add_child(ctrl_inventory_item) _refresh_selection() @@ -262,10 +258,10 @@ func _refresh_selection() -> void: if !draw_selections: return - if !_ctrl_item_container.get_ref(): + if !is_instance_valid(_ctrl_item_container): return - for ctrl_item in _ctrl_item_container.get_ref().get_children(): + for ctrl_item in _ctrl_item_container.get_children(): ctrl_item.selected = ctrl_item.item && (ctrl_item.item == _selected_item) ctrl_item.selection_bg_color = selection_color @@ -359,7 +355,7 @@ func _on_dragable_dropped(dragable: CtrlDragable, drop_position: Vector2) -> voi if item == null: return - if !inventory: + if !is_instance_valid(inventory): return if inventory.has_item(item): diff --git a/addons/gloot/ui/ctrl_inventory_grid_ex.gd b/addons/gloot/ui/ctrl_inventory_grid_ex.gd index c4ca67bb..af44db2b 100644 --- a/addons/gloot/ui/ctrl_inventory_grid_ex.gd +++ b/addons/gloot/ui/ctrl_inventory_grid_ex.gd @@ -46,7 +46,7 @@ func _refresh() -> void: func _refresh_selection() -> void: super._refresh_selection() - if !_selection_panel: + if !is_instance_valid(_selection_panel): return _selection_panel.visible = (_selected_item != null) && (selection_style != null) if _selected_item: @@ -59,7 +59,7 @@ func _refresh_selection() -> void: func _refresh_field_background_grid() -> void: - if _field_background_grid: + if is_instance_valid(_field_background_grid): remove_child(_field_background_grid) _field_background_grid.queue_free() _field_background_grid = null @@ -69,7 +69,7 @@ func _refresh_field_background_grid() -> void: func _create_field_background_grid() -> void: - if !inventory || _field_background_grid != null: + if !is_instance_valid(inventory) || is_instance_valid(_field_background_grid): return _field_background_grid = Control.new() @@ -89,7 +89,7 @@ func _create_field_background_grid() -> void: func _create_selection_panel() -> void: - if _selection_panel != null: + if !is_instance_valid(_selection_panel): return _selection_panel = Panel.new() add_child(_selection_panel); @@ -116,7 +116,7 @@ func _ready() -> void: func _on_selection_changed() -> void: - if !inventory: + if !is_instance_valid(inventory): return if !field_selected_style: return @@ -135,7 +135,7 @@ func _on_inventory_resized() -> void: func _input(event) -> void: if !(event is InputEventMouseMotion): return - if !inventory: + if !is_instance_valid(inventory): return var hovered_field_coords := Vector2i(-1, -1) diff --git a/addons/gloot/ui/ctrl_inventory_item_rect.gd b/addons/gloot/ui/ctrl_inventory_item_rect.gd index b9f95dcf..2354b220 100644 --- a/addons/gloot/ui/ctrl_inventory_item_rect.gd +++ b/addons/gloot/ui/ctrl_inventory_item_rect.gd @@ -59,7 +59,7 @@ func _connect_item_signals(new_item: InventoryItem) -> void: func _disconnect_item_signals() -> void: - if item == null: + if !is_instance_valid(item): return if item.protoset_changed.is_connected(_refresh): @@ -71,13 +71,13 @@ func _disconnect_item_signals() -> void: func _get_item_size() -> Vector2: - if item && item.get_inventory(): + if is_instance_valid(item) && item.get_inventory(): return item.get_inventory().get_item_size(item) return Vector2(1, 1) func _get_item_position() -> Vector2: - if item && item.get_inventory(): + if is_instance_valid(item) && item.get_inventory(): return item.get_inventory().get_item_position(item) return Vector2(0, 0) @@ -106,7 +106,7 @@ func _ready() -> void: _refresh() func _update_selection() -> void: - if _selection_rect == null: + if !is_instance_valid(_selection_rect): return _selection_rect.visible = selected _selection_rect.color = selection_bg_color @@ -114,10 +114,10 @@ func _update_selection() -> void: func _update_texture() -> void: - if _texture_rect == null: + if !is_instance_valid(_texture_rect): return _texture_rect.texture = texture - if item == null: + if !is_instance_valid(item): return if GridConstraint.is_item_rotated(item): _texture_rect.size = Vector2(size.y, size.x) @@ -135,9 +135,9 @@ func _update_texture() -> void: func _update_stack_size() -> void: - if _stack_size_label == null: + if !is_instance_valid(_stack_size_label): return - if item == null: + if !is_instance_valid(item): _stack_size_label.text = "" return var stack_size: int = StacksConstraint.get_item_stack_size(item) diff --git a/addons/gloot/ui/ctrl_inventory_stacked.gd b/addons/gloot/ui/ctrl_inventory_stacked.gd index 68f6a463..435ee3a3 100644 --- a/addons/gloot/ui/ctrl_inventory_stacked.gd +++ b/addons/gloot/ui/ctrl_inventory_stacked.gd @@ -63,10 +63,10 @@ func _disconnect_inventory_signals() -> void: func _refresh(): super._refresh() - if _label: + if is_instance_valid(_label): _label.visible = label_visible _label.text = "%d/%d" % [inventory.occupied_space, inventory.capacity] - if _progress_bar: + if is_instance_valid(_progress_bar): _progress_bar.visible = progress_bar_visible _progress_bar.min_value = 0 _progress_bar.max_value = inventory.capacity diff --git a/addons/gloot/ui/ctrl_item_slot.gd b/addons/gloot/ui/ctrl_item_slot.gd index cff4351b..7e17cc2d 100644 --- a/addons/gloot/ui/ctrl_item_slot.gd +++ b/addons/gloot/ui/ctrl_item_slot.gd @@ -50,7 +50,7 @@ const CtrlDragable = preload("res://addons/gloot/ui/ctrl_dragable.gd") if label_visible == new_label_visible: return label_visible = new_label_visible - if _label: + if is_instance_valid(_label): _label.visible = label_visible var item_slot: ItemSlotBase : set(new_item_slot): @@ -77,7 +77,7 @@ func _get_configuration_warnings() -> PackedStringArray: func _connect_item_slot_signals() -> void: - if !item_slot: + if !is_instance_valid(item_slot): return if !item_slot.item_equipped.is_connected(_refresh): @@ -87,7 +87,7 @@ func _connect_item_slot_signals() -> void: func _disconnect_item_slot_signals() -> void: - if !item_slot: + if !is_instance_valid(item_slot): return if item_slot.item_equipped.is_connected(_refresh): @@ -99,7 +99,7 @@ func _disconnect_item_slot_signals() -> void: func _ready(): if Engine.is_editor_hint(): # Clean up, in case it is duplicated in the editor - if _hbox_container: + if is_instance_valid(_hbox_container): _hbox_container.queue_free() var node: Node = get_node_or_null(item_slot_path) @@ -150,7 +150,7 @@ func _on_dragable_dropped(dragable: CtrlDragable, drop_position: Vector2) -> voi if !item: return - if !item_slot: + if !is_instance_valid(item_slot): return if !item_slot.can_hold_item(item): @@ -193,16 +193,16 @@ func _on_any_dragable_dropped(dragable: CtrlDragable, zone: CtrlDropZone, drop_p func _refresh() -> void: _clear() - if item_slot == null: + if !is_instance_valid(item_slot): return if item_slot.get_item() == null: return var item = item_slot.get_item() - if _label: + if is_instance_valid(_label): _label.text = item.get_property(CtrlInventory.KEY_NAME, item.prototype_id) - if _ctrl_inventory_item_rect: + if is_instance_valid(_ctrl_inventory_item_rect): _ctrl_inventory_item_rect.item = item if item.get_texture(): _ctrl_inventory_item_rect.texture = item.get_texture() @@ -212,9 +212,9 @@ func _refresh() -> void: func _clear() -> void: - if _label: + if is_instance_valid(_label): _label.text = "" - if _ctrl_inventory_item_rect: + if is_instance_valid(_ctrl_inventory_item_rect): _ctrl_inventory_item_rect.item = null _ctrl_inventory_item_rect.texture = default_item_icon diff --git a/addons/gloot/ui/ctrl_item_slot_ex.gd b/addons/gloot/ui/ctrl_item_slot_ex.gd index 80d35b53..13c98e30 100644 --- a/addons/gloot/ui/ctrl_item_slot_ex.gd +++ b/addons/gloot/ui/ctrl_item_slot_ex.gd @@ -17,7 +17,7 @@ var _background_panel: Panel func _ready(): super._ready() resized.connect(func(): - if _background_panel: + if is_instance_valid(_background_panel): _background_panel.size = size ) @@ -28,7 +28,7 @@ func _refresh() -> void: func _update_background() -> void: - if !_background_panel: + if !is_instance_valid(_background_panel): _background_panel = Panel.new() add_child(_background_panel) move_child(_background_panel, 0)