A lot of Fixes and improvements.

-Changed: Downgraded from LWJGL 3 Version 3.3.0 to 3.2.4 because of Incompats with Submodules
-Changed: Reworked Asset Providers to use Java-NIO.
-Added: IAsset supports now SubFiles that are related to the main file.
-Fixed: Axises would trigger with Keyboard keys even if the keys were consumed.
-Added: GuiComponents can now be customized by adding custom renderers.
-Changed: TextField now only trigger user action if it can lose focus xD
This commit is contained in:
Speiger 2021-08-30 04:01:16 +02:00
parent 84522cc130
commit b00e330db9
18 changed files with 244 additions and 195 deletions

View File

@ -1,23 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>SimpleJavaEngine</name>
<comment>Project SimpleJavaEngine created by Buildship.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<comment></comment>
<projects/>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments/>
</buildCommand>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments/>
</buildCommand>
</buildSpec>
<linkedResources/>
<filteredResources/>
</projectDescription>

View File

@ -1,4 +1,4 @@
org.gradle.jvmargs=-Xmx2G
lwjglVersion = 3.3.0-SNAPSHOT
lwjglVersion = 3.2.4-SNAPSHOT
lwjglNatives = natives-windows

View File

@ -42,6 +42,11 @@ public final class AssetLocation
return of(domain+":"+location + "/" + subPath);
}
public AssetLocation alternate(String alterversion)
{
return of(domain+":"+location+"."+alterversion);
}
@Override
public String toString()
{

View File

@ -3,6 +3,8 @@ package speiger.src.coreengine.assets;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -16,36 +18,40 @@ import speiger.src.coreengine.assets.reloader.IReloadableResource;
public class AssetManager implements IReloadableResource
{
Map<String, DomainAssets> domains = new Object2ObjectLinkedOpenHashMap<String, DomainAssets>();
File file;
Map<String, DomainAssets> domains = new Object2ObjectLinkedOpenHashMap<>();
Path path;
public AssetManager(File file)
{
this.file = file;
this(file.toPath());
}
public File getMainAsset()
public AssetManager(Path path)
{
return file;
this.path = path;
}
public Path getMainAsset()
{
return path;
}
@Override
public void reload()
{
domains.clear();
loadAssetPackage(file);
loadAssetPackage(path);
}
public void loadAssetPackage(File file)
{
if(file.isDirectory())
{
loadAssets(new FolderAssetPackage(file));
}
else if(isZipFile(file))
{
loadAssets(new ZipAssetPackage(file));
}
loadAssetPackage(file.toPath());
}
public void loadAssetPackage(Path path)
{
if(Files.notExists(path)) return;
if(Files.isDirectory(path)) loadAssets(new FolderAssetPackage(path));
else if(isZipFile(path)) loadAssets(new ZipAssetPackage(path));
}
public void loadAssets(IAssetPackage packages)
@ -72,7 +78,7 @@ public class AssetManager implements IReloadableResource
DomainAssets asset = domains.get(location.getDomain());
if(asset == null)
{
throw new FileNotFoundException("File["+location.toString()+"] not found");
throw new FileNotFoundException("Domain & File["+location.toString()+"] not found");
}
return asset.getAsset(location);
}
@ -96,7 +102,7 @@ public class AssetManager implements IReloadableResource
DomainAssets asset = domains.get(location.getDomain());
if(asset == null)
{
throw new FileNotFoundException("File["+location.toString()+"] not found");
throw new FileNotFoundException("Domain & File["+location.toString()+"] not found");
}
return asset.getMultiAsset(location, subLocations);
}
@ -111,16 +117,10 @@ public class AssetManager implements IReloadableResource
return asset.getAllAssets(location);
}
protected boolean isZipFile(File file)
protected boolean isZipFile(Path file)
{
try(ZipFile zip = new ZipFile(file))
{
return true;
}
catch(Exception e)
{
}
return false;
try(ZipFile zip = new ZipFile(file.toFile())) { return true; }
catch(Exception e) { return false; }
}
static class DomainAssets
@ -137,15 +137,12 @@ public class AssetManager implements IReloadableResource
for(int i = packages.size() - 1;i>=0;i--)
{
IAsset asset = packages.get(i).getAsset(location);
if(asset != null)
{
return asset;
}
if(asset != null) return asset;
}
throw new FileNotFoundException("File["+location.toString()+"] not found");
}
public MultiAsset getMultiAsset(AssetLocation location, AssetLocation[] subLocations)
public MultiAsset getMultiAsset(AssetLocation location, AssetLocation... subLocations)
{
for(int i = packages.size() - 1;i>=0;i--)
{
@ -171,10 +168,7 @@ public class AssetManager implements IReloadableResource
for(IAssetPackage entry : packages)
{
IAsset asset = entry.getAsset(location);
if(asset != null)
{
assets.add(asset);
}
if(asset != null) assets.add(asset);
}
if(assets.isEmpty())
{

View File

@ -12,6 +12,8 @@ public interface IAsset extends Closeable
{
public AssetLocation getLocation();
public IAsset subAsset(String alternative);
public InputStream getStream() throws IOException;
public BufferedImage getTexture() throws Exception;

View File

@ -19,10 +19,7 @@ public class MultiAsset implements Closeable
{
for(int i = 0,m=assets.length;i<m;i++)
{
if(assets[i] != null)
{
assets[i].close();
}
if(assets[i] != null) assets[i].close();
}
assets = null;
}

View File

@ -1,41 +1,45 @@
package speiger.src.coreengine.assets.impl;
import java.awt.image.BufferedImage;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import javax.imageio.ImageIO;
import com.google.gson.JsonObject;
import speiger.src.collections.objects.lists.ObjectArrayList;
import speiger.src.coreengine.assets.AssetLocation;
import speiger.src.coreengine.assets.IAsset;
import speiger.src.coreengine.utils.helpers.JsonUtil;
public class FileAsset implements IAsset
public class FolderAsset implements IAsset
{
File file;
AssetLocation location;
List<Closeable> toClose = new ArrayList<Closeable>();
Path path;
List<Closeable> closeable;
public FileAsset(File file, AssetLocation location)
public FolderAsset(AssetLocation location, Path path)
{
this(location, path, new ObjectArrayList<>());
}
public FolderAsset(AssetLocation location, Path path, List<Closeable> closeable)
{
this.file = file;
this.location = location;
this.path = path;
this.closeable = closeable;
}
@Override
public void close() throws IOException
{
for(Closeable close : toClose)
for(Closeable close : closeable)
{
try
{
@ -46,7 +50,14 @@ public class FileAsset implements IAsset
e.printStackTrace();
}
}
toClose.clear();
closeable.clear();
}
@Override
public IAsset subAsset(String alternative)
{
Path newPath = path.resolveSibling(path.getFileName().toString()+"."+alternative);
return Files.exists(newPath) ? new FolderAsset(location.alternate(alternative), newPath, closeable) : null;
}
@Override
@ -58,30 +69,30 @@ public class FileAsset implements IAsset
@Override
public InputStream getStream() throws IOException
{
return new BufferedInputStream(markClosed(new FileInputStream(file)));
}
@Override
public BufferedReader getStringReader() throws IOException
{
return new BufferedReader(markClosed(new FileReader(file)));
return markClosed(Files.newInputStream(path));
}
@Override
public BufferedImage getTexture() throws Exception
{
return ImageIO.read(file);
return ImageIO.read(getStream());
}
@Override
public BufferedReader getStringReader() throws IOException
{
return markClosed(Files.newBufferedReader(path));
}
@Override
public JsonObject getJsonObject() throws IOException
{
return JsonUtil.loadFile(file);
return JsonUtil.loadFile(path);
}
protected <T extends Closeable> T markClosed(T value)
{
toClose.add(value);
closeable.add(value);
return value;
}
}

View File

@ -1,47 +1,54 @@
package speiger.src.coreengine.assets.impl;
import java.io.File;
import java.io.FileFilter;
import java.util.ArrayList;
import java.io.IOException;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import speiger.src.collections.objects.lists.ObjectArrayList;
import speiger.src.coreengine.assets.AssetLocation;
import speiger.src.coreengine.assets.IAsset;
import speiger.src.coreengine.assets.IAssetPackage;
import speiger.src.coreengine.assets.impl.FolderAsset;
public class FolderAssetPackage implements IAssetPackage
{
static final FileFilter FOLDER_FILTER = new FileFilter(){
@Override
public boolean accept(File f)
{
return f.isDirectory();
}
};
File file;
Path baseFolder;
public FolderAssetPackage(File file)
public FolderAssetPackage(File baseFolder)
{
this.file = file;
this(baseFolder.toPath());
}
public FolderAssetPackage(Path baseFolder)
{
this.baseFolder = baseFolder;
}
@Override
public List<String> getDomains()
{
List<String> result = new ArrayList<String>();
File asset = new File(file, "assets/");
for(File file : asset.listFiles(FOLDER_FILTER))
List<String> domains = new ObjectArrayList<>();
try(DirectoryStream<Path> dirs = Files.newDirectoryStream(baseFolder.resolve("assets")))
{
result.add(file.getAbsolutePath().substring(asset.getAbsolutePath().length() + 1).replace("\\", "/").replace("\"", "/"));
for(Path path : dirs)
{
domains.add(path.getFileName().toString());
}
}
return result;
catch(IOException e)
{
e.printStackTrace();
}
return domains;
}
@Override
public IAsset getAsset(AssetLocation location)
{
File asset = new File(file, location.getActualLocation());
return asset.isFile() ? new FileAsset(asset, location) : null;
Path path = baseFolder.resolve(location.getActualLocation());
return Files.exists(path) ? new FolderAsset(location, path) : null;
}
}

View File

@ -1,13 +1,11 @@
package speiger.src.coreengine.assets.impl;
import java.awt.image.BufferedImage;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.nio.file.Files;
import java.nio.file.Path;
import javax.imageio.ImageIO;
@ -19,29 +17,44 @@ import speiger.src.coreengine.utils.helpers.JsonUtil;
public class ZipAsset implements IAsset
{
ZipFile file;
ZipEntry entry;
Runnable closer;
AssetLocation location;
Runnable runnable;
Path path;
public ZipAsset(ZipFile file, ZipEntry entry, AssetLocation location, Runnable runnable)
public ZipAsset(Runnable closer, AssetLocation location, Path path)
{
this.file = file;
this.entry = entry;
this.closer = closer;
this.location = location;
this.runnable = runnable;
this.path = path;
}
@Override
public void close() throws IOException
{
if(runnable != null)
if(closer != null)
{
runnable.run();
runnable = null;
closer.run();
closer = null;
}
}
private void closeInternal()
{
if(closer != null)
{
closer.run();
closer = null;
}
}
@Override
public IAsset subAsset(String alternative)
{
if(closer == null) return null;
Path newPath = path.resolveSibling(path.getFileName().toString()+"."+alternative);
return Files.exists(newPath) ? new ZipAsset(this::closeInternal, location.alternate(alternative), newPath) : null;
}
@Override
public AssetLocation getLocation()
{
@ -51,25 +64,24 @@ public class ZipAsset implements IAsset
@Override
public InputStream getStream() throws IOException
{
return new BufferedInputStream(file.getInputStream(entry));
return Files.newInputStream(path);
}
@Override
public BufferedImage getTexture() throws Exception
{
return ImageIO.read(file.getInputStream(entry));
return ImageIO.read(getStream());
}
@Override
public BufferedReader getStringReader() throws IOException
{
return new BufferedReader(new InputStreamReader(file.getInputStream(entry)));
return Files.newBufferedReader(path);
}
@Override
public JsonObject getJsonObject() throws IOException
{
return JsonUtil.loadFile(file.getInputStream(entry));
return JsonUtil.loadFile(path);
}
}

View File

@ -2,91 +2,73 @@ package speiger.src.coreengine.assets.impl;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.nio.file.DirectoryStream;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import speiger.src.collections.objects.lists.ObjectArrayList;
import speiger.src.coreengine.assets.AssetLocation;
import speiger.src.coreengine.assets.IAsset;
import speiger.src.coreengine.assets.IAssetPackage;
import speiger.src.coreengine.utils.collections.iterators.IterableWrapper;
public class ZipAssetPackage implements IAssetPackage
{
public static final int ASSET_OFFSET = "assets/".length();
File file;
ZipFile cache = null;
Path baseFolder;
FileSystem cache;
AtomicInteger usedReferences = new AtomicInteger();
Runnable referenceCleaner = this::cleanReference;
public ZipAssetPackage(File file)
{
this.file = file;
this(file.toPath());
}
protected ZipFile getReference() throws IOException
public ZipAssetPackage(Path baseFolder)
{
usedReferences.getAndIncrement();
if(cache == null) cache = new ZipFile(file);
return cache;
this.baseFolder = baseFolder;
}
protected void onReferenceClosed()
private void cleanReference()
{
int left = usedReferences.decrementAndGet();
if(left == 0 && cache != null)
{
try
{
cache.close();
}
try { cache.close(); }
catch(Exception e) {e.printStackTrace();}
cache = null;
}
else if(left < 0)
{
usedReferences.set(0);
}
else if(left < 0) usedReferences.set(0);
}
protected FileSystem getReference() throws IOException
{
usedReferences.getAndIncrement();
if(cache == null) cache = FileSystems.newFileSystem(baseFolder, null);
return cache;
}
@Override
public List<String> getDomains()
{
try
List<String> domains = new ObjectArrayList<>();
try(FileSystem system = FileSystems.newFileSystem(baseFolder, null))
{
List<String> result = new ArrayList<String>();
ZipFile zip = new ZipFile(file);
for(ZipEntry entry : IterableWrapper.wrap(zip.entries()))
try(DirectoryStream<Path> dirs = Files.newDirectoryStream(system.getPath("assets")))
{
String name = entry.getName();
if(isPathValid(name))
for(Path path : dirs)
{
result.add(name.substring(ASSET_OFFSET, name.length() - 1));
String s = path.getFileName().toString();
domains.add(s.substring(0, s.length()-1));
}
}
zip.close();
return result;
catch(Exception e) { e.printStackTrace(); }
}
catch(IOException e)
{
e.printStackTrace();
return Collections.emptyList();
}
}
private boolean isPathValid(String input)
{
if(input.startsWith("assets/"))
{
int index = input.indexOf("/", ASSET_OFFSET);
if(index != -1 && input.length() - index <= 1)
{
return true;
}
}
return false;
catch(Exception e) { e.printStackTrace(); }
return domains;
}
@Override
@ -94,18 +76,9 @@ public class ZipAssetPackage implements IAssetPackage
{
try
{
ZipFile zip = getReference();
ZipEntry entry = zip.getEntry(location.getActualLocation());
if(entry != null)
{
return new ZipAsset(zip, entry, location, this::onReferenceClosed);
}
Path path = getReference().getPath(location.getActualLocation());
return Files.exists(path) ? new ZipAsset(referenceCleaner, location, path) : null;
}
catch(Exception e)
{
e.printStackTrace();
}
onReferenceClosed();
return null;
catch(Exception e) { return null; }
}
}

View File

@ -6,7 +6,6 @@ import speiger.src.collections.objects.sets.ObjectLinkedOpenHashSet;
public class ResourceReloader
{
// public static ResourceReloader INSTANCE = new ResourceReloader();
Set<IReloadableResource> resources = new ObjectLinkedOpenHashSet<IReloadableResource>();
boolean globalRemoval = false;
boolean reloading = false;

View File

@ -23,6 +23,7 @@ import speiger.src.coreengine.rendering.gui.helper.box.GuiBox;
import speiger.src.coreengine.rendering.gui.helper.box.IGuiBox;
import speiger.src.coreengine.rendering.gui.helper.constrains.ComponentConstrains;
import speiger.src.coreengine.rendering.gui.helper.constrains.Constrain;
import speiger.src.coreengine.rendering.gui.renderer.IComponentRenderer;
import speiger.src.coreengine.rendering.gui.renderer.UIRenderer;
import speiger.src.coreengine.rendering.input.Keyboard;
import speiger.src.coreengine.rendering.input.bindings.utils.BindingType;
@ -60,6 +61,7 @@ public abstract class GuiComponent extends FlagHolder
ComponentConstrains constraints = null;
Animator animation = null;
KeyBindAction binding = null;
IComponentRenderer<GuiComponent> customRenderer;
Set<Consumer<GuiComponent>>[] listeners = CollectionUtils.createSets(3, true);
Set<GuiComponent> children = new ObjectLinkedOpenHashSet<>();
Set<GuiComponent> popupChildren = new ObjectLinkedOpenHashSet<>();
@ -429,6 +431,12 @@ public abstract class GuiComponent extends FlagHolder
return this;
}
public <T extends GuiComponent> GuiComponent setCustomRenderer(IComponentRenderer<T> renderer)
{
customRenderer = (IComponentRenderer<GuiComponent>)renderer;
return this;
}
private void addBindingTooltip()
{
tooltips.addComponent(binding.getTooltip(), new TextComponent(0F, 0F, 200F, 0F, "Key: "+ModType.getMods(binding.mod)+BindingType.KEYBOARD.getName(binding.key)).setLimitedHeight(false).setAlignment(Align.LEFT_TOP, Align.LEFT_TOP).setScale(0.5F));
@ -790,11 +798,22 @@ public abstract class GuiComponent extends FlagHolder
public final void onRender(int mouseX, int mouseY, float particalTicks)
{
onPreRender();
getRenderer().setVisibility(totalVisibility).setBrightness(brightness);
if(renderSelf(mouseX, mouseY, particalTicks)) renderChildren(mouseX, mouseY, particalTicks);
onPostRender();
getRenderer().resetEffects();
if(customRenderer != null)
{
customRenderer.onPreRender(this);
getRenderer().setVisibility(totalVisibility).setBrightness(brightness);
if(customRenderer.render(this)) renderChildren(mouseX, mouseY, particalTicks);
customRenderer.onPostRender(this);
getRenderer().resetEffects();
}
else
{
onPreRender();
getRenderer().setVisibility(totalVisibility).setBrightness(brightness);
if(renderSelf(mouseX, mouseY, particalTicks)) renderChildren(mouseX, mouseY, particalTicks);
onPostRender();
getRenderer().resetEffects();
}
if(getGui() instanceof GuiScreenBase)
{
((GuiScreenBase)getGui()).drawBox(this);

View File

@ -581,11 +581,14 @@ public class TextFieldComponent extends GuiComponent
@Override
public void onFocusLost()
{
if(isFlagSet(FLAG_FOCUS))
if(isFlagSet(FLAG_CAN_LOSE_FOCUS))
{
notifyListeners(LISTENER_USER_ACTION);
if(isFlagSet(FLAG_FOCUS))
{
notifyListeners(LISTENER_USER_ACTION);
}
setFocused(false);
}
setFocused(false);
}
protected void handleDoubleClick(int position)

View File

@ -20,7 +20,7 @@ public class VerticalLayout implements Consumer<GuiComponent>
this.components.addAll(components);
for(int i = 0;i<components.size();i++)
{
components.get(i).addChangeListener(this);
components.get(i).addChangeListener(this).addCloseListener(this::removeComponent);
}
this.box = box;
this.padding = padding;

View File

@ -5,7 +5,6 @@ import speiger.src.coreengine.rendering.gui.components.ButtonComponent;
import speiger.src.coreengine.rendering.gui.components.TextComponent;
import speiger.src.coreengine.rendering.gui.components.TextFieldComponent;
import speiger.src.coreengine.rendering.gui.components.WindowComponent;
import speiger.src.coreengine.rendering.gui.helper.constrains.ComponentConstrains;
import speiger.src.coreengine.rendering.gui.helper.constrains.ParentConstrain;
import speiger.src.coreengine.rendering.gui.helper.constrains.PixelConstrain;
import speiger.src.coreengine.rendering.gui.helper.constrains.RelativeConstrain;
@ -14,7 +13,7 @@ import speiger.src.coreengine.rendering.gui.helper.constrains.TextConstrain;
public class TextInputComponent extends WindowComponent
{
TextComponent message = new TextComponent().setLimitedHeight(false).setTextScale(0.5F);
TextFieldComponent input = new TextFieldComponent(ColorObject.GRAY);
TextFieldComponent input = new TextFieldComponent(ColorObject.GRAY).setCanLoseFocus(false).setInfiniteText(true).setMaxTextLength(Integer.MAX_VALUE).setFocused(true);
ButtonComponent confirm = new ButtonComponent("Confirm", ColorObject.DARK_GREEN);
ButtonComponent cancel = new ButtonComponent("Cancel", ColorObject.RED);
@ -46,13 +45,19 @@ public class TextInputComponent extends WindowComponent
confirm.getText().setTextScale(0.5F);
cancel.getText().setTextScale(0.5F);
input.getRawText().setTextScale(0.5F);
addChild(confirm.addChangeListener(minimizedListener).addUserActionListener((T) -> notifyListeners(LISTENER_USER_ACTION)).addUserActionListener(closeListener), new ComponentConstrains(new RelativeConstrain(0F), new ParentConstrain(10F).invert(), new RelativeConstrain(0.5F), new PixelConstrain(10F)));
addChild(cancel.addChangeListener(minimizedListener).addUserActionListener(closeListener), new ComponentConstrains(new RelativeConstrain(0.5F), new ParentConstrain(10F).invert(), new RelativeConstrain(0.5F), new PixelConstrain(10F)));
addChild(message, new ComponentConstrains(new PixelConstrain(10F), new PixelConstrain(11F), new ParentConstrain(10F), TextConstrain.height(message)));
addChild(input, new ComponentConstrains(new PixelConstrain(10F), TextConstrain.height(message).setPadding(15F), new ParentConstrain(10F), new PixelConstrain(12F)));
addChild(confirm.addChangeListener(minimizedListener).addUserActionListener(this::onListen), new RelativeConstrain(0F), new ParentConstrain(10F).invert(), new RelativeConstrain(0.5F), new PixelConstrain(10F));
addChild(cancel.addChangeListener(minimizedListener).addUserActionListener(closeListener), new RelativeConstrain(0.5F), new ParentConstrain(10F).invert(), new RelativeConstrain(0.5F), new PixelConstrain(10F));
addChild(message.addChangeListener(minimizedListener), new PixelConstrain(10F), new PixelConstrain(11F), new ParentConstrain(10F), TextConstrain.height(message));
addChild(input.addChangeListener(minimizedListener).addUserActionListener(this::onListen), new PixelConstrain(10F), TextConstrain.height(message).setPadding(15F), new ParentConstrain(10F), new PixelConstrain(12F));
getBox().setHeight(45F + message.getMetadata().getMaxHeight());
}
private void onListen()
{
notifyListeners(LISTENER_USER_ACTION);
closeListener.accept(this);
}
@Override
public boolean isPopup()
{

View File

@ -0,0 +1,10 @@
package speiger.src.coreengine.rendering.gui.renderer;
import speiger.src.coreengine.rendering.gui.GuiComponent;
public interface IComponentRenderer<T extends GuiComponent>
{
public void onPreRender(T component);
public boolean render(T component);
public void onPostRender(T component);
}

View File

@ -15,6 +15,7 @@ public class Keyboard
{
public static final Keyboard INSTANCE = new Keyboard();
boolean[] pressedKeys = new boolean[350];
boolean[] nonConsumedKeys = new boolean[350];
EventBus bus;
BiPredicate<Integer, Keyboard> filter;
@ -49,6 +50,7 @@ public class Keyboard
else
{
pressedKeys[key] = false;
nonConsumedKeys[key] = false;
InputBinding.BINDINGS.updatePressing(BindingType.KEYBOARD, key, false);
}
}
@ -63,6 +65,7 @@ public class Keyboard
{
return;
}
nonConsumedKeys[key] = true;
InputBinding.BINDINGS.updatePressing(BindingType.KEYBOARD, key, true);
}
}
@ -92,6 +95,11 @@ public class Keyboard
return key <= 162;
}
public static boolean isKeyFullyPressed(int key)
{
return INSTANCE.isPressed(key) && !INSTANCE.isConsumed(key);
}
public static boolean isKeyPressed(int key)
{
return INSTANCE.isPressed(key);
@ -101,4 +109,9 @@ public class Keyboard
{
return pressedKeys[key];
}
public boolean isConsumed(int key)
{
return !nonConsumedKeys[key];
}
}

View File

@ -21,7 +21,7 @@ public enum BindingType
@Override
public boolean isPressed(int key)
{
return Keyboard.isKeyPressed(key);
return Keyboard.isKeyFullyPressed(key);
}
},
MOUSE