更新部分图片素材,修改选人界面,标题页面增加退出键
This commit is contained in:
@@ -1,10 +1,11 @@
|
|||||||
package uno.mloluyu.desktop;
|
package uno.mloluyu.desktop;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.Input;
|
||||||
|
import com.badlogic.gdx.InputProcessor;
|
||||||
import com.badlogic.gdx.graphics.Texture;
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
|
import uno.mloluyu.characters.AdvancedFighter;
|
||||||
import uno.mloluyu.network.NetworkManager;
|
import uno.mloluyu.network.NetworkManager;
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
@@ -14,7 +15,6 @@ import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
|||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
||||||
|
|
||||||
import uno.mloluyu.characters.AdvancedFighter;
|
|
||||||
import uno.mloluyu.characters.SimpleFighter;
|
import uno.mloluyu.characters.SimpleFighter;
|
||||||
import uno.mloluyu.util.ClearScreen;
|
import uno.mloluyu.util.ClearScreen;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -22,25 +22,32 @@ import java.util.List;
|
|||||||
|
|
||||||
import static uno.mloluyu.util.Font.loadChineseFont;
|
import static uno.mloluyu.util.Font.loadChineseFont;
|
||||||
|
|
||||||
public class CharacterSelectScreen extends ScreenAdapter {
|
public class CharacterSelectScreen extends ScreenAdapter implements InputProcessor {
|
||||||
private boolean multiplayerMode = false; // 默认为单人模式
|
private boolean multiplayerMode = false; // 默认为单人模式
|
||||||
|
|
||||||
private final MainGame game;
|
private final MainGame game;
|
||||||
private SpriteBatch batch;
|
private SpriteBatch batch;
|
||||||
private BitmapFont font;
|
private BitmapFont font;
|
||||||
private ShapeRenderer shapeRenderer;
|
private ShapeRenderer shapeRenderer;
|
||||||
|
private SimpleFighter selectedFighter1;
|
||||||
|
private SimpleFighter selectedFighter2;
|
||||||
|
|
||||||
private final List<Texture> bgs = Arrays.asList(
|
private final List<Texture> bgs = Arrays.asList(
|
||||||
new Texture(Gdx.files.internal("src/main/resources/selectpage/10b_back_blue2p.png")),
|
new Texture(Gdx.files.internal("src/main/resources/selectpage/10b_back_blue2p.png")),
|
||||||
new Texture(Gdx.files.internal("src/main/resources/selectpage/11b_back_red1p.png")),
|
//new Texture(Gdx.files.internal("src/main/resources/selectpage/back_door.png")),
|
||||||
new Texture(Gdx.files.internal("src/main/resources/selectpage/back_door.png"))
|
new Texture(Gdx.files.internal("src/main/resources/selectpage/11b_back_red1p.png"))
|
||||||
);
|
);
|
||||||
private final List<Texture> charsTexts = Arrays.asList(
|
private final List<Texture> charsTexts = Arrays.asList(
|
||||||
new Texture(Gdx.files.internal("src/main/resources/selectpage/character_03.png")),
|
new Texture(Gdx.files.internal("src/main/resources/selectpage/character_03.png")),
|
||||||
new Texture(Gdx.files.internal("src/main/resources/selectpage/character_00.png"))
|
new Texture(Gdx.files.internal("src/main/resources/selectpage/character_00.png"))
|
||||||
);
|
);
|
||||||
private final List<String> characters = Arrays.asList("Alice", "Reimu", "暂定");
|
private final List<String> characters = Arrays.asList("Alice", "Reimu", "暂定");
|
||||||
private int selectedIndex = -1;
|
private Texture profile1p = charsTexts.get(0);
|
||||||
|
private Texture profile2p = charsTexts.get(1);
|
||||||
|
private Texture selectText;
|
||||||
|
|
||||||
|
private static int selectedIndex = 0;
|
||||||
|
private static boolean is1P = true;
|
||||||
|
|
||||||
private static final int BUTTON_WIDTH = 300;
|
private static final int BUTTON_WIDTH = 300;
|
||||||
private static final int BUTTON_HEIGHT = 80;
|
private static final int BUTTON_HEIGHT = 80;
|
||||||
@@ -50,6 +57,7 @@ public class CharacterSelectScreen extends ScreenAdapter {
|
|||||||
|
|
||||||
public CharacterSelectScreen(MainGame game) {
|
public CharacterSelectScreen(MainGame game) {
|
||||||
this.game = game;
|
this.game = game;
|
||||||
|
Gdx.input.setInputProcessor(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMultiplayerMode(boolean multiplayerMode) {
|
public void setMultiplayerMode(boolean multiplayerMode) {
|
||||||
@@ -71,10 +79,9 @@ public class CharacterSelectScreen extends ScreenAdapter {
|
|||||||
|
|
||||||
int mouseX = Gdx.input.getX();
|
int mouseX = Gdx.input.getX();
|
||||||
int mouseY = Gdx.graphics.getHeight() - Gdx.input.getY();
|
int mouseY = Gdx.graphics.getHeight() - Gdx.input.getY();
|
||||||
|
renderBackground();
|
||||||
renderCharacters(mouseX, mouseY);
|
renderCharacters(multiplayerMode);
|
||||||
renderButtons(mouseX, mouseY);
|
// renderTexts();
|
||||||
renderTexts();
|
|
||||||
|
|
||||||
handleInput(mouseX, mouseY);
|
handleInput(mouseX, mouseY);
|
||||||
if (multiplayerMode) {
|
if (multiplayerMode) {
|
||||||
@@ -90,88 +97,41 @@ public class CharacterSelectScreen extends ScreenAdapter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renderCharacters(int mouseX, int mouseY) {
|
private void renderBackground() {
|
||||||
shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
|
|
||||||
for (int i = 0; i < characters.size(); i++) {
|
|
||||||
int x = 200;
|
|
||||||
int y = 500 - i * 120;
|
|
||||||
boolean hovered = isHovered(mouseX, mouseY, x, y, BUTTON_WIDTH, BUTTON_HEIGHT);
|
|
||||||
shapeRenderer.setColor(selectedIndex == i ? Color.GREEN : (hovered ? Color.LIGHT_GRAY : Color.DARK_GRAY));
|
|
||||||
shapeRenderer.rect(x, y, BUTTON_WIDTH, BUTTON_HEIGHT);
|
|
||||||
}
|
|
||||||
shapeRenderer.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void renderButtons(int mouseX, int mouseY) {
|
|
||||||
shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
|
|
||||||
drawButton(CONFIRM_Y, mouseX, mouseY, "确认");
|
|
||||||
drawButton(BACK_Y, mouseX, mouseY, "返回");
|
|
||||||
shapeRenderer.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void renderTexts() {
|
|
||||||
batch.begin();
|
batch.begin();
|
||||||
font.draw(batch, "选择你的角色", 200, 650);
|
for (int i = 0; i < bgs.size(); i ++) {
|
||||||
for (int i = 0; i < characters.size(); i++) {
|
batch.draw(bgs.get(i), 0, 528 * i, 1920, 528);
|
||||||
int x = 200 + 30;
|
|
||||||
int y = 500 - i * 120 + 50;
|
|
||||||
font.draw(batch, characters.get(i), x, y);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
if (selectedIndex != -1) {
|
|
||||||
font.draw(batch, "已选择: " + characters.get(selectedIndex), 200, 100);
|
|
||||||
}
|
|
||||||
drawButtonText(CONFIRM_Y, "确认");
|
|
||||||
drawButtonText(BACK_Y, "返回");
|
|
||||||
batch.end();
|
batch.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawButton(int y, int mouseX, int mouseY, String label) {
|
private void renderCharacters(boolean multiplayerMode) {
|
||||||
boolean hovered = isHovered(mouseX, mouseY, BUTTON_X, y, BUTTON_WIDTH, BUTTON_HEIGHT);
|
batch.begin();
|
||||||
shapeRenderer.setColor(hovered ? Color.LIGHT_GRAY : Color.DARK_GRAY);
|
batch.draw(profile1p, 0, 0, profile1p.getWidth()*3, profile1p.getHeight()*3);
|
||||||
shapeRenderer.rect(BUTTON_X, y, BUTTON_WIDTH, BUTTON_HEIGHT);
|
batch.draw(profile2p, 0, 528, profile2p.getWidth()*3, profile2p.getHeight()*3);
|
||||||
}
|
batch.end();
|
||||||
|
|
||||||
private void drawButtonText(int y, String text) {
|
|
||||||
float textX = BUTTON_X + BUTTON_WIDTH / 2f - font.getScaleX() * text.length() * 10;
|
|
||||||
float textY = y + BUTTON_HEIGHT / 2f + 20;
|
|
||||||
font.draw(batch, text, textX, textY);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isHovered(int x, int y, int bx, int by, int bw, int bh) {
|
|
||||||
return x >= bx && x <= bx + bw && y >= by && y <= by + bh;
|
|
||||||
}
|
}
|
||||||
|
//
|
||||||
|
// private void renderTexts() {
|
||||||
|
// batch.begin();
|
||||||
|
// font.draw(batch, "选择你的角色", 200, 650);
|
||||||
|
// for (int i = 0; i < characters.size(); i++) {
|
||||||
|
// int x = 200 + 30;
|
||||||
|
// int y = 500 - i * 120 + 50;
|
||||||
|
// font.draw(batch, characters.get(i), x, y);
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
// if (selectedIndex != -1) {
|
||||||
|
// font.draw(batch, "已选择: " + characters.get(selectedIndex), 200, 100);
|
||||||
|
// }
|
||||||
|
// drawButtonText(CONFIRM_Y, "确认");
|
||||||
|
// drawButtonText(BACK_Y, "返回");
|
||||||
|
// batch.end();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
|
||||||
private void handleInput(int mouseX, int mouseY) {
|
private void handleInput(int mouseX, int mouseY) {
|
||||||
if (Gdx.input.justTouched()) {
|
if (selectedFighter1 != null && selectedFighter2 != null) {
|
||||||
// 检查是否点击了角色按钮
|
|
||||||
for (int i = 0; i < characters.size(); i++) {
|
|
||||||
int x = 200;
|
|
||||||
int y = 500 - i * 120;
|
|
||||||
if (isHovered(mouseX, mouseY, x, y, BUTTON_WIDTH, BUTTON_HEIGHT)) {
|
|
||||||
selectedIndex = i;
|
|
||||||
Gdx.app.log("Character", "选择了角色: " + characters.get(i));
|
|
||||||
return; // 防止同时触发其他按钮
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 点击确认按钮
|
|
||||||
if (isHovered(mouseX, mouseY, BUTTON_X, CONFIRM_Y, BUTTON_WIDTH, BUTTON_HEIGHT)) {
|
|
||||||
if (selectedIndex != -1) {
|
|
||||||
String selectedCharacter = characters.get(selectedIndex);
|
|
||||||
Gdx.app.log("Character", "确认角色: " + selectedCharacter);
|
|
||||||
|
|
||||||
SimpleFighter fighter = null;
|
|
||||||
switch (selectedCharacter) {
|
|
||||||
case "Alice":
|
|
||||||
fighter = new AdvancedFighter("Alice");
|
|
||||||
break;
|
|
||||||
case "Reimu":
|
|
||||||
fighter = new AdvancedFighter("Reimu");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fighter != null) {
|
|
||||||
if (multiplayerMode) {
|
if (multiplayerMode) {
|
||||||
// 设置唯一玩家 ID 并发送角色选择
|
// 设置唯一玩家 ID 并发送角色选择
|
||||||
if (NetworkManager.getInstance().getLocalPlayerId() == null) {
|
if (NetworkManager.getInstance().getLocalPlayerId() == null) {
|
||||||
@@ -179,21 +139,12 @@ public class CharacterSelectScreen extends ScreenAdapter {
|
|||||||
NetworkManager.getInstance().setLocalPlayerId(playerId);
|
NetworkManager.getInstance().setLocalPlayerId(playerId);
|
||||||
Gdx.app.log("Network", "设置玩家ID: " + playerId);
|
Gdx.app.log("Network", "设置玩家ID: " + playerId);
|
||||||
}
|
}
|
||||||
NetworkManager.getInstance().sendCharacterSelection(selectedCharacter);
|
NetworkManager.getInstance().sendCharacterSelection(selectedFighter1.getName());
|
||||||
}
|
|
||||||
|
|
||||||
game.setScreen(new GameScreen(game, fighter));
|
|
||||||
}
|
}
|
||||||
|
game.setScreen(new GameScreen(game, selectedFighter1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 点击返回按钮
|
|
||||||
if (isHovered(mouseX, mouseY, BUTTON_X, BACK_Y, BUTTON_WIDTH, BUTTON_HEIGHT)) {
|
|
||||||
Gdx.app.log("Character", "返回主菜单");
|
|
||||||
game.setScreen(new MainMenuScreen(game));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
@@ -201,4 +152,78 @@ public class CharacterSelectScreen extends ScreenAdapter {
|
|||||||
font.dispose();
|
font.dispose();
|
||||||
shapeRenderer.dispose();
|
shapeRenderer.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean keyDown(int i) {
|
||||||
|
boolean value = false;
|
||||||
|
if (!multiplayerMode) {
|
||||||
|
if (i == Input.Keys.LEFT || i == Input.Keys.RIGHT) {
|
||||||
|
selectText = charsTexts.get(selectedIndex);
|
||||||
|
selectedIndex = (selectedIndex + 1) % charsTexts.size();
|
||||||
|
if (is1P) {
|
||||||
|
profile1p = selectText;
|
||||||
|
} else {
|
||||||
|
profile2p = selectText;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
value = true;
|
||||||
|
} else {
|
||||||
|
//占坑说是
|
||||||
|
}
|
||||||
|
if (i == Input.Keys.Z) {
|
||||||
|
if (is1P) {
|
||||||
|
selectedFighter1 = new AdvancedFighter(characters.get(selectedIndex));
|
||||||
|
} else {
|
||||||
|
selectedFighter2 = new AdvancedFighter(characters.get(selectedIndex));
|
||||||
|
}
|
||||||
|
is1P = false;
|
||||||
|
selectedIndex = 1;
|
||||||
|
value = true;
|
||||||
|
}
|
||||||
|
if (i == Input.Keys.ESCAPE) {
|
||||||
|
Gdx.app.log("Character", "返回主菜单");
|
||||||
|
game.setScreen(new MainMenuScreen(game));
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean keyUp(int i) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean keyTyped(char c) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean touchDown(int i, int i1, int i2, int i3) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean touchUp(int i, int i1, int i2, int i3) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean touchCancelled(int i, int i1, int i2, int i3) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean touchDragged(int i, int i1, int i2) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean mouseMoved(int i, int i1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean scrolled(float v, float v1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ public class MainMenuScreen extends ScreenAdapter {
|
|||||||
public MainMenuScreen(MainGame game) {
|
public MainMenuScreen(MainGame game) {
|
||||||
this.game = game;
|
this.game = game;
|
||||||
texture = new Texture(Gdx.files.internal("src\\main\\resources\\bg.png"));
|
texture = new Texture(Gdx.files.internal("src\\main\\resources\\bg.png"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,16 +1,12 @@
|
|||||||
package uno.mloluyu.versatile;
|
package uno.mloluyu.versatile;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.InputAdapter;
|
||||||
|
import com.badlogic.gdx.utils.Array;
|
||||||
|
import uno.mloluyu.characters.SimpleFighter;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
|
||||||
import com.badlogic.gdx.Input;
|
|
||||||
import com.badlogic.gdx.InputAdapter;
|
|
||||||
import com.badlogic.gdx.utils.Array;
|
|
||||||
import uno.mloluyu.characters.character.Action;
|
|
||||||
import uno.mloluyu.characters.character.Fighter;
|
|
||||||
import uno.mloluyu.characters.SimpleFighter;
|
|
||||||
|
|
||||||
public class FighterController extends InputAdapter {
|
public class FighterController extends InputAdapter {
|
||||||
private final SimpleFighter fighter;
|
private final SimpleFighter fighter;
|
||||||
private final Array<Integer> pressedKeys = new Array<>();
|
private final Array<Integer> pressedKeys = new Array<>();
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 2.3 MiB |
Binary file not shown.
|
Before Width: | Height: | Size: 3.0 MiB |
Binary file not shown.
|
Before Width: | Height: | Size: 1.1 MiB |
Reference in New Issue
Block a user