use of com.badlogic.gdx.graphics.Texture in project Mindustry by Anuken.
the class MapEditor method applyFilterPreview.
public void applyFilterPreview() {
if (filterPixmap != null && (filterPixmap.getWidth() != pixmap.getWidth() || filterPixmap.getHeight() != pixmap.getHeight())) {
filterPixmap.dispose();
filterTexture.dispose();
filterPixmap = null;
filterTexture = null;
}
if (filterPixmap == null) {
filterPixmap = Pixmaps.copy(pixmap);
filter.process(filterPixmap);
filterTexture = new Texture(filterPixmap);
} else {
filterPixmap.drawPixmap(pixmap, 0, 0);
filter.process(filterPixmap);
filterTexture.draw(filterPixmap, 0, 0);
}
}
use of com.badlogic.gdx.graphics.Texture in project Mindustry by Anuken.
the class MapEditor method setPixmap.
public void setPixmap(Pixmap out) {
if (pixmap.getWidth() == out.getWidth() && pixmap.getHeight() == out.getHeight()) {
pixmap.dispose();
pixmap = out;
texture.draw(out, 0, 0);
} else {
pixmap.dispose();
texture.dispose();
pixmap = out;
texture = new Texture(out);
}
pixmap.setColor(ColorMapper.getColor(drawBlock));
map.pixmap = pixmap;
map.texture = texture;
}
use of com.badlogic.gdx.graphics.Texture in project Mindustry by Anuken.
the class Maps method loadMapFile.
private boolean loadMapFile(FileHandle file, boolean logException) {
try {
Array<Map> arr = json.fromJson(ArrayContainer.class, file).maps;
if (arr != null) {
// can be an empty map file
for (Map map : arr) {
map.pixmap = new Pixmap(file.sibling(map.name + ".png"));
if (!headless)
map.texture = new Texture(map.pixmap);
maps.put(map.id, map);
mapNames.put(map.name, map);
lastID = Math.max(lastID, map.id);
if (!map.custom) {
defaultMaps.add(map);
}
}
}
return true;
} catch (GdxRuntimeException e) {
Log.err(e);
return true;
} catch (Exception e) {
if (logException) {
Log.err(e);
Log.err("Failed loading map file: {0}", file);
}
return false;
}
}
use of com.badlogic.gdx.graphics.Texture in project skin-composer by raeleus.
the class AtlasData method readAtlas.
public void readAtlas(FileHandle fileHandle) throws Exception {
if (fileHandle.exists()) {
FileHandle saveFile = main.getProjectData().getSaveFile();
FileHandle targetDirectory;
if (saveFile != null) {
targetDirectory = saveFile.sibling(saveFile.nameWithoutExtension() + "_data/");
} else {
targetDirectory = Gdx.files.local("temp/" + main.getProjectData().getId() + "_data/");
}
targetDirectory.mkdirs();
TextureAtlas atlas = new TextureAtlas(fileHandle);
Array<AtlasRegion> regions = atlas.getRegions();
for (AtlasRegion region : regions) {
Texture texture = region.getTexture();
if (!texture.getTextureData().isPrepared()) {
texture.getTextureData().prepare();
}
Pixmap pixmap = texture.getTextureData().consumePixmap();
pixmap.setBlending(Pixmap.Blending.None);
Pixmap savePixmap;
String name;
if (region.splits == null && region.pads == null) {
name = region.name + ".png";
savePixmap = new Pixmap(region.getRegionWidth(), region.getRegionHeight(), Pixmap.Format.RGBA8888);
for (int x = 0; x < region.getRegionWidth(); x++) {
for (int y = 0; y < region.getRegionHeight(); y++) {
int colorInt = pixmap.getPixel(region.getRegionX() + x, region.getRegionY() + y);
savePixmap.drawPixel(x, y, colorInt);
}
}
} else {
name = region.name + ".9.png";
savePixmap = new Pixmap(region.getRegionWidth() + 2, region.getRegionHeight() + 2, pixmap.getFormat());
int x;
int y;
// draw 9 patch lines
savePixmap.setColor(Color.BLACK);
if (region.splits != null) {
x = 0;
for (y = region.splits[2] + 1; y < savePixmap.getHeight() - region.splits[3] - 1; y++) {
savePixmap.drawPixel(x, y);
}
y = 0;
for (x = region.splits[0] + 1; x < savePixmap.getWidth() - region.splits[1] - 1; x++) {
savePixmap.drawPixel(x, y);
}
}
if (region.pads != null) {
x = savePixmap.getWidth() - 1;
for (y = region.pads[2] + 1; y < savePixmap.getHeight() - region.pads[3] - 1; y++) {
savePixmap.drawPixel(x, y);
}
y = savePixmap.getHeight() - 1;
for (x = region.pads[0] + 1; x < savePixmap.getWidth() - region.pads[1] - 1; x++) {
savePixmap.drawPixel(x, y);
}
}
for (x = 0; x < region.getRegionWidth(); x++) {
for (y = 0; y < region.getRegionHeight(); y++) {
int colorInt = pixmap.getPixel(region.getRegionX() + x, region.getRegionY() + y);
savePixmap.drawPixel(x + 1, y + 1, colorInt);
}
}
}
FileHandle outputFile = targetDirectory.child(name);
PixmapIO.writePNG(outputFile, savePixmap);
DrawableData drawable = new DrawableData(outputFile);
// delete drawables with the same name
for (DrawableData originalData : new Array<>(main.getProjectData().getAtlasData().getDrawables())) {
if (originalData.name.equals(drawable.name)) {
main.getProjectData().getAtlasData().getDrawables().removeValue(originalData, true);
}
}
drawables.add(drawable);
}
} else {
throw new FileNotFoundException();
}
}
use of com.badlogic.gdx.graphics.Texture in project ProjektGG by eskalon.
the class ServerBrowserScreen method initUI.
@Override
protected void initUI() {
backgroundTexture = assetManager.get(BACKGROUND_IMAGE_PATH);
Sound clickSound = assetManager.get(BUTTON_SOUND);
// mainTable.setBackground(skin.getDrawable("parchment-small"));
Table serverTable = new Table();
ScrollPane pane = new ScrollPane(serverTable);
// TODO gegen echte Server-Daten austauschen
String ip = "127.0.0.1";
int port = 12345;
ImageTextButton joinButton = new ImageTextButton("Beitreten", skin);
joinButton.addListener(new InputListener() {
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
clickSound.play(1F);
game.getNetworkHandler().setUpConnectionAsClient(ip, port);
connectingDialog = new Dialog("Verbinden...", skin);
connectingDialog.text("Spiel beitreten...");
connectingDialog.show(stage);
return true;
}
});
ImageTextButton backButton = new ImageTextButton("Zur�ck", skin);
backButton.addListener(new InputListener() {
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
clickSound.play(1F);
game.pushScreen("mainMenu");
return true;
}
});
ImageTextButton createLobbyButton = new ImageTextButton("Spiel erstellen", skin);
createLobbyButton.addListener(new InputListener() {
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
clickSound.play(1F);
game.pushScreen("lobbyCreation");
return true;
}
});
ImageTextButton directConnectButton = new ImageTextButton("Direkt verbinden", skin);
directConnectButton.addListener(new InputListener() {
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
clickSound.play(1F);
TextField portInputField = new TextField("55789", skin);
portInputField.setTextFieldFilter(new TextField.TextFieldFilter.DigitsOnlyFilter());
TextField ipInputField = new TextField("127.0.0.1", skin);
Dialog dialog = new Dialog("Direkt verbinden", skin) {
public void result(Object obj) {
if ((Boolean) obj) {
game.getNetworkHandler().setUpConnectionAsClient(ipInputField.getText(), Integer.valueOf(portInputField.getText()));
connectingDialog = new Dialog("Verbinden...", skin);
connectingDialog.text("Spiel beitreten...");
connectingDialog.show(stage);
}
}
};
dialog.text("IP: ").button("Zur�ck", false).button("Verbinden", true).key(Keys.ENTER, true).key(Keys.ESCAPE, false);
dialog.getContentTable().add(ipInputField).width(170).row();
dialog.getContentTable().add(new Label("Port:", skin));
dialog.getContentTable().add(portInputField).width(90).left();
dialog.show(stage);
return true;
}
});
Table buttonTable = new Table();
buttonTable.add(backButton);
buttonTable.add(createLobbyButton).padLeft(55);
buttonTable.add(directConnectButton).padLeft(55);
serverTable.left().top().add(new Image((Texture) assetManager.get(TICK_IMAGE_PATH))).padRight(15).padLeft(12);
serverTable.add(new Label("Spiel 2", skin)).expandX();
serverTable.add(joinButton).padRight(12);
serverTable.row().padTop(20);
mainTable.add(serverTable).width(580).height(405).row();
mainTable.add(buttonTable).height(50).bottom();
}
Aggregations