extends Node2D # texture_from_color: Generated an image texture from a color, to be used as colored icons for the # material list from the material color func texture_from_color(c: Color, size: Vector2i = Vector2i(16, 16)) -> Texture2D: var img := Image.create(size.x, size.y, false, Image.FORMAT_RGBA8) img.fill(c) return ImageTexture.create_from_image(img) func _ready() -> void: # Fill the list of Materials var id = 0 for material in $World.get_materials(): $Control/MaterialList.add_item(material.name, texture_from_color(material.color), true) if material.name == "Bedrock": $Control/MaterialList.select(id) id += 1 func _unhandled_input(event) -> void: if event is InputEventMouseButton: if event.pressed == false and event.canceled == false: $World.set_material_at_position(event.position.y, event.position.x, $Control/MaterialList.get_item_text($Control/MaterialList.get_selected_items()[0])) if event is InputEventMouseMotion: # Holding left button if event.button_mask == 1: $World.set_material_at_position(event.position.y, event.position.x, $Control/MaterialList.get_item_text($Control/MaterialList.get_selected_items()[0])) func _on_refresh_button_pressed() -> void: Game.material_just_changed.emit()