Skip to content

Commit

Permalink
Fixed compilation error
Browse files Browse the repository at this point in the history
  • Loading branch information
Zelaux committed Jun 16, 2024
1 parent 0a646ed commit e42050d
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 66 deletions.
82 changes: 82 additions & 0 deletions tiledStructures/src/mmc/ui/tiledStructures/ConnectorStyle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package mmc.ui.tiledStructures;

import arc.Core;
import arc.graphics.Color;
import arc.graphics.Pixmap;
import arc.graphics.Texture;
import arc.graphics.g2d.NinePatch;
import arc.graphics.g2d.TextureAtlas;
import arc.scene.style.ScaledNinePatchDrawable;
import arc.scene.ui.Button;
import arc.util.Reflect;
import arc.util.Tmp;
import mindustry.gen.Tex;
import org.jetbrains.annotations.NotNull;

public class ConnectorStyle {
public Button.ButtonStyle inputStyle;
public Button.ButtonStyle outputStyle;

public ConnectorStyle(Button.ButtonStyle inputStyle, Button.ButtonStyle outputStyle) {
this.inputStyle = inputStyle;
this.outputStyle = outputStyle;
}

public ConnectorStyle() {
}

public static ConnectorStyle defaultStyle() {
if (!Core.scene.hasStyle(ConnectorStyle.class)) {
Core.scene.addStyle(ConnectorStyle.class, innerDefault());
}
return Core.scene.getStyle(ConnectorStyle.class);
}

@NotNull
private static ConnectorStyle innerDefault() {
float drawableScale = Reflect.get(TextureAtlas.class, Core.atlas, "drawableScale");
Color fillColor = Tmp.c1.set(0x252525FF);
Button.ButtonStyle input = new Button.ButtonStyle() {{
down = Tex.buttonSideLeftDown;
up = Tex.buttonSideLeft;
over = Tex.buttonSideLeftOver;
TextureAtlas.AtlasRegion region = Core.atlas.find("button-side-left-over");
Pixmap pixmap = Core.atlas.getPixmap(region).crop();

pixmap.each((x, y) -> {
if (pixmap.getA(x, y) > 0) {
pixmap.set(x, y, fillColor);
}
});

int[] splits = region.splits;
NinePatch patch = new NinePatch(new Texture(pixmap), splits[0], splits[1], splits[2], splits[3]);
pixmap.dispose();
int[] pads = region.pads;
if (pads != null) patch.setPadding(pads[0], pads[1], pads[2], pads[3]);
disabled = new ScaledNinePatchDrawable(patch, drawableScale);
}};
Button.ButtonStyle output = new Button.ButtonStyle() {{
down = Tex.buttonSideRightDown;
up = Tex.buttonSideRight;
over = Tex.buttonSideRightOver;

TextureAtlas.AtlasRegion region = Core.atlas.find("button-side-right-over");
Pixmap pixmap = Core.atlas.getPixmap(region).crop();

pixmap.each((x, y) -> {
if (pixmap.getA(x, y) > 0) {
pixmap.set(x, y, fillColor);
}
});

int[] splits = region.splits;
NinePatch patch = new NinePatch(new Texture(pixmap), splits[0], splits[1], splits[2], splits[3]);
pixmap.dispose();
int[] pads = region.pads;
if (pads != null) patch.setPadding(pads[0], pads[1], pads[2], pads[3]);
disabled = new ScaledNinePatchDrawable(patch, drawableScale);
}};
return new ConnectorStyle(input, output);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -594,73 +594,7 @@ public float getPrefHeight(){
return bounds * unitSize;
}

public static class ConnectorStyle{
public ButtonStyle inputStyle;
public ButtonStyle outputStyle;

public ConnectorStyle(ButtonStyle inputStyle, ButtonStyle outputStyle){
this.inputStyle = inputStyle;
this.outputStyle = outputStyle;
}

public ConnectorStyle(){
}

public static ConnectorStyle defaultStyle(){
if(!Core.scene.hasStyle(ConnectorStyle.class)){
Core.scene.addStyle(ConnectorStyle.class, innerDefault());
}
return Core.scene.getStyle(ConnectorStyle.class);
}

@NotNull
private static ConnectorStyle innerDefault(){
float drawableScale = Reflect.get(TextureAtlas.class, Core.atlas, "drawableScale");
Color fillColor = Tmp.c1.set(0x252525FF);
ButtonStyle input = new ButtonStyle(){{
down = Tex.buttonSideLeftDown;
up = Tex.buttonSideLeft;
over = Tex.buttonSideLeftOver;
AtlasRegion region = Core.atlas.find("button-side-left-over");
Pixmap pixmap = Core.atlas.getPixmap(region).crop();

pixmap.each((x, y) -> {
if(pixmap.getA(x, y) > 0){
pixmap.set(x, y, fillColor);
}
});

int[] splits = region.splits;
NinePatch patch = new NinePatch(new Texture(pixmap), splits[0], splits[1], splits[2], splits[3]);
pixmap.dispose();
int[] pads = region.pads;
if(pads != null) patch.setPadding(pads[0], pads[1], pads[2], pads[3]);
disabled = new ScaledNinePatchDrawable(patch, drawableScale);
}};
ButtonStyle output = new ButtonStyle(){{
down = Tex.buttonSideRightDown;
up = Tex.buttonSideRight;
over = Tex.buttonSideRightOver;

AtlasRegion region = Core.atlas.find("button-side-right-over");
Pixmap pixmap = Core.atlas.getPixmap(region).crop();

pixmap.each((x, y) -> {
if(pixmap.getA(x, y) > 0){
pixmap.set(x, y, fillColor);
}
});

int[] splits = region.splits;
NinePatch patch = new NinePatch(new Texture(pixmap), splits[0], splits[1], splits[2], splits[3]);
pixmap.dispose();
int[] pads = region.pads;
if(pads != null) patch.setPadding(pads[0], pads[1], pads[2], pads[3]);
disabled = new ScaledNinePatchDrawable(patch, drawableScale);
}};
return new ConnectorStyle(input, output);
}
}

public class StructureTile extends Table{
public final TiledStructure<?> obj;
Expand Down

0 comments on commit e42050d

Please sign in to comment.