feat(renderer): add CustomControlConfiguration interface and integrate custom control handling in G2DDrawControl

This commit is contained in:
extio-de
2026-01-04 14:11:39 +01:00
parent 034604c1d8
commit f8dbe3d405
2 changed files with 51 additions and 8 deletions

View File

@@ -0,0 +1,13 @@
package de.extio.game_engine.renderer.g2d.control;
import de.extio.game_engine.renderer.g2d.control.impl.G2DBaseControlImpl;
public interface CustomControlConfiguration<T extends G2DBaseControlImpl> {
Class<T> getControlInterface();
T createControl();
void setCustomData(T controlImpl, Object data);
}

View File

@@ -72,6 +72,8 @@ public class G2DDrawControl extends G2DAbstractRenderingBo implements ControlRen
private SetFocusData setFocusData; private SetFocusData setFocusData;
private Object customData;
private boolean visible; private boolean visible;
private boolean enabled = true; private boolean enabled = true;
@@ -84,8 +86,11 @@ public class G2DDrawControl extends G2DAbstractRenderingBo implements ControlRen
private final Area2 tempArea = new Area2(MutableCoordI2.create(), MutableCoordI2.create()); private final Area2 tempArea = new Area2(MutableCoordI2.create(), MutableCoordI2.create());
public G2DDrawControl() { private final List<CustomControlConfiguration<? extends G2DBaseControlImpl>> customControlConfigurations;
public G2DDrawControl(final List<CustomControlConfiguration<? extends G2DBaseControlImpl>> customControlConfigurations) {
super(RenderingBoLayer.UI0); super(RenderingBoLayer.UI0);
this.customControlConfigurations = customControlConfigurations;
} }
@Override @Override
@@ -144,6 +149,9 @@ public class G2DDrawControl extends G2DAbstractRenderingBo implements ControlRen
else if (data instanceof final SetFocusData setFocusData) { else if (data instanceof final SetFocusData setFocusData) {
this.setFocusData = setFocusData; this.setFocusData = setFocusData;
} }
else {
this.customData = data;
}
return this; return this;
} }
@@ -198,14 +206,17 @@ public class G2DDrawControl extends G2DAbstractRenderingBo implements ControlRen
var control = (G2DBaseControlImpl) CACHED_CONTROLS.get(this.id); var control = (G2DBaseControlImpl) CACHED_CONTROLS.get(this.id);
if (control == null) { if (control == null) {
if (this.clazz == ButtonControl.class) { if (this.clazz == null) {
LOGGER.warn("G2DDrawControl: control type not specified for control id {}", this.id);
return;
}
else if (this.clazz == ButtonControl.class) {
control = new G2DButtonControlImpl(); control = new G2DButtonControlImpl();
} }
else if (this.clazz == LabelControl.class) { else if (this.clazz == LabelControl.class) {
control = new G2DLabelControlImpl(); control = new G2DLabelControlImpl();
} }
else if (this.clazz == TextfieldControl.class) { else if (this.clazz == TextfieldControl.class) {
// control = new G2DTextfieldControlImpl();
control = new G2DTextfieldControlImpl2(); control = new G2DTextfieldControlImpl2();
} }
else if (this.clazz == ToggleButtonControl.class) { else if (this.clazz == ToggleButtonControl.class) {
@@ -232,12 +243,19 @@ public class G2DDrawControl extends G2DAbstractRenderingBo implements ControlRen
else if (this.clazz == TooltipControl.class) { else if (this.clazz == TooltipControl.class) {
control = new G2DTooltipControl(); control = new G2DTooltipControl();
} }
else if (this.clazz == null) {
LOGGER.warn("G2DDrawControl: control type not specified for control id {}", this.id);
return;
}
else { else {
throw new UnsupportedOperationException("Not implemented " + this.clazz.getName()); if (this.customControlConfigurations != null) {
for (final var customControlConfiguration : this.customControlConfigurations) {
if (customControlConfiguration.getControlInterface().equals(this.clazz)) {
control = customControlConfiguration.createControl();
break;
}
}
}
if (control == null) {
throw new IllegalArgumentException("Control type not registered: " + this.clazz.getName());
}
} }
control.setScaleFactor(scaleFactor) control.setScaleFactor(scaleFactor)
@@ -320,6 +338,16 @@ public class G2DDrawControl extends G2DAbstractRenderingBo implements ControlRen
else if (this.clazz == TextfieldControl.class && this.textfieldData != null) { else if (this.clazz == TextfieldControl.class && this.textfieldData != null) {
((TextfieldControl) control).setCustomData(this.textfieldData); ((TextfieldControl) control).setCustomData(this.textfieldData);
} }
else {
if (this.customControlConfigurations != null) {
for (final var customControlConfiguration : this.customControlConfigurations) {
if (customControlConfiguration.getControlInterface().equals(this.clazz)) {
((CustomControlConfiguration) customControlConfiguration).setCustomData(control, this.customData);
break;
}
}
}
}
} }
@Override @Override
@@ -342,6 +370,7 @@ public class G2DDrawControl extends G2DAbstractRenderingBo implements ControlRen
this.sliderData = o.sliderData; this.sliderData = o.sliderData;
this.tableData = o.tableData; this.tableData = o.tableData;
this.setFocusData = o.setFocusData; this.setFocusData = o.setFocusData;
this.customData = o.customData;
this.visible = o.visible; this.visible = o.visible;
this.enabled = o.enabled; this.enabled = o.enabled;
this.tooltip = o.tooltip; this.tooltip = o.tooltip;
@@ -369,6 +398,7 @@ public class G2DDrawControl extends G2DAbstractRenderingBo implements ControlRen
this.sliderData = null; this.sliderData = null;
this.tableData = null; this.tableData = null;
this.setFocusData = null; this.setFocusData = null;
this.customData = null;
this.visible = false; this.visible = false;
this.enabled = true; this.enabled = true;
this.tooltip = null; this.tooltip = null;