use of org.terasology.engine.logic.console.Message in project Terasology by MovingBlocks.
the class CyclingTabCompletionEngine method complete.
@Override
public String complete(String rawCommand) {
if (rawCommand.length() <= 0) {
reset();
previousMessage = new Message("Type 'help' to list all commands.");
console.addMessage(previousMessage);
return null;
} else if (query == null) {
query = rawCommand;
}
String commandNameRaw = console.processCommandName(query);
Name commandName = new Name(commandNameRaw);
List<String> commandParameters = console.processParameters(query);
ConsoleCommand command = console.getCommand(commandName);
int suggestedIndex = commandParameters.size() + (query.charAt(query.length() - 1) == ' ' ? 1 : 0);
Set<String> matches = findMatches(commandName, commandParameters, command, suggestedIndex);
if (matches == null || matches.size() <= 0) {
return query;
}
if (previousMatches == null || !matches.equals(Sets.newHashSet(previousMatches))) {
reset(false);
if (matches.size() == 1) {
return generateResult(matches.iterator().next(), commandName, commandParameters, suggestedIndex);
}
/* if (matches.length > MAX_CYCLES) {
console.addMessage(new Message("Too many hits, please refine your search"));
return query;
}*/
// TODO Find out a better way to handle too many results while returning useful information
previousMatches = Lists.newArrayList(matches);
Collections.sort(previousMatches);
}
StringBuilder matchMessageString = new StringBuilder();
for (int i = 0; i < previousMatches.size(); i++) {
if (i > 0) {
matchMessageString.append(' ');
}
String match = previousMatches.get(i);
if (selectionIndex == i) {
match = FontColor.getColored(match, ConsoleColors.COMMAND);
}
matchMessageString.append(match);
}
Message matchMessage = new Message(matchMessageString.toString());
String suggestion = previousMatches.get(selectionIndex);
if (previousMessage != null) {
console.replaceMessage(previousMessage, matchMessage);
} else {
console.addMessage(matchMessage);
}
previousMessage = matchMessage;
selectionIndex = (selectionIndex + 1) % previousMatches.size();
return generateResult(suggestion, commandName, commandParameters, suggestedIndex);
}
use of org.terasology.engine.logic.console.Message in project Terasology by MovingBlocks.
the class ConsoleScreen method initialise.
@Override
public void initialise() {
setAnimationSystem(new SwipeMenuAnimationSystem(0.2f, Direction.TOP_TO_BOTTOM));
final ScrollableArea scrollArea = find("scrollArea", ScrollableArea.class);
scrollArea.moveToBottom();
commandLine = find("commandLine", UICommandEntry.class);
getManager().setFocus(commandLine);
commandLine.setTabCompletionEngine(new CyclingTabCompletionEngine(console, localPlayer));
commandLine.bindCommandHistory(new ReadOnlyBinding<List<String>>() {
@Override
public List<String> get() {
return console.getPreviousCommands();
}
});
commandLine.subscribe(widget -> {
String text = commandLine.getText();
if (StringUtils.isNotBlank(text)) {
console.execute(text, localPlayer.getClientEntity());
}
scrollArea.moveToBottom();
});
final UIText history = find("messageHistory", UIText.class);
history.bindText(new ReadOnlyBinding<String>() {
@Override
public String get() {
StringBuilder messageList = new StringBuilder();
for (Message message : console.getMessages()) {
messageList.append(FontColor.getColored(message.getMessage(), message.getType().getColor()));
if (message.hasNewLine()) {
messageList.append(Console.NEW_LINE);
}
}
return messageList.toString();
}
});
}
use of org.terasology.engine.logic.console.Message in project Terasology by MovingBlocks.
the class ChatScreen method initialise.
@Override
public void initialise() {
final ScrollableArea scrollArea = find("scrollArea", ScrollableArea.class);
scrollArea.moveToBottom();
commandLine = find("commandLine", UIText.class);
getManager().setFocus(commandLine);
commandLine.subscribe(widget -> {
String text = commandLine.getText();
if (StringUtils.isNotBlank(text)) {
String command = "say";
List<String> params = Collections.singletonList(text);
// TODO: move command execution to separate class
console.execute(new Name(command), params, localPlayer.getClientEntity());
commandLine.setText("");
scrollArea.moveToBottom();
NotificationOverlay overlay = nuiManager.addOverlay(NotificationOverlay.ASSET_URI, NotificationOverlay.class);
overlay.setVisible(true);
nuiManager.closeScreen(this);
} else {
commandLine.setText("");
nuiManager.closeScreen(this);
}
});
final UILabel history = find("messageHistory", UILabel.class);
history.bindText(new ReadOnlyBinding<String>() {
@Override
public String get() {
Iterable<Message> messageIterable = console.getMessages(CoreMessageType.CHAT, CoreMessageType.NOTIFICATION);
Stream<Message> messageStream = StreamSupport.stream(messageIterable.spliterator(), false);
return messageStream.map(Message::getMessage).collect(Collectors.joining(Console.NEW_LINE));
}
});
}
Aggregations