diff --git a/src/main/java/de/extio/game_engine/renderer/g2d/control/G2DDrawControl.java b/src/main/java/de/extio/game_engine/renderer/g2d/control/G2DDrawControl.java index 008cbd6..a0f4e75 100644 --- a/src/main/java/de/extio/game_engine/renderer/g2d/control/G2DDrawControl.java +++ b/src/main/java/de/extio/game_engine/renderer/g2d/control/G2DDrawControl.java @@ -42,6 +42,8 @@ public class G2DDrawControl extends G2DAbstractRenderingBo implements ControlRen private Class clazz; private String caption; + + private long lastCaptionUpdateTime; private String controlGroup; @@ -96,6 +98,7 @@ public class G2DDrawControl extends G2DAbstractRenderingBo implements ControlRen @Override public ControlRenderingBo setCaption(final String caption) { this.caption = caption; + this.lastCaptionUpdateTime = System.currentTimeMillis(); return this; } @@ -336,6 +339,9 @@ public class G2DDrawControl extends G2DAbstractRenderingBo implements ControlRen } else if (this.clazz == TextfieldControl.class && this.textfieldData != null) { ((TextfieldControl) control).setCustomData(this.textfieldData); + if (control instanceof final G2DTextfieldControlImpl2 tfc2) { + tfc2.setLastCaptionUpdateTime(this.lastCaptionUpdateTime); + } } else { for (final var customControlConfiguration : this.customControlConfigurations) { @@ -355,6 +361,7 @@ public class G2DDrawControl extends G2DAbstractRenderingBo implements ControlRen this.id = o.id; this.clazz = o.clazz; this.caption = o.caption; + this.lastCaptionUpdateTime = o.lastCaptionUpdateTime; this.controlGroup = o.controlGroup; this.fontSize = o.fontSize; this.labelData = o.labelData; @@ -384,6 +391,7 @@ public class G2DDrawControl extends G2DAbstractRenderingBo implements ControlRen this.id = null; this.clazz = null; this.caption = null; + this.lastCaptionUpdateTime = 0L; this.controlGroup = null; this.fontSize = G2DDrawFont.FONT_SIZE_DEFAULT; this.labelData = null; diff --git a/src/main/java/de/extio/game_engine/renderer/g2d/control/impl/G2DTextfieldControlImpl2.java b/src/main/java/de/extio/game_engine/renderer/g2d/control/impl/G2DTextfieldControlImpl2.java index 47402f3..e5a280b 100644 --- a/src/main/java/de/extio/game_engine/renderer/g2d/control/impl/G2DTextfieldControlImpl2.java +++ b/src/main/java/de/extio/game_engine/renderer/g2d/control/impl/G2DTextfieldControlImpl2.java @@ -34,6 +34,10 @@ public class G2DTextfieldControlImpl2 extends G2DBaseControlImpl implements Text private boolean readonly; private String lastCaption = ""; + + private long lastCaptionUpdateTime; + + private long lastCaptionUpdateTimeInternal; private String lastText = ""; @@ -82,15 +86,19 @@ public class G2DTextfieldControlImpl2 extends G2DBaseControlImpl implements Text if (this.multiLine) { this.modified |= caption != null && !caption.equals(this.caption); } - else { - this.modified |= caption != null && (!caption.equals(this.caption) || !caption.equals(this.textComponent.getText())); - } if (caption != null) { this.lastCaption = caption; } this.caption = caption; return this; } + + public void setLastCaptionUpdateTime(final long lastCaptionUpdateTime) { + if (! this.multiLine) { + this.modified |= this.lastCaptionUpdateTime != lastCaptionUpdateTime; + } + this.lastCaptionUpdateTime = lastCaptionUpdateTime; + } @Override public void build() { @@ -301,7 +309,7 @@ public class G2DTextfieldControlImpl2 extends G2DBaseControlImpl implements Text } } else { - if (this.caption != null && !this.textComponent.getText().equals(this.caption)) { + if (this.caption != null && !this.textComponent.getText().equals(this.caption) && (this.lastCaptionUpdateTimeInternal == 0L || this.lastCaptionUpdateTimeInternal < this.lastCaptionUpdateTime)) { final var pos = this.textComponent.getCaretPosition(); this.safeInvoke(() -> this.textComponent.setText(this.caption)); if (pos < this.textComponent.getText().length()) { @@ -309,6 +317,7 @@ public class G2DTextfieldControlImpl2 extends G2DBaseControlImpl implements Text } this.lastText = this.caption; + this.lastCaptionUpdateTimeInternal = this.lastCaptionUpdateTime; } } } @@ -382,5 +391,4 @@ public class G2DTextfieldControlImpl2 extends G2DBaseControlImpl implements Text this.scrollbar.setControlId(id + "_scroll"); return super.setControlId(id); } - }