Add GUI tabs, strategy presets and Baritone bridge wiring
- GUI: three tabs (Build / Placement / Supply placeholder) - Presets max/safe/custom: BuildSettings.applyPreset, `.build preset` - BaritoneBridge implements Walker and is passed to BuilderFeature.create - Tests for the preset subcommand
This commit is contained in:
parent
da99a448e1
commit
e2bdf031a8
15 changed files with 503 additions and 148 deletions
18
README.md
18
README.md
|
|
@ -45,14 +45,24 @@ Gradle запускается на JVM 25: если дефолтная JVM др
|
|||
| `.build shape box\|checker\|walls` | форма застройки области |
|
||||
| `.build layers 1..3` | слоёв за один проход колонны |
|
||||
| `.build strategy <id>` | стратегия постановки (см. таблицу ниже) |
|
||||
| `.build preset max\|safe\|custom` | пресет: «макс» (S1+S2, задержка 0) или «безопасный» (S3+S5, задержка 150 мс) |
|
||||
| `.build set <ключ> <знач>` | параметр стратегии (`delayMs`, `reach`, `hover`, `flySpeed`, `bandLayers`, `burst`) |
|
||||
|
||||
### GUI (Right Shift)
|
||||
|
||||
Pos1/Pos2 — зафиксировать текущую позицию ног; Старт/Пауза/Продолжить/Стоп; форма;
|
||||
стратегия (циклическая кнопка — панель параметров выбранной стратегии перестраивается
|
||||
автоматически); слайдеры параметров стратегии; тема (оранжевый/белый/мятный/песочный
|
||||
акцент, выбор сохраняется в `config/satura/render.json`); ID блока (Enter — применить).
|
||||
Экран из трёх вкладок.
|
||||
|
||||
**Стройка** — Pos1/Pos2 (позиция ног), Старт/Пауза/Стоп, форма, тема
|
||||
(оранжевый/белый/мятный/песочный акцент, выбор сохраняется в `config/satura/render.json`),
|
||||
ID блока (Enter — применить).
|
||||
|
||||
**Постановка** — стратегия (циклическая кнопка — панель параметров выбранной стратегии
|
||||
перестраивается автоматически), пресеты одним кликом: `max` (S1+S2, задержка 0 мс),
|
||||
`safe` (S3+S5, задержка 150 мс — для серверов с анти-читом), `custom` (текущие значения);
|
||||
слайдеры параметров стратегии.
|
||||
|
||||
**Снабжение** — появится в фазе 11 (маршруты до сундуков, телепорты, авто-подбор).
|
||||
|
||||
Внизу — живой статус: этап, прогресс, блоков/с, дыры. Во время стройки тот же статус
|
||||
раз в секунду дублируется над хотбаром.
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import dev.loki.satura.core.command.builtin.HelpCommand;
|
|||
import dev.loki.satura.core.config.ConfigStore;
|
||||
import dev.loki.satura.core.event.EventBus;
|
||||
import dev.loki.satura.feature.builder.BuilderFeature;
|
||||
import dev.loki.satura.feature.builder.baritone.BaritoneBridge;
|
||||
import dev.loki.satura.gui.BuilderUi;
|
||||
import dev.loki.satura.gui.ThemePref;
|
||||
import dev.loki.satura.render.RenderDebug;
|
||||
|
|
@ -36,7 +37,7 @@ public final class SaturaClient implements ClientModInitializer {
|
|||
commands.register(new HelpCommand(commands));
|
||||
EventBus events = new EventBus();
|
||||
ConfigStore config = new ConfigStore(FabricLoader.getInstance().getConfigDir().resolve(MOD_ID));
|
||||
BuilderFeature builder = BuilderFeature.create(commands, events, config);
|
||||
BuilderFeature builder = BuilderFeature.create(commands, events, config, BaritoneBridge.create());
|
||||
CoreServices.install(new CoreServices(events, commands, config));
|
||||
ClientTickEvents.END_CLIENT_TICK.register(client -> builder.tick());
|
||||
RenderDebug.installIfEnabled(Renderer.shared());
|
||||
|
|
|
|||
|
|
@ -36,6 +36,18 @@ public final class BuildSettings {
|
|||
private static final String DEFAULT_BLOCK = "hand";
|
||||
private static final String DEFAULT_SHAPE = "box";
|
||||
|
||||
/** Preset ids: max speed (S1+S2), safe for anti-cheat servers (S3+S5), custom (keeps values). */
|
||||
public static final String PRESET_MAX = "max";
|
||||
public static final String PRESET_SAFE = "safe";
|
||||
public static final String PRESET_CUSTOM = "custom";
|
||||
private static final String STRATEGY_MAX_1 = "band_stack";
|
||||
private static final String STRATEGY_MAX_2 = "column_drop";
|
||||
private static final String STRATEGY_SAFE_1 = "precise";
|
||||
private static final String STRATEGY_SAFE_2 = "ground_walk";
|
||||
private static final int SAFE_DELAY_MS = 150;
|
||||
private static final int MAX_DELAY_MS = 0;
|
||||
private static final List<String> PRESET_IDS = List.of(PRESET_MAX, PRESET_SAFE, PRESET_CUSTOM);
|
||||
|
||||
private final Map<String, Shape> shapes = new LinkedHashMap<>();
|
||||
private final Map<String, PlaceStrategy> strategies = new LinkedHashMap<>();
|
||||
private String block;
|
||||
|
|
@ -142,6 +154,37 @@ public final class BuildSettings {
|
|||
}
|
||||
}
|
||||
|
||||
public List<String> presetIds() {
|
||||
return PRESET_IDS;
|
||||
}
|
||||
|
||||
/** One-click presets: strategy choice plus the matching delays; custom keeps the current values. */
|
||||
public String applyPreset(final String id) {
|
||||
return switch (id) {
|
||||
case PRESET_MAX -> {
|
||||
setStrategy(STRATEGY_MAX_1);
|
||||
setDelay(STRATEGY_MAX_1, MAX_DELAY_MS);
|
||||
setDelay(STRATEGY_MAX_2, MAX_DELAY_MS);
|
||||
yield "Пресет: макс (" + STRATEGY_MAX_1 + ", задержка " + MAX_DELAY_MS + " мс)";
|
||||
}
|
||||
case PRESET_SAFE -> {
|
||||
setStrategy(STRATEGY_SAFE_1);
|
||||
setDelay(STRATEGY_SAFE_1, SAFE_DELAY_MS);
|
||||
setDelay(STRATEGY_SAFE_2, SAFE_DELAY_MS);
|
||||
yield "Пресет: безопасный (" + STRATEGY_SAFE_1 + ", задержка " + SAFE_DELAY_MS + " мс)";
|
||||
}
|
||||
case PRESET_CUSTOM -> "Пресет: свои значения";
|
||||
default -> throw new IllegalArgumentException("пресет: " + PRESET_IDS);
|
||||
};
|
||||
}
|
||||
|
||||
private void setDelay(final String strategyId, final int delayMs) {
|
||||
final PlaceStrategy s = strategies.get(strategyId);
|
||||
if (s != null && s.options().contains(CommonOptions.DELAY_MS)) {
|
||||
s.values().set(CommonOptions.DELAY_MS.key(), delayMs);
|
||||
}
|
||||
}
|
||||
|
||||
public Profile toProfile(final String name) {
|
||||
Profile p = Profile.empty(name).with(KEY_BLOCK, block).with(KEY_SHAPE, shape)
|
||||
.with(KEY_STRATEGY, strategy).with(KEY_LAYERS, String.valueOf(layers));
|
||||
|
|
|
|||
|
|
@ -193,6 +193,16 @@ public final class BuilderFeature implements BuildControl {
|
|||
return changed("Слоёв за проход: " + layers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> presetIds() {
|
||||
return settings.presetIds();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String applyPreset(final String id) {
|
||||
return changed(settings.applyPreset(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> blockIds() {
|
||||
return assembler.blocks().ids();
|
||||
|
|
|
|||
|
|
@ -1,14 +1,18 @@
|
|||
package dev.loki.satura.feature.builder.baritone;
|
||||
|
||||
import dev.loki.satura.feature.builder.engine.walk.Walker;
|
||||
import java.util.function.BooleanSupplier;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/** Bridge to Baritone (Aethereal): reflection only; any error disables the bridge with a single log entry. */
|
||||
/**
|
||||
* Bridge to Baritone (Aethereal): reflection only; any error disables the bridge with a single log
|
||||
* entry. Implements both walker ports, so it plugs straight into the feature factory.
|
||||
*/
|
||||
@SuppressWarnings({"PMD.AvoidFieldNameMatchingMethodName", "PMD.AvoidCatchingGenericException",
|
||||
"PMD.GuardLogStatement"})
|
||||
public final class BaritoneBridge implements WalkerPort {
|
||||
public final class BaritoneBridge implements WalkerPort, Walker {
|
||||
|
||||
static final String MOD_ID = "baritone-meteor";
|
||||
private static final Logger LOG = LoggerFactory.getLogger(BaritoneBridge.class);
|
||||
|
|
|
|||
|
|
@ -25,6 +25,10 @@ public interface BuildControl {
|
|||
|
||||
String setLayers(int layers);
|
||||
|
||||
List<String> presetIds();
|
||||
|
||||
String applyPreset(String id);
|
||||
|
||||
List<String> blockIds();
|
||||
|
||||
List<String> strategyIds();
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ final class BuildSubs {
|
|||
SubCommand.value("strategy", c::strategyIds, c::setStrategy),
|
||||
SubCommand.value("shape", c::shapeIds, c::setShape),
|
||||
SubCommand.value("layers", () -> List.of("1", "2", "3"), v -> c.setLayers(parse(v))),
|
||||
SubCommand.value("preset", c::presetIds, c::applyPreset),
|
||||
set(c));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,53 +1,48 @@
|
|||
package dev.loki.satura.gui.screen;
|
||||
|
||||
import dev.loki.satura.core.config.ConfigStore;
|
||||
import dev.loki.satura.feature.builder.BuildSettings;
|
||||
import dev.loki.satura.feature.builder.BuilderFeature;
|
||||
import dev.loki.satura.feature.builder.engine.Stage;
|
||||
import dev.loki.satura.gui.ThemePref;
|
||||
import dev.loki.satura.gui.widget.CycleButton;
|
||||
import dev.loki.satura.gui.widget.NumberSlider;
|
||||
import dev.loki.satura.gui.screen.content.BuildTab;
|
||||
import dev.loki.satura.gui.screen.content.PlaceTab;
|
||||
import dev.loki.satura.gui.screen.content.SupplyTab;
|
||||
import dev.loki.satura.render.Renderer;
|
||||
import dev.loki.satura.render.Theme;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Supplier;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.client.gui.widget.ClickableWidget;
|
||||
import net.minecraft.client.gui.widget.TextFieldWidget;
|
||||
import net.minecraft.client.input.KeyInput;
|
||||
import net.minecraft.client.option.KeyBinding;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
/**
|
||||
* Builder screen: selection, start/pause/stop, shape, strategy (with its own option sliders),
|
||||
* block id, theme, status line. Strategy change rebuilds the option area.
|
||||
* Tabbed builder screen: the panel, the tab bar (build / placement / supply) and the status
|
||||
* line are shared; tab content is provided by {@link Tab} implementations.
|
||||
*/
|
||||
@SuppressWarnings("PMD.AvoidCatchingGenericException")
|
||||
public final class BuilderScreen extends Screen {
|
||||
public final class BuilderScreen extends Screen implements Tab.Host {
|
||||
|
||||
private static final int FIXED_ROWS = 6;
|
||||
private static final int TAB_COUNT = 3;
|
||||
private static final int TAB_BUILD = 0;
|
||||
private static final int TAB_PLACE = 1;
|
||||
private static final int TAB_BAR_ROWS = 1;
|
||||
private static final int GRID_THIRD = 3;
|
||||
private static final int NOTICE_TICKS = 100;
|
||||
private static final int MAX_BLOCK_LEN = 64;
|
||||
private static final int POS1 = 1;
|
||||
private static final int POS2 = 2;
|
||||
private static final String LANG_POS1 = "satura.gui.pos1";
|
||||
private static final String LANG_POS2 = "satura.gui.pos2";
|
||||
private static final String LANG_PAUSE = "satura.gui.pause";
|
||||
private static final String LANG_RESUME = "satura.gui.resume";
|
||||
private static final String NOTICE_ERROR = "ошибка";
|
||||
private static final List<String> TAB_KEYS =
|
||||
List.of("satura.gui.tab.build", "satura.gui.tab.place", "satura.gui.tab.supply");
|
||||
|
||||
private final BuilderFeature builder;
|
||||
private final KeyBinding openMenu;
|
||||
private final ConfigStore store;
|
||||
private Panel panel;
|
||||
private ButtonWidget pos1Button;
|
||||
private ButtonWidget pos2Button;
|
||||
private ButtonWidget pauseButton;
|
||||
private TextFieldWidget blockField;
|
||||
private Text notice = Text.empty();
|
||||
private Tab tab;
|
||||
private int tabIndex = TAB_BUILD;
|
||||
private Text noticeText = Text.empty();
|
||||
private int noticeTicks;
|
||||
private boolean reinitQueued;
|
||||
|
||||
|
|
@ -60,42 +55,13 @@ public final class BuilderScreen extends Screen {
|
|||
|
||||
@Override
|
||||
protected void init() {
|
||||
final List<BuildSettings.Slider> options = visibleOptions();
|
||||
panel = new Panel(width, height, FIXED_ROWS + options.size());
|
||||
final int inner = panel.inner();
|
||||
final int left = panel.left();
|
||||
final int half = (inner - Panel.GAP) / 2;
|
||||
final int third = (inner - Panel.GAP * 2) / 3;
|
||||
int y = panel.top() + Panel.PAD + Panel.TITLE_H + Panel.GAP;
|
||||
pos1Button = addDrawableChild(button(LANG_POS1, () -> capture(POS1), left, y, half));
|
||||
pos2Button = addDrawableChild(button(LANG_POS2, () -> capture(POS2), left + half + Panel.GAP, y, half));
|
||||
y += Panel.WIDGET_H + Panel.GAP;
|
||||
addDrawableChild(button("satura.gui.start", () -> run(builder::start), left, y, third));
|
||||
pauseButton = addDrawableChild(button(LANG_PAUSE,
|
||||
() -> run(() -> builder.stage() == Stage.PAUSED ? builder.resume() : builder.pause()),
|
||||
left + third + Panel.GAP, y, third));
|
||||
addDrawableChild(button("satura.gui.stop", () -> run(builder::stop),
|
||||
left + (third + Panel.GAP) * 2, y, third));
|
||||
y += Panel.WIDGET_H + Panel.GAP;
|
||||
addDrawableChild(new CycleButton(left, y, inner, Panel.WIDGET_H, "satura.gui.shape",
|
||||
builder.shapeIds(), builder.settings().shapeId(), id -> run(() -> builder.setShape(id))));
|
||||
y += Panel.WIDGET_H + Panel.GAP;
|
||||
addDrawableChild(new CycleButton(left, y, inner, Panel.WIDGET_H, "satura.gui.strategy",
|
||||
builder.strategyIds(), builder.settings().strategy().id(), this::changeStrategy));
|
||||
y += Panel.WIDGET_H + Panel.GAP;
|
||||
for (final BuildSettings.Slider option : options) {
|
||||
addDrawableChild(optionSlider(left, y, inner, option));
|
||||
y += Panel.WIDGET_H + Panel.GAP;
|
||||
}
|
||||
addDrawableChild(new CycleButton(left, y, inner, Panel.WIDGET_H, "satura.gui.theme",
|
||||
Theme.all().stream().map(Theme::id).toList(), Theme.get().id(),
|
||||
id -> run(() -> setTheme(id))));
|
||||
y += Panel.WIDGET_H + Panel.GAP;
|
||||
blockField = new TextFieldWidget(textRenderer, left, y, inner, Panel.WIDGET_H,
|
||||
Text.translatable("satura.gui.block"));
|
||||
blockField.setMaxLength(MAX_BLOCK_LEN);
|
||||
blockField.setText(builder.settings().block());
|
||||
addSelectableChild(blockField);
|
||||
final int rowCap = Math.max(0, usableRows() - TAB_BAR_ROWS);
|
||||
tab = createTab(rowCap);
|
||||
panel = new Panel(width, height, TAB_BAR_ROWS + tab.rows());
|
||||
final Tab.Grid grid = grid();
|
||||
final int barY = panel.top() + Panel.PAD + Panel.TITLE_H + Panel.GAP;
|
||||
addTabButtons(barY, grid);
|
||||
tab.build(barY + Panel.WIDGET_H + Panel.GAP, grid);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -108,10 +74,7 @@ public final class BuilderScreen extends Screen {
|
|||
if (noticeTicks > 0) {
|
||||
noticeTicks--;
|
||||
}
|
||||
pos1Button.setMessage(posLabel(LANG_POS1, builder.selection().pos1()));
|
||||
pos2Button.setMessage(posLabel(LANG_POS2, builder.selection().pos2()));
|
||||
pauseButton.setMessage(Text.translatable(
|
||||
builder.stage() == Stage.PAUSED ? LANG_RESUME : LANG_PAUSE));
|
||||
tab.tick();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -119,10 +82,14 @@ public final class BuilderScreen extends Screen {
|
|||
super.render(context, mouseX, mouseY, delta);
|
||||
context.drawCenteredTextWithShadow(textRenderer, title, width / 2,
|
||||
panel.top() + Panel.PAD, Theme.TEXT);
|
||||
final String status = trim(builder.status());
|
||||
context.drawTextWithShadow(textRenderer, trim(notice.getString()),
|
||||
int lineY = panel.top() + Panel.PAD + Panel.TITLE_H + Panel.GAP * 2 + Panel.WIDGET_H;
|
||||
for (final Text line : tab.lines()) {
|
||||
context.drawTextWithShadow(textRenderer, line, panel.left(), lineY, Theme.TEXT_MUTED);
|
||||
lineY += Panel.LINE_H;
|
||||
}
|
||||
context.drawTextWithShadow(textRenderer, trim(noticeText.getString()),
|
||||
panel.left(), panel.statusY(), Theme.get().accentHover());
|
||||
context.drawTextWithShadow(textRenderer, status,
|
||||
context.drawTextWithShadow(textRenderer, trim(builder.status()),
|
||||
panel.left(), panel.statusY() + Panel.LINE_H, Theme.TEXT_MUTED);
|
||||
}
|
||||
|
||||
|
|
@ -139,16 +106,12 @@ public final class BuilderScreen extends Screen {
|
|||
close();
|
||||
return true;
|
||||
}
|
||||
if (blockField.isFocused() && input.isEnter()) {
|
||||
commitBlock();
|
||||
return true;
|
||||
}
|
||||
return super.keyPressed(input);
|
||||
return tab.key(input) || super.keyPressed(input);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removed() {
|
||||
commitBlock();
|
||||
tab.close();
|
||||
super.removed();
|
||||
}
|
||||
|
||||
|
|
@ -157,86 +120,85 @@ public final class BuilderScreen extends Screen {
|
|||
return false;
|
||||
}
|
||||
|
||||
/** Strategy options; truncated when the screen is too short (GUI scale 4). */
|
||||
private List<BuildSettings.Slider> visibleOptions() {
|
||||
final List<BuildSettings.Slider> options = builder.settings().optionSliders();
|
||||
final int usable = height - Panel.PAD * 2 - Panel.TITLE_H - Panel.GAP * 2
|
||||
- Panel.STATUS_ROWS * Panel.LINE_H;
|
||||
final int maxRows = usable / (Panel.WIDGET_H + Panel.GAP) - FIXED_ROWS;
|
||||
if (maxRows >= options.size()) {
|
||||
return options;
|
||||
}
|
||||
return maxRows <= 0 ? List.of() : options.subList(0, maxRows);
|
||||
@Override
|
||||
public <W extends ClickableWidget> W add(final W widget) {
|
||||
return addDrawableChild(widget);
|
||||
}
|
||||
|
||||
private NumberSlider optionSlider(final int left, final int y, final int inner,
|
||||
final BuildSettings.Slider option) {
|
||||
return new NumberSlider(left, y, inner, Panel.WIDGET_H,
|
||||
new NumberSlider.Spec(option.min(), option.max(), option.step(), option.value()),
|
||||
v -> Text.literal(option.label() + ": " + format(option, v)),
|
||||
v -> run(() -> builder.setOption(option.key(), format(option, v))));
|
||||
@Override
|
||||
public void addField(final TextFieldWidget field) {
|
||||
addSelectableChild(field);
|
||||
}
|
||||
|
||||
private void changeStrategy(final String id) {
|
||||
run(() -> builder.setStrategy(id));
|
||||
reinitQueued = true;
|
||||
}
|
||||
|
||||
private String setTheme(final String id) {
|
||||
return ThemePref.apply(store, id);
|
||||
}
|
||||
|
||||
private void run(final Supplier<String> action) {
|
||||
@Override
|
||||
public void run(final Supplier<String> action) {
|
||||
try {
|
||||
showNotice(action.get());
|
||||
} catch (RuntimeException e) {
|
||||
showNotice(e.getMessage() == null ? "ошибка" : e.getMessage());
|
||||
showNotice(e.getMessage() == null ? NOTICE_ERROR : e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notice(final String text) {
|
||||
showNotice(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reinit() {
|
||||
reinitQueued = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextRenderer font() {
|
||||
return textRenderer;
|
||||
}
|
||||
|
||||
/** Widget rows that fit between the title and the status block (GUI scale aware). */
|
||||
private int usableRows() {
|
||||
final int usable = height - Panel.PAD * 2 - Panel.TITLE_H - Panel.GAP * 2
|
||||
- Panel.STATUS_ROWS * Panel.LINE_H;
|
||||
return usable / (Panel.WIDGET_H + Panel.GAP);
|
||||
}
|
||||
|
||||
private Tab createTab(final int rowCap) {
|
||||
return switch (tabIndex) {
|
||||
case TAB_BUILD -> new BuildTab(this, builder, store);
|
||||
case TAB_PLACE -> new PlaceTab(this, builder, rowCap);
|
||||
default -> new SupplyTab();
|
||||
};
|
||||
}
|
||||
|
||||
private Tab.Grid grid() {
|
||||
return new Tab.Grid(panel.left(), panel.inner(),
|
||||
(panel.inner() - Panel.GAP) / 2,
|
||||
(panel.inner() - Panel.GAP * 2) / GRID_THIRD,
|
||||
Panel.WIDGET_H, Panel.GAP);
|
||||
}
|
||||
|
||||
private void addTabButtons(final int y, final Tab.Grid g) {
|
||||
for (int i = 0; i < TAB_COUNT; i++) {
|
||||
final int index = i;
|
||||
addDrawableChild(ButtonWidget.builder(Text.translatable(TAB_KEYS.get(i)),
|
||||
b -> switchTab(index))
|
||||
.dimensions(g.left() + (g.third() + Panel.GAP) * i, y, g.third(), Panel.WIDGET_H)
|
||||
.build());
|
||||
}
|
||||
}
|
||||
|
||||
private void switchTab(final int index) {
|
||||
if (index != tabIndex) {
|
||||
tabIndex = index;
|
||||
reinitQueued = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void showNotice(final String text) {
|
||||
notice = Text.literal(text);
|
||||
noticeText = Text.literal(text);
|
||||
noticeTicks = NOTICE_TICKS;
|
||||
}
|
||||
|
||||
private void commitBlock() {
|
||||
final String id = blockField.getText().strip();
|
||||
if (!id.isEmpty() && !id.equals(builder.settings().block())) {
|
||||
run(() -> builder.setBlock(id));
|
||||
}
|
||||
}
|
||||
|
||||
private void capture(final int which) {
|
||||
if (client.player == null) {
|
||||
showNotice("зайди в мир");
|
||||
return;
|
||||
}
|
||||
final BlockPos pos = client.player.getBlockPos();
|
||||
if (which == POS1) {
|
||||
builder.selection().setPos1(pos);
|
||||
} else {
|
||||
builder.selection().setPos2(pos);
|
||||
}
|
||||
showNotice("Pos" + which + ": " + pos.toShortString());
|
||||
}
|
||||
|
||||
private Text posLabel(final String key, final Optional<BlockPos> pos) {
|
||||
return Text.translatable(key, pos.<String>map(BlockPos::toShortString).orElse("-"));
|
||||
}
|
||||
|
||||
private String format(final BuildSettings.Slider option, final double value) {
|
||||
return option.integer()
|
||||
? String.valueOf(Math.round(value))
|
||||
: String.format(Locale.ROOT, "%.1f", value);
|
||||
}
|
||||
|
||||
private String trim(final String text) {
|
||||
return textRenderer.trimToWidth(text, Panel.WIDTH - Panel.PAD * 2);
|
||||
}
|
||||
|
||||
private static ButtonWidget button(final String key, final Runnable action,
|
||||
final int x, final int y, final int w) {
|
||||
return ButtonWidget.builder(Text.translatable(key), b -> action.run())
|
||||
.dimensions(x, y, w, Panel.WIDGET_H).build();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
66
src/main/java/dev/loki/satura/gui/screen/Tab.java
Normal file
66
src/main/java/dev/loki/satura/gui/screen/Tab.java
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
package dev.loki.satura.gui.screen;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.gui.widget.ClickableWidget;
|
||||
import net.minecraft.client.gui.widget.TextFieldWidget;
|
||||
import net.minecraft.client.input.KeyInput;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
/**
|
||||
* Content of one screen tab: a fixed number of widget rows built top-down. The screen owns
|
||||
* the panel, the tab bar and the status line; a tab only fills its own rows.
|
||||
*/
|
||||
public interface Tab {
|
||||
|
||||
/** Widget rows this tab needs (the panel is sized from it). */
|
||||
int rows();
|
||||
|
||||
/** Adds widgets starting at y (first content row), using the panel grid. */
|
||||
void build(int y, Grid grid);
|
||||
|
||||
/** Static text lines drawn in the empty content area (a tab with no widgets). */
|
||||
default List<Text> lines() {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
/** Periodic label refresh; called from the screen tick. */
|
||||
default void tick() {
|
||||
}
|
||||
|
||||
/** The screen is closing; commit pending input here. */
|
||||
default void close() {
|
||||
}
|
||||
|
||||
/** Key event; true = consumed. */
|
||||
default boolean key(KeyInput input) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Column layout of the content area, computed by the screen from the panel geometry. */
|
||||
record Grid(int left, int inner, int half, int third, int rowH, int gap) {
|
||||
}
|
||||
|
||||
/** Services the host screen provides to tab content. */
|
||||
interface Host {
|
||||
|
||||
/** Registers a widget (button, slider, cycle) and returns it. */
|
||||
<W extends ClickableWidget> W add(W widget);
|
||||
|
||||
/** Registers a text field (focusable, committed by the tab). */
|
||||
void addField(TextFieldWidget field);
|
||||
|
||||
/** Runs the action, turning the reply or the error into a notice. */
|
||||
void run(Supplier<String> action);
|
||||
|
||||
/** Shows a notice line for a short time. */
|
||||
void notice(String text);
|
||||
|
||||
/** Rebuilds the screen (tab switch, strategy change). */
|
||||
void reinit();
|
||||
|
||||
/** Font for text fields. */
|
||||
TextRenderer font();
|
||||
}
|
||||
}
|
||||
135
src/main/java/dev/loki/satura/gui/screen/content/BuildTab.java
Normal file
135
src/main/java/dev/loki/satura/gui/screen/content/BuildTab.java
Normal file
|
|
@ -0,0 +1,135 @@
|
|||
package dev.loki.satura.gui.screen.content;
|
||||
|
||||
import dev.loki.satura.core.config.ConfigStore;
|
||||
import dev.loki.satura.feature.builder.BuilderFeature;
|
||||
import dev.loki.satura.feature.builder.engine.Stage;
|
||||
import dev.loki.satura.gui.ThemePref;
|
||||
import dev.loki.satura.gui.screen.Tab;
|
||||
import dev.loki.satura.gui.widget.CycleButton;
|
||||
import dev.loki.satura.render.Theme;
|
||||
import java.util.Optional;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.client.gui.widget.TextFieldWidget;
|
||||
import net.minecraft.client.input.KeyInput;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
/** Build tab: selection, start/pause/stop, shape, theme and the block id field. */
|
||||
public final class BuildTab implements Tab {
|
||||
|
||||
private static final int WIDGET_ROWS = 5;
|
||||
private static final int BLOCK_LEN = 64;
|
||||
private static final String LANG_POS1 = "satura.gui.pos1";
|
||||
private static final String LANG_POS2 = "satura.gui.pos2";
|
||||
private static final String LANG_PAUSE = "satura.gui.pause";
|
||||
private static final String LANG_RESUME = "satura.gui.resume";
|
||||
private static final int POS1 = 1;
|
||||
private static final int POS2 = 2;
|
||||
|
||||
private final Host host;
|
||||
private final BuilderFeature builder;
|
||||
private final ConfigStore store;
|
||||
private ButtonWidget pos1;
|
||||
private ButtonWidget pos2;
|
||||
private ButtonWidget pause;
|
||||
private TextFieldWidget block;
|
||||
|
||||
public BuildTab(final Host host, final BuilderFeature builder, final ConfigStore store) {
|
||||
this.host = host;
|
||||
this.builder = builder;
|
||||
this.store = store;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int rows() {
|
||||
return WIDGET_ROWS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(final int y, final Grid g) {
|
||||
int row = y;
|
||||
pos1 = host.add(button(LANG_POS1, () -> capture(POS1), g.left(), row, g.half(), g.rowH()));
|
||||
pos2 = host.add(button(LANG_POS2, () -> capture(POS2),
|
||||
g.left() + g.half() + g.gap(), row, g.half(), g.rowH()));
|
||||
row += g.rowH() + g.gap();
|
||||
host.add(button("satura.gui.start", () -> host.run(builder::start),
|
||||
g.left(), row, g.third(), g.rowH()));
|
||||
pause = host.add(button(LANG_PAUSE, this::togglePause,
|
||||
g.left() + g.third() + g.gap(), row, g.third(), g.rowH()));
|
||||
host.add(button("satura.gui.stop", () -> host.run(builder::stop),
|
||||
g.left() + (g.third() + g.gap()) * 2, row, g.third(), g.rowH()));
|
||||
row += g.rowH() + g.gap();
|
||||
host.add(new CycleButton(g.left(), row, g.inner(), g.rowH(), "satura.gui.shape",
|
||||
builder.shapeIds(), builder.settings().shapeId(),
|
||||
id -> host.run(() -> builder.setShape(id))));
|
||||
row += g.rowH() + g.gap();
|
||||
host.add(new CycleButton(g.left(), row, g.inner(), g.rowH(), "satura.gui.theme",
|
||||
Theme.all().stream().map(Theme::id).toList(), Theme.get().id(),
|
||||
id -> host.run(() -> ThemePref.apply(store, id))));
|
||||
row += g.rowH() + g.gap();
|
||||
block = new TextFieldWidget(host.font(), g.left(), row, g.inner(), g.rowH(),
|
||||
Text.translatable("satura.gui.block"));
|
||||
block.setMaxLength(BLOCK_LEN);
|
||||
block.setText(builder.settings().block());
|
||||
host.addField(block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
pos1.setMessage(posLabel(LANG_POS1, builder.selection().pos1()));
|
||||
pos2.setMessage(posLabel(LANG_POS2, builder.selection().pos2()));
|
||||
pause.setMessage(Text.translatable(
|
||||
builder.stage() == Stage.PAUSED ? LANG_RESUME : LANG_PAUSE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean key(final KeyInput input) {
|
||||
if (block.isFocused() && input.isEnter()) {
|
||||
commitBlock();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
commitBlock();
|
||||
}
|
||||
|
||||
private void togglePause() {
|
||||
host.run(() -> builder.stage() == Stage.PAUSED ? builder.resume() : builder.pause());
|
||||
}
|
||||
|
||||
private void commitBlock() {
|
||||
final String id = block.getText().strip();
|
||||
if (!id.isEmpty() && !id.equals(builder.settings().block())) {
|
||||
host.run(() -> builder.setBlock(id));
|
||||
}
|
||||
}
|
||||
|
||||
private void capture(final int which) {
|
||||
final var player = MinecraftClient.getInstance().player;
|
||||
if (player == null) {
|
||||
host.notice("зайди в мир");
|
||||
return;
|
||||
}
|
||||
final BlockPos pos = player.getBlockPos();
|
||||
if (which == POS1) {
|
||||
builder.selection().setPos1(pos);
|
||||
} else {
|
||||
builder.selection().setPos2(pos);
|
||||
}
|
||||
host.notice("Pos" + which + ": " + pos.toShortString());
|
||||
}
|
||||
|
||||
private Text posLabel(final String key, final Optional<BlockPos> pos) {
|
||||
return Text.translatable(key, pos.<String>map(BlockPos::toShortString).orElse("-"));
|
||||
}
|
||||
|
||||
private ButtonWidget button(final String key, final Runnable action, final int x, final int y,
|
||||
final int w, final int h) {
|
||||
return ButtonWidget.builder(Text.translatable(key), b -> action.run())
|
||||
.dimensions(x, y, w, h).build();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,74 @@
|
|||
package dev.loki.satura.gui.screen.content;
|
||||
|
||||
import dev.loki.satura.feature.builder.BuildSettings;
|
||||
import dev.loki.satura.feature.builder.BuilderFeature;
|
||||
import dev.loki.satura.gui.screen.Tab;
|
||||
import dev.loki.satura.gui.widget.CycleButton;
|
||||
import dev.loki.satura.gui.widget.NumberSlider;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
/** Placement tab: strategy choice with its own option sliders and one-click presets. */
|
||||
public final class PlaceTab implements Tab {
|
||||
|
||||
private static final int FIXED_ROWS = 2;
|
||||
|
||||
private final Host host;
|
||||
private final BuilderFeature builder;
|
||||
private final List<BuildSettings.Slider> sliders;
|
||||
|
||||
public PlaceTab(final Host host, final BuilderFeature builder, final int rowCap) {
|
||||
this.host = host;
|
||||
this.builder = builder;
|
||||
final List<BuildSettings.Slider> all = builder.settings().optionSliders();
|
||||
final int sliderCap = Math.max(0, rowCap - FIXED_ROWS);
|
||||
this.sliders = all.size() <= sliderCap ? all : all.subList(0, sliderCap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int rows() {
|
||||
return FIXED_ROWS + sliders.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(final int y, final Grid g) {
|
||||
int row = y;
|
||||
host.add(new CycleButton(g.left(), row, g.inner(), g.rowH(), "satura.gui.strategy",
|
||||
builder.strategyIds(), builder.settings().strategy().id(),
|
||||
id -> {
|
||||
host.run(() -> builder.setStrategy(id));
|
||||
host.reinit();
|
||||
}));
|
||||
row += g.rowH() + g.gap();
|
||||
host.add(new CycleButton(g.left(), row, g.inner(), g.rowH(), "satura.gui.preset",
|
||||
builder.presetIds(), BuildSettings.PRESET_CUSTOM, this::applyPreset));
|
||||
row += g.rowH() + g.gap();
|
||||
for (final BuildSettings.Slider option : sliders) {
|
||||
host.add(new NumberSlider(g.left(), row, g.inner(), g.rowH(),
|
||||
new NumberSlider.Spec(option.min(), option.max(), option.step(), option.value()),
|
||||
v -> Text.literal(option.label() + ": " + format(option, v)),
|
||||
v -> host.run(() -> builder.setOption(option.key(), format(option, v)))));
|
||||
row += g.rowH() + g.gap();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Text> lines() {
|
||||
if (!sliders.isEmpty()) {
|
||||
return List.of();
|
||||
}
|
||||
return List.of(Text.translatable("satura.gui.options.hidden"));
|
||||
}
|
||||
|
||||
private void applyPreset(final String id) {
|
||||
host.run(() -> builder.applyPreset(id));
|
||||
host.reinit();
|
||||
}
|
||||
|
||||
private String format(final BuildSettings.Slider option, final double value) {
|
||||
return option.integer()
|
||||
? String.valueOf(Math.round(value))
|
||||
: String.format(Locale.ROOT, "%.1f", value);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
package dev.loki.satura.gui.screen.content;
|
||||
|
||||
import dev.loki.satura.gui.screen.Tab;
|
||||
import java.util.List;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
/** Supply tab placeholder: the supply feature itself arrives with the next plan phase. */
|
||||
public final class SupplyTab implements Tab {
|
||||
|
||||
@Override
|
||||
public int rows() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(final int y, final Grid grid) {
|
||||
// No widgets yet; the plan phase for supply will fill this tab.
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Text> lines() {
|
||||
return List.of(Text.translatable("satura.gui.supply.todo"),
|
||||
Text.translatable("satura.gui.supply.todo2"));
|
||||
}
|
||||
}
|
||||
|
|
@ -3,6 +3,9 @@
|
|||
"key.satura.open_menu": "Open builder menu",
|
||||
"key.satura.toggle": "Pause / resume build",
|
||||
"key.category.satura.main": "Satura",
|
||||
"satura.gui.tab.build": "Build",
|
||||
"satura.gui.tab.place": "Placement",
|
||||
"satura.gui.tab.supply": "Supply",
|
||||
"satura.gui.pos1": "Pos1: %s",
|
||||
"satura.gui.pos2": "Pos2: %s",
|
||||
"satura.gui.start": "Start",
|
||||
|
|
@ -11,8 +14,12 @@
|
|||
"satura.gui.stop": "Stop",
|
||||
"satura.gui.shape": "Shape: %s",
|
||||
"satura.gui.strategy": "Strategy: %s",
|
||||
"satura.gui.preset": "Preset: %s",
|
||||
"satura.gui.theme": "Theme: %s",
|
||||
"satura.gui.layers": "Layers: %s",
|
||||
"satura.gui.delay": "Delay: %s ms",
|
||||
"satura.gui.block": "Block"
|
||||
"satura.gui.block": "Block",
|
||||
"satura.gui.options.hidden": "Too many parameters - lower the GUI scale",
|
||||
"satura.gui.supply.todo": "Supply (next plan phase): chest routes,",
|
||||
"satura.gui.supply.todo2": "teleport there/back, automatic restock."
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@
|
|||
"key.satura.open_menu": "Открыть меню билдера",
|
||||
"key.satura.toggle": "Пауза / продолжить билд",
|
||||
"key.category.satura.main": "Satura",
|
||||
"satura.gui.tab.build": "Стройка",
|
||||
"satura.gui.tab.place": "Постановка",
|
||||
"satura.gui.tab.supply": "Снабжение",
|
||||
"satura.gui.pos1": "Pos1: %s",
|
||||
"satura.gui.pos2": "Pos2: %s",
|
||||
"satura.gui.start": "Старт",
|
||||
|
|
@ -11,8 +14,12 @@
|
|||
"satura.gui.stop": "Стоп",
|
||||
"satura.gui.shape": "Форма: %s",
|
||||
"satura.gui.strategy": "Стратегия: %s",
|
||||
"satura.gui.preset": "Пресет: %s",
|
||||
"satura.gui.theme": "Тема: %s",
|
||||
"satura.gui.layers": "Слоёв: %s",
|
||||
"satura.gui.delay": "Задержка: %s мс",
|
||||
"satura.gui.block": "Блок"
|
||||
"satura.gui.block": "Блок",
|
||||
"satura.gui.options.hidden": "Параметров слишком много — уменьшите масштаб GUI",
|
||||
"satura.gui.supply.todo": "Снабжение (фаза 11): маршруты до сундуков,",
|
||||
"satura.gui.supply.todo2": "телепорт туда/обратно, авто-подбор блоков."
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,8 @@ class BuildCommandTest {
|
|||
@Override public String setOption(final String k, final String v) { return log("set " + k + "=" + v); }
|
||||
@Override public String setShape(final String id) { return log("shape " + id); }
|
||||
@Override public String setLayers(final int n) { return log("layers " + n); }
|
||||
@Override public List<String> presetIds() { return List.of("max", "safe", "custom"); }
|
||||
@Override public String applyPreset(final String id) { return log("preset " + id); }
|
||||
@Override public List<String> blockIds() { return List.of("stone"); }
|
||||
@Override public List<String> strategyIds() { return List.of("band_stack", "column_drop"); }
|
||||
@Override public List<String> optionKeys() { return List.of("delayMs"); }
|
||||
|
|
@ -41,7 +43,9 @@ class BuildCommandTest {
|
|||
command.execute(List.of("set", "delayMs", "5"), replies::add);
|
||||
command.execute(List.of("layers", "3"), replies::add);
|
||||
command.execute(List.of("SHAPE", "walls"), replies::add);
|
||||
assertEquals(List.of("start", "block stone", "set delayMs=5", "layers 3", "shape walls"), calls);
|
||||
command.execute(List.of("preset", "safe"), replies::add);
|
||||
assertEquals(List.of("start", "block stone", "set delayMs=5", "layers 3", "shape walls",
|
||||
"preset safe"), calls);
|
||||
assertEquals(calls, replies);
|
||||
}
|
||||
|
||||
|
|
@ -61,7 +65,9 @@ class BuildCommandTest {
|
|||
@Test
|
||||
void suggests() {
|
||||
assertTrue(command.suggest(List.of("")).contains("strategy"));
|
||||
assertTrue(command.suggest(List.of("")).contains("preset"));
|
||||
assertEquals(List.of("band_stack", "column_drop"), command.suggest(List.of("strategy", "")));
|
||||
assertEquals(List.of("max", "safe", "custom"), command.suggest(List.of("preset", "")));
|
||||
assertEquals(List.of("delayMs"), command.suggest(List.of("set", "")));
|
||||
assertTrue(command.suggest(List.of("block", "")).contains("hand"));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue