Skip to content
Permalink
Browse files

Add files via upload

  • Loading branch information
triptych committed Mar 17, 2019
1 parent e6ba09c commit 20fbd21e11cdb5178623c794a8cfe71c27496300
Showing with 99 additions and 2 deletions.
  1. +54 −2 RSS_Reader_Tutorial/rss_reader.gd
  2. +45 −0 RSS_Reader_Tutorial/rss_reader.tscn
@@ -8,7 +8,7 @@ var link_arr = []

# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
load_data()

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

func _on_OpenButton_pressed():
print("Button pressed!")
clearFields()
populateEdit()


func populateEdit():
#pass
$HTTPRequest.request("http://rss.cnn.com/rss/edition.rss")
var url = $SettingsDialog/RSSURLText.text
$HTTPRequest.request(url)

func clearFields():
title_arr.clear()
desc_arr.clear()
link_arr.clear()
$ItemList.clear()
$DescriptionField.text = ""
$LinkButton.text = ""

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



func _on_SettingsButton_pressed():
$SettingsDialog.popup()


func _on_ClearButton_pressed():
$SettingsDialog/RSSURLText.text = ""

func save_data():
print('saving data')
print(OS.get_user_data_dir())
var save_config = File.new()
var save_data = {
"url": $SettingsDialog/RSSURLText.text
}

save_config.open("user://save_config.save", File.WRITE)
save_config.store_line(to_json(save_data))
save_config.close()



func _on_SaveButton_pressed():
save_data()

func load_data():
print('loading data')
var save_config = File.new()
if not save_config.file_exists("user://save_config.save"):
return #error no save game!
save_config.open("user://save_config.save", File.READ)
var text = save_config.get_as_text()
var url = parse_json(text)['url']
print('Loading JSON: ' + text)
print('URL: ' + url)

$SettingsDialog/RSSURLText.text = url
save_config.close()


@@ -15,6 +15,7 @@ margin_bottom = 34.7426
text = "Open"

[node name="TextEdit" type="TextEdit" parent="."]
visible = false
margin_left = 11.1466
margin_top = 285.321
margin_right = 342.147
@@ -41,7 +42,51 @@ margin_top = 222.0
margin_right = 868.0
margin_bottom = 236.0

[node name="SettingsButton" type="Button" parent="."]
margin_left = 803.709
margin_top = 9.03579
margin_right = 866.709
margin_bottom = 29.0358
text = "Settings"

[node name="SettingsDialog" type="WindowDialog" parent="."]
visible = true
margin_left = 131.0
margin_top = 148.0
margin_right = 609.0
margin_bottom = 314.0

[node name="Label" type="Label" parent="SettingsDialog"]
margin_left = 25.6806
margin_top = 13.7915
margin_right = 65.6806
margin_bottom = 27.7915
text = "The RSS Feed URL"

[node name="RSSURLText" type="LineEdit" parent="SettingsDialog"]
margin_left = 34.0
margin_top = 46.0
margin_right = 442.0
margin_bottom = 70.0

[node name="ClearButton" type="Button" parent="SettingsDialog"]
margin_left = 393.77
margin_top = 85.6022
margin_right = 437.77
margin_bottom = 105.602
text = "Clear"

[node name="SaveButton" type="Button" parent="SettingsDialog"]
margin_left = 327.666
margin_top = 84.651
margin_right = 339.666
margin_bottom = 104.651
text = "Save"

[connection signal="pressed" from="OpenButton" to="." method="_on_OpenButton_pressed"]
[connection signal="request_completed" from="HTTPRequest" to="." method="_on_HTTPRequest_request_completed"]
[connection signal="item_selected" from="ItemList" to="." method="_on_ItemList_item_selected"]
[connection signal="pressed" from="LinkButton" to="." method="_on_LinkButton_pressed"]
[connection signal="pressed" from="SettingsButton" to="." method="_on_SettingsButton_pressed"]
[connection signal="pressed" from="SettingsDialog/ClearButton" to="." method="_on_ClearButton_pressed"]
[connection signal="pressed" from="SettingsDialog/SaveButton" to="." method="_on_SaveButton_pressed"]

0 comments on commit 20fbd21

Please sign in to comment.
You can’t perform that action at this time.