-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better news display. Adds news cache
- Loading branch information
Showing
5 changed files
with
1,703 additions
and
1,591 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
extends VBoxContainer | ||
|
||
|
||
var url = "https://example.com" | ||
|
||
onready var title = $title | ||
onready var author = $author | ||
onready var thumb = $body/thumb_container/thumb | ||
onready var contents = $body/contents | ||
|
||
# Called when the node enters the scene tree for the first time. | ||
func _ready(): | ||
pass # Replace with function body. | ||
|
||
|
||
# Called every frame. 'delta' is the elapsed time since the previous frame. | ||
#func _process(delta): | ||
# pass | ||
|
||
|
||
func _on_gui_input(event): | ||
if event is InputEventMouseButton and event.button_index == BUTTON_LEFT and event.pressed: | ||
OS.shell_open(url) | ||
|
||
func set_info(info : Dictionary): | ||
url = info.link | ||
hint_tooltip = url | ||
title.text = info.title | ||
author.text = "%s (%s)" % [info.author, info.date] | ||
contents.text = info.contents | ||
_load_image(info.image) | ||
|
||
func _load_image(url): | ||
var local_path = "user://images/" + url.get_file() | ||
var dir = Directory.new() | ||
if not dir.file_exists(local_path): | ||
$req.download_file = local_path | ||
$req.request(url) | ||
var response = yield($req,"request_completed") | ||
if not response[1] == 200: | ||
printerr("Could not find or download image") | ||
return | ||
var img = Image.new() | ||
img.load(local_path) | ||
var tex = ImageTexture.new() | ||
tex.create_from_image(img) | ||
thumb.texture = tex |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
[gd_scene load_steps=3 format=2] | ||
|
||
[ext_resource path="res://scenes/NewsItem.gd" type="Script" id=1] | ||
|
||
[sub_resource type="StyleBoxFlat" id=1] | ||
content_margin_left = 10.0 | ||
content_margin_right = 10.0 | ||
content_margin_top = 10.0 | ||
content_margin_bottom = 10.0 | ||
bg_color = Color( 0.2, 0.247059, 0.403922, 1 ) | ||
corner_radius_top_left = 5 | ||
corner_radius_top_right = 5 | ||
corner_radius_bottom_right = 5 | ||
corner_radius_bottom_left = 5 | ||
|
||
[node name="NewsItem" type="VBoxContainer"] | ||
anchor_right = 1.0 | ||
anchor_bottom = 1.0 | ||
mouse_default_cursor_shape = 2 | ||
size_flags_horizontal = 3 | ||
size_flags_vertical = 3 | ||
script = ExtResource( 1 ) | ||
|
||
[node name="title" type="Label" parent="."] | ||
margin_right = 1066.0 | ||
margin_bottom = 34.0 | ||
custom_colors/font_color = Color( 0.921569, 0.921569, 0.921569, 1 ) | ||
custom_styles/normal = SubResource( 1 ) | ||
text = "Title" | ||
autowrap = true | ||
uppercase = true | ||
|
||
[node name="author" type="Label" parent="."] | ||
margin_top = 38.0 | ||
margin_right = 1066.0 | ||
margin_bottom = 52.0 | ||
text = "Author" | ||
autowrap = true | ||
|
||
[node name="body" type="HBoxContainer" parent="."] | ||
margin_top = 56.0 | ||
margin_right = 1066.0 | ||
margin_bottom = 600.0 | ||
size_flags_vertical = 3 | ||
|
||
[node name="thumb_container" type="CenterContainer" parent="body"] | ||
margin_right = 100.0 | ||
margin_bottom = 544.0 | ||
rect_min_size = Vector2( 100, 100 ) | ||
|
||
[node name="thumb" type="TextureRect" parent="body/thumb_container"] | ||
margin_top = 222.0 | ||
margin_right = 100.0 | ||
margin_bottom = 322.0 | ||
grow_horizontal = 2 | ||
grow_vertical = 2 | ||
rect_min_size = Vector2( 100, 100 ) | ||
size_flags_horizontal = 13 | ||
size_flags_vertical = 13 | ||
expand = true | ||
stretch_mode = 7 | ||
|
||
[node name="contents" type="Label" parent="body"] | ||
margin_left = 104.0 | ||
margin_right = 1066.0 | ||
margin_bottom = 544.0 | ||
rect_min_size = Vector2( 300, 0 ) | ||
size_flags_horizontal = 3 | ||
size_flags_vertical = 7 | ||
autowrap = true | ||
|
||
[node name="req" type="HTTPRequest" parent="."] | ||
|
||
[connection signal="gui_input" from="." to="." method="_on_gui_input"] |