diff --git a/command.gd b/command.gd new file mode 100644 index 0000000..5e11c6e --- /dev/null +++ b/command.gd @@ -0,0 +1,5 @@ +extends Resource +class_name Command + +@export var name: String +@export var modal_name: String diff --git a/command.gd.uid b/command.gd.uid new file mode 100644 index 0000000..11e6962 --- /dev/null +++ b/command.gd.uid @@ -0,0 +1 @@ +uid://cn8rc6jyllrf0 diff --git a/commands/command_button.gd b/commands/command_button.gd new file mode 100644 index 0000000..a237022 --- /dev/null +++ b/commands/command_button.gd @@ -0,0 +1,14 @@ +extends Button + +signal command_succcess(c: Command) + +@export var command: Command + +func _ready() -> void: + sync() + +func sync(): + text = command.name + +func _on_pressed() -> void: + command_succcess.emit(command) diff --git a/commands/command_button.gd.uid b/commands/command_button.gd.uid new file mode 100644 index 0000000..1fcfe02 --- /dev/null +++ b/commands/command_button.gd.uid @@ -0,0 +1 @@ +uid://m5qf37ordikh diff --git a/commands/command_button.tscn b/commands/command_button.tscn new file mode 100644 index 0000000..420a110 --- /dev/null +++ b/commands/command_button.tscn @@ -0,0 +1,8 @@ +[gd_scene format=3 uid="uid://cno33rgilttxt"] + +[ext_resource type="PackedScene" uid="uid://dqb4a1igddv71" path="res://gui/bribe_button.tscn" id="1_j6j61"] +[ext_resource type="Script" uid="uid://m5qf37ordikh" path="res://commands/command_button.gd" id="2_0fnf4"] + +[node name="CommandButton" unique_id=1084248382 instance=ExtResource("1_j6j61")] +script = ExtResource("2_0fnf4") +command = null diff --git a/commands/move.gd b/commands/move.gd new file mode 100644 index 0000000..056fd8b --- /dev/null +++ b/commands/move.gd @@ -0,0 +1,2 @@ +extends Command +class_name MoveCommand diff --git a/commands/move.gd.uid b/commands/move.gd.uid new file mode 100644 index 0000000..82486ed --- /dev/null +++ b/commands/move.gd.uid @@ -0,0 +1 @@ +uid://jxfw3ptlwg8d diff --git a/commands/move_command.tres b/commands/move_command.tres new file mode 100644 index 0000000..025b639 --- /dev/null +++ b/commands/move_command.tres @@ -0,0 +1,9 @@ +[gd_resource type="Resource" script_class="MoveCommand" format=3 uid="uid://u6lls6n0xw3n"] + +[ext_resource type="Script" uid="uid://jxfw3ptlwg8d" path="res://commands/move.gd" id="1_cox6k"] + +[resource] +script = ExtResource("1_cox6k") +name = "Move" +modal_name = "Moving!" +metadata/_custom_type_script = "uid://jxfw3ptlwg8d" diff --git a/currency/currency.gd b/currency/currency.gd index 1f0a1d5..aa3d55e 100644 --- a/currency/currency.gd +++ b/currency/currency.gd @@ -7,3 +7,4 @@ class_name Currency @export var thumbnail: Texture2D @export var color: Color = Color.PINK @export var wants: Array[Production] +@export var commands: Array[Command] = [preload("res://commands/move_command.tres")] diff --git a/currency/members/MemberSprite.tscn b/currency/members/MemberSprite.tscn index 059c0b9..5d85577 100644 --- a/currency/members/MemberSprite.tscn +++ b/currency/members/MemberSprite.tscn @@ -9,6 +9,7 @@ shader = ExtResource("1_tm326") [sub_resource type="CanvasTexture" id="CanvasTexture_wgite"] [node name="MemberSprite" type="TextureRect" unique_id=283117283] +z_index = 100 material = SubResource("ShaderMaterial_tm326") mouse_default_cursor_shape = 2 texture = SubResource("CanvasTexture_wgite") diff --git a/currency/sentient/farmer.tres b/currency/sentient/farmer.tres index 4f3ce37..1f7d75d 100644 --- a/currency/sentient/farmer.tres +++ b/currency/sentient/farmer.tres @@ -2,6 +2,8 @@ [ext_resource type="Script" uid="uid://dddyxbkq0ienn" path="res://currency/production.gd" id="1_35xhy"] [ext_resource type="Script" uid="uid://hcvynq5fjypj" path="res://currency/sentient_currency.gd" id="1_kipvp"] +[ext_resource type="Script" uid="uid://cn8rc6jyllrf0" path="res://command.gd" id="1_uh6l7"] +[ext_resource type="Resource" uid="uid://u6lls6n0xw3n" path="res://commands/move_command.tres" id="2_7lva1"] [ext_resource type="Resource" uid="uid://boshkhnywnk27" path="res://currency/production/human_production_shared_1.tres" id="2_jkjll"] [ext_resource type="Resource" uid="uid://mgb7y1r3eapq" path="res://currency/production/human_production_shared_2.tres" id="3_kfqfp"] [ext_resource type="Resource" uid="uid://b5qok0rcalr" path="res://currency/sentient/cow.tres" id="5_uddvy"] diff --git a/economy.gd b/economy.gd index eda8b96..f94f198 100644 --- a/economy.gd +++ b/economy.gd @@ -83,7 +83,9 @@ func simulate(): produce(o) production_log.emit(null, o) if e.timeline != null: - Dialogic.start(e.timeline) + GameState.add_letter.emit(e.into_letter()) + if randf() < 0.01: + LetterGeneration.try_generate_offer() func get_all_currencies_in(dir: StringName): diff --git a/event.gd b/event.gd index 240772b..04f7bda 100644 --- a/event.gd +++ b/event.gd @@ -9,8 +9,10 @@ enum EventNature { Random, Certain, } -@export var probability: float = 0.005 +@export var probability: float = 0.01 @export var nature: EventNature = EventNature.Random +@export var email_source: Currency = preload("res://currency/sentient/town_crier.tres") +@export var email_subject: String = "Something is amok!" func requirements_satisfied() -> bool: for requirement in requirements: @@ -28,3 +30,9 @@ func outcome() -> Array[Production]: stuff.append_array(extra_mods) return stuff +func into_letter() -> EventLetter: + var el := EventLetter.new() + el.source = email_source + el.subject_field = email_subject + el.timeline = timeline + return el diff --git a/game.tscn b/game.tscn index 5fb05fb..d056222 100644 --- a/game.tscn +++ b/game.tscn @@ -2,6 +2,9 @@ [ext_resource type="PackedScene" uid="uid://bdk1r2u8clllr" path="res://map.tscn" id="1_e2o6t"] [ext_resource type="PackedScene" uid="uid://d06w1wtct0mfs" path="res://test/test_economy.tscn" id="2_feb5d"] +[ext_resource type="PackedScene" uid="uid://coebykrbnhlif" path="res://currency/members/MemberSprite.tscn" id="3_7jktm"] +[ext_resource type="Resource" uid="uid://dn0c1pfq04obw" path="res://currency/sentient/farmer.tres" id="4_ryrav"] +[ext_resource type="Resource" uid="uid://b7lxfjhx4qhts" path="res://allegiance/good.tres" id="5_eow3j"] [node name="Game" type="Node2D" unique_id=1791439508] @@ -10,3 +13,11 @@ [node name="CanvasLayer" type="CanvasLayer" parent="." unique_id=1213874033] [node name="TestEconomy" parent="CanvasLayer" unique_id=629898212 instance=ExtResource("2_feb5d")] + +[node name="MemberSprite" parent="." unique_id=283117283 instance=ExtResource("3_7jktm")] +offset_left = 294.0 +offset_top = 1177.0 +offset_right = 345.0 +offset_bottom = 1219.0 +currency = ExtResource("4_ryrav") +allegiance = ExtResource("5_eow3j") diff --git a/gui/bribe_button.tscn b/gui/bribe_button.tscn index 6ca6c6b..099841a 100644 --- a/gui/bribe_button.tscn +++ b/gui/bribe_button.tscn @@ -3,6 +3,7 @@ [ext_resource type="Script" uid="uid://olr6663hny8n" path="res://bribe_button.gd" id="1_2abdb"] [node name="BribeButton" type="Button" unique_id=1084248382] +custom_minimum_size = Vector2(0, 50) text = "< num > of < currency >" script = ExtResource("1_2abdb") diff --git a/gui/currency_inspector_panel.gd b/gui/currency_inspector_panel.gd index 0b554a7..4ffd8ad 100644 --- a/gui/currency_inspector_panel.gd +++ b/gui/currency_inspector_panel.gd @@ -5,7 +5,11 @@ var currency: Currency = null func _ready() -> void: UserContext.currency_inspect.connect(currency_inspect) UserContext.member_inspect.connect(member_inspect) + UserContext.modal_command_change.connect(modal_command_change) update() + +func modal_command_change(_c: Command): + visible = false func member_inspect(_m: CurrencyMemberSprite): visible = false diff --git a/gui/inbox_event_only.tscn b/gui/inbox_event_only.tscn new file mode 100644 index 0000000..c7117fa --- /dev/null +++ b/gui/inbox_event_only.tscn @@ -0,0 +1,8 @@ +[gd_scene format=3 uid="uid://choixlqgx0jo7"] + +[ext_resource type="PackedScene" uid="uid://da2ldx7una0a2" path="res://gui/inbox_message_subject.tscn" id="1_nc3yv"] + +[node name="InboxEvent" unique_id=1590519653 instance=ExtResource("1_nc3yv")] + +[node name="ReplyButton" parent="MarginContainer/HBoxContainer" parent_id_path=PackedInt32Array(1418860833) index="2" unique_id=803741826] +visible = false diff --git a/gui/inbox_message_subject.gd b/gui/inbox_message_subject.gd index 6dd5f7e..fc4d930 100644 --- a/gui/inbox_message_subject.gd +++ b/gui/inbox_message_subject.gd @@ -7,8 +7,9 @@ func _ready() -> void: %Source.text = letter.source.name %Subject.text = letter.subject_field -func on_remove_letter(_l: Letter): - queue_free() +func on_remove_letter(l: Letter): + if letter == l: + queue_free() func _on_pressed() -> void: letter.start() diff --git a/gui/inbox_panel.gd b/gui/inbox_panel.gd index 59fe72a..fff1837 100644 --- a/gui/inbox_panel.gd +++ b/gui/inbox_panel.gd @@ -6,11 +6,14 @@ func _ready() -> void: visible = false func add_letter(l: Letter): - var ldis := preload("res://gui/inbox_message_subject.tscn").instantiate() + var ldis: Button + if l is EventLetter: + ldis = preload("res://gui/inbox_event_only.tscn").instantiate() + else: + ldis = preload("res://gui/inbox_message_subject.tscn").instantiate() ldis.letter = l %Letters.add_child(ldis) - func open(): visible = true diff --git a/gui/production_chart.gd b/gui/production_chart.gd index 41ae7f2..e07f5b4 100644 --- a/gui/production_chart.gd +++ b/gui/production_chart.gd @@ -2,6 +2,10 @@ extends VBoxContainer func _ready() -> void: Economy.productions_update.connect(sync) + UserContext.modal_command_change.connect(modal_command_change) + +func modal_command_change(c: Command): + visible = c == null func sync(productions: Array[Production]): for child in get_children(): diff --git a/letters/event_letter.gd b/letters/event_letter.gd new file mode 100644 index 0000000..4581a6c --- /dev/null +++ b/letters/event_letter.gd @@ -0,0 +1,10 @@ +extends Letter +class_name EventLetter + +func start(): + Dialogic.start(timeline) + await Dialogic.timeline_ended + GameState.remove_letter.emit(self) + +func reply(): + push_error("reply Not implemented!") diff --git a/letters/event_letter.gd.uid b/letters/event_letter.gd.uid new file mode 100644 index 0000000..7d3cde2 --- /dev/null +++ b/letters/event_letter.gd.uid @@ -0,0 +1 @@ +uid://d30k84i53crwu diff --git a/member_inspector_panel.gd b/member_inspector_panel.gd index e0dd381..e1b1e67 100644 --- a/member_inspector_panel.gd +++ b/member_inspector_panel.gd @@ -5,8 +5,12 @@ extends "res://gui/currency_inspector_panel.gd" func _ready() -> void: UserContext.currency_inspect.connect(currency_inspect) UserContext.member_inspect.connect(member_inspect) + UserContext.modal_command_change.connect(modal_command_change) update() +func modal_command_change(_c: Command): + visible = false + func member_inspect(m: CurrencyMemberSprite): if member != null: member.tree_exiting.disconnect(member_left) @@ -22,6 +26,9 @@ func member_left(): func clear_bribes(): for child in %BribesList.get_children(): child.queue_free() +func clear_commands(): + for child in %CommandsList.get_children(): + child.queue_free() func bribe_success(): member.allegiance = preload("res://allegiance/good.tres") @@ -35,6 +42,13 @@ func load_bribes(): btn.bribe_succees.connect(bribe_success) %BribesList.add_child(btn) +func load_commands(): + for p in member.currency.commands: + var btn := preload("res://commands/command_button.tscn").instantiate() + btn.command = p + btn.command_succcess.connect(UserContext.modal) + %CommandsList.add_child(btn) + func currency_inspect(_c: Currency): visible = false @@ -47,8 +61,13 @@ func update(): %CurrencyMemberSprite.allegiance = member.allegiance %CurrencyMemberSprite.sync() clear_bribes() + clear_commands() %Bribes.visible = false + %Commands.visible = true if member.allegiance != preload("res://allegiance/good.tres"): load_bribes() %Bribes.visible = true + %Commands.visible = false + else: + load_commands() diff --git a/member_inspector_panel.tscn b/member_inspector_panel.tscn index 0722179..00ed234 100644 --- a/member_inspector_panel.tscn +++ b/member_inspector_panel.tscn @@ -39,3 +39,12 @@ text = "Bribe with" [node name="BribesList" type="VBoxContainer" parent="VBoxContainer" parent_id_path=PackedInt32Array(362599487) index="10" unique_id=476203914] unique_name_in_owner = true layout_mode = 2 + +[node name="Commands" type="Label" parent="VBoxContainer" parent_id_path=PackedInt32Array(362599487) index="11" unique_id=87746800] +unique_name_in_owner = true +layout_mode = 2 +text = "Command" + +[node name="CommandsList" type="VBoxContainer" parent="VBoxContainer" parent_id_path=PackedInt32Array(362599487) index="12" unique_id=73835062] +unique_name_in_owner = true +layout_mode = 2 diff --git a/test/command_modal.gd b/test/command_modal.gd new file mode 100644 index 0000000..fee0bb0 --- /dev/null +++ b/test/command_modal.gd @@ -0,0 +1,12 @@ +extends Label + +func _ready() -> void: + UserContext.modal_command_change.connect(modal_command_change) + modal_command_change(null) + +func modal_command_change(c: Command): + if c == null: + visible = false + return + visible = true + text = c.modal_name + " " + UserContext.selected_member.currency.name diff --git a/test/command_modal.gd.uid b/test/command_modal.gd.uid new file mode 100644 index 0000000..8b516ae --- /dev/null +++ b/test/command_modal.gd.uid @@ -0,0 +1 @@ +uid://cvwxv4hfw4u0o diff --git a/test/test_economy.gd b/test/test_economy.gd index 8d4e62f..8f55f62 100644 --- a/test/test_economy.gd +++ b/test/test_economy.gd @@ -6,11 +6,9 @@ func _on_get_cow_pressed() -> void: p.amount += 1 - func _on_run_simulate_pressed() -> void: Economy.simulate() func _on_open_inbox_pressed() -> void: UserContext.open_inbox.emit() - LetterGeneration.try_generate_offer() diff --git a/test/test_economy.tscn b/test/test_economy.tscn index ecc5fe5..3f3efb8 100644 --- a/test/test_economy.tscn +++ b/test/test_economy.tscn @@ -9,6 +9,7 @@ [ext_resource type="PackedScene" uid="uid://coebykrbnhlif" path="res://currency/members/MemberSprite.tscn" id="6_vua3v"] [ext_resource type="Resource" uid="uid://ihsvxienxbeu" path="res://currency/sentient/knight.tres" id="7_s0mui"] [ext_resource type="Resource" uid="uid://dfbgxc6nlcjct" path="res://allegiance/bad.tres" id="8_i7808"] +[ext_resource type="Script" uid="uid://cvwxv4hfw4u0o" path="res://test/command_modal.gd" id="10_ccsa3"] [node name="TestEconomy" type="Control" unique_id=629898212] layout_mode = 3 @@ -17,6 +18,7 @@ anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 +mouse_filter = 2 script = ExtResource("1_s48qe") [node name="ScrollContainer2" type="ScrollContainer" parent="." unique_id=872959271] @@ -69,18 +71,15 @@ text = "Get cow" layout_mode = 2 text = "Run simulate" -[node name="OpenInbox" type="Button" parent="Control/VBoxContainer" unique_id=1148713984] -layout_mode = 2 -text = "OpenInbox" - [node name="CurrencyInspectorPanel" parent="." unique_id=169191981 instance=ExtResource("4_7ya5o")] layout_mode = 1 +offset_left = -467.0 +offset_right = 33.0 [node name="MemberInspectorPanel" parent="." unique_id=1641024074 instance=ExtResource("5_i7808")] -custom_minimum_size = Vector2(0, 100) layout_mode = 1 -offset_left = -189.0 -offset_right = -189.0 +offset_left = -468.0 +offset_right = 32.0 [node name="InboxPanel" parent="." unique_id=534578339 instance=ExtResource("5_n4oyp")] layout_mode = 1 @@ -99,8 +98,37 @@ offset_bottom = 406.0 currency = ExtResource("7_s0mui") allegiance = ExtResource("8_i7808") +[node name="CommandModal" type="Label" parent="." unique_id=562980582] +layout_mode = 1 +anchors_preset = 5 +anchor_left = 0.5 +anchor_right = 0.5 +offset_left = -63.0 +offset_top = 19.0 +offset_right = 64.0 +offset_bottom = 42.0 +grow_horizontal = 2 +theme_override_font_sizes/font_size = 52 +text = "" +script = ExtResource("10_ccsa3") + +[node name="OpenInbox" type="Button" parent="." unique_id=1148713984] +layout_mode = 1 +anchors_preset = 3 +anchor_left = 1.0 +anchor_top = 1.0 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_left = -114.0 +offset_top = -64.0 +offset_right = -20.0 +offset_bottom = -33.0 +grow_horizontal = 0 +grow_vertical = 0 +text = "OpenInbox" + [connection signal="pressed" from="Control/VBoxContainer/GetCow" to="." method="_on_get_cow_pressed"] [connection signal="pressed" from="Control/VBoxContainer/RunSimulate" to="." method="_on_run_simulate_pressed"] -[connection signal="pressed" from="Control/VBoxContainer/OpenInbox" to="." method="_on_open_inbox_pressed"] +[connection signal="pressed" from="OpenInbox" to="." method="_on_open_inbox_pressed"] [editable path="MemberSprite"] diff --git a/user_context.gd b/user_context.gd index 7947a6e..d9989ea 100644 --- a/user_context.gd +++ b/user_context.gd @@ -13,14 +13,30 @@ var selected_member: CurrencyMemberSprite = null var focused_members: Array[CurrencyMemberSprite] = [] signal selected_member_change(current: CurrencyMemberSprite) +var modal_command: Command +signal modal_command_change(c: Command) + +func modal(c: Command): + modal_command = c + modal_command_change.emit(c) + func select_focused_member(): var candidate := focused_member() if candidate == null: return + if selected_member != null: + unselect_member() selected_member = candidate + selected_member.tree_exiting.connect(unselect_member) selected_member_change.emit(selected_member) UserContext.member_inspect.emit(selected_member) +func unselect_member(): + if selected_member == null: + return + selected_member.tree_exiting.disconnect(unselect_member) + selected_member = null + func focused_member() -> CurrencyMemberSprite: if focused_members.size() == 0: return null