Skip to content

Commit

Permalink
Add separate menu (and keybind) for opening entity selectors menu
Browse files Browse the repository at this point in the history
  • Loading branch information
mchorse committed Jun 26, 2020
1 parent 3b25fec commit 026f88f
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 36 deletions.
12 changes: 11 additions & 1 deletion src/main/java/mchorse/metamorph/client/KeyboardHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import mchorse.metamorph.capabilities.morphing.IMorphing;
import mchorse.metamorph.capabilities.morphing.Morphing;
import mchorse.metamorph.client.gui.creative.GuiCreativeScreen;
import mchorse.metamorph.client.gui.creative.GuiSelectorsScreen;
import mchorse.metamorph.network.Dispatcher;
import mchorse.metamorph.network.common.survival.PacketAction;
import mchorse.metamorph.network.common.survival.PacketSelectMorph;
Expand All @@ -30,6 +31,7 @@ public class KeyboardHandler
/* Action key */
private KeyBinding keyAction;
private KeyBinding keyCreativeMenu;
private KeyBinding keySelectorMenu;
private KeyBinding keySurvivalMenu;

/* Morph related keys */
Expand All @@ -42,13 +44,15 @@ public KeyboardHandler()
/* Create key bindings */
keyAction = new KeyBinding("key.metamorph.action", Keyboard.KEY_V, category);
keyCreativeMenu = new KeyBinding("key.metamorph.creative_menu", Keyboard.KEY_B, category);
keySelectorMenu = new KeyBinding("key.metamorph.selector_menu", Keyboard.KEY_MINUS, category);
keySurvivalMenu = new KeyBinding("key.metamorph.survival_menu", Keyboard.KEY_X, category);

keyDemorph = new KeyBinding("key.metamorph.demorph", Keyboard.KEY_PERIOD, category);

/* Register them in the client registry */
ClientRegistry.registerKeyBinding(keyAction);
ClientRegistry.registerKeyBinding(keyCreativeMenu);
ClientRegistry.registerKeyBinding(keySelectorMenu);
ClientRegistry.registerKeyBinding(keySurvivalMenu);

ClientRegistry.registerKeyBinding(keyDemorph);
Expand All @@ -66,7 +70,13 @@ public void onKey(InputEvent.KeyInputEvent event)

if (this.keyCreativeMenu.isPressed() && player.isCreative())
{
mc.displayGuiScreen(new GuiCreativeScreen());
mc.displayGuiScreen(new GuiCreativeScreen(mc));
wasUsed = true;
}

if (this.keySelectorMenu.isPressed())
{
mc.displayGuiScreen(new GuiSelectorsScreen(mc));
wasUsed = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,9 @@ public GuiCreativeMorphsList(Minecraft mc, Consumer<AbstractMorph> callback)
/* Morph editor keybinds */
IKey category = IKey.lang("metamorph.gui.creative.keys.category");

this.exitKey = this.keys().register(IKey.lang("metamorph.gui.creative.keys.exit"), Keyboard.KEY_ESCAPE, this::exit).category(category);
this.exitKey = this.keys().register(IKey.lang("metamorph.gui.creative.keys.exit"), Keyboard.KEY_ESCAPE, this::exit).category(category).active(this::updateExitKey);

this.reload();
this.updateExitKey();

this.morphs.keys().register(IKey.lang("metamorph.gui.creative.keys.edit"), Keyboard.KEY_E, this::enterEditMorph).category(category);
this.morphs.keys().register(IKey.lang("metamorph.gui.creative.keys.quick"), Keyboard.KEY_Q, this::toggleQuickEdit).category(category);
Expand All @@ -139,9 +138,9 @@ public void exit()
GuiBase.getCurrent().setContextMenu(null);
}

protected void updateExitKey()
protected boolean updateExitKey()
{
this.exitKey.active = this.editor.delegate != null || !this.nestedEdits.isEmpty();
return this.editor.delegate != null || !this.nestedEdits.isEmpty();
}

