Split mod into core, recording, replay, render[todo], paths[todo] and extras[wip] modules

Move everything to com.replaymod package
Add KeyBindingRegistry and SettingsRegistry
Recreate settings GUI with new GUI API and dynamically from SettingsRegistry
Use ReplayFile from ReplayStudio
ReplayHandler is now object oriented
Add GuiOverlay, GuiSlider and GuiTexturedButton to GUI API
Rewrite both overlays to use new GUI API
Fix size capping in vertical and horizontal layout
Allow CustomLayouts to have parents
Fix tooltip rendering when close to screen border
Allow changing of columns in GridLayout
This commit is contained in:
johni0702
2015-10-03 17:36:03 +02:00
parent 8bd051eb27
commit f925d56ca2
141 changed files with 6294 additions and 5582 deletions

View File

@@ -0,0 +1,101 @@
package com.replaymod.extras;
import com.replaymod.core.ReplayMod;
import com.replaymod.replay.events.ReplayOpenEvent;
import com.replaymod.replay.gui.overlay.GuiReplayOverlay;
import de.johni0702.minecraft.gui.container.GuiPanel;
import de.johni0702.minecraft.gui.element.GuiButton;
import de.johni0702.minecraft.gui.element.GuiElement;
import de.johni0702.minecraft.gui.element.GuiLabel;
import de.johni0702.minecraft.gui.element.GuiTexturedButton;
import de.johni0702.minecraft.gui.layout.CustomLayout;
import de.johni0702.minecraft.gui.layout.GridLayout;
import de.johni0702.minecraft.gui.layout.HorizontalLayout;
import de.johni0702.minecraft.gui.layout.LayoutData;
import net.minecraft.client.settings.KeyBinding;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import org.lwjgl.input.Keyboard;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
public class HotkeyButtons implements Extra {
private ReplayMod mod;
@Override
public void register(ReplayMod mod) throws Exception {
this.mod = mod;
FMLCommonHandler.instance().bus().register(this);
}
@SubscribeEvent
public void postReplayOpen(ReplayOpenEvent.Post event) {
GuiReplayOverlay overlay = event.getReplayHandler().getOverlay();
new Gui(mod, overlay);
}
public static final class Gui {
private final GuiTexturedButton toggleButton;
private final GridLayout panelLayout;
private final GuiPanel panel;
private boolean open;
public Gui(ReplayMod mod, GuiReplayOverlay overlay) {
toggleButton = new GuiTexturedButton(overlay).setSize(20, 20)
.setTexture(ReplayMod.TEXTURE, ReplayMod.TEXTURE_SIZE).setTexturePosH(0, 0)
.onClick(new Runnable() {
@Override
public void run() {
open = !open;
}
});
panel = new GuiPanel(overlay) {
@Override
public Collection<GuiElement> getChildren() {
return open ? super.getChildren() : Collections.<GuiElement>emptyList();
}
@Override
public Map<GuiElement, LayoutData> getElements() {
return open ? super.getElements() : Collections.<GuiElement, LayoutData>emptyMap();
}
}.setLayout(panelLayout = new GridLayout().setSpacingX(5).setSpacingY(5).setColumns(1));
for (final KeyBinding keyBinding : mod.getKeyBindingRegistry().getKeyBindings().values()) {
String keyName = "???";
try {
keyName = Keyboard.getKeyName(keyBinding.getKeyCode());
} catch (ArrayIndexOutOfBoundsException e) {
// Apparently windows likes to press strange keys, see https://www.replaymod.com/forum/thread/55
}
panel.addElements(null, new GuiPanel().setSize(150, 20).setLayout(new HorizontalLayout().setSpacing(2))
.addElements(new HorizontalLayout.Data(0.5),
new GuiButton().setSize(20, 20).setLabel(keyName).onClick(new Runnable() {
@Override
public void run() {
keyBinding.pressTime++;
FMLCommonHandler.instance().fireKeyInput();
}
}),
new GuiLabel().setI18nText(keyBinding.getKeyDescription())
));
}
overlay.setLayout(new CustomLayout<GuiReplayOverlay>(overlay.getLayout()) {
@Override
protected void layout(GuiReplayOverlay container, int width, int height) {
panelLayout.setColumns((width - 10) / 105);
size(panel, panelLayout.calcMinSize(container));
pos(toggleButton, 5, height - 25);
pos(panel, 5, y(toggleButton) - 5 - height(panel));
}
});
}
}
}