2026-02-05 21:38:30 +01:00

81 lines
2.1 KiB
ActionScript

class ShaderComponentRender {
Entity entity;
ShaderComponent shaderComponent;
ShaderComponentRender(Entity _entity) {
entity = _entity;
shaderComponent = entity.getComponent<ShaderComponent>();
}
void setShader(any@ shaderData) {
Shader shader;
if (shaderData.retrieve(shader)) {
shaderComponent.shader = shader;
}
}
void setTexture(any@ textureData) {
Texture texture;
if (textureData.retrieve(texture)) {
shaderComponent.texture = texture;
}
}
void render() {
if (!entity.hasComponent<ShaderComponent>())
return;
// Shader icon
if (shaderComponent.hasShader) {
ImGui::drawIcon(StudioAPI::loadIcon("shader.png"), 32);
} else {
ImGui::drawIcon(StudioAPI::loadIcon("empty.png"), 32);
}
ImGui::dragDropTarget("SHADER", ReciverFunction(this.setShader));
if (shaderComponent.hasShader) {
ImGui::sameline();
ImGui::space();
ImGui::sameline();
Shader shader = shaderComponent.shader;
ImGui::titleCenterY(shader.name, 32);
ImGui::dragDropTarget("SHADER", ReciverFunction(this.setShader));
}
ImGui::space();
// Texture icon
Texture texture = shaderComponent.texture;
if (texture.isValid()) {
ImGui::drawIcon(texture, 32);
} else {
ImGui::drawIcon(StudioAPI::loadIcon("empty.png"), 32);
}
ImGui::dragDropTarget("TEXTURE", ReciverFunction(this.setTexture));
if (texture.isValid()) {
ImGui::sameline();
ImGui::space();
ImGui::sameline();
ImGui::titleCenterY(texture.name, 32);
ImGui::dragDropTarget("TEXTURE", ReciverFunction(this.setTexture));
}
ImGui::space(0, 20);
if (ImGui::button("Clear")) {
shaderComponent.clear();
}
}
void remove() {
if (ImGui::menuItem("Remove")) {
entity.removeComponent<ShaderComponent>();
}
}
}