diff --git a/gymkhana/addons/escoria-ui-return-monkey-island/esc/commands/item_count_add.gd b/gymkhana/addons/escoria-ui-return-monkey-island/esc/commands/item_count_add.gd new file mode 100644 index 00000000..a639ac02 --- /dev/null +++ b/gymkhana/addons/escoria-ui-return-monkey-island/esc/commands/item_count_add.gd @@ -0,0 +1,39 @@ +# `item_count_add item_id value` +# +# Add value to the count in a item. +# - item_id: string: id of the item to apply +# - value: int: number to add +# +# @ESC +extends ESCBaseCommand +class_name ItemCountAddCommand + + +var item_count_manager = ESCItemCountManager.new() + +# Return the descriptor of the arguments of this command +func configure() -> ESCCommandArgumentDescriptor: + return ESCCommandArgumentDescriptor.new( + 1, + [TYPE_STRING, TYPE_INT], + [null, 1] + ) + + +# Validate wether the given arguments match the command descriptor +func validate(arguments: Array): + if not escoria.object_manager.has(arguments[0]): + escoria.logger.report_errors( + "item_count_add: invalid object", + ["Object %s not registered" % arguments[0]] + ) + return false + + return .validate(arguments) + + +# Run the command +func run(command_params: Array) -> int: + item_count_manager.add(command_params[0], command_params[1]) + + return ESCExecution.RC_OK diff --git a/gymkhana/addons/escoria-ui-return-monkey-island/esc/esc_item_count_manager.gd b/gymkhana/addons/escoria-ui-return-monkey-island/esc/esc_item_count_manager.gd new file mode 100644 index 00000000..99a55afd --- /dev/null +++ b/gymkhana/addons/escoria-ui-return-monkey-island/esc/esc_item_count_manager.gd @@ -0,0 +1,76 @@ +# A manager for inventory objects +extends Resource +class_name ESCItemCountManager + + +func add(global_id: String, value:= 1) -> void: + var item = get_item(global_id) + item.count = item.count + value + updateSprite(item) + + +func remove(global_id: String, value:= 1) -> void: + var item = get_item(global_id) + item.count = item.count - value + updateSprite(item) + + +func set(global_id: String, value: int) -> void: + var item = get_item(global_id) + item.count = value + updateSprite(item) + + +func removeFromInventoryIfCountLessThan(global_id: String, value:= 1) -> void: + var item = get_item(global_id) + if item.count < value: + escoria.inventory_manager.remove_item(global_id) + + +func get_item(global_id: String) -> ESCItem: + var node = escoria.object_manager.get_object(global_id).node + if not node is ESCItem: + escoria.logger.error( + "item_count_add: invalid object", + ["Object is not an ESCItem"] + ) + return null + + return node + + +func updateSprite(item: ESCItemWithTooltip) -> void: + var child_node = item.get_node("Sprite") as Sprite + if not child_node is Sprite: + escoria.logger.report_errors( + "item_count_add: invalid sprite", + ["No Sprite node found"] + ) + + var texture_path = getCountTexturePath(item) + var texture = load(texture_path) + + # Update texture in scene + var sprite = child_node as Sprite + sprite.texture = texture + + # Update texture in scene + # TODO optional inventory_texture + # TODO change inventory texture without removing and adding the item + # https://github.com/godot-escoria/escoria-issues/issues/364 + # https://discord.com/channels/884336424780984330/1124614097917460584/1127151969614696548 + item.inventory_texture = texture + if escoria.inventory_manager.inventory_has(item.global_id): + escoria.inventory_manager.remove_item(item.global_id) + escoria.inventory_manager.add_item(item.global_id) + + +func getCountTexturePath(item: ESCItemWithTooltip) -> String: + var count = item.count + var textures = item.count_textures # TODO sort dictionaries by start key + var i = 0 + + while (i < textures.size() - 1) and count >= textures[i + 1].start: + i = i + 1 + + return textures[i].texture diff --git a/gymkhana/addons/escoria-ui-return-monkey-island/esc_item_with_tooltip.gd b/gymkhana/addons/escoria-ui-return-monkey-island/esc_item_with_tooltip.gd index dfaae5c0..6b7d8a52 100644 --- a/gymkhana/addons/escoria-ui-return-monkey-island/esc_item_with_tooltip.gd +++ b/gymkhana/addons/escoria-ui-return-monkey-island/esc_item_with_tooltip.gd @@ -19,12 +19,26 @@ export(Dictionary) var tooltips = {} # Action 3 tooltip texts if item is target. Dictionary with tool's global id as key. export(Dictionary) var action3_target_texts = {} -# Action 4 tooltip texts if item is target. Dictionary with tool's global id as key. +# Action 4 tooltip texts if item is target. Dictionary with tool's global id as key export(Dictionary) var action4_target_texts = {} # If action used by player is in this list, this is a valid target (second item in combination) export(Array) var target_when_selected_action_is_in = [] +# If item is countable (E.g. money) marks the quantity +export(int) var count = 0 + +# If item is countable (E.g. money) marks which texture to use depending of count value. +# Each element is a Dictionary with start and texture keys: +# [ +# { "start": 0, "texture": "res://gymkhana/items/inventory/assets/no_money.png"}, +# { "start": 1, "texture": "res://gymkhana/items/inventory/assets/one_coin.png"}, +# { "start": 2, "texture": "res://gymkhana/items/inventory/assets/two_coins.png"}, +# { "start": 3, "texture": "res://gymkhana/items/inventory/assets/coins.png"}, +# { "start": 10, "texture": "res://gymkhana/items/inventory/assets/bills.png"}, +# ] +export(Array) var count_textures = [] + var outline: ItemOutline var isHighlighted: bool diff --git a/gymkhana/items/inventory/turno_cocina_frontal.esc b/gymkhana/items/inventory/turno_cocina_frontal.esc index f25f4a6d..8c204361 100644 --- a/gymkhana/items/inventory/turno_cocina_frontal.esc +++ b/gymkhana/items/inventory/turno_cocina_frontal.esc @@ -1,3 +1,2 @@ :action3 say player "Es mi frontal de toda la vida, le tengo cariño" - diff --git a/gymkhana/items/inventory/turno_cocina_patata.esc b/gymkhana/items/inventory/turno_cocina_patata.esc index db47f32c..57020570 100644 --- a/gymkhana/items/inventory/turno_cocina_patata.esc +++ b/gymkhana/items/inventory/turno_cocina_patata.esc @@ -1,6 +1,11 @@ :action1 -say player "Que cosa tan curiosa" - + say player "Que patata más bonita, cómo se nota que es de la huerta." + :action2 -say player "No lo quiero coger" + say player "Bieen! una patata!" + set_active turno_cocina_patata false + item_count_add turno_cocina_patata + inventory_add turno_cocina_patata +:action3 + say player "Que patata más bonita, cómo se nota que es de la huerta." diff --git a/gymkhana/items/inventory/turno_cocina_patata.tscn b/gymkhana/items/inventory/turno_cocina_patata.tscn index 7ac37fc8..1b4bc386 100644 --- a/gymkhana/items/inventory/turno_cocina_patata.tscn +++ b/gymkhana/items/inventory/turno_cocina_patata.tscn @@ -15,12 +15,17 @@ esc_script = "res://gymkhana/items/inventory/turno_cocina_patata.esc" inventory_texture = ExtResource( 2 ) dialog_color = Color( 1, 1, 1, 1 ) tooltips = { - "action1": "¿Que es esto?", - "action2": "Coger", - "action3": "Mirar", - "action4": "Usar" +"action1": "Admirar la patata", +"action2": "Cogerla", +"action3": "Admirar la patata", } animations = null +count_textures = [ + { "start": 1, "texture": "res://gymkhana/items/inventory/assets/turno_cocina_patata.png" }, + { "start": 2, "texture": "res://gymkhana/items/inventory/assets/turno_cocina_dos_patatas.png" }, + { "start": 3, "texture": "res://gymkhana/items/inventory/assets/turno_cocina_tres_patatas.png" }, + { "start": 4, "texture": "res://gymkhana/items/inventory/assets/turno_cocina_cuatro_patatas.png" }, +] [node name="Sprite" type="Sprite" parent="."] position = Vector2( -2, 0 ) @@ -33,4 +38,4 @@ shape = SubResource( 1 ) [node name="ESCLocation" type="Position2D" parent="."] position = Vector2( -51, 69 ) -script = ExtResource( 3 ) \ No newline at end of file +script = ExtResource( 3 ) diff --git a/gymkhana/items/inventory/turno_cocina_patata_grande.esc b/gymkhana/items/inventory/turno_cocina_patata_grande.esc index ed68455d..6eb1a3db 100644 --- a/gymkhana/items/inventory/turno_cocina_patata_grande.esc +++ b/gymkhana/items/inventory/turno_cocina_patata_grande.esc @@ -1,13 +1,13 @@ :action1 -say player "Hay una patata!" +say player "Solo veo pieles de cebollas." :action2 -say current_player "Bieeen!!! una patata!" +say current_player "Bieeen!!! Había una patata!" set_active turno_cocina_patata_grande false inventory_add turno_cocina_patata_grande :action3 -say current_player "Es bien grande" +say current_player "Es la segunda patata más grande que he visto nunca." :action4 -say current_player "Así no me sirve de nada" \ No newline at end of file +say current_player "Creo que necesito patatas normales, no patatas gigantes..." diff --git a/gymkhana/items/inventory/turno_cocina_patata_grande.tscn b/gymkhana/items/inventory/turno_cocina_patata_grande.tscn index 0e6094c0..cab61616 100644 --- a/gymkhana/items/inventory/turno_cocina_patata_grande.tscn +++ b/gymkhana/items/inventory/turno_cocina_patata_grande.tscn @@ -11,10 +11,4 @@ esc_script = "res://gymkhana/items/inventory/turno_cocina_patata_grande.esc" combine_when_selected_action_is_in = [ ] inventory_texture = ExtResource( 2 ) dialog_color = Color( 1, 1, 1, 1 ) -tooltips = { - "action1": "¿Que es esto?", - "action2": "Coger", - "action3": "Mirar", - "action4": "Usar" -} animations = null diff --git a/gymkhana/items/inventory/turno_cocina_peso.esc b/gymkhana/items/inventory/turno_cocina_peso.esc index 0c8385db..6bce9d69 100644 --- a/gymkhana/items/inventory/turno_cocina_peso.esc +++ b/gymkhana/items/inventory/turno_cocina_peso.esc @@ -1,5 +1,5 @@ :action1 -say player "Es un peso, con esto podría coger la cantidad exacta de algún ingrediente" + say player "Es un peso, con esto podría coger la cantidad exacta de algún ingrediente" :action2 say current_player "Podria ser útil!!" diff --git a/gymkhana/rooms/turno_cocina/cocina/cocina.tscn b/gymkhana/rooms/turno_cocina/cocina/cocina.tscn index 9e45425c..49ecd074 100644 --- a/gymkhana/rooms/turno_cocina/cocina/cocina.tscn +++ b/gymkhana/rooms/turno_cocina/cocina/cocina.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=13 format=2] +[gd_scene load_steps=14 format=2] [ext_resource path="res://addons/escoria-core/game/core-scripts/esc_room.gd" type="Script" id=1] [ext_resource path="res://gymkhana/characters/oier/oier.tscn" type="PackedScene" id=2] @@ -11,6 +11,7 @@ [ext_resource path="res://gymkhana/rooms/turno_cocina/cocina/assets/foreground-silla.png" type="Texture" id=9] [ext_resource path="res://gymkhana/items/inventory/turno_cocina_peso.tscn" type="PackedScene" id=10] [ext_resource path="res://gymkhana/items/inventory/turno_cocina_bol.tscn" type="PackedScene" id=11] +[ext_resource path="res://gymkhana/items/inventory/turno_cocina_patata.tscn" type="PackedScene" id=12] [sub_resource type="NavigationPolygon" id=3] vertices = PoolVector2Array( 2398, 485, 2442, 499, 2446, 617, 2409, 597, 2283, 493, 144, 568, 3, 570, -56, 524, 111, 445, 162, 471, 229, 445, 200, 465, 252, 478, 305, 524, 273, 570, 2287, 687, 2062, 635, 2113, 565, 696, 737, 512, 591, 703, 699, 1269, 739, 1241, 699, 1502, 646, 1409, 752, 1345, 667, 1489, 627, 1347, 563, 1480, 587, 1466, 514, 1345, 505, 1382, 439, 2109, 424, 2238, 386, 1788, 325, 2018, 419, 1787, 383, 1466, 412, 1493, 479, 1305.5, 467, 1337.5, 449, 1306.5, 498 ) @@ -39,7 +40,7 @@ player_doubleclick_speed_multiplier = 2.0 [node name="Foreground-mesa" type="Sprite" parent="ESCTerrain"] position = Vector2( 1786, 424 ) -z_index = 4096 +z_index = 1000 texture = ExtResource( 8 ) [node name="NavigationPolygonInstance" type="NavigationPolygonInstance" parent="ESCTerrain"] @@ -60,7 +61,7 @@ is_exit = true combine_when_selected_action_is_in = [ ] dialog_color = Color( 1, 1, 1, 1 ) tooltips = { - "action1": "Ir detrás" +"action1": "Ir detrás" } animations = null @@ -84,7 +85,7 @@ is_exit = true combine_when_selected_action_is_in = [ ] dialog_color = Color( 1, 1, 1, 1 ) tooltips = { - "action1": "Salir de la cocina" +"action1": "Salir de la cocina" } animations = null @@ -130,8 +131,8 @@ esc_script = "res://gymkhana/rooms/turno_cocina/cocina/esc/fregadero_der.esc" combine_when_selected_action_is_in = [ ] dialog_color = Color( 1, 1, 1, 1 ) tooltips = { - "action1": "Mirar fregadero", - "action2": "Usar" +"action1": "Mirar fregadero", +"action2": "Usar" } action3_target_texts = { "turno_cocina_bol": "Llenar el bol de agua", @@ -155,8 +156,8 @@ esc_script = "res://gymkhana/rooms/turno_cocina/cocina/esc/fregadero_izq.esc" combine_when_selected_action_is_in = [ ] dialog_color = Color( 1, 1, 1, 1 ) tooltips = { - "action1": "Mirar fregadero", - "action2": "Usar" +"action1": "Mirar el fregadero", +"action2": "Usar" } action3_target_texts = { "turno_cocina_bol": "Llenar el bol de agua", @@ -180,11 +181,11 @@ esc_script = "res://gymkhana/rooms/turno_cocina/cocina/esc/debajo_sofa.esc" combine_when_selected_action_is_in = [ "action4" ] dialog_color = Color( 1, 1, 1, 1 ) tooltips = { - "action1": "Mirar debajo del sofa", - "action2": "Meter la mano" +"action1": "Mirar debajo del sofa", +"action2": "Meter la mano" } action3_target_texts = { -"turno_cocina_frontal": "Mirar denajo del sofa" +"turno_cocina_frontal": "Alumbrar debajo del sofa" } target_when_selected_action_is_in = [ "action3" ] animations = null @@ -195,3 +196,19 @@ polygon = PoolVector2Array( 484, 406, 485, 421, 556, 423, 551, 415, 550, 409, 55 [node name="ESCLocation" type="Position2D" parent="debajo_sofa"] position = Vector2( 420, 494 ) script = ExtResource( 5 ) + +[node name="turno_cocina_patata" parent="." instance=ExtResource( 12 )] +position = Vector2( 2202, 343 ) +rotation = -0.270526 +scale = Vector2( 0.35, 0.35 ) +z_index = 1001 +combine_when_selected_action_is_in = [ ] + +[node name="turno_cocina_patata_collision" type="CollisionPolygon2D" parent="turno_cocina_patata"] +position = Vector2( 9.0867, -13.5233 ) +z_index = 1001 +polygon = PoolVector2Array( 6.50781, 0.0583801, 20.7368, 12.8992, 7.896, 27.1279, -19.937, 31.269, -42.4258, 16.1375, -26.0684, -0.0810547 ) + +[node name="turno_cocina_patata_location" type="Position2D" parent="turno_cocina_patata"] +position = Vector2( 93.1357, 65.3632 ) +script = ExtResource( 5 ) diff --git a/gymkhana/rooms/turno_cocina/cocina/esc/debajo_sofa.esc b/gymkhana/rooms/turno_cocina/cocina/esc/debajo_sofa.esc index 364e2ccb..b4cc5f03 100644 --- a/gymkhana/rooms/turno_cocina/cocina/esc/debajo_sofa.esc +++ b/gymkhana/rooms/turno_cocina/cocina/esc/debajo_sofa.esc @@ -8,15 +8,10 @@ stop say player "Bieen! una patata!" + item_count_add turno_cocina_patata inventory_add turno_cocina_patata set_active cocina_debajo_sofa false -:action3 turno_cocina_bol_lentejas - say player "Agua a ojo... en su justa medida." - inventory_remove turno_cocina_peso_bol - inventory_add turno_cocina_bol_lentejas - inventory_add turno_cocina_peso - :action3 turno_cocina_frontal say player "Veo una patata!!" set_global turno_cocina_frontal_debajo_sofa true diff --git a/gymkhana/rooms/turno_cocina/despensa/despensa.tscn b/gymkhana/rooms/turno_cocina/despensa/despensa.tscn index ea03721a..36863f73 100644 --- a/gymkhana/rooms/turno_cocina/despensa/despensa.tscn +++ b/gymkhana/rooms/turno_cocina/despensa/despensa.tscn @@ -141,7 +141,7 @@ pause_mode = 1 position = Vector2( 941, 385 ) script = ExtResource( 6 ) global_id = "turno_cocina_despensa_bidon_izq" -esc_script = "res://gymkhana/rooms/turno_cocina/despensa/esc/bidon_der.esc" +esc_script = "res://gymkhana/rooms/turno_cocina/despensa/esc/bidon_izq.esc" combine_when_selected_action_is_in = [ ] dialog_color = Color( 1, 1, 1, 1 ) tooltips = { @@ -163,7 +163,10 @@ script = ExtResource( 5 ) position = Vector2( 440, 161 ) scale = Vector2( 0.880435, 0.88735 ) tooltips = { - "action1": "Mirar" + "action1": "Mirar", + "action2": "Rascar por el fondo", + "action3": "Mirar", + "action4": "Usar" } [node name="ESCLocation2" type="Position2D" parent="turno_cocina_patata_grande"] diff --git a/gymkhana/rooms/turno_cocina/despensa/esc/bidon_izq.esc b/gymkhana/rooms/turno_cocina/despensa/esc/bidon_izq.esc index 5fe7e802..263ab9bc 100644 --- a/gymkhana/rooms/turno_cocina/despensa/esc/bidon_izq.esc +++ b/gymkhana/rooms/turno_cocina/despensa/esc/bidon_izq.esc @@ -1,5 +1,5 @@ :action1 -say player "Está lleno de algo que no se que es." +say player "Está lleno de algo que no sé que es." :action2 -say player "Lo que hay dentro no lo necesito para nada." \ No newline at end of file +say player "Lo que hay dentro no lo necesito para nada." diff --git a/project.godot b/project.godot index 748c3154..ed762ca3 100644 --- a/project.godot +++ b/project.godot @@ -204,7 +204,7 @@ _global_script_classes=[ { "language": "GDScript", "path": "res://addons/escoria-core/game/scenes/dialogs/esc_dialog_options_chooser.gd" }, { -"base": "Node", +"base": "StateMachine", "class": "ESCDialogPlayer", "language": "GDScript", "path": "res://addons/escoria-core/game/scenes/dialogs/esc_dialog_player.gd" @@ -284,6 +284,11 @@ _global_script_classes=[ { "language": "GDScript", "path": "res://addons/escoria-core/game/core-scripts/esc_item.gd" }, { +"base": "Resource", +"class": "ESCItemCountManager", +"language": "GDScript", +"path": "res://gymkhana/addons/escoria-ui-return-monkey-island/esc/esc_item_count_manager.gd" +}, { "base": "ESCItem", "class": "ESCItemWithTooltip", "language": "GDScript", @@ -494,6 +499,11 @@ _global_script_classes=[ { "language": "GDScript", "path": "res://addons/escoria-core/game/core-scripts/esc/commands/inventory_remove.gd" }, { +"base": "ESCBaseCommand", +"class": "ItemCountAddCommand", +"language": "GDScript", +"path": "res://gymkhana/addons/escoria-ui-return-monkey-island/esc/commands/item_count_add.gd" +}, { "base": "Polygon2D", "class": "ItemOutline", "language": "GDScript", @@ -765,6 +775,7 @@ _global_script_class_icons={ "ESCInventoryItem": "", "ESCInventoryManager": "", "ESCItem": "res://addons/escoria-core/design/esc_item.svg", +"ESCItemCountManager": "", "ESCItemWithTooltip": "res://addons/escoria-core/design/esc_item.svg", "ESCLocation": "res://addons/escoria-core/design/esc_location.svg", "ESCMain": "", @@ -807,6 +818,7 @@ _global_script_class_icons={ "IncGlobalCommand": "", "InventoryAddCommand": "", "InventoryRemoveCommand": "", +"ItemCountAddCommand": "", "ItemOutline": "res://addons/escoria-core/design/esc_item.svg", "PlayLibSound": "", "PlaySndCommand": "",