-
Notifications
You must be signed in to change notification settings - Fork 24
Map icons #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Map icons #47
Changes from all commits
ea8cc19
6a86a51
32f5bbe
e2dbaeb
307ee0a
853db76
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,10 @@ | ||
| extends Sprite3D | ||
|
|
||
| const Utils = preload("utils.gd") | ||
|
|
||
| var texture_path | ||
| func set_icon_image(texture_path: String): | ||
| self.texture_path = texture_path | ||
|
|
||
| var texture_file = File.new() | ||
| var image = Image.new() | ||
| texture_file.open(texture_path, File.READ) | ||
| image.load_png_from_buffer(texture_file.get_buffer(texture_file.get_len())) | ||
| texture_file.close() | ||
| image.lock() | ||
|
|
||
| var texture = ImageTexture.new() | ||
| texture.create_from_image(image) #, 6) | ||
|
|
||
|
|
||
| var texture = Utils.new().generate_texture(texture_path, 'RGB') | ||
| self.texture = texture | ||
| self.material_override.set_shader_param("texture_albedo", texture) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| extends Sprite | ||
|
|
||
| const Utils = preload("utils.gd") | ||
|
|
||
| func set_icon_image(texture_path: String): | ||
| var texture = Utils.new().generate_texture(texture_path, 'RGB') | ||
| self.texture = texture | ||
| # TODO: Figure out a better heuristic. Why 0.05? | ||
| var scaling_factor = 0.05 | ||
| self.apply_scale(Vector2(scaling_factor, scaling_factor)) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| [gd_scene load_steps=4 format=2] | ||
|
|
||
| [ext_resource path="res://Icon2D.gd" type="Script" id=1] | ||
|
|
||
| [sub_resource type="Shader" id=1] | ||
| code = "shader_type canvas_item; | ||
| render_mode unshaded,blend_mix; | ||
|
|
||
| uniform vec2 minimap_corner; | ||
| uniform vec2 minimap_corner2; | ||
|
|
||
| void fragment() { | ||
| COLOR = vec4(0,0,0,0); | ||
| vec2 screen_pixel_size = vec2(textureSize(SCREEN_TEXTURE, 0)); | ||
| vec2 screen_pixel = SCREEN_UV * screen_pixel_size; | ||
| if (screen_pixel.x > minimap_corner.x && screen_pixel.x < minimap_corner2.x | ||
| && screen_pixel.y > minimap_corner.y && screen_pixel.y < minimap_corner2.y) { | ||
| COLOR = texture(TEXTURE, vec2(UV.y, -UV.x)); | ||
| } | ||
| }" | ||
|
|
||
| [sub_resource type="ShaderMaterial" id=2] | ||
| shader = SubResource( 1 ) | ||
| shader_param/minimap_corner = Vector2( 0, 0 ) | ||
| shader_param/minimap_corner2 = Vector2( 0, 0 ) | ||
|
|
||
| [node name="Icon2D" type="Sprite"] | ||
| material = SubResource( 2 ) | ||
| script = ExtResource( 1 ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| class_name Utils | ||
|
|
||
| func load_image_from_path(path: String): | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any chance I can convince you to use the same texture loaders for both the icon textures and the path textures? It would be a nice decrease in complexity. Also take a look at #19 to make sure that your solution is compatible with that eventual goal, otherwise the texture loading might need to be rewritten again at a later date.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good suggestion, have attempted to reuse the util function for both paths and icons. Also accept another parameter, |
||
| var file = File.new() | ||
| if !file.file_exists(path): | ||
| print("Warning: File does not exist: ", path) | ||
| var image = Image.new() | ||
| file.open(path, File.READ) | ||
| image.load_png_from_buffer(file.get_buffer(file.get_len())) | ||
| file.close() | ||
| image.lock() | ||
| return image | ||
|
|
||
| func generate_texture(texture_path: String, color_space: String): | ||
| var image = load_image_from_path(texture_path) | ||
| var texture = ImageTexture.new() | ||
| var flag = 7 | ||
| var accepted_color_spaces = ['sRGB', 'RGB'] | ||
| if color_space == 'sRGB': | ||
| flag = 22 | ||
| if !accepted_color_spaces.has(color_space): | ||
| print("Only RGB and sRGB accepted. Defaulting to RGB.") | ||
| texture.create_from_image(image, flag) | ||
| texture.storage = ImageTexture.STORAGE_COMPRESS_LOSSLESS | ||
| return texture | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename. It's not just minimap_path now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the non minimap I have the two types split into different parent nodes.
Burrito/Spatial.gd
Lines 410 to 417 in 55fff1e
Maybe it makes sense to also do that for the minimap now that it will have icons.