Update SpawnArmor.java

This commit is contained in:
zxcPandora 2023-10-29 20:54:48 +08:00
parent c2b7efd310
commit 15b882e60e

View File

@ -231,29 +231,42 @@ public class SpawnArmor extends TestItem {
return null; return null;
} }
/**
* 护甲设置窗口类继承自Window类
*/
private class ArmorSetting extends Window { private class ArmorSetting extends Window {
private static final int WIDTH = 150;
// 定义常量
private static final int WIDTH = 150; // 窗口宽度
private static final int HEIGHT = 250; // 窗口高度 private static final int HEIGHT = 250; // 窗口高度
private static final int GAP = 2; private static final int GAP = 2; // 间隔大小
private static final int BTN_SIZE = 18; // 按钮尺寸 private static final int BTN_SIZE = 18; // 按钮尺寸
private static final int MAX_ICONS_PER_LINE = 7; // 每行最大图标数量 private static final int MAX_ICONS_PER_LINE = 7; // 每行最大图标数量
private Class[] AllArmor; // 所有武器的Class数组 // 成员变量
private CheckBox CheckBox_curse; private Class[] AllArmor; // 所有护甲的Class数组
private RenderedTextBlock RenderedTextBlock_enchantInfo; private CheckBox CheckBox_curse; // 诅咒物品复选框
private OptionSlider OptionSlider_enchantId; private RenderedTextBlock RenderedTextBlock_enchantInfo; // 附魔信息文本块
private OptionSlider OptionSlider_enchantRarity; private OptionSlider OptionSlider_enchantId; // 附魔编号选项滑块
private RedButton RedButton_create; private OptionSlider OptionSlider_enchantRarity; // 附魔种类选项滑块
private final ArrayList<IconButton> IconButtons = new ArrayList<>(); private RedButton RedButton_create; // 创建武器按钮
private final ArrayList<IconButton> IconButtons = new ArrayList<>(); // 图标按钮列表
private final RedButton Button_Level; // 武器等级按钮 private final RedButton Button_Level; // 武器等级按钮
/**
* 构造函数用于初始化窗口
*/
public ArmorSetting() { public ArmorSetting() {
super(); super();
// 设置窗口尺寸
resize(WIDTH, HEIGHT); resize(WIDTH, HEIGHT);
// 创建护甲列表及图标
createArmorList(); createArmorList();
createArmorImage(AllArmor); createArmorImage(AllArmor);
// 创建护甲等级按钮
Button_Level = new RedButton(Messages.get(this, "select_armor")) { Button_Level = new RedButton(Messages.get(this, "select_armor")) {
@Override @Override
protected void onClick() { protected void onClick() {
@ -280,12 +293,14 @@ public class SpawnArmor extends TestItem {
Button_Level.text(((Armor) Reflection.newInstance(getArmor(armor_id).getClass())).name()); Button_Level.text(((Armor) Reflection.newInstance(getArmor(armor_id).getClass())).name());
add(Button_Level); add(Button_Level);
// 创建附魔信息文本块
RenderedTextBlock_enchantInfo = PixelScene.renderTextBlock("", 6); RenderedTextBlock_enchantInfo = PixelScene.renderTextBlock("", 6);
RenderedTextBlock_enchantInfo.text(infoBuilder()); RenderedTextBlock_enchantInfo.text(infoBuilder());
RenderedTextBlock_enchantInfo.visible = true; RenderedTextBlock_enchantInfo.visible = true;
RenderedTextBlock_enchantInfo.maxWidth(WIDTH); RenderedTextBlock_enchantInfo.maxWidth(WIDTH);
add(RenderedTextBlock_enchantInfo); add(RenderedTextBlock_enchantInfo);
// 创建附魔种类选项滑块
OptionSlider_enchantRarity = new OptionSlider(Messages.get(this, "enchant_rarity"), "0", "4", 0, 4) { OptionSlider_enchantRarity = new OptionSlider(Messages.get(this, "enchant_rarity"), "0", "4", 0, 4) {
@Override @Override
protected void onChange() { protected void onChange() {
@ -296,6 +311,7 @@ public class SpawnArmor extends TestItem {
OptionSlider_enchantRarity.setSelectedValue(enchant_rarity); OptionSlider_enchantRarity.setSelectedValue(enchant_rarity);
add(OptionSlider_enchantRarity); add(OptionSlider_enchantRarity);
// 创建附魔编号选项滑块
OptionSlider_enchantId = new OptionSlider(Messages.get(this, "enchant_id"), "0", "7", 0, 7) { OptionSlider_enchantId = new OptionSlider(Messages.get(this, "enchant_id"), "0", "7", 0, 7) {
@Override @Override
protected void onChange() { protected void onChange() {
@ -306,6 +322,7 @@ public class SpawnArmor extends TestItem {
OptionSlider_enchantId.setSelectedValue(enchant_id); OptionSlider_enchantId.setSelectedValue(enchant_id);
add(OptionSlider_enchantId); add(OptionSlider_enchantId);
// 创建诅咒物品复选框
CheckBox_curse = new CheckBox(Messages.get(this, "cursed")) { CheckBox_curse = new CheckBox(Messages.get(this, "cursed")) {
@Override @Override
protected void onClick() { protected void onClick() {
@ -316,6 +333,7 @@ public class SpawnArmor extends TestItem {
CheckBox_curse.checked(cursed); CheckBox_curse.checked(cursed);
add(CheckBox_curse); add(CheckBox_curse);
// 创建生成护甲按钮
RedButton_create = new RedButton(Messages.get(this, "create")) { RedButton_create = new RedButton(Messages.get(this, "create")) {
@Override @Override
protected void onClick() { protected void onClick() {
@ -327,6 +345,9 @@ public class SpawnArmor extends TestItem {
layout(); layout();
} }
/**
* 封装一个同步UI的方法用于调整UI组件的位置和大小
*/
private void layout() { private void layout() {
Button_Level.setRect(0, GAP , WIDTH, 24); Button_Level.setRect(0, GAP , WIDTH, 24);
RenderedTextBlock_enchantInfo.setPos(0, GAP + Button_Level.top() + Button_Level.height()); RenderedTextBlock_enchantInfo.setPos(0, GAP + Button_Level.top() + Button_Level.height());
@ -337,6 +358,16 @@ public class SpawnArmor extends TestItem {
resize(WIDTH, (int) RedButton_create.bottom()); resize(WIDTH, (int) RedButton_create.bottom());
} }
@Override
public synchronized void update() {
super.update();
// 实时同步UI
layout();
}
/**
* 创建护甲列表
*/
private void createArmorList() { private void createArmorList() {
//AllArmor = Generator.Category.ARMOR.classes.clone(); //AllArmor = Generator.Category.ARMOR.classes.clone();
AllArmor = new Class<?>[]{ AllArmor = new Class<?>[]{
@ -348,6 +379,12 @@ public class SpawnArmor extends TestItem {
LamellarArmor.class, LamellarArmor.class,
AncityArmor.class}; AncityArmor.class};
} }
/**
* 创建护甲图标并添加到窗口中
*
* @param all 所有护甲的Class数组
*/
private void createArmorImage(Class<? extends Armor>[] all) { private void createArmorImage(Class<? extends Armor>[] all) {
float left = BTN_SIZE / 2f; float left = BTN_SIZE / 2f;
float top = 27; float top = 27;
@ -359,7 +396,7 @@ public class SpawnArmor extends TestItem {
@Override @Override
protected void onClick() { protected void onClick() {
armor_id = Math.min(maxSlots(armor_id) - 1, j); armor_id = Math.min(maxSlots(armor_id) - 1, j);
updateSelectedWeaponText(); updateSelectedArmorText();
super.onClick(); super.onClick();
} }
}; };
@ -378,12 +415,19 @@ public class SpawnArmor extends TestItem {
} }
} }
private void updateSelectedWeaponText() { /**
* 更新选中的武器文本
*/
private void updateSelectedArmorText() {
Armor armor = (Armor) Reflection.newInstance(getArmor(armor_id).getClass()); Armor armor = (Armor) Reflection.newInstance(getArmor(armor_id).getClass());
Button_Level.text(armor.name()); Button_Level.text(armor.name());
layout(); layout();
} }
/**
* 获取附魔信息文本
* @return 附魔信息文本
*/
private String infoBuilder() { private String infoBuilder() {
//String desc = Messages.get(BossRushArmor.class, "enchant_id_pre", enchant_rarity); //String desc = Messages.get(BossRushArmor.class, "enchant_id_pre", enchant_rarity);
String desc = ""; String desc = "";