Skip to content

Commit

Permalink
added equipped items 1st iteration but UI is wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
Patataman committed Aug 2, 2021
1 parent 52b3fea commit f54e119
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 83 deletions.
Binary file added assets/prototipos/elementos/items/helmet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
94 changes: 27 additions & 67 deletions real_deal/scenes/menu/Inventory.tscn
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[gd_scene load_steps=4 format=2]
[gd_scene load_steps=3 format=2]

[ext_resource path="res://assets/sprites/cards_ilustrations/ilustration_placeholder.png" type="Texture" id=1]
[ext_resource path="res://assets/prototipos/personaje/Prototipo Final/lateral_izq.png" type="Texture" id=2]
[ext_resource path="res://real_deal/scripts/menu/Inventory.gd" type="Script" id=3]

Expand Down Expand Up @@ -47,7 +46,30 @@ custom_constants/separation = 15
margin_right = 188.0
margin_bottom = 400.0

[node name="MarginContainer" type="MarginContainer" parent="Container/TabContainer/PanelPJ/HBox/Equipo"]
margin_right = 188.0
margin_bottom = 400.0

[node name="ItemsContainer" type="HBoxContainer" parent="Container/TabContainer/PanelPJ/HBox/Equipo/MarginContainer"]
margin_top = 200.0
margin_right = 188.0
margin_bottom = 200.0
size_flags_horizontal = 3
size_flags_vertical = 6
alignment = 1

[node name="Items" type="GridContainer" parent="Container/TabContainer/PanelPJ/HBox/Equipo/MarginContainer/ItemsContainer"]
margin_left = 94.0
margin_right = 94.0
custom_constants/vseparation = 150
custom_constants/hseparation = 90
columns = 2
__meta__ = {
"_edit_use_anchors_": false
}

[node name="Background" type="TextureRect" parent="Container/TabContainer/PanelPJ/HBox/Equipo"]
show_behind_parent = true
margin_top = 94.0
margin_right = 188.0
margin_bottom = 305.0
Expand All @@ -58,65 +80,6 @@ size_flags_stretch_ratio = 0.0
texture = ExtResource( 2 )
stretch_mode = 4

[node name="ItemsIzq" type="HBoxContainer" parent="Container/TabContainer/PanelPJ/HBox/Equipo"]
margin_top = 115.0
margin_right = 188.0
margin_bottom = 285.0
size_flags_vertical = 4

[node name="Items" type="GridContainer" parent="Container/TabContainer/PanelPJ/HBox/Equipo/ItemsIzq"]
margin_right = 60.0
margin_bottom = 170.0
custom_constants/vseparation = 10

[node name="TextureRect2" type="TextureRect" parent="Container/TabContainer/PanelPJ/HBox/Equipo/ItemsIzq/Items"]
margin_right = 60.0
margin_bottom = 50.0
texture = ExtResource( 1 )

[node name="TextureRect4" type="TextureRect" parent="Container/TabContainer/PanelPJ/HBox/Equipo/ItemsIzq/Items"]
margin_top = 60.0
margin_right = 60.0
margin_bottom = 110.0
texture = ExtResource( 1 )

[node name="TextureRect3" type="TextureRect" parent="Container/TabContainer/PanelPJ/HBox/Equipo/ItemsIzq/Items"]
margin_top = 120.0
margin_right = 60.0
margin_bottom = 170.0
texture = ExtResource( 1 )

[node name="ItemsDrch" type="HBoxContainer" parent="Container/TabContainer/PanelPJ/HBox/Equipo"]
margin_top = 115.0
margin_right = 188.0
margin_bottom = 285.0
size_flags_vertical = 4
size_flags_stretch_ratio = 0.0
alignment = 2

[node name="Items" type="GridContainer" parent="Container/TabContainer/PanelPJ/HBox/Equipo/ItemsDrch"]
margin_left = 128.0
margin_right = 188.0
margin_bottom = 170.0
custom_constants/vseparation = 10

[node name="TextureRect" type="TextureRect" parent="Container/TabContainer/PanelPJ/HBox/Equipo/ItemsDrch/Items"]
margin_right = 60.0
margin_bottom = 50.0
texture = ExtResource( 1 )

[node name="TextureRect2" type="TextureRect" parent="Container/TabContainer/PanelPJ/HBox/Equipo/ItemsDrch/Items"]
margin_top = 60.0
margin_right = 60.0
margin_bottom = 110.0
texture = ExtResource( 1 )

[node name="TextureRect3" type="TextureRect" parent="Container/TabContainer/PanelPJ/HBox/Equipo/ItemsDrch/Items"]
margin_top = 120.0
margin_right = 60.0
margin_bottom = 170.0
texture = ExtResource( 1 )

