-
Notifications
You must be signed in to change notification settings - Fork 19
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
Map icons #47
base: master
Are you sure you want to change the base?
Map icons #47
Changes from 2 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) | ||
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) | ||
self.texture = texture | ||
# TODO: Figure out a better heuristic. Why 0.2? | ||
var scaling_factor = 0.1 | ||
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 | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -284,8 +284,9 @@ func reset_minimap_masks(): | |||||||||||||||||
compass_corner2 = compass_corner1 + Vector2(compass_width, compass_height) | ||||||||||||||||||
|
||||||||||||||||||
for minimap_path in $Control/MiniMap.get_children(): | ||||||||||||||||||
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. Rename. It's not just minimap_path now. 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. In the non minimap I have the two types split into different parent nodes. Lines 410 to 417 in 55fff1e
Maybe it makes sense to also do that for the minimap now that it will have icons. |
||||||||||||||||||
minimap_path.material.set_shader_param("minimap_corner", compass_corner1) | ||||||||||||||||||
minimap_path.material.set_shader_param("minimap_corner2", compass_corner2) | ||||||||||||||||||
if minimap_path.material != null: | ||||||||||||||||||
minimap_path.material.set_shader_param("minimap_corner", compass_corner1) | ||||||||||||||||||
minimap_path.material.set_shader_param("minimap_corner2", compass_corner2) | ||||||||||||||||||
|
||||||||||||||||||
var markerdata = {} | ||||||||||||||||||
var marker_file_path = "" | ||||||||||||||||||
|
@@ -329,6 +330,7 @@ var route_scene = load("res://Route.tscn") | |||||||||||||||||
var icon_scene = load("res://Icon.tscn") | ||||||||||||||||||
var path2d_scene = load("res://Route2D.tscn") | ||||||||||||||||||
var gizmo_scene = load("res://Gizmo/PointEdit.tscn") | ||||||||||||||||||
var icon2d_scene = load("res://Icon2D.tscn") | ||||||||||||||||||
|
||||||||||||||||||
##########Gizmo Stuff########### | ||||||||||||||||||
# How long the ray to search for 3D clickable object should be. | ||||||||||||||||||
|
@@ -501,6 +503,11 @@ func gen_new_icon(position: Vector3, texture_path: String): | |||||||||||||||||
#icon_markers.append(new_icon) | ||||||||||||||||||
icons.add_child(new_icon) | ||||||||||||||||||
|
||||||||||||||||||
var minimap_icon = icon2d_scene.instance() | ||||||||||||||||||
minimap_icon.set_position(Vector2(position[0], position[2])) | ||||||||||||||||||
minimap_icon.set_icon_image(texture_path) | ||||||||||||||||||
minimap.add_child(minimap_icon) | ||||||||||||||||||
|
||||||||||||||||||
# This function take all of the currently rendered objects and converts it into | ||||||||||||||||||
# the data format that is saved/loaded from. | ||||||||||||||||||
func data_from_renderview(): | ||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
class_name Utils | ||
|
||
func load_image_from_path(path: String): | ||
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. 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() | ||
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): | ||
var image = load_image_from_path(texture_path) | ||
var texture = ImageTexture.new() | ||
texture.create_from_image(image) | ||
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.
This was the complexity that prevented me from doing this in the previous version. Maybe look at what taco or blish hud does for this? I do not know what the right answer is.