public Runnable showGlobalMorphs(AbstractMorph morph)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,18 @@ public class GuiCreativeMorphsMenu extends GuiCreativeMorphsList
{
private GuiButtonElement close;
private GuiButtonElement acquire;
private boolean menu;

public GuiCreativeMorphsMenu(Minecraft mc, Consumer<AbstractMorph> callback)
{
this(mc, false, callback);
}

public GuiCreativeMorphsMenu(Minecraft mc, boolean menu, Consumer<AbstractMorph> callback)
{
super(mc, callback);

this.menu = menu;
this.acquire = new GuiButtonElement(mc, IKey.lang("metamorph.gui.acquire"), (b) ->
{
AbstractMorph cell = this.getSelected();
Expand All @@ -43,9 +50,12 @@ public GuiCreativeMorphsMenu(Minecraft mc, Consumer<AbstractMorph> callback)

this.bar.flex().row(0).preferred(1);
this.bar.prepend(this.acquire);
this.bar.add(this.close);

this.exitKey.active = true;
if (!this.menu)
{
this.bar.add(this.close);
}

this.markContainer();

this.keys().register(IKey.lang("metamorph.gui.creative.keys.acquire"), Keyboard.KEY_A, () -> this.acquire.clickItself(GuiBase.getCurrent())).category(this.exitKey.category).active(() -> !this.isEditMode());
Expand All @@ -54,7 +64,7 @@ public GuiCreativeMorphsMenu(Minecraft mc, Consumer<AbstractMorph> callback)
@Override
public void exit()
{
if (!this.isEditMode() && !this.isNested())
if (!this.menu && !this.isEditMode() && !this.isNested())
{
this.finish();
this.removeFromParent();
Expand All @@ -68,9 +78,14 @@ public void exit()
}

@Override
protected void updateExitKey()
protected boolean updateExitKey()
{
this.exitKey.active = true;
if (this.menu)
{
return this.isEditMode() || this.isNested();
}

return true;
}

@Override
Expand All @@ -97,7 +112,11 @@ public boolean mouseScrolled(GuiContext context)
public void draw(GuiContext context)
{
GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT);
Gui.drawRect(this.area.x, this.area.y, this.area.ex(), this.area.ey(), 0xaa000000);

if (!this.menu)
{
Gui.drawRect(this.area.x, this.area.y, this.area.ex(), this.area.ey(), 0xaa000000);
}

super.draw(context);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,8 @@ public class GuiCreativeScreen extends GuiBase
private GuiButtonElement close;
private GuiCreativeMorphsList pane;

public GuiCreativeScreen()
public GuiCreativeScreen(Minecraft mc)
{
Minecraft mc = Minecraft.getMinecraft();

this.selectors = new GuiSelectorEditor(mc);
this.selectors.setVisible(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,31 @@ public class GuiSelectorEditor extends GuiElement
private EntitySelector selector;
private Timer timer = new Timer(200);
private boolean selecting;
private boolean menu;

public GuiSelectorEditor(Minecraft mc)
{
this(mc, false);
}

public GuiSelectorEditor(Minecraft mc, boolean menu)
{
super(mc);

this.menu = menu;

this.selectors = new GuiSelectorListElement(mc, this::fillData);
this.selectors.sorting().background(0xff000000).setList(EntityModelHandler.selectors);
this.selectors.context(() ->
{
GuiSimpleContextMenu menu = new GuiSimpleContextMenu(mc).action(Icons.ADD, IKey.lang("metamorph.gui.selectors.add"), this::addSelector);
GuiSimpleContextMenu contextMenu = new GuiSimpleContextMenu(mc).action(Icons.ADD, IKey.lang("metamorph.gui.selectors.add"), this::addSelector);

if (!this.selectors.getCurrent().isEmpty())
{
menu.action(Icons.REMOVE, IKey.lang("metamorph.gui.selectors.remove"), this::removeSelector);
contextMenu.action(Icons.REMOVE, IKey.lang("metamorph.gui.selectors.remove"), this::removeSelector);
}

return menu;
return contextMenu;
});

this.form = new GuiElement(mc);
Expand Down Expand Up @@ -101,7 +109,13 @@ public GuiSelectorEditor(Minecraft mc)
GuiLabel type = Elements.label(IKey.lang("metamorph.gui.selectors.type"), 16).anchor(0, 1);
GuiLabel match = Elements.label(IKey.lang("metamorph.gui.selectors.match"), 16).anchor(0, 1);

this.form.add(title.tooltip(IKey.lang("metamorph.gui.selectors.tooltip")), name, this.name, type, this.type, match, this.match, this.active,this.pick);
this.form.add(title.tooltip(IKey.lang("metamorph.gui.selectors.tooltip")), name, this.name, type, this.type, match, this.match, this.active);

if (!this.menu)
{
this.form.add(this.pick);
}

this.markContainer().add(this.form, this.selectors);

this.selectors.setIndex(0);
Expand Down Expand Up @@ -160,6 +174,24 @@ private void fillData(List<EntitySelector> selectors)
this.active.toggled(selector.enabled);
}

public void setMorph(AbstractMorph morph)
{
if (!this.isVisible() || this.selector == null)
{
return;
}

if (this.selecting || this.menu)
{
this.selector.morph = morph == null ? null : morph.toNBT();
}

this.pick.setEnabled(true);
this.selecting = false;
this.selector.updateTime();
this.timer.mark();
}

@Override
public void draw(GuiContext context)
{
Expand All @@ -178,24 +210,6 @@ public void draw(GuiContext context)
}
}

public void setMorph(AbstractMorph morph)
{
if (!this.isVisible() || this.selector == null)
{
return;
}

if (this.selecting && this.selector != null)
{
this.selector.morph = morph == null ? null : morph.toNBT();
}

this.pick.setEnabled(true);
this.selecting = false;
this.selector.updateTime();
this.timer.mark();
}

public static class GuiSelectorListElement extends GuiListElement<EntitySelector>
{
public GuiSelectorListElement(Minecraft mc, Consumer<List<EntitySelector>> callback)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package mchorse.metamorph.client.gui.creative;

import mchorse.mclib.client.gui.framework.GuiBase;
import mchorse.mclib.client.gui.framework.elements.utils.GuiDraw;
import mchorse.metamorph.Metamorph;
import net.minecraft.client.Minecraft;

public class GuiSelectorsScreen extends GuiBase
{
public GuiSelectorEditor editor;
public GuiCreativeMorphsMenu menu;

public GuiSelectorsScreen(Minecraft mc)
{
this.editor = new GuiSelectorEditor(mc, true);
this.menu = new GuiCreativeMorphsMenu(mc, true, this.editor::setMorph);
this.menu.setVisible(true);

this.editor.flex().relative(this.viewport).wTo(this.menu.flex()).h(1F);
this.menu.flex().relative(this.viewport).x(140).h(1F).wTo(this.root.flex(), 1F);

this.root.add(this.menu, this.editor);
}

@Override
public boolean doesGuiPauseGame()
{
return Metamorph.pauseGUIInSP.get();
}

@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
GuiDraw.drawCustomBackground(0, 0, this.width, this.height);

super.drawScreen(mouseX, mouseY, partialTicks);
}
}
1 change: 1 addition & 0 deletions src/main/resources/assets/metamorph/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ entity.metamorph.Morph.name=Morph
key.metamorph=Metamorph
key.metamorph.action=Use action
key.metamorph.creative_menu=Open creative morph menu
key.metamorph.selector_menu=Open entity selectors menu
key.metamorph.survival_menu=Open survival morph menu
key.metamorph.demorph=Demorph (turn back to player)

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/metamorph/lang/ru_RU.lang
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ entity.metamorph.Morph.name=Морф
key.metamorph=Метаморф
key.metamorph.action=Использовать действие
key.metamorph.creative_menu=Открыть меню превращения креатива
key.metamorph.selector_menu=Открыть меню селекторов существ
key.metamorph.survival_menu=Открыть меню превращения выживания
key.metamorph.demorph=Сбросить морф (обратно стать игроком)

Expand Down

0 comments on commit 026f88f

Please sign in to comment.