[node name="VSeparator" type="VSeparator" parent="Container/TabContainer/PanelPJ/HBox"]
margin_left = 203.0
margin_right = 207.0
Expand All @@ -136,16 +99,13 @@ size_flags_horizontal = 5
size_flags_vertical = 5
alignment = 1

[node name="Items" type="CenterContainer" parent="Container/TabContainer/PanelPJ/HBox/Stats/VBox"]
[node name="ItemsCenter" type="MarginContainer" parent="Container/TabContainer/PanelPJ/HBox/Stats/VBox"]
margin_top = 191.0
margin_right = 94.0
margin_bottom = 191.0
size_flags_horizontal = 5
size_flags_vertical = 5

[node name="Grid" type="GridContainer" parent="Container/TabContainer/PanelPJ/HBox/Stats/VBox/Items"]
margin_left = 47.0
margin_right = 47.0
[node name="Grid" type="GridContainer" parent="Container/TabContainer/PanelPJ/HBox/Stats/VBox/ItemsCenter"]
margin_right = 94.0
custom_constants/vseparation = 0
custom_constants/hseparation = 20
columns = 6
Expand Down
2 changes: 1 addition & 1 deletion real_deal/scripts/menu/CartaMazo.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ extends Control

var card_database = load("res://real_deal/scripts/utils/CardsDatabase.gd").DATA

signal a_coleccion;
# signal a_coleccion;
var card_name;


Expand Down
54 changes: 46 additions & 8 deletions real_deal/scripts/menu/Inventory.gd
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,32 @@ func _ready():
self.init_tab_personalizacion();
#### TAB MAZO ####
self.init_tab_mazo();


func draw_equipped_items():
""" Dibuja los objetos equipados
"""
print("draw")
var equipo_node = $Container/TabContainer/PanelPJ/HBox/Equipo;
var player_equipped = PlayerManager.equipped_items
for n in equipo_node.get_node("MarginContainer/ItemsContainer/Items").get_children():
equipo_node.get_node("MarginContainer/ItemsContainer/Items").remove_child(n)
n.queue_free()

for item in player_equipped:
# Rellenamos con los items del jugador
var itemNode = Item.instance()
itemNode.init_item(item)
itemNode.connect("is_equipment", self, "draw_equipped_items")
equipo_node.get_node("MarginContainer/ItemsContainer/Items").add_child(itemNode);

var item_count = equipo_node.get_node("MarginContainer/ItemsContainer/Items").get_child_count()
while item_count == 0 or item_count < 4:
# Rellenamos con casillas vacías
var itemNode = Item.instance()
itemNode.connect("is_equipment", self, "draw_equipped_items")
equipo_node.get_node("MarginContainer/ItemsContainer/Items").add_child(itemNode);
item_count += 1

func init_tab_personalizacion(items=[]):
""" Inicializa las dimensiones y cosas correspondientes al tab
Expand All @@ -24,30 +49,43 @@ func init_tab_personalizacion(items=[]):
equipo_node.rect_min_size = Vector2(panel_node.get_size().x*0.3, equipo_node.get_size().y);
stats_node.rect_min_size = Vector2(panel_node.get_size().x*0.65, stats_node.get_size().y);

# Contenedor equipo
# Contenedor objetos equipados
self.draw_equipped_items()

equipo_node.get_node("MarginContainer").add_constant_override("margin_left", 50);
equipo_node.get_node("MarginContainer").add_constant_override("margin_top", 50);
equipo_node.get_node("MarginContainer").add_constant_override("margin_right", 0);
########################

# Contenedor items
# Iteramos por los objetos del jugador
var player_items = PlayerManager.inventory.get_items()
for item in player_items:
# Rellenamos con los items del jugador
var itemNode = Item.instance()
itemNode.init_item(item)
stats_node.get_node("VBox/Items/Grid").add_child(itemNode);
itemNode.connect("is_equipment", self, "draw_equipped_items")
stats_node.get_node("VBox/ItemsCenter/Grid").add_child(itemNode);

var item_count = stats_node.get_node("VBox/Items/Grid").get_child_count()
var item_count = stats_node.get_node("VBox/ItemsCenter/Grid").get_child_count()
while item_count == 0 or item_count % 12 != 0:
# Rellenamos con casillas vacías
var itemNode = Item.instance()
stats_node.get_node("VBox/Items/Grid").add_child(itemNode);
itemNode.connect("is_equipment", self, "draw_equipped_items")
stats_node.get_node("VBox/ItemsCenter/Grid").add_child(itemNode);
item_count += 1

stats_node.get_node("VBox/Items/Grid").add_constant_override("hseparation", 90)
stats_node.get_node("VBox/Items/Grid").add_constant_override("vseparation", 90)
stats_node.get_node("VBox/ItemsCenter/Grid").add_constant_override("hseparation", 20)
stats_node.get_node("VBox/ItemsCenter/Grid").add_constant_override("vseparation", 20)

stats_node.get_node("VBox/ItemsCenter").rect_min_size.y = stats_node.rect_min_size.y/2;
stats_node.get_node("VBox/ItemsCenter").rect_min_size.x = stats_node.rect_min_size.x;
stats_node.get_node("VBox/ItemsCenter").add_constant_override("margin_left", 50);
stats_node.get_node("VBox/ItemsCenter").add_constant_override("margin_top", 50);
########################

# Contenedor estadísticas
stats_node.get_node("VBox/Stats/Text").text = "AAAA CHUGUENÑAAAA CHIBABA ULIASNDJADjaiDISAD";

stats_node.get_node("VBox/Items").rect_min_size.y = stats_node.rect_min_size.y/2;
stats_node.get_node("VBox/Stats").rect_min_size.y = stats_node.rect_min_size.y/2;
#########################

Expand Down
15 changes: 9 additions & 6 deletions real_deal/scripts/utils/player/ItemNode.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"""
extends Control

