Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Mar 16, 2025. It is now read-only.

Latest commit

 

History

History
History
182 lines (160 loc) · 7.02 KB

File metadata and controls

182 lines (160 loc) · 7.02 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
using System.Collections.Generic;
using System.Linq;
using Godot;
using SpaceExplorer.Scripts.Minable;
public class UpgradeInfo {
public string Name { get; set; }
public string Description { get; set; }
public HashSet<string> UpgradeDependencies { get; set; }
public string NodePath { get; set; }
public Dictionary<MinableType, int> ResourceCost { get; set; }
public UpgradeInfo(
string name,
string description,
HashSet<string> upgradeDependencies,
string nodePath,
Dictionary<MinableType, int> resourceCost)
{
Name = name;
Description = description;
UpgradeDependencies = upgradeDependencies;
NodePath = nodePath;
ResourceCost = resourceCost;
}
}
public class UpgradeMenu : Panel
{
private static IDictionary<string, UpgradeInfo> Upgrades = new Dictionary<string, UpgradeInfo>
{
{
"RocketPower", new UpgradeInfo(
name: "Rocket Power!",
nodePath: "VBoxContainer/HBox/RocketPower",
upgradeDependencies: new HashSet<string>(),
resourceCost: new Dictionary<MinableType, int>{ { MinableType.Aluminum, 5 } },
description:
@"If we are going to be able to take ourselves anywhere, we will need
to modify our rockets to produce some more power!")
},
{
"Radio", new UpgradeInfo(
name: "Radio tower",
nodePath: "VBoxContainer/HBox2/Radio",
upgradeDependencies: new HashSet<string> { "RocketPower" },
resourceCost: new Dictionary<MinableType, int>{ { MinableType.Aluminum, 2 }, { MinableType.Copper, 8 } },
description:
@"This radio tower will help us find celestial bodies containing the
resources to get us home.")
},
{
"TitaniumHull", new UpgradeInfo(
name: "Titanium hull",
nodePath: "VBoxContainer/HBox3/TitaniumHull",
upgradeDependencies: new HashSet<string> { "Radio" },
resourceCost: new Dictionary<MinableType, int>{ { MinableType.Titanium, 10 }, { MinableType.Aluminum, 3 } },
description:
"A hull made of titanium that is capable of handling high temperature environments.")
},
{
"Antifreeze", new UpgradeInfo(
name: "Antifreeze",
nodePath: "VBoxContainer/HBox3/Antifreeze",
upgradeDependencies: new HashSet<string> { "Radio" },
resourceCost: new Dictionary<MinableType, int>{ { MinableType.Glycol, 8 } },
description:
"Antifreeze additive for our fuel so that it does not freeze in cold environments.")
},
{
"RadiationShielding", new UpgradeInfo(
name: "Radiation shielding",
nodePath: "VBoxContainer/HBox4/RadiationShielding",
upgradeDependencies: new HashSet<string> { "TitaniumHull", "Antifreeze" },
resourceCost: new Dictionary<MinableType, int>{ { MinableType.Tungsten, 8 }, { MinableType.Lead, 8 }, },
description:
"Adds radiation shielding to our hull to protect ourselves against radioactive environments")
},
{
"WarpDrive", new UpgradeInfo(
name: "Warp drive",
nodePath: "VBoxContainer/HBox5/WarpDrive",
upgradeDependencies: new HashSet<string> { "RadiationShielding" },
resourceCost: new Dictionary<MinableType, int>{ { MinableType.Uranium, 10 } },
description: "A warp drive to take us home!")
}
};
public UpgradeInfo SelectedUpgrade { get { return Upgrades[_selectedUpgradeKey]; } }
[Signal] public delegate void CraftedUpgradesChanged(List<string> currentUpgrades);
private RichTextLabel _nameLabel = null!;
private RichTextLabel _descriptionLabel = null!;
private Control _currentlyFocusedControl = null!;
private Dictionary<string, Button> _upgradeButtons = new Dictionary<string, Button>();
private string _selectedUpgradeKey = "RocketPower";
private HashSet<string> _craftedUpgrades = new HashSet<string>();
public override void _Ready()
{
_nameLabel = GetNode<RichTextLabel>("InfoVBox/NameLabel");
_descriptionLabel = GetNode<RichTextLabel>("InfoVBox/DescriptionLabel");
_currentlyFocusedControl = GetNode<Button>("VBoxContainer/HBox/RocketPower");
foreach(var upgrade in Upgrades)
GetNode<Button>(upgrade.Value.NodePath).Connect("gui_input", this, nameof(OnUpgradeButtonInput));
GetViewport().Connect("gui_focus_changed", this, nameof(OnGuiFocusChanged));
Connect("visibility_changed", this, nameof(OnVisibilityChanged));
GetNode<Button>("CraftButton").Connect("gui_input", this, nameof(OnUpgradeButtonInput));
_currentlyFocusedControl.GrabFocus();
}
private void OnUpgradeButtonInput(InputEvent inputEvent)
{
if(!inputEvent.IsActionReleased("ui_accept"))
return;
var selectedUpgrade = Upgrades[_selectedUpgradeKey];
var button = GetNode<Button>(selectedUpgrade.NodePath);
if(button.Disabled)
{
GetNode<AudioStreamPlayer>("../../UiDeclineSound").Play();
return;
}
var canAfford = selectedUpgrade.ResourceCost.All(kvp =>
ResourceInventory.ResourceCounts.ContainsKey(kvp.Key) &&
ResourceInventory.ResourceCounts[kvp.Key] >= kvp.Value);
if (!canAfford)
{
GetNode<AudioStreamPlayer>("../../UiDeclineSound").Play();
return;
}
ResourceInventory.SubtractResources(selectedUpgrade.ResourceCost);
GetNode<AudioStreamPlayer>("../../UiAcceptSound").Play();
_craftedUpgrades.Add(_selectedUpgradeKey);
EmitSignal(nameof(CraftedUpgradesChanged), _craftedUpgrades.ToList());
SetDisabledState();
}
private void SetDisabledState()
{
foreach(var upgrade in Upgrades){
var button = GetNode<Button>(upgrade.Value.NodePath);
button.Disabled =
_craftedUpgrades.Contains(upgrade.Key)
|| !upgrade.Value.UpgradeDependencies.All(key => _craftedUpgrades.Contains(key));
}
}
private void OnVisibilityChanged()
{
if(Visible)
_currentlyFocusedControl.GrabFocus();
}
private void OnGuiFocusChanged(Control control)
{
if(control is not UpgradeButton upgradeButton)
return;
var upgradeKey = upgradeButton.Name;
var upgradeInfo = Upgrades[upgradeKey];
if (upgradeInfo is null)
throw new System.Exception("Upgrade info is null");
_nameLabel.Text = upgradeInfo.Name;
_descriptionLabel.Text = upgradeInfo.Description;
_currentlyFocusedControl = upgradeButton;
_selectedUpgradeKey = upgradeKey;
}
public override void _Process(float delta)
{
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.