Skip to content

Commit 20fbd21

Browse files
authored
Add files via upload
1 parent e6ba09c commit 20fbd21

2 files changed

Lines changed: 99 additions & 2 deletions

File tree

RSS_Reader_Tutorial/rss_reader.gd

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var link_arr = []
88

99
# Called when the node enters the scene tree for the first time.
1010
func _ready():
11-
pass # Replace with function body.
11+
load_data()
1212

1313
# Called every frame. 'delta' is the elapsed time since the previous frame.
1414
#func _process(delta):
@@ -17,11 +17,22 @@ func _ready():
1717

1818
func _on_OpenButton_pressed():
1919
print("Button pressed!")
20+
clearFields()
2021
populateEdit()
22+
2123

2224
func populateEdit():
2325
#pass
24-
$HTTPRequest.request("http://rss.cnn.com/rss/edition.rss")
26+
var url = $SettingsDialog/RSSURLText.text
27+
$HTTPRequest.request(url)
28+
29+
func clearFields():
30+
title_arr.clear()
31+
desc_arr.clear()
32+
link_arr.clear()
33+
$ItemList.clear()
34+
$DescriptionField.text = ""
35+
$LinkButton.text = ""
2536

2637
func _on_HTTPRequest_request_completed(result, response_code, headers, body):
2738
$TextEdit.set_text(body.get_string_from_utf8())
@@ -96,3 +107,44 @@ func _on_ItemList_item_selected(index):
96107
func _on_LinkButton_pressed():
97108
OS.shell_open($LinkButton.text)
98109

110+
111+
112+
func _on_SettingsButton_pressed():
113+
$SettingsDialog.popup()
114+
115+
116+
func _on_ClearButton_pressed():
117+
$SettingsDialog/RSSURLText.text = ""
118+
119+
func save_data():
120+
print('saving data')
121+
print(OS.get_user_data_dir())
122+
var save_config = File.new()
123+
var save_data = {
124+
"url": $SettingsDialog/RSSURLText.text
125+
}
126+
127+
save_config.open("user://save_config.save", File.WRITE)
128+
save_config.store_line(to_json(save_data))
129+
save_config.close()
130+
131+
132+
133+
func _on_SaveButton_pressed():
134+
save_data()
135+
136+
func load_data():
137+
print('loading data')
138+
var save_config = File.new()
139+
if not save_config.file_exists("user://save_config.save"):
140+
return #error no save game!
141+
save_config.open("user://save_config.save", File.READ)
142+
var text = save_config.get_as_text()
143+
var url = parse_json(text)['url']
144+
print('Loading JSON: ' + text)
145+
print('URL: ' + url)
146+
147+
$SettingsDialog/RSSURLText.text = url
148+
save_config.close()
149+
150+

RSS_Reader_Tutorial/rss_reader.tscn

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ margin_bottom = 34.7426
1515
text = "Open"
1616

1717
[node name="TextEdit" type="TextEdit" parent="."]
18+
visible = false
1819
margin_left = 11.1466
1920
margin_top = 285.321
2021
margin_right = 342.147
@@ -41,7 +42,51 @@ margin_top = 222.0
4142
margin_right = 868.0
4243
margin_bottom = 236.0
4344

45+
[node name="SettingsButton" type="Button" parent="."]
46+
margin_left = 803.709
47+
margin_top = 9.03579
48+
margin_right = 866.709
49+
margin_bottom = 29.0358
50+
text = "Settings"
51+
52+
[node name="SettingsDialog" type="WindowDialog" parent="."]
53+
visible = true
54+
margin_left = 131.0
55+
margin_top = 148.0
56+
margin_right = 609.0
57+
margin_bottom = 314.0
58+
59+
[node name="Label" type="Label" parent="SettingsDialog"]
60+
margin_left = 25.6806
61+
margin_top = 13.7915
62+
margin_right = 65.6806
63+
margin_bottom = 27.7915
64+
text = "The RSS Feed URL"
65+
66+
[node name="RSSURLText" type="LineEdit" parent="SettingsDialog"]
67+
margin_left = 34.0
68+
margin_top = 46.0
69+
margin_right = 442.0
70+
margin_bottom = 70.0
71+
72+
[node name="ClearButton" type="Button" parent="SettingsDialog"]
73+
margin_left = 393.77
74+
margin_top = 85.6022
75+
margin_right = 437.77
76+
margin_bottom = 105.602
77+
text = "Clear"
78+
79+
[node name="SaveButton" type="Button" parent="SettingsDialog"]
80+
margin_left = 327.666
81+
margin_top = 84.651
82+
margin_right = 339.666
83+
margin_bottom = 104.651
84+
text = "Save"
85+
4486
[connection signal="pressed" from="OpenButton" to="." method="_on_OpenButton_pressed"]
4587
[connection signal="request_completed" from="HTTPRequest" to="." method="_on_HTTPRequest_request_completed"]
4688
[connection signal="item_selected" from="ItemList" to="." method="_on_ItemList_item_selected"]
4789
[connection signal="pressed" from="LinkButton" to="." method="_on_LinkButton_pressed"]
90+
[connection signal="pressed" from="SettingsButton" to="." method="_on_SettingsButton_pressed"]
91+
[connection signal="pressed" from="SettingsDialog/ClearButton" to="." method="_on_ClearButton_pressed"]
92+
[connection signal="pressed" from="SettingsDialog/SaveButton" to="." method="_on_SaveButton_pressed"]

0 commit comments

Comments
 (0)