diff --git a/assets/portraits/default.png b/assets/portraits/default.png new file mode 100644 index 0000000..c98fbb6 Binary files /dev/null and b/assets/portraits/default.png differ diff --git a/assets/MManPortrait.png.import b/assets/portraits/default.png.import similarity index 70% rename from assets/MManPortrait.png.import rename to assets/portraits/default.png.import index 53014f9..8e77c84 100644 --- a/assets/MManPortrait.png.import +++ b/assets/portraits/default.png.import @@ -2,15 +2,15 @@ importer="texture" type="StreamTexture" -path="res://.import/MManPortrait.png-4e2ec0d6412baee3672a65d68519d9e1.stex" +path="res://.import/default.png-88b8771544923be91ca280c327742454.stex" metadata={ "vram_texture": false } [deps] -source_file="res://assets/MManPortrait.png" -dest_files=[ "res://.import/MManPortrait.png-4e2ec0d6412baee3672a65d68519d9e1.stex" ] +source_file="res://assets/portraits/default.png" +dest_files=[ "res://.import/default.png-88b8771544923be91ca280c327742454.stex" ] [params] diff --git a/assets/text/dialog/WarriorGirl_Intro.tres b/assets/text/dialog/WarriorGirl_Intro.tres new file mode 100644 index 0000000..0ba90fd --- /dev/null +++ b/assets/text/dialog/WarriorGirl_Intro.tres @@ -0,0 +1,9 @@ +[gd_resource type="Resource" load_steps=3 format=2] + +[ext_resource path="res://src/classes/dialog_item.gd" type="Script" id=1] +[ext_resource path="res://assets_tmp/MManPortrait.png" type="Texture" id=2] + +[resource] +script = ExtResource( 1 ) +portrait = ExtResource( 2 ) +text_lines = PoolStringArray( "Hey there. I heard you\'re Gangsta.", "Well I\'m pretty gangsta myself!" ) diff --git a/assets/MManPortrait.png b/assets_tmp/MManPortrait.png similarity index 100% rename from assets/MManPortrait.png rename to assets_tmp/MManPortrait.png diff --git a/assets_tmp/MManPortrait.png.import b/assets_tmp/MManPortrait.png.import new file mode 100644 index 0000000..482c006 --- /dev/null +++ b/assets_tmp/MManPortrait.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/MManPortrait.png-c012ca0947bb1e1b73c5a27d8f73a91f.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets_tmp/MManPortrait.png" +dest_files=[ "res://.import/MManPortrait.png-c012ca0947bb1e1b73c5a27d8f73a91f.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=false +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/lib/singleton_autoloads/UIManager.gd b/lib/singleton_autoloads/UIManager.gd index cefe39b..0f283be 100644 --- a/lib/singleton_autoloads/UIManager.gd +++ b/lib/singleton_autoloads/UIManager.gd @@ -11,6 +11,13 @@ var current_pane = UI_PANES.OFF var debug_text :String +var _dialog_item :DialogItem + +var playing_dialog :bool = false +var current_dialog_index :int + +signal ui_change() + # Declare member variables here. Examples: # var a = 2 # var b = "text" @@ -20,9 +27,32 @@ var debug_text :String func _ready(): pass # Replace with function body. +func play_dialog_item(dialog_item :DialogItem, dialog_index :int = 0): + _dialog_item = dialog_item + if _dialog_item.text_lines.size() > 0: + current_dialog_index = dialog_index + playing_dialog = true + dialog_text = _dialog_item.text_lines[current_dialog_index] + dialog_portrait = _dialog_item.portrait + current_pane = UI_PANES.DIALOG + emit_signal("ui_change") + + +func stop_dialog(): + dialog_text = 'foo' + current_pane = UI_PANES.HUD + emit_signal("ui_change") # Called every frame. 'delta' is the elapsed time since the previous frame. -#func _process(delta): -# debug_text = '' -# for _player_id in NetworkManager.get_player_ids(): -# debug_text += str(_player_id) + '\n' +func _process(delta): + if playing_dialog: + var foo = '' + ##TODO: Lockout input on player before dialog happens. + if Input.is_action_just_pressed("crouch_1"): + if _dialog_item.text_lines.size() > (current_dialog_index + 1): + current_dialog_index += 1 + dialog_text = _dialog_item.text_lines[current_dialog_index] + dialog_portrait = _dialog_item.portrait + emit_signal("ui_change") + else: + stop_dialog() diff --git a/project.godot b/project.godot index 647b941..7bb2dfe 100644 --- a/project.godot +++ b/project.godot @@ -35,6 +35,11 @@ _global_script_classes=[ { "path": "res://lib/classes/collision_shape2D_state_receiver.gd" }, { "base": "Resource", +"class": "DialogItem", +"language": "GDScript", +"path": "res://src/classes/dialog_item.gd" +}, { +"base": "Resource", "class": "GameSettings", "language": "GDScript", "path": "res://src/game_settings.gd" @@ -185,6 +190,7 @@ _global_script_class_icons={ "AudioStreamPlayer_StateReceiver": "", "CameraGuide": "", "CollisionShape2D_StateReceiver": "", +"DialogItem": "", "GameSettings": "", "HealthComponent": "", "HealthPickup": "", diff --git a/src/Interactables/interactable_npc_dialog.gd b/src/Interactables/interactable_npc_dialog.gd index 034070f..38298f9 100644 --- a/src/Interactables/interactable_npc_dialog.gd +++ b/src/Interactables/interactable_npc_dialog.gd @@ -8,10 +8,31 @@ extends Interactable export (String) var dialog_text export (bool) var auto_start = false -# Called when the node enters the scene tree for the first time. -#func _ready(): -# pass # Replace with function body. +export (Array, Resource) var dialog_items +# Called when the node enters the scene tree for the first time. +func _ready(): + assert(verify_resources(), "Dialog contains invalid resources") + +func verify_resources() -> bool: + for r in dialog_items: + if not r is DialogItem: + return false + return true + +func trigger_interaction(): + var dialog :DialogItem = dialog_items[0] +# UiManager.dialog_text = dialog.text_lines[0] +# UiManager.dialog_portrait = dialog.portrait +# UiManager.current_pane = UiManager.UI_PANES.DIALOG + UiManager.play_dialog_item(dialog) + +func disable_dialog(): + UiManager.current_pane = UiManager.UI_PANES.HUD + +func _on_Interactable_Component_body_exited(body): + ._on_Interactable_Component_body_exited(body) + disable_dialog() # Called every frame. 'delta' is the elapsed time since the previous frame. #func _process(delta): diff --git a/src/actors/npcs/WarriorGirl/WarriorGirl.gd b/src/actors/npcs/WarriorGirl/WarriorGirl.gd index 0a5c292..f3217b2 100644 --- a/src/actors/npcs/WarriorGirl/WarriorGirl.gd +++ b/src/actors/npcs/WarriorGirl/WarriorGirl.gd @@ -22,3 +22,4 @@ func _on_NPC_Dialog_body_entered(body): func _on_NPC_Dialog_body_exited(body): movement_state_machine.change_to_known_state("default") + diff --git a/src/actors/npcs/WarriorGirl/WarriorGirl.tscn b/src/actors/npcs/WarriorGirl/WarriorGirl.tscn index bbb2eb4..68556b3 100644 --- a/src/actors/npcs/WarriorGirl/WarriorGirl.tscn +++ b/src/actors/npcs/WarriorGirl/WarriorGirl.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=9 format=2] +[gd_scene load_steps=10 format=2] [ext_resource path="res://lib/parent_scenes/actor.tscn" type="PackedScene" id=1] [ext_resource path="res://assets/actors/npcs/WarriorGirl/WarriorGirl.tres" type="SpriteFrames" id=2] @@ -6,6 +6,7 @@ [ext_resource path="res://src/Interactables/interactable_npc_dialog.tscn" type="PackedScene" id=4] [ext_resource path="res://src/actors/npcs/WarriorGirl/WarriorGirl.gd" type="Script" id=5] [ext_resource path="res://src/actors/npcs/draw_sword.tres" type="Resource" id=6] +[ext_resource path="res://assets/text/dialog/WarriorGirl_Intro.tres" type="Resource" id=7] [sub_resource type="RectangleShape2D" id=1] extents = Vector2( 9, 14 ) @@ -34,6 +35,7 @@ shape = SubResource( 1 ) [node name="NPC_Dialog" parent="." index="5" instance=ExtResource( 4 )] collision_mask = 2 dialog_text = "Hello, I am a human." +dialog_items = [ ExtResource( 7 ) ] [node name="CollisionShape2D" type="CollisionShape2D" parent="NPC_Dialog" index="0"] modulate = Color( 0, 1, 0, 1 ) diff --git a/src/actors/players/playerE/PlayerE.gd b/src/actors/players/playerE/PlayerE.gd index 0a0aa01..b2f5741 100644 --- a/src/actors/players/playerE/PlayerE.gd +++ b/src/actors/players/playerE/PlayerE.gd @@ -147,6 +147,7 @@ func touch_the_thing(the_thing: Interactable) -> bool: if the_thing is Interactable_NPC_Dialog: ## Get this to the UI mananger print("NPC wants to say: ",the_thing.dialog_text) + the_thing.trigger_interaction() return true diff --git a/src/classes/dialog_item.gd b/src/classes/dialog_item.gd new file mode 100644 index 0000000..872f905 --- /dev/null +++ b/src/classes/dialog_item.gd @@ -0,0 +1,20 @@ +class_name DialogItem +extends Resource + +# Declare member variables here. Examples: +# var a = 2 +# var b = "text" + +export(Texture) var portrait +export(PoolStringArray) var text_lines + +# Called when the node enters the scene tree for the first time. +func _ready(): + ##TODO: I forgot the better way to determine a valid item is null or empty + if portrait == null: + push_warning("No protrait defined for dialog item.") + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +#func _process(delta): +# pass diff --git a/src/ui/HUD.gd b/src/ui/HUD.gd index 4d29acd..a1d9e62 100644 --- a/src/ui/HUD.gd +++ b/src/ui/HUD.gd @@ -37,6 +37,8 @@ func _ready(): tween.tween_property(DialogIndicator, "modulate", Color.darkgray, 1) tween.tween_property(DialogIndicator, "modulate", Color.white , 1) ##tween.tween_property(DialogIndicator, "modulate", Color.RED, 1) + UiManager.connect("ui_change",self,"reset_current_pane_tracker") + # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta): @@ -64,3 +66,7 @@ func _unhandled_input(event): if current_pane == UiManager.UI_PANES.DIALOG and Input.is_action_just_pressed("ui_accept"): UiManager.current_pane = UiManager.UI_PANES.HUD #get_tree().paused = false + +func reset_current_pane_tracker(): + current_pane = 0 +