Skip to content

Commit

Permalink
Fix <Ctrl>+<Number> keybinds not working for tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
Motschen committed Mar 9, 2023
1 parent 79eb893 commit c881db8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,9 @@ protected MidnightConfigScreen(Screen parent, String modid) {
public final String modid;
public MidnightConfigListWidget list;
public boolean reload = false;
public TabManager tabManager = new TabManager(a -> refresh(), a -> refresh());
public TabManager tabManager = new TabManager(a -> {}, a -> {});
public Tab prevTab;
public TabNavigationWidget tabNavigation;
public ButtonWidget done;

// Real Time config update //
Expand Down Expand Up @@ -242,6 +243,11 @@ public void loadValues() {
} catch (IllegalAccessException ignored) {}
}
}
@Override
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
if (this.tabNavigation.trySwitchTabsWithKey(keyCode)) return true;
return super.keyPressed(keyCode, scanCode, modifiers);
}
public Tooltip getTooltip(EntryInfo info) {
return Tooltip.of(info.error != null ? info.error : I18n.hasTranslation(translationPrefix+info.field.getName()+".tooltip") ? Text.translatable(translationPrefix+info.field.getName()+".tooltip") : Text.empty());
}
Expand Down Expand Up @@ -270,7 +276,7 @@ public void init() {
} else e.tab = tabs.get(name);
}
}
TabNavigationWidget tabNavigation = TabNavigationWidget.builder(tabManager, this.width).tabs(tabs.values().toArray(new Tab[0])).build();
tabNavigation = TabNavigationWidget.builder(tabManager, this.width).tabs(tabs.values().toArray(new Tab[0])).build();
if (tabs.size() > 1) this.addDrawableChild(tabNavigation);
if (!reload) tabNavigation.selectTab(0, false);
tabNavigation.init();
Expand All @@ -280,10 +286,6 @@ public void init() {
loadValues();
Objects.requireNonNull(client).setScreen(parent);
}).dimensions(this.width / 2 - 154, this.height - 28, 150, 20).build());

this.list = new MidnightConfigListWidget(this.client, this.width, this.height, 32, this.height - 32, 25);
if (this.client != null && this.client.world != null) this.list.setRenderBackground(false);
this.addSelectableChild(this.list);
done = this.addDrawableChild(ButtonWidget.builder(ScreenTexts.DONE, (button) -> {
for (EntryInfo info : entries)
if (info.id.equals(modid)) {
Expand All @@ -294,6 +296,11 @@ public void init() {
write(modid);
Objects.requireNonNull(client).setScreen(parent);
}).dimensions(this.width / 2 + 4, this.height - 28, 150, 20).build());

this.list = new MidnightConfigListWidget(this.client, this.width, this.height, 32, this.height - 32, 25);
if (this.client != null && this.client.world != null) this.list.setRenderBackground(false);
this.addSelectableChild(this.list);

fillList();
}
public void fillList() {
Expand Down
5 changes: 5 additions & 0 deletions fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
"eu.midnightdust.lib.config.AutoModMenu"
]
},
"depends": {
"fabric-models-v0": "*",
"fabric-resource-loader-v0": "*",
"minecraft": ">=1.19.4-rc.1"
},

"mixins": [
"midnightlib.mixins.json"
Expand Down

0 comments on commit c881db8

Please sign in to comment.