mirror of
https://github.com/D4M13N-D3V/godot_grid_inventory.git
synced 2025-03-14 08:14:55 +00:00
feat added item rotation when dragging
This commit is contained in:
parent
06f511f182
commit
286d51bbcf
22
grid_inventory_system/scenes/InventorySlot.tscn
Normal file
22
grid_inventory_system/scenes/InventorySlot.tscn
Normal file
@ -0,0 +1,22 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://b1nobn0glk4ru"]
|
||||
|
||||
[ext_resource type="Script" path="res://grid_inventory_system/scripts/InventorySlot.gd" id="1_wp4po"]
|
||||
[ext_resource type="Texture2D" uid="uid://bdvx58rwnaeev" path="res://icon.svg" id="2_1w5re"]
|
||||
|
||||
[node name="InventorySlot" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_right = -1888.0
|
||||
offset_bottom = -1048.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1_wp4po")
|
||||
|
||||
[node name="TextureRect" type="TextureRect" parent="."]
|
||||
layout_mode = 1
|
||||
offset_right = 10.0
|
||||
offset_bottom = 10.0
|
||||
texture = ExtResource("2_1w5re")
|
||||
expand_mode = 1
|
25
grid_inventory_system/scenes/Item.tscn
Normal file
25
grid_inventory_system/scenes/Item.tscn
Normal file
@ -0,0 +1,25 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://dtir5hovd6i3h"]
|
||||
|
||||
[ext_resource type="Script" path="res://grid_inventory_system/scripts/Item.gd" id="1_cs6rn"]
|
||||
[ext_resource type="Texture2D" uid="uid://bdvx58rwnaeev" path="res://icon.svg" id="2_uetec"]
|
||||
|
||||
[node name="Item" type="Control" node_paths=PackedStringArray("graphic")]
|
||||
clip_contents = true
|
||||
layout_mode = 3
|
||||
anchors_preset = 0
|
||||
offset_right = 100.0
|
||||
offset_bottom = 100.0
|
||||
script = ExtResource("1_cs6rn")
|
||||
graphic = NodePath("Graphic")
|
||||
|
||||
[node name="Graphic" type="TextureRect" parent="."]
|
||||
unique_name_in_owner = true
|
||||
clip_contents = true
|
||||
layout_mode = 0
|
||||
offset_right = 40.0
|
||||
offset_bottom = 40.0
|
||||
pivot_offset = Vector2(20, 20)
|
||||
texture = ExtResource("2_uetec")
|
||||
expand_mode = 1
|
||||
|
||||
[node name="Node" type="Node" parent="."]
|
@ -1,7 +0,0 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://dtir5hovd6i3h"]
|
||||
|
||||
[ext_resource type="Script" path="res://grid_inventory_system/scripts/ItemGraphic.gd" id="1_bih4t"]
|
||||
|
||||
[node name="Item" type="TextureRect"]
|
||||
expand_mode = 3
|
||||
script = ExtResource("1_bih4t")
|
@ -1,6 +1,6 @@
|
||||
extends Control
|
||||
class_name InventoryController
|
||||
const ITEM_BASE = preload("res://grid_inventory_system/scenes/ItemGraphic.tscn")
|
||||
const ITEM_BASE = preload("res://grid_inventory_system/scenes/Item.tscn")
|
||||
|
||||
@export var inventory_open_input:String = "inventory_open"
|
||||
@export var inventory_close_input:String = "inventory_close"
|
||||
@ -40,8 +40,8 @@ func _process(delta):
|
||||
inventory_open = false
|
||||
inventory_background.visible=false
|
||||
|
||||
#if(Input.is_action_just_pressed(inventory_rotate_input) and inventory_open==true and inventory_item_dragged != null):
|
||||
# inventory_item_dragged.rotation_degrees = inventory_item_dragged.rotation_degrees + 90.0
|
||||
if(Input.is_action_just_pressed(inventory_rotate_input) and inventory_open==true and inventory_item_dragged != null):
|
||||
inventory_item_dragged.rotate_item(90)
|
||||
|
||||
var cursor_pos = get_global_mouse_position()
|
||||
|
||||
@ -86,10 +86,7 @@ func use(cursor_pos):
|
||||
func pickup_item(item_id):
|
||||
var item = ITEM_BASE.instantiate()
|
||||
item.set_meta("id", item_id)
|
||||
var dbItem = ItemDb.get_item(item_id)
|
||||
item.item_config = dbItem
|
||||
item.set_size(Vector2(dbItem.item_size.x, dbItem.item_size.y))
|
||||
item.texture = dbItem.item_texture
|
||||
item.init_item(item_id)
|
||||
if not inventory_grid.insert_item_at_first_available_spot(item):
|
||||
item.queue_free()
|
||||
return false
|
||||
|
11
grid_inventory_system/scripts/InventorySlot.gd
Normal file
11
grid_inventory_system/scripts/InventorySlot.gd
Normal file
@ -0,0 +1,11 @@
|
||||
extends Control
|
||||
|
||||
enum slot_state { free, used }
|
||||
|
||||
@export var in_use = false
|
||||
|
||||
func used():
|
||||
in_use = true
|
||||
|
||||
func free():
|
||||
in_use = false
|
31
grid_inventory_system/scripts/Item.gd
Normal file
31
grid_inventory_system/scripts/Item.gd
Normal file
@ -0,0 +1,31 @@
|
||||
extends Control
|
||||
class_name ItemGraphic
|
||||
@export var item_config:ItemConfiguration
|
||||
@export var graphic:TextureRect
|
||||
|
||||
func init_item(item_id):
|
||||
var dbItem = ItemDb.get_item(item_id)
|
||||
item_config = dbItem
|
||||
graphic.set_size(Vector2(dbItem.item_size.x, dbItem.item_size.y))
|
||||
set_size(Vector2(dbItem.item_size.x, dbItem.item_size.y))
|
||||
graphic.texture = dbItem.item_texture
|
||||
graphic.pivot_offset = Vector2(graphic.size.x/2.0, graphic.size.y/2.0)
|
||||
pivot_offset = Vector2(graphic.size.x/2.0, graphic.size.y/2.0)
|
||||
graphic.position = Vector2()
|
||||
graphic.position = Vector2()
|
||||
graphic.position = Vector2()
|
||||
graphic.position = Vector2()
|
||||
graphic.position = Vector2()
|
||||
graphic.position = Vector2()
|
||||
graphic.position = Vector2()
|
||||
print("TEST")
|
||||
|
||||
func rotate_item(amount):
|
||||
graphic.rotation_degrees = graphic.rotation_degrees+amount
|
||||
if(graphic.rotation_degrees==90 or graphic.rotation_degrees==270):
|
||||
set_size(Vector2(item_config.item_size.y, item_config.item_size.x))
|
||||
else:
|
||||
set_size(Vector2(item_config.item_size.x, item_config.item_size.y))
|
||||
|
||||
if(graphic.rotation_degrees==360):
|
||||
graphic.rotation_degrees=0
|
@ -1,3 +0,0 @@
|
||||
extends TextureRect
|
||||
class_name ItemGraphic
|
||||
@export var item_config:ItemConfiguration
|
@ -60,7 +60,3 @@ mouse={
|
||||
"deadzone": 0.5,
|
||||
"events": []
|
||||
}
|
||||
|
||||
[rendering]
|
||||
|
||||
renderer/rendering_method="gl_compatibility"
|
||||
|
Loading…
x
Reference in New Issue
Block a user