Skip to content

Commit 57a6d65

Browse files
committed
Draw an outline to indicate selected building
1 parent ca5e3ba commit 57a6d65

18 files changed

+110
-92
lines changed

Building.gd

+14-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,16 @@ export(Texture) var texture : Texture = null setget set_texture, get_texture
99
export(bool) var selected : bool = false setget set_selected, get_selected
1010
export(bool) var upgrade_available : bool = false setget set_upgrade_available
1111

12+
var outline_material : ShaderMaterial
13+
1214
func _ready():
1315
if get_parent().decorative:
1416
return
17+
18+
outline_material = ShaderMaterial.new()
19+
outline_material.shader = preload("res://Outline.gdshader")
20+
outline_material.set_shader_param('line_thickness', 25)
21+
1522
shake()
1623

1724

@@ -31,11 +38,16 @@ func get_texture():
3138

3239

3340
func set_selected(value : bool):
34-
$selection.visible = value
41+
if not is_inside_tree():
42+
return
43+
if value:
44+
$texture.material = outline_material
45+
else:
46+
$texture.material = null
3547

3648

3749
func get_selected() -> bool:
38-
return $selection.visible
50+
return $texture.material == null
3951

4052

4153
func set_upgrade_available(value : bool):

Building.tscn

+8-21
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,27 @@
1-
[gd_scene load_steps=6 format=2]
1+
[gd_scene load_steps=5 format=2]
22

3-
[ext_resource path="res://assets/gfx/sprites/selection.png" type="Texture" id=1]
43
[ext_resource path="res://Building.gd" type="Script" id=2]
54
[ext_resource path="res://assets/fonts/Secuela-Bold.otf" type="DynamicFontData" id=3]
65

7-
[sub_resource type="DynamicFont" id=1]
6+
[sub_resource type="DynamicFont" id=3]
87
size = 8
98
outline_size = 1
109
use_mipmaps = true
1110
use_filter = true
1211
font_data = ExtResource( 3 )
1312

14-
[sub_resource type="RectangleShape2D" id=2]
13+
[sub_resource type="RectangleShape2D" id=4]
1514
extents = Vector2( 3, 22 )
1615

1716
[node name="Building" type="Node2D"]
1817
script = ExtResource( 2 )
18+
selected = true
1919

