Skip to content

Commit

Permalink
添加钻头,顺便增加了选择的提示
Browse files Browse the repository at this point in the history
  • Loading branch information
bin-tenkuu committed Nov 9, 2020
1 parent 34c455f commit 84abe84
Show file tree
Hide file tree
Showing 8 changed files with 323 additions and 32 deletions.
Binary file added assets/sprites/blocks/Bin_Block5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 1 addition & 2 deletions mod.hjson
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ name:进攻返利Mod
displayName:进攻返利mod
description:'''
[red]打开服务器获得更多操作[]
击败敌对单位获得{0-波数*100}随机资源
击毁敌对建筑获得100%建造资源
建筑:物品转换器,核心连接器,跳波灭火器,单位召唤器
建筑:物品转换器,核心连接器,跳波灭火器,单位召唤器,钻头
'''
author:bin
main:com.TestMod
Expand Down
70 changes: 60 additions & 10 deletions src/com/Tools.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,74 @@
package com;

import arc.math.Mathf;
import arc.math.Rand;
import arc.func.Cons;
import arc.func.Prov;
import arc.scene.style.TextureRegionDrawable;
import arc.scene.ui.ButtonGroup;
import arc.scene.ui.ImageButton;
import arc.scene.ui.ScrollPane;
import arc.scene.ui.layout.Scl;
import arc.scene.ui.layout.Table;
import arc.struct.Seq;
import mindustry.Vars;
import mindustry.core.NetClient;
import mindustry.type.Item;
import mindustry.type.ItemStack;
import mindustry.ctype.UnlockableContent;
import mindustry.entities.Units;
import mindustry.ui.Cicon;
import mindustry.ui.Styles;

