use of org.terasology.engine.input.BindButtonEvent in project Terasology by MovingBlocks.
the class EventCopier method copyEvent.
public Event copyEvent(Event toBeCopied) {
if (toBeCopied instanceof PlaySoundEvent) {
return toBeCopied;
} else if (toBeCopied instanceof BindButtonEvent) {
BindButtonEvent originalEvent = (BindButtonEvent) toBeCopied;
BindButtonEvent newEvent = (BindButtonEvent) createNewBindEvent(originalEvent);
newEvent.prepare(originalEvent.getId(), originalEvent.getState(), originalEvent.getDelta());
inputEventSetup(newEvent, originalEvent);
return newEvent;
} else if (toBeCopied instanceof KeyEvent) {
KeyEvent originalEvent = (KeyEvent) toBeCopied;
KeyEvent newEvent = createNewKeyEvent(originalEvent);
inputEventSetup(newEvent, originalEvent);
return newEvent;
} else if (toBeCopied instanceof BindAxisEvent) {
BindAxisEvent originalEvent = (BindAxisEvent) toBeCopied;
BindAxisEvent newEvent = (BindAxisEvent) createNewBindEvent(originalEvent);
newEvent.prepare(originalEvent.getId(), (float) originalEvent.getValue(), originalEvent.getDelta());
inputEventSetup(newEvent, originalEvent);
return newEvent;
} else if (toBeCopied instanceof MouseAxisEvent) {
MouseAxisEvent originalEvent = (MouseAxisEvent) toBeCopied;
MouseAxisEvent newEvent = createNewMouseAxisEvent(originalEvent);
inputEventSetup(newEvent, originalEvent);
return newEvent;
} else if (toBeCopied instanceof CameraTargetChangedEvent) {
CameraTargetChangedEvent originalEvent = (CameraTargetChangedEvent) toBeCopied;
return new CameraTargetChangedEvent(originalEvent.getOldTarget(), originalEvent.getNewTarget());
} else if (toBeCopied instanceof CharacterMoveInputEvent) {
CharacterMoveInputEvent originalEvent = (CharacterMoveInputEvent) toBeCopied;
return new CharacterMoveInputEvent(originalEvent.getSequenceNumber(), originalEvent.getPitch(), originalEvent.getYaw(), originalEvent.getMovementDirection(), originalEvent.isRunning(), originalEvent.isCrouching(), originalEvent.isJumping(), originalEvent.getDeltaMs());
} else if (toBeCopied instanceof MouseButtonEvent) {
MouseButtonEvent originalEvent = (MouseButtonEvent) toBeCopied;
MouseButtonEvent newEvent = new MouseButtonEvent(originalEvent.getButton(), originalEvent.getState(), originalEvent.getDelta());
newEvent.setMousePosition(originalEvent.getMousePosition());
inputEventSetup(newEvent, originalEvent);
return newEvent;
} else if (toBeCopied instanceof MouseWheelEvent) {
MouseWheelEvent originalEvent = (MouseWheelEvent) toBeCopied;
MouseWheelEvent newEvent = new MouseWheelEvent(originalEvent.getMousePosition(), originalEvent.getWheelTurns(), originalEvent.getDelta());
inputEventSetup(newEvent, originalEvent);
return newEvent;
} else if (toBeCopied instanceof GetMaxSpeedEvent) {
GetMaxSpeedEvent originalEvent = (GetMaxSpeedEvent) toBeCopied;
GetMaxSpeedEvent newEvent = new GetMaxSpeedEvent(originalEvent.getBaseValue(), originalEvent.getMovementMode());
newEvent.setModifiers(originalEvent.getModifiers());
newEvent.setMultipliers(originalEvent.getMultipliers());
newEvent.setPostModifiers(originalEvent.getPostModifiers());
return newEvent;
} else if (toBeCopied instanceof AttackEvent) {
AttackEvent originalEvent = (AttackEvent) toBeCopied;
AttackEvent newEvent = new AttackEvent(originalEvent.getInstigator(), originalEvent.getDirectCause());
return newEvent;
} else {
return null;
}
}
use of org.terasology.engine.input.BindButtonEvent in project Terasology by MovingBlocks.
the class BindsSubsystem method registerButtonBinds.
private void registerButtonBinds(ModuleEnvironment environment) {
Iterable<Class<?>> classes = environment.getTypesAnnotatedWith(RegisterBindButton.class);
for (Class<?> registerBindClass : classes) {
RegisterBindButton info = registerBindClass.getAnnotation(RegisterBindButton.class);
SimpleUri bindUri = new SimpleUri(environment.getModuleProviding(registerBindClass), info.id());
if (BindButtonEvent.class.isAssignableFrom(registerBindClass)) {
try {
BindableButton bindButton = registerBindButton(bindUri, info.description(), (BindButtonEvent) registerBindClass.newInstance());
bindButton.setMode(info.mode());
bindButton.setRepeating(info.repeating());
bindsConfiguration.getBinds(bindUri).stream().filter(input -> input != null).forEach(input -> linkBindButtonToInput(input, bindUri));
logger.debug("Registered button bind: {}", bindUri);
} catch (InstantiationException | IllegalAccessException e) {
logger.error("Failed to register button bind \"{}\"", e);
}
} else {
logger.error("Failed to register button bind \"{}\", does not extend BindButtonEvent", bindUri);
}
}
}
use of org.terasology.engine.input.BindButtonEvent in project Terasology by MovingBlocks.
the class SortOrderSystem method postBegin.
/**
* Initializes sort order.
*/
public void postBegin() {
initialized = true;
controlPressed = false;
Map<Integer, BindableButton> keys = bindsManager.getKeyBinds();
BindButtonSubscriber controlSubscriber = new BindButtonSubscriber() {
@Override
public boolean onPress(float delta, EntityRef target) {
if (!containsConsole()) {
controlPressed = true;
} else {
controlPressed = false;
}
return false;
}
@Override
public boolean onRepeat(float delta, EntityRef target) {
return false;
}
@Override
public boolean onRelease(float delta, EntityRef target) {
controlPressed = false;
return false;
}
};
BindButtonSubscriber tabSubscriber = new BindButtonSubscriber() {
@Override
public boolean onPress(float delta, EntityRef target) {
if (controlPressed) {
target.send(new FocusChangedEvent());
}
return false;
}
@Override
public boolean onRepeat(float delta, EntityRef target) {
if (controlPressed) {
target.send(new FocusChangedEvent());
}
return false;
}
@Override
public boolean onRelease(float delta, EntityRef target) {
return false;
}
};
if (keys.containsKey(Keyboard.Key.RIGHT_CTRL.getId())) {
keys.get(Keyboard.Key.RIGHT_CTRL.getId()).subscribe(controlSubscriber);
} else {
keys.put(Keyboard.Key.RIGHT_CTRL.getId(), new BindableButtonImpl(new SimpleUri("ctrlMod"), "Control Modifier", new BindButtonEvent()));
keys.get(Keyboard.Key.RIGHT_CTRL.getId()).subscribe(controlSubscriber);
}
if (keys.containsKey(Keyboard.Key.LEFT_CTRL.getId())) {
keys.get(Keyboard.Key.LEFT_CTRL.getId()).subscribe(controlSubscriber);
} else {
keys.put(Keyboard.Key.LEFT_CTRL.getId(), new BindableButtonImpl(new SimpleUri("ctrlMod"), "Control Modifier", new BindButtonEvent()));
keys.get(Keyboard.Key.LEFT_CTRL.getId()).subscribe(controlSubscriber);
}
if (keys.containsKey(Keyboard.Key.TAB.getId())) {
keys.get(Keyboard.Key.TAB.getId()).subscribe(tabSubscriber);
} else {
keys.put(Keyboard.Key.TAB.getId(), new BindableButtonImpl(new SimpleUri("changeFocus"), "Change Focus", new BindButtonEvent()));
keys.get(Keyboard.Key.TAB.getId()).subscribe(tabSubscriber);
}
current = 0;
index = 0;
layersFilled = new ArrayList<>();
enabledWidgets = new ArrayList<>();
used = new ArrayList<>();
inSortOrder = false;
}
Aggregations