forked from Anuken/MindustryJavaModTemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
34c455f
commit 84abe84
Showing
8 changed files
with
323 additions
and
32 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.