2020
[node name="texture" type="TextureRect" parent="."]
21-
margin_left = -16.0
22-
margin_top = -32.0
23-
margin_right = 16.0
24-
margin_bottom = 32.0
25-
expand = true
26-
__meta__ = {
27-
"_edit_use_anchors_": false
28-
}
29-
30-
[node name="selection" type="TextureRect" parent="."]
31-
visible = false
32-
margin_left = -16.0
21+
margin_left = -24.0
3322
margin_top = -32.0
34-
margin_right = 16.0
23+
margin_right = 24.0
3524
margin_bottom = 32.0
36-
mouse_filter = 2
37-
texture = ExtResource( 1 )
3825
expand = true
3926
__meta__ = {
4027
"_edit_use_anchors_": false
@@ -48,7 +35,7 @@ margin_left = -16.0
4835
margin_top = -51.8608
4936
margin_right = 13.0
5037
margin_bottom = -43.8608
51-
custom_fonts/font = SubResource( 1 )
38+
custom_fonts/font = SubResource( 3 )
5239
custom_colors/font_color = Color( 0, 0, 0, 1 )
5340
text = "UPGRADE"
5441
__meta__ = {
@@ -67,7 +54,7 @@ collision_mask = 8
6754

6855
[node name="shape" type="CollisionShape2D" parent="area"]
6956
position = Vector2( 0, -18 )
70-
shape = SubResource( 2 )
57+
shape = SubResource( 4 )
7158

7259
[connection signal="gui_input" from="texture" to="." method="_on_texture_gui_input"]
7360
[connection signal="mouse_entered" from="texture" to="." method="_on_texture_mouse_entered"]

Outline.gdshader

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
Shader edited from the one at: https://godotshaders.com/shader/rainbow-outline/
3+
4+
Original credits:
5+
6+
Rainbow outline by @Farfalk and @ThePadDev, July 2021
7+
8+
Apply to canvas items with transparent backgrounds.
9+
Check that there is sufficient transparent background space for the outline!
10+
11+
CC0 License (but citation is welcome <3)
12+
*/
13+
14+
shader_type canvas_item;
15+
16+
uniform float line_thickness : hint_range(0, 25) = 1.0; // thickness of the line
17+
18+
const float pi = 3.14159265;
19+
20+
float sinx(float x) {
21+
// a sine-like function with where the first half of the each sine wave
22+
// has a different period than the second one.
23+
24+
const float light = 1.0;
25+
const float dark = 0.1;
26+
x = mod(x, pi*(light + dark));
27+
if (x <= pi*light) {
28+
return sin(x/light);
29+
} else {
30+
return -sin((x + light*pi)/dark);
31+
}
32+
}
33+
34+
void fragment() {
35+
vec2 size = TEXTURE_PIXEL_SIZE * line_thickness;
36+
37+
float outline = texture(TEXTURE, UV + vec2(-size.x, 0)).a;
38+
outline += texture(TEXTURE, UV + vec2(0, size.y)).a;
39+
outline += texture(TEXTURE, UV + vec2(size.x, 0)).a;
40+
outline += texture(TEXTURE, UV + vec2(0, -size.y)).a;
41+
outline += texture(TEXTURE, UV + vec2(-size.x, size.y)).a;
42+
outline += texture(TEXTURE, UV + vec2(size.x, size.y)).a;
43+
outline += texture(TEXTURE, UV + vec2(-size.x, -size.y)).a;
44+
outline += texture(TEXTURE, UV + vec2(size.x, -size.y)).a;
45+
outline = min(outline, 1.0);
46+
47+
float value = (sinx(TIME) + 1.0) / 2.0;
48+
vec4 animated_line_color = vec4(1.0, 1.0, 1.0 - value, 1.0);
49+
50+
vec4 color = texture(TEXTURE, UV);
51+
COLOR = mix(color, animated_line_color, outline - color.a);
52+
}

World.tscn

+35-35
Original file line numberDiff line numberDiff line change
@@ -19,64 +19,64 @@
1919
[ext_resource path="res://assets/gfx/icons/settings.png" type="Texture" id=18]
2020
[ext_resource path="res://EndScreen.tscn" type="PackedScene" id=19]
2121

22-
[sub_resource type="RectangleShape2D" id=15]
22+
[sub_resource type="RectangleShape2D" id=1]
2323
extents = Vector2( 5, 22 )
2424

25-
[sub_resource type="CircleShape2D" id=1]
25+
[sub_resource type="CircleShape2D" id=2]
2626
radius = 276.474
2727

28-
[sub_resource type="StyleBoxFlat" id=2]
28+
[sub_resource type="StyleBoxFlat" id=3]
2929
bg_color = Color( 0.215686, 0.580392, 0.431373, 1 )
3030

31-
[sub_resource type="StreamTexture" id=3]
31+
[sub_resource type="StreamTexture" id=4]
3232
resource_local_to_scene = true
3333
flags = 5
3434
load_path = "res://.import/factory.png-511f58d2a3b3f08c311f8e6bbfc28779.stex"
3535

36-
[sub_resource type="AtlasTexture" id=4]
36+
[sub_resource type="AtlasTexture" id=5]
3737
flags = 5
38-
atlas = SubResource( 3 )
39-
region = Rect2( 0, 300, 512, 600 )
38+
atlas = SubResource( 4 )
39+
region = Rect2( 128, 300, 512, 600 )
4040

41-
[sub_resource type="StreamTexture" id=5]
41+
[sub_resource type="StreamTexture" id=6]
4242
flags = 5
4343
load_path = "res://.import/mine.png-6e597bfb5a7c7612bb55dc80efe8800f.stex"
4444

45-
[sub_resource type="AtlasTexture" id=6]
45+
[sub_resource type="AtlasTexture" id=7]
4646
flags = 5
47-
atlas = SubResource( 5 )
48-
region = Rect2( 0, 320, 512, 600 )
47+
atlas = SubResource( 6 )
48+
region = Rect2( 128, 320, 512, 600 )
4949

50-
[sub_resource type="AtlasTexture" id=7]
50+
[sub_resource type="AtlasTexture" id=8]
5151
flags = 5
5252
atlas = ExtResource( 1 )
53-
region = Rect2( 0, 320, 512, 600 )
53+
region = Rect2( 128, 320, 512, 600 )
5454

55-
[sub_resource type="AtlasTexture" id=8]
55+
[sub_resource type="AtlasTexture" id=9]
5656
flags = 5
5757
atlas = ExtResource( 2 )
58-
region = Rect2( 0, 310, 512, 600 )
58+
region = Rect2( 128, 310, 512, 600 )
5959

60-
[sub_resource type="AtlasTexture" id=9]
60+
[sub_resource type="AtlasTexture" id=10]
6161
flags = 5
6262
atlas = ExtResource( 5 )
63-
region = Rect2( 0, 310, 512, 600 )
63+
region = Rect2( 128, 310, 512, 600 )
6464

65-
[sub_resource type="StyleBoxFlat" id=10]
65+
[sub_resource type="StyleBoxFlat" id=11]
6666
bg_color = Color( 0.6, 0.898039, 0.313726, 1 )
6767

68-
[sub_resource type="DynamicFont" id=11]
68+
[sub_resource type="DynamicFont" id=12]
6969
use_filter = true
7070
font_data = ExtResource( 7 )
7171

72-
[sub_resource type="DynamicFont" id=12]
72+
[sub_resource type="DynamicFont" id=13]
7373
use_filter = true
7474
font_data = ExtResource( 6 )
7575

76-
[sub_resource type="StyleBoxFlat" id=13]
76+
[sub_resource type="StyleBoxFlat" id=14]
7777
bg_color = Color( 0.6, 0.6, 0.6, 0.501961 )
7878

79-
[sub_resource type="StyleBoxFlat" id=14]
79+
[sub_resource type="StyleBoxFlat" id=15]
8080
bg_color = Color( 0.6, 0.6, 0.6, 0.501961 )
8181

8282
[node name="World" type="Node2D"]
@@ -116,10 +116,10 @@ texture = ExtResource( 1 )
116116

117117
[node name="shape" type="CollisionShape2D" parent="placing_area/preview_icon"]
118118
position = Vector2( 0, 12 )
119-
shape = SubResource( 15 )
119+
shape = SubResource( 1 )
120120

121121
[node name="shape" type="CollisionShape2D" parent="placing_area"]
122-
shape = SubResource( 1 )
122+
shape = SubResource( 2 )
123123

124124
[node name="planet" type="Sprite" parent="placing_area"]
125125
scale = Vector2( 0.4, 0.4 )
@@ -142,7 +142,7 @@ __meta__ = {
142142
[node name="toolbox" type="PanelContainer" parent="hud/hbox"]
143143
margin_right = 40.0
144144
margin_bottom = 720.0
145-
custom_styles/panel = SubResource( 2 )
145+
custom_styles/panel = SubResource( 3 )
146146

147147
[node name="vbox" type="VBoxContainer" parent="hud/hbox/toolbox"]
148148
margin_right = 40.0
@@ -159,7 +159,7 @@ margin_bottom = 40.0
159159
rect_min_size = Vector2( 40, 40 )
160160
focus_mode = 0
161161
theme = ExtResource( 17 )
162-
icon = SubResource( 4 )
162+
icon = SubResource( 5 )
163163
flat = false
164164
expand_icon = true
165165

@@ -170,7 +170,7 @@ margin_bottom = 80.0
170170
rect_min_size = Vector2( 40, 40 )
171171
focus_mode = 0
172172
theme = ExtResource( 17 )
173-
icon = SubResource( 6 )
173+
icon = SubResource( 7 )
174174
flat = false
175175
expand_icon = true
176176

@@ -181,7 +181,7 @@ margin_bottom = 120.0
181181
rect_min_size = Vector2( 40, 40 )
182182
focus_mode = 0
183183
theme = ExtResource( 17 )
184-
icon = SubResource( 7 )
184+
icon = SubResource( 8 )
185185
flat = false
186186
expand_icon = true
187187

@@ -192,7 +192,7 @@ margin_bottom = 160.0
192192
rect_min_size = Vector2( 40, 40 )
193193
focus_mode = 0
194194
theme = ExtResource( 17 )
195-
icon = SubResource( 8 )
195+
icon = SubResource( 9 )
196196
flat = false
197197
expand_icon = true
198198

@@ -203,7 +203,7 @@ margin_bottom = 200.0
203203
rect_min_size = Vector2( 40, 40 )
204204
focus_mode = 0
205205
theme = ExtResource( 17 )
206-
icon = SubResource( 9 )
206+
icon = SubResource( 10 )
207207
flat = false
208208
expand_icon = true
209209

@@ -230,7 +230,7 @@ margin_right = 190.0
230230
margin_bottom = 720.0
231231
rect_min_size = Vector2( 150, 0 )
232232
mouse_filter = 2
233-
custom_styles/panel = SubResource( 10 )
233+
custom_styles/panel = SubResource( 11 )
234234
__meta__ = {
235235
"_edit_use_anchors_": false
236236
}
@@ -257,8 +257,8 @@ mouse_filter = 2
257257
[node name="description" type="RichTextLabel" parent="hud/hbox/building_panel/MarginContainer/VBoxContainer"]
258258
margin_right = 142.0
259259
margin_bottom = 48.0
260-
custom_fonts/bold_font = SubResource( 11 )
261-
custom_fonts/normal_font = SubResource( 12 )
260+
custom_fonts/bold_font = SubResource( 12 )
261+
custom_fonts/normal_font = SubResource( 13 )
262262
custom_colors/default_color = Color( 0, 0, 0, 1 )
263263
bbcode_enabled = true
264264
bbcode_text = "[b]foobar[/b]
@@ -301,7 +301,7 @@ margin_bottom = 36.0
301301
rect_min_size = Vector2( 0, 36 )
302302
mouse_filter = 2
303303
size_flags_horizontal = 3
304-
custom_styles/panel = SubResource( 13 )
304+
custom_styles/panel = SubResource( 14 )
305305

306306
[node name="margin" type="MarginContainer" parent="hud/hbox/vbox/resource_bar"]
307307
margin_right = 1090.0
@@ -404,7 +404,7 @@ margin_right = 1090.0
404404
margin_bottom = 720.0
405405
rect_min_size = Vector2( 0, 36 )
406406
mouse_filter = 2
407-
custom_styles/panel = SubResource( 14 )
407+
custom_styles/panel = SubResource( 15 )
408408

409409
[node name="margin" type="MarginContainer" parent="hud/hbox/vbox/info_bar"]
410410
margin_right = 1090.0

assets/gfx/sprites/apartment.kra

-5.79 KB
Binary file not shown.

assets/gfx/sprites/apartment.png

2.41 KB
Loading

assets/gfx/sprites/bar.kra

31.1 KB
Binary file not shown.

assets/gfx/sprites/bar.png

6.28 KB
Loading

assets/gfx/sprites/factory.kra

441 KB
Binary file not shown.

assets/gfx/sprites/factory.png

1.56 KB
Loading

assets/gfx/sprites/mine.kra

442 KB
Binary file not shown.

assets/gfx/sprites/mine.png

2.79 KB
Loading

assets/gfx/sprites/powerplant.kra

28.4 KB
Binary file not shown.

assets/gfx/sprites/powerplant.png

2.01 KB
Loading

assets/gfx/sprites/selection.kra

-340 KB
Binary file not shown.

assets/gfx/sprites/selection.png

-83.8 KB
Binary file not shown.

assets/gfx/sprites/selection.png.import

-34
This file was deleted.

licenses.txt

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ Smoke Particles by Kenney - CC0 - https://www.kenney.nl/assets/smoke-particles
33
UI Audio by Kenney - CC0 - https://www.kenney.nl/assets/ui-audio
44
Big Eyes by Rafael Krux - CC0 - https://freepd.com/epic.php
55
Rough Rumble (splash sound) - CC0 - https://freesound.org/people/TMPZ_1/sounds/440804/ - edited
6+
Rainbow Outline shader - CC0 - https://godotshaders.com/shader/rainbow-outline/ - edited

0 commit comments

Comments
 (0)