From d6a2f4b56794df369c5cec50dff6695ba99d263f Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Mon, 26 May 2025 13:11:27 -0500 Subject: [PATCH] Cleaned and improved some event stuff --- locale/en_AU.po | 33 +++++++++---- project.godot | 7 ++- scenes/Maps/TestMap/TestMap.tscn | 50 +++++++++++++------- scenes/Singletons/Event.tscn | 9 ++++ scenes/Singletons/Quest.tscn | 8 ++-- scenes/Singletons/UI.tscn | 6 +-- scenes/UI/EventFlagMenu.tscn | 42 +++++++++++----- scenes/UI/VNTextbox.tscn | 23 ++++++--- scripts/Cooking/Recipe.gd | 7 ++- scripts/Entity/Component/EntityInteractor.gd | 7 +++ scripts/Entity/ItemOnGround.gd | 6 +-- scripts/Event/Event.gd | 11 +++-- scripts/Event/EventConversation.gd | 13 +++-- scripts/Event/EventTextbox.gd | 20 ++++++-- scripts/Event/Flow/EventGroup.gd | 11 +---- scripts/Event/Flow/EventWithChildren.gd | 27 ++++++++--- scripts/Event/Item/EventGetItem.gd | 45 +++++++++++++++--- scripts/Event/Item/EventItem.gd | 2 +- scripts/Map/Map.gd | 9 +++- scripts/Scene/MainMenuScene.gd | 2 +- scripts/Singleton/EventSystem.gd | 23 ++++++++- scripts/Singleton/ItemSystem.gd | 2 +- scripts/Singleton/LocaleSystem.gd | 9 ---- scripts/Singleton/UISystem.gd | 23 +++++++++ scripts/TransContext.gd | 2 - scripts/UI/EventFlagMenu.gd | 3 ++ scripts/UI/VNTextbox.gd | 4 +- 27 files changed, 296 insertions(+), 108 deletions(-) create mode 100644 scenes/Singletons/Event.tscn diff --git a/locale/en_AU.po b/locale/en_AU.po index cb1e0b9..b395dd1 100644 --- a/locale/en_AU.po +++ b/locale/en_AU.po @@ -62,13 +62,13 @@ msgstr[1] "Received {quantity} {item.title}." # QUESTS # msgid "quest.test_quest.title" -msgstr "Test Quest" +msgstr "Learn to cook!" -msgid "quest.test_quest.onion.title" -msgstr "Scavenge Onions" +msgid "quest.test_quest.sweet_potato.title" +msgstr "Scavenge Sweet Potatoes" -msgid "quest.test_quest.onion.description" -msgstr "Find and collect {quantity} {item.title} and bring them back to {npc}." +msgid "quest.test_quest.sweet_potato.description" +msgstr "Find and collect {quantity} {item.title} so you can learn to cook!" # # ITEMS @@ -120,7 +120,24 @@ msgstr "" "\n" "Press [input action=debug][/input] to open the debug menu" +# ============================================================================== +# +# MAPS +# +# ============================================================================== -# TEST -msgid "test" -msgstr "Test {item.title} String" \ No newline at end of file +# +# Test Map +# +msgid "map.test_map.title" +msgstr "Test Map" + +# Events +msgid "map.test_map.event.gather_onion.text0" +msgstr "I am giving you a quest to gather some ingredients." + +msgid "map.test_map.event.gather_onion.text1" +msgstr "Take this to help you on your way." + +msgid "map.test_map.event.gather_onion.text2" +msgstr "How goes the quest? Have you gathered the ingredients?" \ No newline at end of file diff --git a/project.godot b/project.godot index f06f725..e8168f1 100644 --- a/project.godot +++ b/project.godot @@ -27,10 +27,15 @@ SCENE_MANAGER="*res://scripts/Singleton/SceneSystem.gd" UI="*res://scenes/Singletons/UI.tscn" VN="*res://scripts/Singleton/VNSystem.gd" LOAD="*res://scenes/Singletons/Load.tscn" -EVENT="*res://scripts/Singleton/EventSystem.gd" RECIPE="*res://scenes/Singletons/Recipe.tscn" LOCALE="*res://scripts/Singleton/LocaleSystem.gd" ControllerIcons="*res://addons/controller_icons/ControllerIcons.gd" +EVENT="*res://scenes/Singletons/Event.tscn" + +[debug] + +gdscript/warnings/unused_variable=0 +gdscript/warnings/shadowed_variable=0 [display] diff --git a/scenes/Maps/TestMap/TestMap.tscn b/scenes/Maps/TestMap/TestMap.tscn index 283e4dc..ceeafdf 100644 --- a/scenes/Maps/TestMap/TestMap.tscn +++ b/scenes/Maps/TestMap/TestMap.tscn @@ -29,7 +29,7 @@ ambient_light_source = 1 [node name="TestMap" type="Node3D"] script = ExtResource("1_ru75d") -mapName = "My cool map" +title = "map.test_map.title" [node name="Entities" type="Node3D" parent="."] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1.19857, 0.684572, 0.968477) @@ -44,11 +44,33 @@ interactEvent = NodePath("../../Events/TestConversation") transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -4.56382, -0.547748, 1.61289) interactEvent = NodePath("../../Events/TestConversation") -[node name="ItemOnGround" parent="Entities" instance=ExtResource("4_ejcqv")] +[node name="Onion0" parent="Entities" instance=ExtResource("4_ejcqv")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.546944, -0.547748, -3.46628) itemType = 2 quantity = 2 +[node name="Onion1" parent="Entities" instance=ExtResource("4_ejcqv")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1.25922, -0.547748, -4.61426) +itemType = 2 +quantity = 2 + +[node name="Onion2" parent="Entities" instance=ExtResource("4_ejcqv")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2.83853, -0.547748, -3.29584) +itemType = 2 +quantity = 2 + +[node name="SweetPotato0" parent="Entities" instance=ExtResource("4_ejcqv")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1.31019, -0.547748, 3.74619) +itemType = 3 + +[node name="SweetPotato1" parent="Entities" instance=ExtResource("4_ejcqv")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.0143311, -0.547748, 4.4158) +itemType = 3 + +[node name="SweetPotato2" parent="Entities" instance=ExtResource("4_ejcqv")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1.05915, -0.547748, 5.04958) +itemType = 3 + [node name="Map" type="Node3D" parent="."] metadata/_edit_lock_ = true @@ -85,39 +107,35 @@ event = 1 eventFlag = 1 metadata/_custom_type_script = "uid://ccujhcc446mvh" -[node name="Text 0" type="Node" parent="Events/TestConversation/After Quest Started"] +[node name="Text 2" type="Node" parent="Events/TestConversation/After Quest Started"] script = ExtResource("6_gxq5o") -text = "Go find those ingredients!" +text = "map.test_map.event.gather_onion.text2" -[node name="Before Quest STarted" type="Node" parent="Events/TestConversation"] +[node name="Before Quest Started" type="Node" parent="Events/TestConversation"] script = ExtResource("13_60ixl") event = 1 type = 2 eventFlag = 1 metadata/_custom_type_script = "uid://ccujhcc446mvh" -[node name="Text 0" type="Node" parent="Events/TestConversation/Before Quest STarted"] +[node name="Text 0" type="Node" parent="Events/TestConversation/Before Quest Started"] script = ExtResource("6_gxq5o") -text = "I am giving you a quest to gather some ingredients." +text = "map.test_map.event.gather_onion.text0" -[node name="Quest" type="Node" parent="Events/TestConversation/Before Quest STarted"] +[node name="Quest" type="Node" parent="Events/TestConversation/Before Quest Started"] script = ExtResource("7_brp0k") metadata/_custom_type_script = "uid://c4d7nithqnx5y" -[node name="Text 1" type="Node" parent="Events/TestConversation/Before Quest STarted"] +[node name="Text 1" type="Node" parent="Events/TestConversation/Before Quest Started"] script = ExtResource("6_gxq5o") -text = "Take this potion to help you on your way." +text = "map.test_map.event.gather_onion.text1" -[node name="Get Item" type="Node" parent="Events/TestConversation/Before Quest STarted"] +[node name="Get Item" type="Node" parent="Events/TestConversation/Before Quest Started"] script = ExtResource("10_avybc") getType = 1 metadata/_custom_type_script = "uid://b41umpbgqfuc2" -[node name="Text 2" type="Node" parent="Events/TestConversation/Before Quest STarted"] -script = ExtResource("6_gxq5o") -text = "Thanks for taking that potion." - -[node name="EventFlagModify" type="Node" parent="Events/TestConversation/Before Quest STarted"] +[node name="EventFlagModify" type="Node" parent="Events/TestConversation/Before Quest Started"] script = ExtResource("12_ncdgy") event = 1 eventFlag = 1 diff --git a/scenes/Singletons/Event.tscn b/scenes/Singletons/Event.tscn new file mode 100644 index 0000000..e1c074c --- /dev/null +++ b/scenes/Singletons/Event.tscn @@ -0,0 +1,9 @@ +[gd_scene load_steps=2 format=3 uid="uid://dqde5pj14u71"] + +[ext_resource type="Script" uid="uid://dy8gbmwddma3b" path="res://scripts/Singleton/EventSystem.gd" id="1_pu13l"] + +[node name="EventSystem" type="Node"] +script = ExtResource("1_pu13l") +metadata/_custom_type_script = "uid://dy8gbmwddma3b" + +[node name="StartedEvents" type="Node" parent="."] diff --git a/scenes/Singletons/Quest.tscn b/scenes/Singletons/Quest.tscn index f8a240a..6af5059 100644 --- a/scenes/Singletons/Quest.tscn +++ b/scenes/Singletons/Quest.tscn @@ -14,10 +14,10 @@ script = ExtResource("2_n4ii1") title = "quest.test_quest.title" metadata/_custom_type_script = "uid://dn0kxbe85n40f" -[node name="Find Onion" type="Node" parent="Quests/Test Quest"] +[node name="Find Sweet Potato" type="Node" parent="Quests/Test Quest"] script = ExtResource("3_l8p7p") -title = "quest.test_quest.onion.title" -description = "quest.test_quest.onion.description" -itemType = 2 +title = "quest.test_quest.sweet_potato.title" +description = "quest.test_quest.sweet_potato.description" +itemType = 3 quantity = 2 metadata/_custom_type_script = "uid://de1ao4huhy0hm" diff --git a/scenes/Singletons/UI.tscn b/scenes/Singletons/UI.tscn index faa8ca5..2631efa 100644 --- a/scenes/Singletons/UI.tscn +++ b/scenes/Singletons/UI.tscn @@ -26,11 +26,11 @@ visible = false layout_mode = 2 anchors_preset = 0 -[node name="VNTextbox" parent="." instance=ExtResource("3_btpxp")] -visible = false +[node name="EventFlagMenu" parent="." instance=ExtResource("5_12prj")] layout_mode = 1 -[node name="EventFlagMenu" parent="." instance=ExtResource("5_12prj")] +[node name="VNTextbox" parent="." instance=ExtResource("3_btpxp")] +visible = false layout_mode = 1 [node name="DebugMenu" parent="." instance=ExtResource("2_is0g4")] diff --git a/scenes/UI/EventFlagMenu.tscn b/scenes/UI/EventFlagMenu.tscn index 9d502ba..ba2e104 100644 --- a/scenes/UI/EventFlagMenu.tscn +++ b/scenes/UI/EventFlagMenu.tscn @@ -2,15 +2,18 @@ [ext_resource type="Script" uid="uid://b4a3ne2vn36mt" path="res://scripts/UI/EventFlagMenu.gd" id="1_nnw5f"] -[node name="EventFlagsMenu" type="Panel" node_paths=PackedStringArray("flagList", "grid")] +[node name="EventFlagsMenu" type="Panel" node_paths=PackedStringArray("flagList", "grid", "btnClose")] anchors_preset = 15 anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 +size_flags_horizontal = 3 +size_flags_vertical = 3 script = ExtResource("1_nnw5f") flagList = NodePath("HBoxContainer/FlagList") -grid = NodePath("HBoxContainer/Control") +grid = NodePath("HBoxContainer/VBoxContainer/Control") +btnClose = NodePath("HBoxContainer/VBoxContainer/HBoxContainer/Button") metadata/_custom_type_script = "uid://b4a3ne2vn36mt" [node name="HBoxContainer" type="HBoxContainer" parent="."] @@ -31,43 +34,56 @@ item_count = 2 item_0/text = "Item 0" item_1/text = "Item 1" -[node name="Control" type="GridContainer" parent="HBoxContainer"] +[node name="VBoxContainer" type="VBoxContainer" parent="HBoxContainer"] +clip_contents = true layout_mode = 2 size_flags_horizontal = 3 -columns = 6 -[node name="Flag0" type="CheckBox" parent="HBoxContainer/Control"] +[node name="HBoxContainer" type="HBoxContainer" parent="HBoxContainer/VBoxContainer"] +layout_mode = 2 +alignment = 2 + +[node name="Button" type="Button" parent="HBoxContainer/VBoxContainer/HBoxContainer"] +layout_mode = 2 +text = "close" + +[node name="Control" type="GridContainer" parent="HBoxContainer/VBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 3 +columns = 5 + +[node name="Flag0" type="CheckBox" parent="HBoxContainer/VBoxContainer/Control"] layout_mode = 2 text = "Flag 0" -[node name="Flag1" type="CheckBox" parent="HBoxContainer/Control"] +[node name="Flag1" type="CheckBox" parent="HBoxContainer/VBoxContainer/Control"] layout_mode = 2 text = "Flag 0" -[node name="Flag2" type="CheckBox" parent="HBoxContainer/Control"] +[node name="Flag2" type="CheckBox" parent="HBoxContainer/VBoxContainer/Control"] layout_mode = 2 text = "Flag 0" -[node name="Flag3" type="CheckBox" parent="HBoxContainer/Control"] +[node name="Flag3" type="CheckBox" parent="HBoxContainer/VBoxContainer/Control"] layout_mode = 2 text = "Flag 0" -[node name="Flag4" type="CheckBox" parent="HBoxContainer/Control"] +[node name="Flag4" type="CheckBox" parent="HBoxContainer/VBoxContainer/Control"] layout_mode = 2 text = "Flag 0" -[node name="Flag5" type="CheckBox" parent="HBoxContainer/Control"] +[node name="Flag5" type="CheckBox" parent="HBoxContainer/VBoxContainer/Control"] layout_mode = 2 text = "Flag 0" -[node name="Flag6" type="CheckBox" parent="HBoxContainer/Control"] +[node name="Flag6" type="CheckBox" parent="HBoxContainer/VBoxContainer/Control"] layout_mode = 2 text = "Flag 0" -[node name="Flag7" type="CheckBox" parent="HBoxContainer/Control"] +[node name="Flag7" type="CheckBox" parent="HBoxContainer/VBoxContainer/Control"] layout_mode = 2 text = "Flag 0" -[node name="Flag8" type="CheckBox" parent="HBoxContainer/Control"] +[node name="Flag8" type="CheckBox" parent="HBoxContainer/VBoxContainer/Control"] layout_mode = 2 text = "Flag 0" diff --git a/scenes/UI/VNTextbox.tscn b/scenes/UI/VNTextbox.tscn index 6a379f1..97d3cbe 100644 --- a/scenes/UI/VNTextbox.tscn +++ b/scenes/UI/VNTextbox.tscn @@ -1,14 +1,15 @@ -[gd_scene load_steps=3 format=3 uid="uid://bkx3l0kckf4a8"] +[gd_scene load_steps=4 format=3 uid="uid://bkx3l0kckf4a8"] [ext_resource type="Theme" uid="uid://dm7ee4aqjr2dl" path="res://ui/UI Theme.tres" id="1_wx4lp"] [ext_resource type="Script" uid="uid://ck62jug2gl4wk" path="res://scripts/UI/VNTextbox.gd" id="2_uo1gm"] +[ext_resource type="Script" uid="uid://cq6bvma0kk6tg" path="res://scripts/UI/AdvancedRichText.gd" id="3_j0315"] [node name="VNTextbox" type="PanelContainer"] anchors_preset = 12 anchor_top = 1.0 anchor_right = 1.0 anchor_bottom = 1.0 -offset_top = -50.0 +offset_top = -58.0 grow_horizontal = 2 grow_vertical = 0 theme = ExtResource("1_wx4lp") @@ -17,12 +18,22 @@ script = ExtResource("2_uo1gm") [node name="MarginContainer" type="MarginContainer" parent="."] layout_mode = 2 theme = ExtResource("1_wx4lp") +theme_override_constants/margin_left = 4 +theme_override_constants/margin_top = 4 +theme_override_constants/margin_right = 4 +theme_override_constants/margin_bottom = 4 [node name="Label" type="RichTextLabel" parent="MarginContainer"] layout_mode = 2 theme = ExtResource("1_wx4lp") bbcode_enabled = true -text = "test -test -test -test" +text = "Text +Text +Text +Text" +script = ExtResource("3_j0315") +advancedText = "Text +Text +Text +Text" +metadata/_custom_type_script = "uid://cq6bvma0kk6tg" diff --git a/scripts/Cooking/Recipe.gd b/scripts/Cooking/Recipe.gd index 4617447..8066270 100644 --- a/scripts/Cooking/Recipe.gd +++ b/scripts/Cooking/Recipe.gd @@ -31,4 +31,9 @@ func make(inventory:Inventory = null) -> void: for output in outputs: inventory.addItem(output.type, output.quantity) - timesMade += 1 \ No newline at end of file + timesMade += 1 + +func getTransContext() -> TransContext: + var ctx = TransContext.new() + ctx.addTrans("title", title) + return ctx \ No newline at end of file diff --git a/scripts/Entity/Component/EntityInteractor.gd b/scripts/Entity/Component/EntityInteractor.gd index cc4f4c7..ed2ac15 100644 --- a/scripts/Entity/Component/EntityInteractor.gd +++ b/scripts/Entity/Component/EntityInteractor.gd @@ -38,6 +38,9 @@ func getRaycastInteractable() -> EntityInteractable: return interactable func _process(delta: float) -> void: + if !entity or entity.isPaused(): + return + match interactorType: InteractorType.PLAYER_INPUT: _processPlayerInput() @@ -49,6 +52,10 @@ func _process(delta: float) -> void: func _processPlayerInput() -> void: if !Input.is_action_just_pressed("interact"): return + + # Conditions where player cannot interact. + if UI.hasInteractionFocus(): + return var interactable:EntityInteractable = getRaycastInteractable() if interactable: diff --git a/scripts/Entity/ItemOnGround.gd b/scripts/Entity/ItemOnGround.gd index cbefef5..83831a7 100644 --- a/scripts/Entity/ItemOnGround.gd +++ b/scripts/Entity/ItemOnGround.gd @@ -22,11 +22,9 @@ func onEntityInteract( interactor:EntityInteractor, interactee:EntityInteractable ) -> void: - print("Interact?") var event = EventGetItem.new() event.itemType = itemType; event.quantity = quantity; + event.removeNode = self + EVENT.addEvent(event) event.onEntityInteract(interactor, interactee) - - get_parent().remove_child(self) - self.queue_free() \ No newline at end of file diff --git a/scripts/Event/Event.gd b/scripts/Event/Event.gd index ebd9dc3..4a65639 100644 --- a/scripts/Event/Event.gd +++ b/scripts/Event/Event.gd @@ -2,15 +2,13 @@ class_name Event extends Node const Entity = preload("res://scripts/Entity/Entity.gd"); +var inEventSystemTree:bool = false; var started:bool = false; var ended:bool = false; var interactor:EntityInteractor = null var interactee:EntityInteractable = null # Godot Methods -func _init() -> void: - pass - func _process(delta: float) -> void: if !started || ended: return @@ -21,6 +19,11 @@ func _process(delta: float) -> void: # Event methods (cleaned up) func start() -> void: + assert( + self.is_inside_tree(), + "Event is trying to start but the node is not part of the scene tree. "+ + "Refer to EventSystem.addEvent" + ) assert(started == false) started = true @@ -34,6 +37,8 @@ func isDone() -> bool: func end() -> void: assert(ended == false) ended = true + if self.inEventSystemTree: + EVENT.removeEvent(self) func isEndingEvent() -> bool: return false diff --git a/scripts/Event/EventConversation.gd b/scripts/Event/EventConversation.gd index 471fa0b..a29c9ea 100644 --- a/scripts/Event/EventConversation.gd +++ b/scripts/Event/EventConversation.gd @@ -17,41 +17,46 @@ func start() -> void: if interactee && interactor: if turnInteractee && interactee.entityDirection && interactor.characterBody: var turn = EventEntityTurn.new() + turn.name = "Conversation Turn Interactee" turn.entity = interactee.entityDirection turn.direction = turn.entity.getDirectionToFace(interactor.characterBody.global_position) - addExtraEvent(turn, 0) + addChildEvent(turn, 0) if turnInteractor && interactor.entityDirection && interactee.characterBody: var turn = EventEntityTurn.new() + turn.name = "Conversation Turn Interactor" turn.entity = interactor.entityDirection turn.direction = turn.entity.getDirectionToFace(interactee.characterBody.global_position) - addExtraEvent(turn, 0) + addChildEvent(turn, 0) # Create start pause event if (pauseInteractee && interactee.entity) || (pauseInteractor && interactor.entity): var startPause = EventPause.new() + startPause.name = "Conversation Start Pause" startPause.pauseType = startPauseType startPause.entities = entities if pauseInteractee && interactee.entity: startPause.includeInteractee = pauseInteractee if pauseInteractor && interactor.entity: startPause.includeInteractor = pauseInteractor - addExtraEvent(startPause, 0) + addChildEvent(startPause, 0) # Create end pause event. endPauseEvent = EventPause.new() + endPauseEvent.name = "Conversation End Pause" endPauseEvent.pauseType = endPauseType endPauseEvent.entities = entities if pauseInteractee && interactee.entity: endPauseEvent.includeInteractee = pauseInteractee if pauseInteractor && interactor.entity: endPauseEvent.includeInteractor = pauseInteractor - addExtraEvent(endPauseEvent, -1) + addChildEvent(endPauseEvent, -1) # Pass off to event group super.start() func end() -> void: + print("Ending conversation event: ", self) # Manually end pause if endPauseEvent != null && !endPauseEvent.started: endPauseEvent.start() diff --git a/scripts/Event/EventTextbox.gd b/scripts/Event/EventTextbox.gd index 4ad49f5..620de7a 100644 --- a/scripts/Event/EventTextbox.gd +++ b/scripts/Event/EventTextbox.gd @@ -1,11 +1,25 @@ class_name EventTextbox extends "res://scripts/Event/Event.gd" -# @export var text:Array[String] = [ "Hello Text" ]; -@export_multiline var text:String = "Hello Text" +@export_multiline var text:String = "" + +var textPlural:String = "" +var count:int = 1 +var transContext:TransContext = null func start() -> void: super.start() - VN.getTextbox().setText(self.text); + + if text.is_empty() && transContext == null: + push_error("EventTextbox text is empty and no TransContext provided.") + return + + if transContext == null: + transContext = TransContext.new() + + if textPlural.is_empty(): + VN.getTextbox().setText(transContext.trans(text)) + else: + VN.getTextbox().setText(transContext.transPlural(text, textPlural, count)); func isDone() -> bool: return super.isDone() && VN.getTextbox().isClosed; diff --git a/scripts/Event/Flow/EventGroup.gd b/scripts/Event/Flow/EventGroup.gd index 41f88ae..a72b628 100644 --- a/scripts/Event/Flow/EventGroup.gd +++ b/scripts/Event/Flow/EventGroup.gd @@ -80,13 +80,4 @@ func reset() -> void: for child in childEvents: child.reset() # Send to the parent to reset the extra events - super.reset() - -func startChild(child:Event) -> void: - # Inherits some properties from this event. - child.interactee = self.interactee - child.interactor = self.interactor - child.start() - - if child.isEndingEvent(): - self.end() \ No newline at end of file + super.reset() \ No newline at end of file diff --git a/scripts/Event/Flow/EventWithChildren.gd b/scripts/Event/Flow/EventWithChildren.gd index eea3a0a..9735c9f 100644 --- a/scripts/Event/Flow/EventWithChildren.gd +++ b/scripts/Event/Flow/EventWithChildren.gd @@ -1,7 +1,7 @@ class_name EventWithChildren extends "res://scripts/Event/Event.gd" var childEvents:Array[Event] = [] -var extraEvents:Array[Event] = [] +var addedEvents:Array[Event] = [] func start(): super.start() @@ -22,16 +22,29 @@ func _updateChildEvents() -> void: childEvents.append(child) func _cleanupExtraEvents(): - for event in extraEvents: + for event in addedEvents: remove_child(event) event.queue_free() - extraEvents = [] + addedEvents = [] _updateChildEvents() -func addExtraEvent(child:Event, position:int) -> void: +func addChildEvent(child:Event, position:int = -1) -> void: assert(started == false || ended == true) - # Add the child to the extra events list - extraEvents.append(child) + if position < 0: + position = childEvents.size() + position + 1 + add_child(child) move_child(child, position) - _updateChildEvents() \ No newline at end of file + addedEvents.append(child) + _updateChildEvents() + +func startChild(child:Event) -> void: + assert(child.get_parent() == self) + + # Inherits some properties from this event. + child.interactee = self.interactee + child.interactor = self.interactor + child.start() + + if child.isEndingEvent(): + self.end() diff --git a/scripts/Event/Item/EventGetItem.gd b/scripts/Event/Item/EventGetItem.gd index 6a27ffd..6393313 100644 --- a/scripts/Event/Item/EventGetItem.gd +++ b/scripts/Event/Item/EventGetItem.gd @@ -1,5 +1,7 @@ class_name EventGetItem extends "res://scripts/Event/Item/EventItem.gd" +const EventConversation = preload("res://scripts/Event/EventConversation.gd") + enum GetType { FOUND, GIVEN, @@ -7,14 +9,20 @@ enum GetType { @export var showText: bool = true @export var getType:GetType = GetType.FOUND; +@export var removeNode:Node = null + +var conversationEvent:EventConversation = null +var textboxEvent:EventTextbox = null func start() -> void: - super.start() getInventory().addItem(itemType, quantity) + # Should show text? if !showText: + super.start() return - + + # What text to show? var textKey:String match getType: GetType.FOUND: @@ -22,12 +30,29 @@ func start() -> void: GetType.GIVEN: textKey = "event.get_item.given" _: - pass + super.start() + return + # Create translation context var ctx = TransContext.new() ctx.addInteger("quantity", quantity) ctx.addContext("item", ITEM.getItem(itemType).getTransContext()) - VN.getTextbox().setText(ctx.transPlural(textKey, textKey + "_plural", quantity)); + + # Create conversation + conversationEvent = EventConversation.new() + addChildEvent(conversationEvent) + + # Create textbox + textboxEvent = EventTextbox.new() + textboxEvent.transContext = ctx + textboxEvent.text = textKey + textboxEvent.textPlural = textKey + "_plural" + textboxEvent.count = quantity + conversationEvent.addChildEvent(textboxEvent) + + # Begin processing + super.start() + startChild(conversationEvent) func isDone() -> bool: if !super.isDone(): @@ -35,5 +60,13 @@ func isDone() -> bool: if !showText: return true - - return VN.getTextbox().isClosed; \ No newline at end of file + return conversationEvent.isDone() + +func end() -> void: + if removeNode: + var parent = removeNode.get_parent() + if parent: + parent.remove_child(removeNode) + removeNode.queue_free() + removeNode = null + super.end() diff --git a/scripts/Event/Item/EventItem.gd b/scripts/Event/Item/EventItem.gd index 5389201..fe4ab26 100644 --- a/scripts/Event/Item/EventItem.gd +++ b/scripts/Event/Item/EventItem.gd @@ -1,4 +1,4 @@ -class_name EventItem extends Event +class_name EventItem extends "res://scripts/Event/Flow/EventWithChildren.gd" const Inventory = preload("res://scripts/Item/Inventory.gd") @export var itemType:Item.Type = Item.Type.POTION diff --git a/scripts/Map/Map.gd b/scripts/Map/Map.gd index 3cfa3f0..ac18c8a 100644 --- a/scripts/Map/Map.gd +++ b/scripts/Map/Map.gd @@ -1,8 +1,13 @@ class_name Map extends Node -@export var mapName:String = "Map" +@export_multiline var title:String = "" @export var mapEnterEvent:Event = null func _ready() -> void: if mapEnterEvent: - mapEnterEvent.start() \ No newline at end of file + mapEnterEvent.start() + +func getTransContext() -> TransContext: + var ctx = TransContext.new() + ctx.set("title", title) + return ctx \ No newline at end of file diff --git a/scripts/Scene/MainMenuScene.gd b/scripts/Scene/MainMenuScene.gd index a26fca2..0b35009 100644 --- a/scripts/Scene/MainMenuScene.gd +++ b/scripts/Scene/MainMenuScene.gd @@ -1,4 +1,4 @@ class_name MainMenuScene extends Node func _enter_tree() -> void: - pass \ No newline at end of file + pass diff --git a/scripts/Singleton/EventSystem.gd b/scripts/Singleton/EventSystem.gd index b4f15aa..e4be8d4 100644 --- a/scripts/Singleton/EventSystem.gd +++ b/scripts/Singleton/EventSystem.gd @@ -47,4 +47,25 @@ func eventAreFlagsOff(event:SpecialEvent, flagsToCheck:int) -> bool: func eventIsAnyOfFlagsOff(event:SpecialEvent, flagsToCheck:int) -> bool: if !eventFlags.has(event): eventFlags[event] = 0; - return (eventFlags[event] & flagsToCheck) != flagsToCheck; \ No newline at end of file + return (eventFlags[event] & flagsToCheck) != flagsToCheck; + +# Adds an event that is created by code into the scene tree and lets it be +# managed properly by the event system. +func addEvent(event:Event) -> void: + assert( + !event.is_inside_tree(), + "Event is already inside the scene tree, cannot add it again." + ) + + $StartedEvents.add_child(event) + event.inEventSystemTree = true + +func removeEvent(event:Event) -> void: + assert( + event.inEventSystemTree, + "Event is not inside event system tree." + ) + + event.inEventSystemTree = false + $StartedEvents.remove_child(event) + event.queue_free() \ No newline at end of file diff --git a/scripts/Singleton/ItemSystem.gd b/scripts/Singleton/ItemSystem.gd index 51978e3..bf6c17d 100644 --- a/scripts/Singleton/ItemSystem.gd +++ b/scripts/Singleton/ItemSystem.gd @@ -32,4 +32,4 @@ func getItem(type:Item.Type) -> Item: return ITEM_MAP[type] func isStackable(itemType:Item.Type) -> bool: - return getItem(itemType).stackable \ No newline at end of file + return getItem(itemType).stackable diff --git a/scripts/Singleton/LocaleSystem.gd b/scripts/Singleton/LocaleSystem.gd index d020981..3629b57 100644 --- a/scripts/Singleton/LocaleSystem.gd +++ b/scripts/Singleton/LocaleSystem.gd @@ -39,15 +39,6 @@ func _init() -> void: var preferred = OS.get_locale() self.setLocaleFromLocaleString(preferred) -func _enter_tree() -> void: - # Test - print("Hello World!") - - var ctx = TransContext.new() - ctx.addInteger("quantity", 2) - ctx.addContext("item", ITEM.getItem(Item.Type.POTION).getTransContext()) - print(ctx.trans("test")) - func setLocaleFromLocaleString(localeString:String) -> void: var parts:PackedStringArray = localeString.split("_") diff --git a/scripts/Singleton/UISystem.gd b/scripts/Singleton/UISystem.gd index e03da90..2054712 100644 --- a/scripts/Singleton/UISystem.gd +++ b/scripts/Singleton/UISystem.gd @@ -4,13 +4,36 @@ var QUEST_MENU:QuestMenu var DEBUG_MENU:DebugMenu var INVENTORY_MENU:FullInventoryMenu var EVENT_FLAG_MENU:EventFlagMenu +var VN_TEXTBOX:VNTextbox func _ready() -> void: QUEST_MENU = $QuestMenu DEBUG_MENU = $DebugMenu INVENTORY_MENU = $FullInventory EVENT_FLAG_MENU = $EventFlagMenu + VN_TEXTBOX = $VNTextbox func _process(delta: float) -> void: # This needs to always be at the end of the parent node's tree get_parent().move_child(self, get_parent().get_child_count() - 1) + +func hasInteractionFocus() -> bool: + # Returns true if the UI system has focus, basically if any UI menu or + # element is open in a way that prevents interaction with the game world. + + if QUEST_MENU.isOpen(): + return true + + if DEBUG_MENU.isOpen(): + return true + + if INVENTORY_MENU.isOpen(): + return true + + if EVENT_FLAG_MENU.isOpen(): + return true + + if !VN_TEXTBOX.isClosed: + return true + + return false \ No newline at end of file diff --git a/scripts/TransContext.gd b/scripts/TransContext.gd index f419c34..6040b13 100644 --- a/scripts/TransContext.gd +++ b/scripts/TransContext.gd @@ -106,8 +106,6 @@ func build( # Merge with our dictionary dict.merge(subDict) - print("Trans context before key prepend: ", dict) - if key != "": # Now prepend the parent key to all keys in the dictionary var newDict:Dictionary[String, String] = {} diff --git a/scripts/UI/EventFlagMenu.gd b/scripts/UI/EventFlagMenu.gd index 715d5ee..b69609d 100644 --- a/scripts/UI/EventFlagMenu.gd +++ b/scripts/UI/EventFlagMenu.gd @@ -2,6 +2,8 @@ class_name EventFlagMenu extends Panel @export var flagList:ItemList @export var grid:GridContainer +@export var btnClose:Button + var checkboxes:Array[CheckBox] = [] var selectedEvent:int = -1 @@ -24,6 +26,7 @@ func _ready() -> void: EVENT.eventFlagUpdated.connect(_on_EventFlagUpdated) flagList.item_selected.connect(_on_EventSelected) + btnClose.pressed.connect(close) func _exit_tree() -> void: EVENT.eventFlagUpdated.disconnect(_on_EventFlagUpdated) diff --git a/scripts/UI/VNTextbox.gd b/scripts/UI/VNTextbox.gd index 3481359..1c05350 100644 --- a/scripts/UI/VNTextbox.gd +++ b/scripts/UI/VNTextbox.gd @@ -70,7 +70,7 @@ func getCountOfCharactersToScrollInView() -> int: func recalculateWrapping(): # Reset label to default. - label.text = text; + label.advancedText = text; label.visible_characters = -1; label.fit_content = true; isMoreViews = false; @@ -98,7 +98,7 @@ func recalculateWrapping(): wrappedText += "\n"; wrappedText += text[i]; - label.text = wrappedText; + label.advancedText = wrappedText; label.fit_content = false; label.visible_characters = 0;