Skip to content

Commit

Permalink
ApplicationThreadを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyLake-git committed Dec 20, 2022
1 parent e77b254 commit 6d040e7
Show file tree
Hide file tree
Showing 15 changed files with 355 additions and 68 deletions.
36 changes: 36 additions & 0 deletions assets/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Manifest-Version: 1.0
Main-Class: com.tres.DesktopLauncher
Class-Path: ashley-1.7.4.jar lwjgl-jemalloc-3.3.1-natives-macos.jar vis-
ui-1.4.11.jar lwjgl-3.3.1-natives-windows.jar lwjgl-jemalloc-3.3.1-nati
ves-linux.jar lwjgl-glfw-3.3.1-natives-macos-arm64.jar box2dlights-1.5.
jar gdx-bullet-1.11.0.jar lwjgl-3.3.1-natives-linux-arm64.jar lwjgl-jem
alloc-3.3.1-natives-windows.jar lwjgl-3.3.1-natives-linux.jar lwjgl-stb
-3.3.1-natives-windows.jar jlayer-1.0.1-gdx.jar lwjgl-stb-3.3.1-natives
-linux-arm32.jar lwjgl-glfw-3.3.1.jar lwjgl-jemalloc-3.3.1-natives-wind
ows-x86.jar lwjgl-opengl-3.3.1-natives-linux-arm64.jar lwjgl-openal-3.3
.1-natives-macos-arm64.jar lwjgl-jemalloc-3.3.1.jar lwjgl-stb-3.3.1-nat
ives-macos.jar discord-rpc.jar lwjgl-opengl-3.3.1-natives-macos-arm64.j
ar lwjgl-3.3.1.jar lwjgl-glfw-3.3.1-natives-windows-x86.jar lwjgl-jemal
loc-3.3.1-natives-linux-arm64.jar lwjgl-glfw-3.3.1-natives-windows.jar
gdx-freetype-1.11.0.jar lwjgl-opengl-3.3.1-natives-windows-x86.jar lwjg
l-openal-3.3.1-natives-macos.jar gdx-controllers-core-2.2.1.jar lwjgl-o
penal-3.3.1.jar gdx-box2d-platform-1.11.0-natives-desktop.jar lwjgl-jem
alloc-3.3.1-natives-linux-arm32.jar lwjgl-glfw-3.3.1-natives-macos.jar
lwjgl-openal-3.3.1-natives-windows-x86.jar jbump-1.0.1.jar lwjgl-glfw-3
.3.1-natives-linux-arm32.jar lwjgl-3.3.1-natives-macos.jar jorbis-0.0.1
7.jar lwjgl-stb-3.3.1-natives-linux-arm64.jar lwjgl-openal-3.3.1-native
s-linux.jar lwjgl-openal-3.3.1-natives-windows.jar lwjgl-opengl-3.3.1.j
ar gdx-bullet-platform-1.11.0-natives-desktop.jar lwjgl-3.3.1-natives-l
inux-arm32.jar lwjgl-stb-3.3.1-natives-linux.jar gdx-jnigen-loader-2.3.
1.jar lwjgl-opengl-3.3.1-natives-linux.jar lwjgl-3.3.1-natives-macos-ar
m64.jar gdx-ai-1.8.2.jar gdx-box2d-1.11.0.jar lwjgl-opengl-3.3.1-native
s-linux-arm32.jar lwjgl-stb-3.3.1-natives-macos-arm64.jar lwjgl-stb-3.3
.1.jar lwjgl-openal-3.3.1-natives-linux-arm32.jar gdx-freetype-platform
-1.11.0-natives-desktop.jar lwjgl-3.3.1-natives-windows-x86.jar gdx-bac
kend-lwjgl3-1.11.0.jar lwjgl-openal-3.3.1-natives-linux-arm64.jar jamep
ad-2.0.14.1.jar lwjgl-opengl-3.3.1-natives-windows.jar gdx-1.11.0.jar g
dx-controllers-desktop-2.2.1.jar lwjgl-glfw-3.3.1-natives-linux-arm64.j
ar gdx-platform-1.11.0-natives-desktop.jar lwjgl-opengl-3.3.1-natives-m
acos.jar lwjgl-glfw-3.3.1-natives-linux.jar lwjgl-jemalloc-3.3.1-native
s-macos-arm64.jar lwjgl-stb-3.3.1-natives-windows-x86.jar

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.tres.network.packet.protocol;

import com.tres.network.packet.Clientbound;
import com.tres.network.packet.DataPacket;
import com.tres.network.packet.PacketDecoder;
import com.tres.network.packet.PacketEncoder;

