Skip to content

Commit

Permalink
Fix creature sprite names in CreaturePanel.
Browse files Browse the repository at this point in the history
  • Loading branch information
nightm4re94 committed Dec 5, 2021
1 parent ecc7942 commit 52d100c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import de.gurkenlabs.utiliti.swing.Icons;
import de.gurkenlabs.utiliti.swing.LabelListCellRenderer;
import java.awt.LayoutManager;
import java.util.Arrays;
import java.util.Map;
import java.util.TreeMap;
import javax.swing.DefaultComboBoxModel;
Expand All @@ -18,11 +19,14 @@

@SuppressWarnings("serial")
public class CreaturePanel extends PropertyPanel {

private final JComboBox<JLabel> comboBoxSpriteSheets;
private final JComboBox<Direction> comboBoxDirection;
private final JCheckBox checkBoxScale;

/** Create the panel. */
/**
* Create the panel.
*/
public CreaturePanel() {
super("panel_creature", Icons.CREATURE);

Expand All @@ -31,31 +35,17 @@ public CreaturePanel() {

this.comboBoxDirection = new JComboBox<>();
this.comboBoxDirection.setModel(new DefaultComboBoxModel<>(Direction.values()));
this.checkBoxScale = new JCheckBox(Resources.strings().get("panel_stretch_spripte"));
this.checkBoxScale = new JCheckBox(Resources.strings().get("panel_stretch_sprite"));

setLayout(this.createLayout());
this.setupChangedListeners();
}

public static String getCreatureSpriteName(String name) {
for (CreatureAnimationState state : CreatureAnimationState.values()) {
if (name.endsWith(state.spriteString())) {
return name.substring(0, name.length() - state.spriteString().length());
}
}

for (Direction dir : Direction.values()) {
String idle = CreatureAnimationState.IDLE.spriteString() + "-" + dir.toString().toLowerCase();
if (name.endsWith(idle)) {
return name.substring(0, name.length() - idle.length());
}

String walk = CreatureAnimationState.WALK.spriteString() + "-" + dir.toString().toLowerCase();
if (name.endsWith(walk)) {
return name.substring(0, name.length() - walk.length());
}
if (Arrays.stream(CreatureAnimationState.values())
.anyMatch(state -> name.contains(state.spriteString()))) {
return name.split("-")[0];
}

return null;
}

Expand All @@ -82,8 +72,8 @@ protected void clearControls() {
protected void setControlValues(IMapObject mapObject) {
selectSpriteSheet(this.comboBoxSpriteSheets, mapObject);
this.comboBoxDirection.setSelectedItem(
mapObject.getEnumValue(
MapObjectProperty.SPAWN_DIRECTION, Direction.class, Direction.UNDEFINED));
mapObject.getEnumValue(
MapObjectProperty.SPAWN_DIRECTION, Direction.class, Direction.UNDEFINED));
this.checkBoxScale.setSelected(mapObject.getBoolValue(MapObjectProperty.SCALE_SPRITE));
}

Expand All @@ -107,10 +97,10 @@ private void loadAvailableCreatureSprites() {

private LayoutManager createLayout() {
LayoutItem[] layoutItems =
new LayoutItem[] {
new LayoutItem("panel_sprite", this.comboBoxSpriteSheets),
new LayoutItem("panel_direction", this.comboBoxDirection),
};
new LayoutItem[]{
new LayoutItem("panel_sprite", this.comboBoxSpriteSheets),
new LayoutItem("panel_direction", this.comboBoxDirection),
};

return this.createLayout(layoutItems, this.checkBoxScale);
}
Expand Down
2 changes: 1 addition & 1 deletion utiliti/src/main/localization/strings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ panel_entities_search_default=Search for entity ...

panel_prop=Prop
panel_material=Material
panel_stretch_spripte=Stretch sprite
panel_stretch_sprite=Stretch sprite
panel_flip_vertical=Vertical flip
panel_flip_horizontal=Horizontal flip
panel_prop_shadow=Shadow
Expand Down

0 comments on commit 52d100c

Please sign in to comment.