Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import ca.teamdman.sfm.client.registry.SFMKeyMappings;
import ca.teamdman.sfm.client.screen.tick_graph.TickTimeGraphRenderState;
import ca.teamdman.sfm.client.screen.widget.SFMButtonBuilder;
import ca.teamdman.sfm.client.screen.widget.SFMPreferredEditorDropdown;
import ca.teamdman.sfm.client.text_editor.SFMTextEditScreenDiskOpenContext;
import ca.teamdman.sfm.common.command.ConfigCommandBehaviourInput;
import ca.teamdman.sfm.common.containermenu.ManagerContainerMenu;
Expand Down Expand Up @@ -375,6 +376,13 @@ protected void init() {
)
.build()
);
this.addRenderableWidget(SFMPreferredEditorDropdown.create(
(this.width - this.imageWidth) / 2 - buttonWidth,
(this.height - this.imageHeight) / 2 + 16 + 50 - buttonHeight - 2,
buttonWidth,
buttonHeight,
false
));
editButton = this.addRenderableWidget(
new SFMButtonBuilder()
.setPosition(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import ca.teamdman.sfm.SFM;
import ca.teamdman.sfm.client.screen.widget.SFMButtonBuilder;
import ca.teamdman.sfm.client.screen.widget.SFMPreferredEditorDropdown;
import ca.teamdman.sfm.client.screen.text_editor.ISFMTextEditScreen;
import ca.teamdman.sfm.client.text_editor.ISFMTextEditScreenOpenContext;
import ca.teamdman.sfm.common.config.SFMConfig;
Expand Down Expand Up @@ -215,6 +216,14 @@ protected void init() {
() -> { }
)))
.build());
this.addRenderableWidget(SFMPreferredEditorDropdown.createForEditor(
22,
this.height - 24,
110,
20,
this,
this::getCurrentText
));
}
sfmlButton = new SFMButtonBuilder()
.setPosition(this.width - 140, this.height - 24)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,17 @@ public static void showExampleListScreen(
) {

setOrPushScreen(new ExamplesScreen((chosenExample, templates) -> {
SFMTextEditScreenV1 screen = new SFMTextEditScreenV1(new SFMTextEditScreenExampleProgramOpenContext(
ISFMTextEditScreen screen = createProgramEditScreen(new SFMTextEditScreenExampleProgramOpenContext(
chosenExample,
diskProgramString,
templates,
labelPositionHolder,
saveCallback
));
setOrPushScreen(screen);
screen.scrollToTop();
showTextEditScreen(screen);
if (screen instanceof SFMTextEditScreenV1 v1) {
v1.scrollToTop();
}
}));
}

Expand Down Expand Up @@ -169,16 +171,18 @@ public static void showItemInspectorScreen(ItemStack stack) {
public static void showChangelog() {

SFMExampleProgram changelogExampleProgram = SFMExampleProgram.getChangelog();
SFMTextEditScreenV1 screen = new SFMTextEditScreenV1(new SFMTextEditScreenExampleProgramOpenContext(
ISFMTextEditScreen screen = createProgramEditScreen(new SFMTextEditScreenExampleProgramOpenContext(
changelogExampleProgram.programString(),
changelogExampleProgram.programString(),
List.of(changelogExampleProgram),
LabelPositionHolder.empty(),
newContent -> {
}
));
setOrPushScreen(screen);
screen.scrollToTop();
showTextEditScreen(screen);
if (screen instanceof SFMTextEditScreenV1 v1) {
v1.scrollToTop();
}
}

public static @Nullable Screen getCurrentScreen() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,18 @@
package ca.teamdman.sfm.client.screen;

import ca.teamdman.sfm.client.registry.SFMTextEditors;
import ca.teamdman.sfm.client.screen.text_editor.ISFMTextEditScreen;
import ca.teamdman.sfm.client.screen.widget.SFMButtonBuilder;
import ca.teamdman.sfm.client.text_editor.SFMTextEditorIntellisenseLevel;
import ca.teamdman.sfm.common.config.SFMClientTextEditorConfig;
import ca.teamdman.sfm.common.localization.LocalizationEntry;
import ca.teamdman.sfm.common.localization.SFMLocalizationDatagen;
import ca.teamdman.sfm.common.util.SFMEnvironmentUtils;
import net.minecraft.client.gui.GuiGraphicsExtractor;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.CommonComponents;

@SuppressWarnings("NotNullFieldNotInitialized")
public class SFMTextEditorConfigScreen extends Screen {
@SFMLocalizationDatagen
public static final LocalizationEntry PROGRAM_EDITOR_CONFIG_PREFERRED_EDITOR = new LocalizationEntry(
"gui.sfm.program_editor_config.preferred_editor",
"Preferred Editor"
);

@SFMLocalizationDatagen
public static final LocalizationEntry PROGRAM_EDITOR_CONFIG_PREFERRED_EDITOR_V1 = new LocalizationEntry(
"gui.sfm.program_editor_config.preferred_editor.v1",
"V1 (Default)"
);

@SFMLocalizationDatagen
public static final LocalizationEntry PROGRAM_EDITOR_CONFIG_PREFERRED_EDITOR_V2 = new LocalizationEntry(
"gui.sfm.program_editor_config.preferred_editor.v2",
"V2"
);

@SFMLocalizationDatagen
public static final LocalizationEntry PROGRAM_EDITOR_CONFIG_SCREEN_TITLE = new LocalizationEntry(
"gui.sfm.program_editor_config.title",
Expand Down Expand Up @@ -78,8 +58,6 @@ public class SFMTextEditorConfigScreen extends Screen {

private final Runnable closeCallback;

private final boolean editorSelectorFeatureFlag = SFMEnvironmentUtils.isInIDE();

private Button lineNumbersOnButton;

private Button lineNumbersOffButton;
Expand All @@ -90,10 +68,6 @@ public class SFMTextEditorConfigScreen extends Screen {

private Button intellisenseAdvancedButton;

private Button preferredEditorV1Button;

private Button preferredEditorV2Button;

public SFMTextEditorConfigScreen(
ISFMTextEditScreen parent,
SFMClientTextEditorConfig config,
Expand Down Expand Up @@ -140,15 +114,6 @@ public void extractRenderState(
y + 50,
0xFFFFFFFF
);
if (editorSelectorFeatureFlag) {
graphics.text(
font,
PROGRAM_EDITOR_CONFIG_PREFERRED_EDITOR.getComponent(),
x,
y + 100,
0xFFFFFFFF
);
}
graphics.centeredText(
font,
this.title,
Expand Down Expand Up @@ -179,6 +144,7 @@ protected void init() {
.setText(CommonComponents.OPTION_ON)
.setOnPress(button -> {
config.showLineNumbers.set(true);
config.showLineNumbers.save();
updateButtonStates();
})
.build();
Expand All @@ -189,6 +155,7 @@ protected void init() {
.setText(CommonComponents.OPTION_OFF)
.setOnPress(button -> {
config.showLineNumbers.set(false);
config.showLineNumbers.save();
updateButtonStates();
})
.build();
Expand All @@ -204,6 +171,7 @@ protected void init() {
.setText(PROGRAM_EDITOR_CONFIG_INTELLISENSE_OFF)
.setOnPress(button -> {
config.intellisenseLevel.set(SFMTextEditorIntellisenseLevel.OFF);
config.intellisenseLevel.save();
updateButtonStates();
parent.onPreferenceChanged();
})
Expand All @@ -215,6 +183,7 @@ protected void init() {
.setText(PROGRAM_EDITOR_CONFIG_INTELLISENSE_BASIC)
.setOnPress(button -> {
config.intellisenseLevel.set(SFMTextEditorIntellisenseLevel.BASIC);
config.intellisenseLevel.save();
updateButtonStates();
parent.onPreferenceChanged();
})
Expand All @@ -228,6 +197,7 @@ protected void init() {
.setText(PROGRAM_EDITOR_CONFIG_INTELLISENSE_ADVANCED)
.setOnPress(button -> {
config.intellisenseLevel.set(SFMTextEditorIntellisenseLevel.ADVANCED);
config.intellisenseLevel.save();
updateButtonStates();
parent.onPreferenceChanged();
})
Expand All @@ -237,36 +207,6 @@ protected void init() {
this.addRenderableWidget(intellisenseBasicButton);
this.addRenderableWidget(intellisenseAdvancedButton);

// Preferred Editor Buttons
preferredEditorV1Button =
new SFMButtonBuilder()
.setPosition(x, y + 2 * spacing)
.setSize(buttonWidth, buttonHeight)
.setText(PROGRAM_EDITOR_CONFIG_PREFERRED_EDITOR_V1)
.setOnPress(button -> {
//noinspection OptionalGetWithoutIsPresent
config.preferredEditor.set(SFMTextEditors.V1.getId().get().identifier().toString());
updateButtonStates();
})
.build();
preferredEditorV2Button =
new SFMButtonBuilder()
.setPosition(x + buttonWidth + buttonSpacing, y + 2 * spacing)
.setSize(buttonWidth, buttonHeight)
.setText(PROGRAM_EDITOR_CONFIG_PREFERRED_EDITOR_V2)
.setOnPress(button -> {
//noinspection OptionalGetWithoutIsPresent
config.preferredEditor.set(SFMTextEditors.V2.getId().get().identifier().toString());
updateButtonStates();
})
.build();
if (editorSelectorFeatureFlag) {
// This behaviour is not ready for release.
this.addRenderableWidget(preferredEditorV1Button);
this.addRenderableWidget(preferredEditorV2Button);
}


// Done Button
this.addRenderableWidget(
new SFMButtonBuilder()
Expand All @@ -290,12 +230,6 @@ private void updateButtonStates() {
config.intellisenseLevel.get() != SFMTextEditorIntellisenseLevel.BASIC;
intellisenseAdvancedButton.active =
config.intellisenseLevel.get() != SFMTextEditorIntellisenseLevel.ADVANCED;

String currentEditor = config.preferredEditor.get();
//noinspection OptionalGetWithoutIsPresent
preferredEditorV1Button.active = !currentEditor.equals(SFMTextEditors.V1.getId().get().identifier().toString());
//noinspection OptionalGetWithoutIsPresent
preferredEditorV2Button.active = !currentEditor.equals(SFMTextEditors.V2.getId().get().identifier().toString());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import ca.teamdman.sfm.client.screen.widget.PickList;
import ca.teamdman.sfm.client.screen.widget.PickListItem;
import ca.teamdman.sfm.client.screen.widget.SFMButtonBuilder;
import ca.teamdman.sfm.client.screen.widget.SFMPreferredEditorDropdown;
import ca.teamdman.sfm.client.text_editor.ISFMTextEditScreenOpenContext;
import ca.teamdman.sfm.client.text_styling.ProgramSyntaxHighlightingHelper;
import ca.teamdman.sfm.common.config.SFMConfig;
Expand Down Expand Up @@ -370,13 +371,21 @@ protected void init() {
.setTooltip(this, font, PROGRAM_EDIT_SCREEN_CONFIG_BUTTON_TOOLTIP)
.build()
);
this.addRenderableWidget(SFMPreferredEditorDropdown.createForEditor(
this.width / 2 - 180,
this.height / 2 - 100 + 195,
110,
20,
this,
() -> textarea.getValue()
));
this.addRenderableWidget(
new SFMButtonBuilder()
.setPosition(
this.width / 2 - 2 - 150,
this.width / 2 - 66,
this.height / 2 - 100 + 195
)
.setSize(200, 20)
.setSize(130, 20)
.setText(CommonComponents.GUI_DONE)
.setOnPress((button) -> this.saveAndClose())
.setTooltip(this, font, PROGRAM_EDIT_SCREEN_DONE_BUTTON_TOOLTIP)
Expand All @@ -385,10 +394,10 @@ protected void init() {
this.addRenderableWidget(
new SFMButtonBuilder()
.setPosition(
this.width / 2 - 2 + 100,
this.width / 2 + 68,
this.height / 2 - 100 + 195
)
.setSize(100, 20)
.setSize(130, 20)
.setText(CommonComponents.GUI_CANCEL)
.setOnPress((button) -> this.onClose())
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import ca.teamdman.sfm.client.screen.SFMScreenRenderUtils;
import ca.teamdman.sfm.client.screen.SFMTextEditorConfigScreen;
import ca.teamdman.sfm.client.screen.widget.SFMButtonBuilder;
import ca.teamdman.sfm.client.screen.widget.SFMPreferredEditorDropdown;
import ca.teamdman.sfm.client.text_editor.Caret;
import ca.teamdman.sfm.client.text_editor.Cursor;
import ca.teamdman.sfm.client.text_editor.ISFMTextEditScreenOpenContext;
Expand Down Expand Up @@ -248,6 +249,14 @@ protected void init() {
.setTooltip(this, font, SFMTextEditScreenV1.PROGRAM_EDIT_SCREEN_CONFIG_BUTTON_TOOLTIP)
.build()
);
this.addRenderableWidget(SFMPreferredEditorDropdown.createForEditor(
22,
this.height - 24,
110,
20,
this,
() -> textEditContext.getContent()
));
}

protected void renderTooltip(
Expand Down
Loading