/**
* @author bin
*/
public final class Tools {

public static ItemStack getRandomItemStack(int num) {
Seq<Item> items = Vars.content.items();
return new ItemStack(items.random(), Mathf.random(num));
public static <T extends UnlockableContent> void buildItemSelectTable(
Table table, Seq<T> items, Prov<T> holder, Cons<T> changed
) {
Tools.buildItemSelectTable(table, items, holder, changed, true);
}

public static void chat(String format, Object... args) {
NetClient.sendMessage(String.format(format, args), "Admin", Vars.player);
/**
* 自动生成选择表
* @param table 表
* @param items 物品集合
* @param holder 需要返回当前选择项以高亮
* @param changed 改变时调用
* @param closeSelected 选择后自动关闭列表
* @param <T> 可解锁对象
*/
public static <T extends UnlockableContent> void buildItemSelectTable(
Table table, Seq<T> items, Prov<T> holder, Cons<T> changed, boolean closeSelected
) {
ButtonGroup<ImageButton> group = new ButtonGroup<>();
group.setMinCheckCount(0);
Table cont = new Table();
cont.defaults().size(40.0F);
int i = 0;

for (T t : items) {
if (t.unlockedNow()) {
ImageButton button =
cont.button(new TextureRegionDrawable(t.icon(Cicon.small)), Styles.clearToggleTransi, 24.0F, () -> {
if (closeSelected) {
Vars.control.input.frag.config.hideConfig();
}
}).group(group).tooltip(t.localizedName).get();
button.changed(() -> changed.get(button.isChecked() ? t : null));
button.update(() -> button.setChecked(holder.get() == t));
if (i++ >= 3) {
cont.row();
i = 0;
}
}
}

for (; i < 4; ++i) {
cont.image(Styles.black6);
}

ScrollPane pane = new ScrollPane(cont, Styles.smallPane);
pane.setScrollingDisabled(true, false);
pane.setOverscroll(false, false);
table.add(pane).maxHeight(Scl.scl(200.0F));
}

}
32 changes: 22 additions & 10 deletions src/com/content/MyContextList.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.content;

import arc.scene.ui.layout.Table;
import com.Tools;
import com.content.blocks.CommendBlock;
import com.content.blocks.FastestDrill;
import com.content.blocks.ItemChange;
import com.content.blocks.LinkCoreBlock;
import mindustry.Vars;
Expand All @@ -17,7 +19,6 @@
import mindustry.type.ItemStack;
import mindustry.ui.Styles;
import mindustry.world.Block;
import mindustry.world.blocks.ItemSelection;
import mindustry.world.meta.BuildVisibility;

/**
Expand All @@ -27,7 +28,7 @@
@SuppressWarnings("unused")
public class MyContextList implements ContentList {
public static Block
Bin_Block1, Bin_Block2, Bin_Block3, Bin_Block4;
Bin_Block1, Bin_Block2, Bin_Block3, Bin_Block4, Bin_Block5;

@Override public void load() {
Bin_Block1 = new ItemChange("Bin_Block1") {
Expand Down Expand Up @@ -64,31 +65,42 @@ public class MyContextList implements ContentList {
this.size = 2;
this.requirements(Category.effect, BuildVisibility.shown, ItemStack.empty);

this.commend = (building, table) -> ItemSelection.buildTable(
this.commend = (building, table) -> Tools.buildItemSelectTable(
table,
Vars.content.units(),
() -> null,
unitType -> {
Unit unit = unitType.create(building.team());
unit.set(building.x, building.y + 1);
unit.add();
}
},
false
);
}
};
Bin_Block5 = new FastestDrill("Bin_Block5") {
{
this.localizedName = "量子钻头";
this.description = "[red]极限产出,不可加速[]\n" +
"[green]我在短暂的钻头生涯当中学到了一件事," +
"越是想要钻的更快,越是会受到各种限制," +
"除非超越钻头,我不做钻头了![]\n" +
"(现在产出速度比物品源还快了";
this.size = 2;
this.requirements(Category.production, BuildVisibility.shown, ItemStack.with(Items.copper, 20));
}
};
}

private static void display(Building building, Table table) {
table.button(Icon.upOpen, Styles.clearTransi, (() -> {
Vars.logic.skipWave();
})).size(50).tooltip("下一波");
table.button(Icon.upOpen, Styles.clearTransi, (() -> Vars.logic.skipWave())).size(50).tooltip("下一波");
table.button(Icon.warningSmall, Styles.clearTransi, (() -> {
for (int i = 0; i < 10; i++) {
Vars.logic.runWave();
}
})).size(50).tooltip("跳10波");
table.button(Icon.file, Styles.clearTransi, () -> {
Groups.all.each(syncs -> syncs instanceof Firec, Entityc::remove);
}).size(50).tooltip("快速灭火");
table.button(Icon.file, Styles.clearTransi, () ->
Groups.all.each(syncs -> syncs instanceof Firec, Entityc::remove)
).size(50).tooltip("快速灭火");
}
}
20 changes: 16 additions & 4 deletions src/com/content/MyTechTreeList.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.content;

import arc.util.Nullable;
import mindustry.content.TechTree;
import mindustry.ctype.ContentList;
import mindustry.ctype.UnlockableContent;
Expand All @@ -16,16 +17,27 @@ public class MyTechTreeList implements ContentList {
public static TechTree.TechNode node(
TechTree.TechNode parent,
UnlockableContent content,
Consumer<TechTree.TechNode> children
@Nullable Consumer<TechTree.TechNode> children
) {
TechTree.TechNode node = new TechTree.TechNode(parent, content, content.researchRequirements());
children.accept(node);
if (children != null) {
children.accept(node);
}
return node;
}

public static TechTree.TechNode node(
TechTree.TechNode parent,
UnlockableContent content
) {
return node(parent, content, (t) -> {});
}

@Override public void load() {
root = node(TechTree.root, MyContextList.Bin_Block1, parent -> {
node(parent, MyContextList.Bin_Block2, techNode -> {});
root = node(TechTree.root, MyContextList.Bin_Block5, (t1) -> {
node(t1, MyContextList.Bin_Block2, (t2) -> {
node(t2, MyContextList.Bin_Block1);
});
});
}
}
Loading

0 comments on commit 84abe84

Please sign in to comment.