signal is_equipment

# Variable interna para contener al item
var item;
# Variable interna para luego en el front identificar
Expand All @@ -12,11 +14,12 @@ var with_item = false

func _ready():
# TESTING ITEM
var test_item = load("res://real_deal/scripts/utils/player/Item.gd").new()
test_item.init_item('berry')
self.init_item(test_item)
# var test_item = load("res://real_deal/scripts/utils/player/Item.gd").new()
# test_item.init_item('berry')
# self.init_item(test_item)
###########
# Si esto no está aquí no se ajustan bien los márgenes para que esté centrado
$Item.rect_min_size = $Item/Image/Background.rect_size*$Item/Image.scale
$Item/Image/Background.set_margins_preset(Control.PRESET_CENTER)


Expand All @@ -32,7 +35,6 @@ func init_item(item):
$Item/Image.set_texture(tmp_texture);
$Item.connect("gui_input", self, "_on_Item_gui_input")
self.add_options_to_item()



func add_options_to_item():
Expand All @@ -49,13 +51,14 @@ func add_options_to_item():

$Menu/ItemList.add_item(text)
$Menu/ItemList.add_item("Descartar")
# $Menu.set_position($Item.



func use():
""" Punto de entrada común para objetos y equipo
"""
self.item.use()
if self.item.type == "equipment":
emit_signal("is_equipment")
# Después de usarlo podemos descartarlo (y así ahorramos código)
self.drop()

Expand Down
9 changes: 8 additions & 1 deletion real_deal/scripts/utils/player/inventory.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@ extends Object
Esta clase está destinada a ser la estructura de datos que gestione
los ITEMS que posee el jugador en su inventario.
"""
var Item = preload("res://real_deal/scripts/utils/player/Item.gd")

var _items = []
var _saved_items = ["helmet", "berry"]
# Deberíamos cambiarlo a un diccionario donde se guarden los objetos usando su referencia y el número de unidades

func _init():
print("jajaja")
print("Inventario - jajaja")
for item in _saved_items:
var it = Item.new()
it.init_item(item)
self._items.append(it)


func add_item(item):
_items.append(item)
Expand Down
3 changes: 3 additions & 0 deletions real_deal/scripts/utils/player/item.gd
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ func equip():
""" Función para equipar un objeto si es de tipo 'equipment'
"""
print("equip")
if len(PlayerManager.equipped_items) < 4:
PlayerManager.equipped_items.append(self)
if self.add_cart:
PlayerManager.deck.append(self.card_name)

Expand All @@ -70,5 +72,6 @@ func unequip():
""" Función a llamar cuando se desequipa un objeto de tipo 'equipment'
"""
print("unequip")
PlayerManager.equipped_items.remove(self)
if self.add_cart:
PlayerManager.deck.erase(self.card_name)
2 changes: 2 additions & 0 deletions real_deal/scripts/utils/player/player_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var max_health
var energy
var max_energy
var card_collection
var equipped_items

func _ready():
self.max_hand_size = 5
Expand Down Expand Up @@ -53,6 +54,7 @@ func _ready():
"fire"
]
self.inventory = Inventory.new()
self.equipped_items = [] # Lista de objetos equipados actualmente (max 4)


func restore_player():
Expand Down

0 comments on commit f54e119

Please sign in to comment.