public class AvailableGamesPacket extends DataPacket implements Clientbound {
@Override
protected void decodePayload(PacketDecoder in) throws Exception {

}

@Override
protected void encodePayload(PacketEncoder out) throws Exception {

}

@Override
public String getName() {
return null;
}

@Override
public ProtocolIds getProtocolId() {
return ProtocolIds.AVAILABLE_GAMES_PACKET;
}
}
2 changes: 1 addition & 1 deletion core/src/com/tres/network/packet/protocol/PacketPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public PacketPool() {
this.register(new GameLevelPacket());
this.register(new AddPlayerPacket());
this.register(new CardActionPacket());
this.register(new RequestGameLevelPacket());
this.register(new RequestAvailableGamesPacket());
}

public void register(DataPacket packet) {
Expand Down
3 changes: 2 additions & 1 deletion core/src/com/tres/network/packet/protocol/ProtocolIds.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public enum ProtocolIds {
GAME_LEVEL_PACKET(10),
ADD_PLAYER_PACKET(11),
CARD_ACTION_PACKET(12),
REQUEST_GAME_LEVEL_PACKET(13);
REQUEST_AVAILABLE_GAMES_PACKET(13),
AVAILABLE_GAMES_PACKET(14);

public static final int PROTOCOL = 3;
public static final int VERSION = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.tres.network.packet.PacketEncoder;
import com.tres.network.packet.Serverbound;

public class RequestGameLevelPacket extends DataPacket implements Serverbound {
public class RequestAvailableGamesPacket extends DataPacket implements Serverbound {

@Override
protected void decodePayload(PacketDecoder in) throws Exception {
Expand All @@ -19,11 +19,11 @@ protected void encodePayload(PacketEncoder out) throws Exception {

@Override
public String getName() {
return "RequestGameLevelPacket";
return "RequestAvailableGamesPacket";
}

@Override
public ProtocolIds getProtocolId() {
return ProtocolIds.REQUEST_GAME_LEVEL_PACKET;
return ProtocolIds.REQUEST_AVAILABLE_GAMES_PACKET;
}
}
50 changes: 50 additions & 0 deletions desktop/src/com/tres/ApplicationThread.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.tres;

import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration;

public class ApplicationThread extends Thread {

protected TresApplication application;

protected Lwjgl3Application window;

protected Lwjgl3ApplicationConfiguration configuration;

protected boolean disposed;

public ApplicationThread(TresApplication application, Lwjgl3ApplicationConfiguration configuration) {
this.application = application;
this.configuration = configuration;
this.disposed = false;

configuration.setForegroundFPS(this.application.getSettings().getForegroundFPS());
}

@Override
public void run() {
this.window = new Lwjgl3Application(this.application, this.configuration);
this.disposed = true;
}

public TresApplication getApplication() {
return application;
}

public Lwjgl3ApplicationConfiguration getConfiguration() {
return configuration;
}

public boolean isDisposed() {
return disposed;
}

@Override
public void interrupt() {
super.interrupt();

if (this.window != null) {
this.window.exit();
}
}
}
22 changes: 14 additions & 8 deletions desktop/src/com/tres/DesktopLauncher.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.tres;

import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration;
import com.tres.client.Client;
import com.tres.utils.Colors;
Expand All @@ -9,23 +8,25 @@
// Please note that on macOS your application needs to be started with the -XstartOnFirstThread JVM argument
public class DesktopLauncher {

protected static Client client;
public static Client client;

public static ApplicationThread applicationThread;
protected static MainLogger logger;

public static void main(String[] arg) {
Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration();
config.setIdleFPS(30);
config.setTitle("Tres");
config.setTitle("Tres Application");
TresApplication game = new TresApplication(config);

config.setForegroundFPS(game.getSettings().getForegroundFPS());
Lwjgl3Application application = new Lwjgl3Application(game, config);
applicationThread = new ApplicationThread(game, config);

logger = new MainLogger("Launcher");
client = new Client();
long startMillis = System.currentTimeMillis();


applicationThread.start();
logger.info("Started");

// initDiscord();
Expand All @@ -38,16 +39,21 @@ public static void main(String[] arg) {
}

// updateRPC(startMillis);
if (client.isClosed() || game.isDisposed()) {
logger.warn("Detected client thread closed");
if (client.isClosed() || applicationThread.isDisposed()) {
logger.warn("Detected client/application thread closed");

logger.info(Colors.wrap("Fetching gui/client status...", Colors.YELLOW_BOLD_BRIGHT));
logger.info(Colors.wrap("Fetching status...", Colors.YELLOW_BOLD_BRIGHT));

if (!client.isClosed()) {
logger.warn("Client not closed. closing...");
client.close();
}

if (!game.isDisposed()) {
logger.warn("Application not disposed. disposing...");
applicationThread.interrupt();
}

break;
}
}
Expand Down
4 changes: 4 additions & 0 deletions desktop/src/com/tres/client/ui/ActorUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.tres.client.ui;

public class ActorUtils {
}
25 changes: 20 additions & 5 deletions desktop/src/com/tres/client/ui/actor/BorderlessButtonActor.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public Button(CharSequence text, float width, float height, Color backgroundColo

protected float pressedTime;

protected boolean disabled;

public BorderlessButtonActor(Vector2 position, Button button) {
setX(position.x - button.width / 2);
setY(position.y - button.height / 2);
Expand All @@ -59,21 +61,26 @@ public BorderlessButtonActor(Vector2 position, Button button) {
recreateTexture((int) button.width, (int) button.height, button.backgroundColor);
}

public void recreateTexture(int width, int height, Color color) {
public void recreateTexture(int width, int height, Color colorDefault) {
if (this.texture != null) this.texture.dispose();
Color color = colorDefault.cpy();
Pixmap pixmap = new Pixmap(width, height, Pixmap.Format.RGBA8888);
if (this.disabled) {
color.add(0.15f, 0.15f, 0.15f, 0);
}
pixmap.setColor(color);
pixmap.fillRectangle(1, 1, width - 2, height - 2);
if (this.hit) {
if (this.hit && !this.disabled) {
pixmap.setColor(0.0f, 0.5f, 0.5f, 1);
pixmap.drawRectangle(0, 0, width, height);
}


if (this.button.confirmSeconds > 0 && this.pressedTime > 0.0001f) {
float percentage = (float) Math.min(1.0, this.pressedTime / this.button.confirmSeconds);
if (percentage >= 1.0) {
pixmap.setColor(1f, 1f, 0f, 0.4f);
} else {
pixmap.setColor(1f, 1f, 0f, 0.4f);
pixmap.setColor(1f, 1f, 1f, 0.4f);
}
pixmap.fillRectangle(0, 0, (int) (width * percentage), height);
Expand All @@ -96,6 +103,14 @@ protected void scaleChanged() {
this.recreateTexture((int) getWidth(), (int) getHeight(), this.button.backgroundColor);
}

public boolean isDisabled() {
return disabled;
}

public void setDisabled(boolean disabled) {
this.disabled = disabled;
}

@Override
public void draw(Batch batch, float parentAlpha) {
this.recreateTexture((int) getWidth(), (int) getHeight(), this.button.backgroundColor);
Expand All @@ -114,7 +129,7 @@ public void act(float delta) {

this.pressed = false;
if (this.button.confirmSeconds > 0) {
if (this.hit && Gdx.input.isButtonPressed(Input.Buttons.LEFT)) {
if (this.hit && !this.disabled && Gdx.input.isButtonPressed(Input.Buttons.LEFT)) {
this.pressedTime += delta;

if (this.pressedTime > this.button.confirmSeconds) {
Expand All @@ -124,7 +139,7 @@ public void act(float delta) {
this.pressedTime = 0.0f;
}
} else {
this.pressed = this.hit && Gdx.input.isButtonJustPressed(Input.Buttons.LEFT);
this.pressed = this.hit && Gdx.input.isButtonJustPressed(Input.Buttons.LEFT) && !this.disabled;
}


Expand Down
28 changes: 28 additions & 0 deletions desktop/src/com/tres/client/ui/actor/TextActor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.tres.client.ui.actor;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.scenes.scene2d.Actor;

public class TextActor extends Actor {

protected CharSequence text;

protected BitmapFont font;
protected Color color;

public TextActor(CharSequence text, BitmapFont font, Color color) {
this.text = text;
this.font = font;
this.color = color;
}

@Override
public void draw(Batch batch, float parentAlpha) {
super.draw(batch, parentAlpha);

this.font.setColor(this.color);
this.font.draw(batch, this.text, getX(), getY());
}
}
6 changes: 6 additions & 0 deletions desktop/src/com/tres/client/ui/actor/ToggleButtonActor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.tres.client.ui.actor;

import com.badlogic.gdx.scenes.scene2d.Actor;

public class ToggleButtonActor extends Actor {
}
38 changes: 38 additions & 0 deletions desktop/src/com/tres/client/ui/layout/Layout.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.tres.client.ui.layout;

import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.Actor;

import java.util.ArrayList;

abstract public class Layout {

protected Vector2 position;
protected int width;
protected int height;

protected ArrayList<Actor> actors;

public Layout(Vector2 position, int width, int height) {
this.position = position;
this.width = width;
this.height = height;

this.actors = new ArrayList<>();
}

abstract public void set(Actor actor, int index);

public void add(Actor actor) {
this.actors.add(actor);

int index = 0;

for (Actor e : this.actors) {
this.set(e, index);

index++;
}
}

}
Loading

0 comments on commit 6d040e7

Please sign in to comment.