checheche/Robo-Bus-A31-HMI/common/gui/repeat_texture_progress_bar.gd

37 lines
1.1 KiB
GDScript3
Raw Normal View History

2024-12-06 21:22:11 +08:00
@tool
extends TextureProgressBar
@export var texture_under_repat :Texture2D = null
@export var texture_progress_repat :Texture2D = null
@export var max = 3:
set(value):
if max != value:
max = value
texture()
@export var interval = 10:
set(value):
if interval != value:
interval = value
texture()
func texture():
#if Engine.is_editor_hint():
texture_under = await count_texture(texture_under_repat)
texture_progress = await count_texture(texture_progress_repat)
max_value = max
size = texture_under.get_size()
pivot_offset = size/2
func count_texture(texture):
var image = Image.new()
var image_du :Image = texture.get_image()
image.set_data(1,1,false,Image.FORMAT_RGBAH,[Color("ffffff00"),Color("ffffff00"),Color("ffffff00"),Color("ffffff00"),Color("ffffff00"),Color("ffffff00"),Color("ffffff00"),Color("ffffff00")])
image.resize(image_du.get_width()*max + interval *(max-1),image_du.get_height())
for x in image_du.get_width():
for y in image_du.get_height():
for i in max:
image.set_pixel(x+((image_du.get_width())*i+interval*i),y,image_du.get_pixel(x,y))
return ImageTexture.create_from_image(image)