Add online (aka ReplayCenter) module
Add localization extra (formally known as LocalizedResourcePack) Add version checker extra
This commit is contained in:
127
src/main/java/com/replaymod/online/gui/GuiLoginPrompt.java
Executable file
127
src/main/java/com/replaymod/online/gui/GuiLoginPrompt.java
Executable file
@@ -0,0 +1,127 @@
|
||||
package com.replaymod.online.gui;
|
||||
|
||||
import com.replaymod.online.api.ApiClient;
|
||||
import de.johni0702.minecraft.gui.container.AbstractGuiScreen;
|
||||
import de.johni0702.minecraft.gui.container.GuiScreen;
|
||||
import de.johni0702.minecraft.gui.element.GuiButton;
|
||||
import de.johni0702.minecraft.gui.element.GuiLabel;
|
||||
import de.johni0702.minecraft.gui.element.GuiPasswordField;
|
||||
import de.johni0702.minecraft.gui.element.GuiTextField;
|
||||
import de.johni0702.minecraft.gui.layout.CustomLayout;
|
||||
import eu.crushedpixel.replaymod.gui.GuiConstants;
|
||||
|
||||
public class GuiLoginPrompt extends AbstractGuiScreen<GuiLoginPrompt> {
|
||||
|
||||
private final GuiScreen parent, successScreen;
|
||||
private final ApiClient apiClient;
|
||||
|
||||
private GuiLabel usernameLabel = new GuiLabel(this).setI18nText("replaymod.gui.username");
|
||||
private GuiLabel passwordLabel = new GuiLabel(this).setI18nText("replaymod.gui.password");
|
||||
private GuiLabel noAccountLabel = new GuiLabel(this).setI18nText("replaymod.gui.login.noacc");
|
||||
private GuiLabel statusLabel = new GuiLabel(this);
|
||||
private GuiButton loginButton = new GuiButton(this).setI18nLabel("replaymod.gui.login").setSize(150, 20).setEnabled(false);
|
||||
private GuiButton cancelButton = new GuiButton(this).setI18nLabel("replaymod.gui.cancel").setSize(150, 20);
|
||||
private GuiButton registerButton = new GuiButton(this).setI18nLabel("replaymod.gui.register").setSize(150, 20);
|
||||
private GuiTextField username = new GuiTextField(this).setSize(145, 20).setMaxLength(16).setFocused(true);
|
||||
private GuiPasswordField password = new GuiPasswordField(this).setSize(145, 20).setNext(username).setPrevious(username)
|
||||
.setMaxLength(GuiConstants.MAX_PW_LENGTH);
|
||||
|
||||
{
|
||||
Runnable doLogin = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!loginButton.isEnabled()) return;
|
||||
statusLabel.setI18nText("replaymod.gui.login.logging");
|
||||
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
switch (apiClient.login(username.getText(), password.getText())) {
|
||||
case SUCCESS:
|
||||
statusLabel.setText("");
|
||||
getMinecraft().addScheduledTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
successScreen.display();
|
||||
}
|
||||
});
|
||||
break;
|
||||
case INVALID_DATA:
|
||||
statusLabel.setI18nText("replaymod.gui.login.incorrect");
|
||||
break;
|
||||
case IO_ERROR:
|
||||
statusLabel.setI18nText("replaymod.gui.login.connectionerror");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}, "replaymod-auth").start();
|
||||
}
|
||||
};
|
||||
username.onEnter(doLogin);
|
||||
password.onEnter(doLogin);
|
||||
loginButton.onClick(doLogin);
|
||||
cancelButton.onClick(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
successScreen.display();
|
||||
}
|
||||
});
|
||||
registerButton.onClick(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
new GuiRegister(apiClient, GuiLoginPrompt.this).display();
|
||||
}
|
||||
});
|
||||
Runnable contentValidation = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
loginButton.setEnabled(!username.getText().isEmpty() && !password.getText().isEmpty());
|
||||
}
|
||||
};
|
||||
username.onTextChanged(contentValidation);
|
||||
password.onTextChanged(contentValidation);
|
||||
}
|
||||
|
||||
public GuiLoginPrompt(ApiClient apiClient, GuiScreen parent, GuiScreen successScreen, boolean manuallyTriggered) {
|
||||
this.apiClient = apiClient;
|
||||
this.parent = parent;
|
||||
this.successScreen = successScreen;
|
||||
|
||||
//if the login prompt was opened automatically (on mod startup), show a "skip" instead of "cancel" button
|
||||
if(!manuallyTriggered) {
|
||||
cancelButton.setI18nLabel("replaymod.gui.login.skip");
|
||||
}
|
||||
|
||||
setLayout(new CustomLayout<GuiLoginPrompt>() {
|
||||
@Override
|
||||
protected void layout(GuiLoginPrompt container, int width, int height) {
|
||||
pos(username, width / 2 - 45, 30);
|
||||
pos(password, width / 2 - 45, 60);
|
||||
pos(loginButton, width / 2 - 152, 110);
|
||||
pos(cancelButton, width / 2 + 2, 110);
|
||||
|
||||
pos(usernameLabel, x(username) - 10 - usernameLabel.getMinSize().getWidth(), y(username) + 7);
|
||||
pos(passwordLabel, x(password) - 10 - passwordLabel.getMinSize().getWidth(), y(password) + 7);
|
||||
pos(statusLabel, width / 2 - statusLabel.getMinSize().getWidth() / 2, 92);
|
||||
|
||||
int labelWidth = noAccountLabel.getMinSize().getWidth();
|
||||
int buttonWidth = registerButton.getMaxSize().getWidth();
|
||||
int lineWidth = labelWidth + 5 + buttonWidth;
|
||||
int lineStart = width / 2 - lineWidth / 2;
|
||||
pos(noAccountLabel, lineStart, height - 22);
|
||||
pos(registerButton, lineStart + labelWidth + 5, height - 30);
|
||||
}
|
||||
});
|
||||
|
||||
setTitle(new GuiLabel().setI18nText("replaymod.gui.login.title"));
|
||||
}
|
||||
|
||||
public GuiScreen getSuccessScreen() {
|
||||
return successScreen;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GuiLoginPrompt getThis() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
162
src/main/java/com/replaymod/online/gui/GuiRegister.java
Normal file
162
src/main/java/com/replaymod/online/gui/GuiRegister.java
Normal file
@@ -0,0 +1,162 @@
|
||||
package com.replaymod.online.gui;
|
||||
|
||||
import com.mojang.authlib.exceptions.AuthenticationException;
|
||||
import com.replaymod.online.api.ApiClient;
|
||||
import com.replaymod.online.api.ApiException;
|
||||
import de.johni0702.minecraft.gui.container.AbstractGuiScreen;
|
||||
import de.johni0702.minecraft.gui.container.GuiPanel;
|
||||
import de.johni0702.minecraft.gui.element.*;
|
||||
import de.johni0702.minecraft.gui.layout.CustomLayout;
|
||||
import de.johni0702.minecraft.gui.layout.HorizontalLayout;
|
||||
import de.johni0702.minecraft.gui.layout.VerticalLayout;
|
||||
import eu.crushedpixel.replaymod.gui.GuiConstants;
|
||||
import eu.crushedpixel.replaymod.utils.EmailAddressUtils;
|
||||
import eu.crushedpixel.replaymod.utils.RegexUtils;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import org.lwjgl.util.Dimension;
|
||||
import org.lwjgl.util.ReadableColor;
|
||||
|
||||
public class GuiRegister extends AbstractGuiScreen<GuiRegister> {
|
||||
private final GuiPanel inputs;
|
||||
private final GuiTextField usernameInput, mailInput;
|
||||
private final GuiPasswordField passwordInput, passwordConfirmation;
|
||||
private final GuiButton registerButton = new GuiButton(this).setI18nLabel("replaymod.gui.register").setSize(150, 20).setDisabled();
|
||||
private final GuiButton cancelButton = new GuiButton(this).setI18nLabel("replaymod.gui.cancel").setSize(150, 20);
|
||||
private final GuiLabel disclaimerLabel = new GuiLabel(this).setI18nText("replaymod.gui.register.disclaimer");
|
||||
private final GuiLabel statusLabel = new GuiLabel(this).setColor(ReadableColor.RED);
|
||||
|
||||
{
|
||||
inputs = new GuiPanel(this).setLayout(new VerticalLayout().setSpacing(10));
|
||||
HorizontalLayout.Data data = new HorizontalLayout.Data(0.5);
|
||||
inputs.addElements(new VerticalLayout.Data(1),
|
||||
new GuiPanel().setLayout(new HorizontalLayout(HorizontalLayout.Alignment.RIGHT).setSpacing(10))
|
||||
.addElements(data, new GuiLabel().setI18nText("replaymod.gui.username"))
|
||||
.addElements(data, usernameInput = new GuiTextField().setMaxLength(16).setSize(145, 20)),
|
||||
new GuiPanel().setLayout(new HorizontalLayout(HorizontalLayout.Alignment.RIGHT).setSpacing(10))
|
||||
.addElements(data, new GuiLabel().setI18nText("replaymod.gui.mail"))
|
||||
.addElements(data, mailInput = new GuiTextField().setSize(145, 20)),
|
||||
new GuiPanel().setLayout(new HorizontalLayout(HorizontalLayout.Alignment.RIGHT).setSpacing(10))
|
||||
.addElements(data, new GuiLabel().setI18nText("replaymod.gui.password"))
|
||||
.addElements(data, passwordInput = new GuiPasswordField().setMaxLength(GuiConstants.MAX_PW_LENGTH+1).setSize(145, 20)),
|
||||
new GuiPanel().setLayout(new HorizontalLayout(HorizontalLayout.Alignment.RIGHT).setSpacing(10))
|
||||
.addElements(data, new GuiLabel().setI18nText("replaymod.gui.register.confirmpw"))
|
||||
.addElements(data, passwordConfirmation = new GuiPasswordField().setMaxLength(GuiConstants.MAX_PW_LENGTH+1).setSize(145, 20))
|
||||
);
|
||||
usernameInput.setNext(mailInput)
|
||||
.getNext().setNext(passwordInput)
|
||||
.getNext().setNext(passwordConfirmation)
|
||||
.getNext().setNext(usernameInput);
|
||||
|
||||
setLayout(new CustomLayout<GuiRegister>() {
|
||||
@Override
|
||||
protected void layout(GuiRegister container, int width, int height) {
|
||||
pos(inputs, width / 2 - inputs.getMinSize().getWidth() / 2, 30);
|
||||
pos(registerButton, width / 2 - 152, 170);
|
||||
pos(cancelButton, width / 2 + 2, 170);
|
||||
pos(statusLabel, width / 2 - statusLabel.getMinSize().getWidth() / 2, 152);
|
||||
|
||||
FontRenderer font = getMinecraft().fontRendererObj;
|
||||
int lineCount = font.listFormattedStringToWidth(disclaimerLabel.getText(), width - 10).size();
|
||||
Dimension dim = new Dimension(width - 10, font.FONT_HEIGHT * lineCount);
|
||||
disclaimerLabel.setSize(dim);
|
||||
pos(disclaimerLabel, 5, height - dim.getHeight() - 5);
|
||||
}
|
||||
});
|
||||
|
||||
setTitle(new GuiLabel().setI18nText("replaymod.gui.register.title"));
|
||||
|
||||
Runnable doRegister = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!registerButton.isEnabled()) return;
|
||||
|
||||
inputs.forEach(IGuiTextField.class).setDisabled();
|
||||
statusLabel.setI18nText("replaymod.gui.login.logging");
|
||||
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
String username = usernameInput.getText().trim();
|
||||
String mail = mailInput.getText().trim();
|
||||
String password = passwordInput.getText();
|
||||
apiClient.register(username, mail, password);
|
||||
|
||||
getMinecraft().addScheduledTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
parent.getSuccessScreen().display();
|
||||
}
|
||||
});
|
||||
} catch (ApiException ae) {
|
||||
statusLabel.setText(ae.getLocalizedMessage());
|
||||
} catch (AuthenticationException aue) {
|
||||
aue.printStackTrace();
|
||||
statusLabel.setI18nText("replaymod.gui.register.error.authfailed");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
statusLabel.setI18nText("replaymod.gui.login.connectionerror");
|
||||
} finally {
|
||||
inputs.forEach(IGuiTextField.class).setEnabled();
|
||||
}
|
||||
}
|
||||
}, "replaymod-register").start();
|
||||
}
|
||||
};
|
||||
inputs.forEach(IGuiTextField.class).onEnter(doRegister);
|
||||
registerButton.onClick(doRegister);
|
||||
|
||||
Runnable contentValidation = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String status = null;
|
||||
if (usernameInput.getText().length() < 5) {
|
||||
status = "replaymod.gui.register.error.shortusername";
|
||||
} else if(!RegexUtils.isValid(RegexUtils.ALPHANUMERIC_UNDERSCORE, usernameInput.getText().trim())) {
|
||||
status = "replaymod.gui.register.error.invalidname";
|
||||
} else if (passwordInput.getText().length() < GuiConstants.MIN_PW_LENGTH) {
|
||||
status = "replaymod.gui.register.error.shortpw";
|
||||
} else if (passwordInput.getText().length() > GuiConstants.MAX_PW_LENGTH) {
|
||||
status = "replaymod.gui.register.error.longpw";
|
||||
} else if (!EmailAddressUtils.isValidEmailAddress(mailInput.getText())) {
|
||||
status = "replaymod.api.invalidmail";
|
||||
} else if (!passwordConfirmation.getText().equals(passwordInput.getText())) {
|
||||
status = "replaymod.gui.register.error.nomatch";
|
||||
}
|
||||
|
||||
registerButton.setEnabled(status == null);
|
||||
|
||||
if (status != null
|
||||
&& !usernameInput.getText().isEmpty()
|
||||
&& !mailInput.getText().isEmpty()
|
||||
&& !passwordInput.getText().isEmpty()
|
||||
&& !passwordConfirmation.getText().isEmpty()) {
|
||||
statusLabel.setI18nText(status);
|
||||
} else {
|
||||
statusLabel.setText("");
|
||||
}
|
||||
}
|
||||
};
|
||||
inputs.forEach(IGuiTextField.class).onTextChanged(contentValidation);
|
||||
|
||||
cancelButton.onClick(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
parent.display();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private final ApiClient apiClient;
|
||||
private final GuiLoginPrompt parent;
|
||||
|
||||
public GuiRegister(ApiClient apiClient, GuiLoginPrompt parent) {
|
||||
this.apiClient = apiClient;
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GuiRegister getThis() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
456
src/main/java/com/replaymod/online/gui/GuiReplayCenter.java
Normal file
456
src/main/java/com/replaymod/online/gui/GuiReplayCenter.java
Normal file
@@ -0,0 +1,456 @@
|
||||
package com.replaymod.online.gui;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.primitives.Ints;
|
||||
import com.google.common.util.concurrent.FutureCallback;
|
||||
import com.google.common.util.concurrent.Futures;
|
||||
import com.mojang.realmsclient.gui.ChatFormatting;
|
||||
import com.replaymod.online.ReplayModOnline;
|
||||
import com.replaymod.online.api.ApiClient;
|
||||
import com.replaymod.online.api.ApiException;
|
||||
import com.replaymod.online.api.replay.SearchQuery;
|
||||
import com.replaymod.online.api.replay.holders.Category;
|
||||
import com.replaymod.online.api.replay.holders.FileInfo;
|
||||
import com.replaymod.online.api.replay.holders.FileRating;
|
||||
import com.replaymod.online.api.replay.holders.Rating;
|
||||
import com.replaymod.online.api.replay.pagination.DownloadedFilePagination;
|
||||
import com.replaymod.online.api.replay.pagination.FavoritedFilePagination;
|
||||
import com.replaymod.online.api.replay.pagination.Pagination;
|
||||
import com.replaymod.online.api.replay.pagination.SearchPagination;
|
||||
import de.johni0702.minecraft.gui.container.AbstractGuiContainer;
|
||||
import de.johni0702.minecraft.gui.container.GuiContainer;
|
||||
import de.johni0702.minecraft.gui.container.GuiPanel;
|
||||
import de.johni0702.minecraft.gui.container.GuiScreen;
|
||||
import de.johni0702.minecraft.gui.element.GuiButton;
|
||||
import de.johni0702.minecraft.gui.element.GuiImage;
|
||||
import de.johni0702.minecraft.gui.element.GuiLabel;
|
||||
import de.johni0702.minecraft.gui.element.IGuiButton;
|
||||
import de.johni0702.minecraft.gui.element.advanced.GuiResourceLoadingList;
|
||||
import de.johni0702.minecraft.gui.layout.CustomLayout;
|
||||
import de.johni0702.minecraft.gui.layout.HorizontalLayout;
|
||||
import de.johni0702.minecraft.gui.layout.VerticalLayout;
|
||||
import de.johni0702.minecraft.gui.popup.GuiYesNoPopup;
|
||||
import de.johni0702.minecraft.gui.utils.Colors;
|
||||
import de.johni0702.minecraft.gui.utils.Consumer;
|
||||
import de.johni0702.replaystudio.replay.ReplayMetaData;
|
||||
import eu.crushedpixel.replaymod.registry.ResourceHelper;
|
||||
import eu.crushedpixel.replaymod.utils.DurationUtils;
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.logging.log4j.core.helpers.Strings;
|
||||
import org.lwjgl.util.Dimension;
|
||||
import org.lwjgl.util.ReadableDimension;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class GuiReplayCenter extends GuiScreen {
|
||||
private final ReplayModOnline mod;
|
||||
private final ApiClient apiClient;
|
||||
|
||||
private GuiButton makeCategory(String name) {
|
||||
return new GuiButton().setI18nLabel("replaymod.gui.center.top." + name).setSize(75, 20);
|
||||
}
|
||||
|
||||
public final GuiButton categoryRecent = makeCategory("recent").onClick(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
show(new SearchPagination(apiClient,
|
||||
new SearchQuery(false, null, null, null, null, null, null, null, null, null)));
|
||||
categoryRecent.setDisabled();
|
||||
}
|
||||
});
|
||||
|
||||
public final GuiButton categoryBest = makeCategory("best").onClick(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
show(new SearchPagination(apiClient,
|
||||
new SearchQuery(true, null, null, null, null, null, null, null, null, null)));
|
||||
categoryBest.setDisabled();
|
||||
}
|
||||
});
|
||||
|
||||
public final GuiButton categoryDownloaded = makeCategory("downloaded").onClick(new Runnable()
|
||||
|
||||
{
|
||||
@Override
|
||||
public void run() {
|
||||
show(new DownloadedFilePagination(mod));
|
||||
categoryDownloaded.setDisabled();
|
||||
}
|
||||
});
|
||||
|
||||
public final GuiButton categoryFavorited = makeCategory("favorited").onClick(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
show(new FavoritedFilePagination(apiClient));
|
||||
categoryFavorited.setDisabled();
|
||||
}
|
||||
});
|
||||
|
||||
public final GuiButton categorySearch = makeCategory("search").onClick(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
searchPopup.open();
|
||||
}
|
||||
});
|
||||
|
||||
public final GuiPanel categories = new GuiPanel(this).setLayout(new HorizontalLayout().setSpacing(5))
|
||||
.addElements(null, categoryRecent, categoryBest, categoryDownloaded, categoryFavorited, categorySearch);
|
||||
|
||||
public final GuiResourceLoadingList<GuiReplayEntry> list = new GuiResourceLoadingList<GuiReplayEntry>(this).onSelectionChanged(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
GuiReplayEntry selected = list.getSelected();
|
||||
replayButtonPanel.forEach(IGuiButton.class).setEnabled(selected != null);
|
||||
if (selected != null) {
|
||||
int replayId = selected.fileInfo.getId();
|
||||
boolean favorited = favoritedReplays.contains(replayId);
|
||||
boolean liked = likedReplays.contains(replayId);
|
||||
boolean disliked = dislikedReplays.contains(replayId);
|
||||
|
||||
loadButton.setI18nLabel(selected.downloaded ? "replaymod.gui.load" : "replaymod.gui.download");
|
||||
|
||||
favoriteButton.setI18nLabel("replaymod.gui.center." + (favorited ? "unfavorite" : "favorite"));
|
||||
// Only allow button usage for either unfavorite or favorite after they've actually downloaded it
|
||||
favoriteButton.setEnabled(favorited || selected.downloaded);
|
||||
|
||||
// Similar for like/dislike buttons
|
||||
likeButton.setEnabled(selected.downloaded);
|
||||
dislikeButton.setEnabled(selected.downloaded);
|
||||
likeButton.setI18nLabel("replaymod.gui." + (liked ? "removelike" : "like"));
|
||||
dislikeButton.setI18nLabel("replaymod.gui." + (disliked ? "removedislike" : "dislike"));
|
||||
}
|
||||
}
|
||||
}).onLoad(new Consumer<Consumer<Supplier<GuiReplayEntry>>>() {
|
||||
@Override
|
||||
public void consume(Consumer<Supplier<GuiReplayEntry>> obj) {
|
||||
// Do not load any replays until the user has selected the category they'd like to view
|
||||
}
|
||||
}).setDrawShadow(true).setDrawSlider(true);
|
||||
|
||||
public final GuiButton loadButton = new GuiButton().onClick(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
FileInfo fileInfo = list.getSelected().fileInfo;
|
||||
mod.startReplay(fileInfo.getId(), fileInfo.getName(), GuiReplayCenter.this);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}).setSize(95, 20).setI18nLabel("replaymod.gui.download").setDisabled();
|
||||
|
||||
public final GuiButton favoriteButton = new GuiButton().onClick(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
int replayId = list.getSelected().fileInfo.getId();
|
||||
boolean favorited = favoritedReplays.contains(replayId);
|
||||
apiClient.favFile(replayId, !favorited);
|
||||
reloadFavorited();
|
||||
list.onSelectionChanged();
|
||||
} catch (IOException | ApiException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}).setSize(95, 20).setI18nLabel("replaymod.gui.center.favorite").setDisabled();
|
||||
|
||||
public final GuiButton likeButton = new GuiButton().onClick(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
int replayId = list.getSelected().fileInfo.getId();
|
||||
boolean liked = likedReplays.contains(replayId);
|
||||
apiClient.rateFile(replayId, liked ? Rating.RatingType.NEUTRAL : Rating.RatingType.LIKE);
|
||||
reloadRated();
|
||||
list.onSelectionChanged();
|
||||
} catch (IOException | ApiException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}).setSize(95, 20).setI18nLabel("replaymod.gui.like").setDisabled();
|
||||
|
||||
public final GuiButton dislikeButton = new GuiButton().onClick(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
int replayId = list.getSelected().fileInfo.getId();
|
||||
boolean disliked = dislikedReplays.contains(replayId);
|
||||
apiClient.rateFile(replayId, disliked ? Rating.RatingType.NEUTRAL : Rating.RatingType.DISLIKE);
|
||||
reloadRated();
|
||||
list.onSelectionChanged();
|
||||
} catch (IOException | ApiException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}).setSize(95, 20).setI18nLabel("replaymod.gui.dislike").setDisabled();
|
||||
|
||||
public final GuiButton logoutButton = new GuiButton().onClick(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Futures.addCallback(GuiYesNoPopup.open(GuiReplayCenter.this,
|
||||
new GuiLabel().setI18nText("replaymod.gui.center.logoutcallback").setColor(Colors.BLACK))
|
||||
.setYesI18nLabel("replaymod.gui.logout").setNoI18nLabel("replaymod.gui.cancel")
|
||||
.getFuture(), new FutureCallback<Boolean>() {
|
||||
@Override
|
||||
public void onSuccess(Boolean result) {
|
||||
if (result) {
|
||||
apiClient.logout();
|
||||
getMinecraft().displayGuiScreen(null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
}).setSize(195, 20).setI18nLabel("replaymod.gui.logout");
|
||||
|
||||
public final GuiButton mainMenuButton = new GuiButton().onClick(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
getMinecraft().displayGuiScreen(null);
|
||||
}
|
||||
}).setSize(195, 20).setI18nLabel("replaymod.gui.mainmenu");
|
||||
|
||||
public final GuiReplayCenterSearch searchPopup;
|
||||
|
||||
public final GuiPanel replayButtonPanel = new GuiPanel().setLayout(new HorizontalLayout().setSpacing(5))
|
||||
.addElements(null, loadButton, favoriteButton, likeButton, dislikeButton);
|
||||
public final GuiPanel generalButtonPanel = new GuiPanel().setLayout(new HorizontalLayout().setSpacing(5))
|
||||
.addElements(null, logoutButton, mainMenuButton);
|
||||
public final GuiPanel buttonPanel = new GuiPanel(this).setLayout(new VerticalLayout().setSpacing(5))
|
||||
.addElements(null, replayButtonPanel, generalButtonPanel);
|
||||
|
||||
private volatile Set<Integer> favoritedReplays = Collections.emptySet();
|
||||
private volatile Set<Integer> likedReplays = Collections.emptySet();
|
||||
private volatile Set<Integer> dislikedReplays = Collections.emptySet();
|
||||
|
||||
public GuiReplayCenter(ReplayModOnline mod) {
|
||||
this.mod = mod;
|
||||
this.apiClient = mod.getApiClient();
|
||||
this.searchPopup = new GuiReplayCenterSearch(this, apiClient);
|
||||
|
||||
setTitle(new GuiLabel().setI18nText("replaymod.gui.replaycenter"));
|
||||
|
||||
setLayout(new CustomLayout<GuiScreen>() {
|
||||
@Override
|
||||
protected void layout(GuiScreen container, int width, int height) {
|
||||
pos(buttonPanel, width / 2 - width(buttonPanel) / 2, height - 10 - height(buttonPanel));
|
||||
|
||||
pos(list, 0, 50);
|
||||
size(list, width, y(buttonPanel) - 10 - y(list));
|
||||
|
||||
pos(categories, width / 2 - width(categories) / 2, y(list) - 7 - height(categories));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void reloadFavorited() {
|
||||
try {
|
||||
favoritedReplays = new HashSet<>(Ints.asList(apiClient.getFavorites()));
|
||||
} catch (IOException | ApiException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void reloadRated() {
|
||||
try {
|
||||
Set<Integer> liked = new HashSet<>(), disliked = new HashSet<>();
|
||||
for (FileRating rating : apiClient.getRatedFiles()) {
|
||||
(rating.isRatingPositive() ? liked : disliked).add(rating.getFile());
|
||||
}
|
||||
this.likedReplays = liked;
|
||||
this.dislikedReplays = disliked;
|
||||
} catch (IOException | ApiException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void show(final Pagination pagination) {
|
||||
list.setOffsetY(0);
|
||||
list.onLoad(new Consumer<Consumer<Supplier<GuiReplayEntry>>>() {
|
||||
@Override
|
||||
public void consume(Consumer<Supplier<GuiReplayEntry>> obj) {
|
||||
if (pagination.getLoadedPages() < 0) {
|
||||
pagination.fetchPage();
|
||||
}
|
||||
|
||||
reloadFavorited();
|
||||
reloadRated();
|
||||
|
||||
int i = 0;
|
||||
for (final FileInfo fileInfo : pagination.getFiles()) {
|
||||
if (Thread.interrupted()) return;
|
||||
try {
|
||||
// Make sure that to int[] conversion doesn't have to occur in main thread
|
||||
final BufferedImage theThumb;
|
||||
if (fileInfo.hasThumbnail()) {
|
||||
BufferedImage buf = apiClient.downloadThumbnail(fileInfo.getId());
|
||||
// This is the same way minecraft calls this method, we cache the result and hand
|
||||
// minecraft a BufferedImage with way simpler logic using the precomputed values
|
||||
final int[] theIntArray = buf.getRGB(0, 0, buf.getWidth(), buf.getHeight(), null, 0, buf.getWidth());
|
||||
theThumb = new BufferedImage(buf.getWidth(), buf.getHeight(), BufferedImage.TYPE_INT_ARGB) {
|
||||
@Override
|
||||
public int[] getRGB(int startX, int startY, int w, int h, int[] rgbArray, int offset, int scansize) {
|
||||
System.arraycopy(theIntArray, 0, rgbArray, 0, theIntArray.length);
|
||||
return null; // Minecraft doesn't use the return value
|
||||
}
|
||||
};
|
||||
} else {
|
||||
theThumb = null;
|
||||
}
|
||||
|
||||
final int sortId = i++;
|
||||
final boolean downloaded = mod.hasDownloaded(fileInfo.getId());
|
||||
obj.consume(new Supplier<GuiReplayEntry>() {
|
||||
@Override
|
||||
public GuiReplayEntry get() {
|
||||
return new GuiReplayEntry(fileInfo, theThumb, sortId, downloaded);
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
FMLLog.getLogger().error("Could not load Replay File " + fileInfo.getId(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}).load();
|
||||
|
||||
categories.forEach(IGuiButton.class).setEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GuiReplayCenter getThis() {
|
||||
return this;
|
||||
}
|
||||
|
||||
private final GuiImage defaultThumbnail = new GuiImage().setTexture(ResourceHelper.getDefaultThumbnail());
|
||||
public class GuiReplayEntry extends AbstractGuiContainer<GuiReplayEntry> implements Comparable<GuiReplayEntry> {
|
||||
public final FileInfo fileInfo;
|
||||
public final GuiLabel name = new GuiLabel();
|
||||
public final GuiLabel author = new GuiLabel();
|
||||
public final GuiLabel date = new GuiLabel().setColor(Colors.LIGHT_GRAY);
|
||||
public final GuiLabel server = new GuiLabel().setColor(Colors.LIGHT_GRAY);
|
||||
public final GuiLabel category = new GuiLabel().setColor(Colors.GREY);
|
||||
public final GuiPanel stats = new GuiPanel().setLayout(new HorizontalLayout().setSpacing(3));
|
||||
public final GuiLabel favorites = new GuiLabel(stats).setColor(Colors.ORANGE);
|
||||
public final GuiLabel likes = new GuiLabel(stats).setColor(Colors.GREEN);
|
||||
public final GuiLabel dislikes = new GuiLabel(stats).setColor(Colors.RED);
|
||||
public final GuiPanel infoPanel = new GuiPanel(this).setLayout(new CustomLayout<GuiPanel>() {
|
||||
@Override
|
||||
protected void layout(GuiPanel container, int width, int height) {
|
||||
pos(name, 0, 0);
|
||||
pos(author, 0, height(name) + 2);
|
||||
pos(server, 0, y(author) + height(author) + 3);
|
||||
pos(category, 0, y(server) + height(server) + 3);
|
||||
|
||||
pos(date, width - width(date), y(author));
|
||||
pos(stats, width - width(stats), y(category));
|
||||
}
|
||||
}).addElements(null, name, author, date, server, category, stats);
|
||||
public final GuiImage thumbnail;
|
||||
public final GuiLabel duration = new GuiLabel();
|
||||
public final GuiPanel durationPanel = new GuiPanel().setBackgroundColor(Colors.HALF_TRANSPARENT)
|
||||
.addElements(null, duration).setLayout(new CustomLayout<GuiPanel>() {
|
||||
@Override
|
||||
protected void layout(GuiPanel container, int width, int height) {
|
||||
pos(duration, 2, 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReadableDimension calcMinSize(GuiContainer<?> container) {
|
||||
ReadableDimension dimension = duration.calcMinSize();
|
||||
return new Dimension(dimension.getWidth() + 2, dimension.getHeight() + 2);
|
||||
}
|
||||
});
|
||||
public final GuiLabel downloads = new GuiLabel();
|
||||
public final GuiPanel downloadsPanel = new GuiPanel().setBackgroundColor(Colors.HALF_TRANSPARENT)
|
||||
.addElements(null, downloads).setLayout(new CustomLayout<GuiPanel>() {
|
||||
@Override
|
||||
protected void layout(GuiPanel container, int width, int height) {
|
||||
pos(downloads, 2, 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReadableDimension calcMinSize(GuiContainer<?> container) {
|
||||
ReadableDimension dimension = downloads.calcMinSize();
|
||||
return new Dimension(dimension.getWidth() + 2, dimension.getHeight() + 2);
|
||||
}
|
||||
});
|
||||
|
||||
private final long dateMillis;
|
||||
private final int sortId;
|
||||
private final boolean downloaded;
|
||||
|
||||
public GuiReplayEntry(FileInfo fileInfo, BufferedImage thumbImage, int sortId, boolean downloaded) {
|
||||
this.fileInfo = fileInfo;
|
||||
this.sortId = sortId;
|
||||
this.downloaded = downloaded;
|
||||
ReplayMetaData metaData = fileInfo.getMetadata();
|
||||
|
||||
name.setText(ChatFormatting.UNDERLINE + FilenameUtils.getBaseName(fileInfo.getName()));
|
||||
author.setI18nText("replaymod.gui.center.author",
|
||||
"" + ChatFormatting.GRAY + ChatFormatting.ITALIC, fileInfo.getOwner());
|
||||
if (Strings.isEmpty(metaData.getServerName())) {
|
||||
server.setI18nText("replaymod.gui.iphidden").setColor(Colors.DARK_RED);
|
||||
} else {
|
||||
server.setText(metaData.getServerName());
|
||||
}
|
||||
dateMillis = metaData.getDate();
|
||||
date.setText(new SimpleDateFormat().format(new Date(dateMillis)));
|
||||
if (thumbImage == null) {
|
||||
thumbnail = new GuiImage(defaultThumbnail);
|
||||
addElements(null, thumbnail);
|
||||
} else {
|
||||
thumbnail = new GuiImage(this).setTexture(thumbImage);
|
||||
}
|
||||
thumbnail.setSize(45 * 16 / 9, 45);
|
||||
duration.setText(DurationUtils.convertSecondsToShortString(metaData.getDuration() / 1000));
|
||||
downloads.setText(fileInfo.getDownloads() + " ⬇");
|
||||
favorites.setText("⭑" + fileInfo.getFavorites());
|
||||
likes.setText("⬆" + fileInfo.getRatings().getPositive());
|
||||
dislikes.setText("⬇" + fileInfo.getRatings().getNegative());
|
||||
category.setText(ChatFormatting.ITALIC + Optional.fromNullable(Category.fromId(fileInfo.getCategory()))
|
||||
.or(Category.MISCELLANEOUS).toNiceString());
|
||||
addElements(null, durationPanel, downloadsPanel);
|
||||
|
||||
setLayout(new CustomLayout<GuiReplayEntry>() {
|
||||
@Override
|
||||
protected void layout(GuiReplayEntry container, int width, int height) {
|
||||
pos(thumbnail, 0, 0);
|
||||
x(durationPanel, width(thumbnail) - width(durationPanel));
|
||||
y(durationPanel, height(thumbnail) - height(durationPanel));
|
||||
x(downloadsPanel, width(thumbnail) - width(downloadsPanel));
|
||||
y(downloadsPanel, height(thumbnail) - height(durationPanel) - height(downloadsPanel));
|
||||
|
||||
pos(infoPanel, width(thumbnail) + 5, 0);
|
||||
size(infoPanel, width - width(thumbnail) - 5, height(thumbnail));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReadableDimension calcMinSize(GuiContainer<?> container) {
|
||||
return new org.lwjgl.util.Dimension(300, thumbnail.getMinSize().getHeight());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GuiReplayEntry getThis() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(GuiReplayEntry o) {
|
||||
return Integer.compare(sortId, o.sortId);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package com.replaymod.online.gui;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.replaymod.online.api.ApiClient;
|
||||
import com.replaymod.online.api.replay.SearchQuery;
|
||||
import com.replaymod.online.api.replay.holders.Category;
|
||||
import com.replaymod.online.api.replay.holders.MinecraftVersion;
|
||||
import com.replaymod.online.api.replay.pagination.SearchPagination;
|
||||
import de.johni0702.minecraft.gui.element.GuiButton;
|
||||
import de.johni0702.minecraft.gui.element.GuiLabel;
|
||||
import de.johni0702.minecraft.gui.element.GuiTextField;
|
||||
import de.johni0702.minecraft.gui.element.GuiToggleButton;
|
||||
import de.johni0702.minecraft.gui.element.advanced.GuiDropdownMenu;
|
||||
import de.johni0702.minecraft.gui.layout.GridLayout;
|
||||
import de.johni0702.minecraft.gui.popup.AbstractGuiPopup;
|
||||
import de.johni0702.minecraft.gui.utils.Colors;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GuiReplayCenterSearch extends AbstractGuiPopup<GuiReplayCenterSearch> {
|
||||
private final GuiReplayCenter replayCenter;
|
||||
private final ApiClient apiClient;
|
||||
public final GuiLabel title = new GuiLabel().setI18nText("replaymod.gui.center.search.filters").setColor(Colors.BLACK);
|
||||
public final GuiTextField name = new GuiTextField().setSize(120, 20).setI18nHint("replaymod.gui.center.search.name");
|
||||
public final GuiTextField server = new GuiTextField().setSize(120, 20).setI18nHint("replaymod.gui.center.search.server");
|
||||
public final GuiDropdownMenu<String> category = new GuiDropdownMenu<String>().setSize(120, 20);
|
||||
public final GuiDropdownMenu<String> version = new GuiDropdownMenu<String>().setSize(120, 20);
|
||||
public final GuiToggleButton<String> gameType = new GuiToggleButton<String>().setSize(120, 20);
|
||||
public final GuiToggleButton<String> sort = new GuiToggleButton<String>().setSize(120, 20);
|
||||
public final GuiButton cancelButton = new GuiButton().setSize(120, 20).onClick(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
close();
|
||||
}
|
||||
}).setI18nLabel("replaymod.gui.cancel");
|
||||
public final GuiButton searchButton = new GuiButton().setSize(120, 20).onClick(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
SearchQuery searchQuery = new SearchQuery();
|
||||
searchQuery.singleplayer = new Boolean[]{null,true, false}[gameType.getSelected()];
|
||||
searchQuery.category = category.getSelected() == 0 ? null : category.getSelected() - 1;
|
||||
searchQuery.version = version.getSelected() == 0
|
||||
? null : MinecraftVersion.values()[version.getSelected() - 1].getApiName();
|
||||
searchQuery.name = Strings.emptyToNull(name.getText().trim());
|
||||
searchQuery.server = Strings.emptyToNull(server.getText().trim());
|
||||
searchQuery.order = sort.getSelected() == 0;
|
||||
|
||||
close();
|
||||
replayCenter.show(new SearchPagination(apiClient, searchQuery));
|
||||
}
|
||||
}).setI18nLabel("replaymod.gui.center.top.search");
|
||||
{
|
||||
List<String> categories = new ArrayList<>();
|
||||
categories.add(I18n.format("replaymod.gui.center.search.category"));
|
||||
for (Category c : Category.values()) {
|
||||
categories.add(c.toNiceString());
|
||||
}
|
||||
category.setValues(categories.toArray(new String[categories.size()]));
|
||||
|
||||
List<String> versions = new ArrayList<>();
|
||||
versions.add(I18n.format("replaymod.gui.center.search.version"));
|
||||
for (MinecraftVersion v : MinecraftVersion.values()) {
|
||||
versions.add(v.toNiceName());
|
||||
}
|
||||
version.setValues(versions.toArray(new String[versions.size()]));
|
||||
|
||||
gameType.setI18nLabel("replaymod.gui.center.search.gametype")
|
||||
.setValues(I18n.format("options.particles.all"),
|
||||
I18n.format("menu.singleplayer"),
|
||||
I18n.format("menu.multiplayer"));
|
||||
sort.setI18nLabel("replaymod.gui.center.search.order")
|
||||
.setValues(I18n.format("replaymod.gui.center.search.order.best"),
|
||||
I18n.format("replaymod.gui.center.search.order.recent"));
|
||||
|
||||
popup.setLayout(new GridLayout().setColumns(3).setSpacingX(5).setSpacingY(5));
|
||||
popup.addElements(null,
|
||||
title, new GuiLabel(), new GuiLabel(),
|
||||
name, category, gameType,
|
||||
server, version, sort,
|
||||
new GuiLabel(), new GuiLabel(), new GuiLabel(),
|
||||
new GuiLabel(), cancelButton, searchButton);
|
||||
|
||||
setBackgroundColor(Colors.DARK_TRANSPARENT);
|
||||
}
|
||||
|
||||
public GuiReplayCenterSearch(GuiReplayCenter replayCenter, ApiClient apiClient) {
|
||||
super(replayCenter);
|
||||
this.replayCenter = replayCenter;
|
||||
this.apiClient = apiClient;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open() {
|
||||
super.open();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GuiReplayCenterSearch getThis() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package com.replaymod.online.gui;
|
||||
|
||||
import com.mojang.realmsclient.gui.ChatFormatting;
|
||||
import com.replaymod.online.ReplayModOnline;
|
||||
import com.replaymod.online.api.ApiClient;
|
||||
import com.replaymod.online.api.ApiException;
|
||||
import de.johni0702.minecraft.gui.container.AbstractGuiScreen;
|
||||
import de.johni0702.minecraft.gui.container.GuiScreen;
|
||||
import de.johni0702.minecraft.gui.element.GuiButton;
|
||||
import de.johni0702.minecraft.gui.element.GuiLabel;
|
||||
import de.johni0702.minecraft.gui.element.advanced.GuiProgressBar;
|
||||
import de.johni0702.minecraft.gui.layout.CustomLayout;
|
||||
import eu.crushedpixel.replaymod.gui.elements.listeners.ProgressUpdateListener;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class GuiReplayDownloading extends AbstractGuiScreen<GuiReplayDownloading> implements ProgressUpdateListener {
|
||||
private final GuiScreen cancelScreen;
|
||||
private final ApiClient apiClient;
|
||||
|
||||
private GuiProgressBar progressBar = new GuiProgressBar(this).setHeight(20);
|
||||
private GuiButton cancelButton = new GuiButton(this).setI18nLabel("gui.cancel").setSize(150, 20).onClick(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
apiClient.cancelDownload();
|
||||
cancelScreen.display();
|
||||
}
|
||||
});
|
||||
|
||||
public GuiReplayDownloading(GuiScreen cancelScreen, final ReplayModOnline mod,
|
||||
final int replayId, String name) {
|
||||
this.cancelScreen = cancelScreen;
|
||||
this.apiClient = mod.getApiClient();
|
||||
setTitle(new GuiLabel().setI18nText("replaymod.gui.viewer.download.title"));
|
||||
final GuiLabel subTitle = new GuiLabel(this).setI18nText("replaymod.gui.viewer.download.message",
|
||||
ChatFormatting.UNDERLINE + name + ChatFormatting.RESET);
|
||||
setLayout(new CustomLayout<GuiReplayDownloading>() {
|
||||
@Override
|
||||
protected void layout(GuiReplayDownloading container, int width, int height) {
|
||||
width(progressBar, width - 20);
|
||||
pos(progressBar, 10, height - 50);
|
||||
|
||||
pos(cancelButton, width - 5 - 150, height - 5 - 20);
|
||||
|
||||
pos(subTitle, width / 2 - subTitle.getMinSize().getWidth() / 2, 40);
|
||||
}
|
||||
});
|
||||
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final File replayFile = mod.getDownloadedFile(replayId);
|
||||
try {
|
||||
apiClient.downloadFile(replayId, replayFile, GuiReplayDownloading.this);
|
||||
if (replayFile.exists()) {
|
||||
getMinecraft().addScheduledTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
mod.getReplayModule().startReplay(replayFile);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (IOException | ApiException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgressChanged(float progress) {
|
||||
progressBar.setProgress(progress);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgressChanged(float progress, String progressString) {
|
||||
onProgressChanged(progress);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GuiReplayDownloading getThis() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
package com.replaymod.online.gui;
|
||||
|
||||
import com.mojang.realmsclient.gui.ChatFormatting;
|
||||
import com.replaymod.online.api.replay.holders.FileInfo;
|
||||
import eu.crushedpixel.replaymod.gui.elements.ComposedElement;
|
||||
import eu.crushedpixel.replaymod.gui.elements.GuiAdvancedButton;
|
||||
import eu.crushedpixel.replaymod.gui.elements.GuiDropdown;
|
||||
import eu.crushedpixel.replaymod.gui.elements.GuiString;
|
||||
import eu.crushedpixel.replaymod.holders.GuiEntryListValueEntry;
|
||||
import eu.crushedpixel.replaymod.utils.ReplayFileIO;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GuiReplayInstanceChooser extends GuiScreen {
|
||||
|
||||
private boolean initialized = false;
|
||||
|
||||
private GuiString dropdownTitle;
|
||||
private GuiDropdown<GuiEntryListValueEntry<File>> fileDropdown;
|
||||
private GuiAdvancedButton chooseButton, cancelButton;
|
||||
private ComposedElement composedElement;
|
||||
|
||||
private List<File> filesToChooseFrom = new ArrayList<File>();
|
||||
|
||||
private final String TITLE = I18n.format("replaymod.gui.viewer.chooser.title");
|
||||
private final String REPLAYFILE = I18n.format("replaymod.gui.editor.replayfile")+":";
|
||||
private final String MESSAGE;
|
||||
|
||||
private final String ORIGINAL = ChatFormatting.GREEN+I18n.format("replaymod.gui.original")+ChatFormatting.RESET;
|
||||
private final String MODIFIED = ChatFormatting.RED+I18n.format("replaymod.gui.modified")+ChatFormatting.RESET;
|
||||
|
||||
public GuiReplayInstanceChooser(final FileInfo fileInfo, File downloadedFile) {
|
||||
int id = fileInfo.getId();
|
||||
|
||||
this.MESSAGE = I18n.format("replaymod.gui.viewer.chooser.message", ChatFormatting.UNDERLINE+fileInfo.getName()+ChatFormatting.RESET);
|
||||
|
||||
//gather all applicable replay files
|
||||
try {
|
||||
File replayFolder = ReplayFileIO.getReplayFolder();
|
||||
|
||||
List<File> chooseableFiles = new ArrayList<File>();
|
||||
|
||||
File[] files = replayFolder.listFiles();
|
||||
if(files != null) {
|
||||
for(File file : files) {
|
||||
try {
|
||||
String extension = FilenameUtils.getExtension(file.getAbsolutePath());
|
||||
if(!"zip".equals(extension)) continue;
|
||||
|
||||
String filename = FilenameUtils.getBaseName(file.getAbsolutePath());
|
||||
String[] split = filename.split("_");
|
||||
String first = split[0];
|
||||
|
||||
if(StringUtils.isNumeric(first) && Integer.valueOf(first) == id) {
|
||||
chooseableFiles.add(file);
|
||||
}
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//if no modified versions of the replay were found, start the downloaded one
|
||||
if(chooseableFiles.isEmpty()) {
|
||||
// TODO
|
||||
// ReplayHandler.startReplay(downloadedFile);
|
||||
return;
|
||||
}
|
||||
|
||||
chooseableFiles.add(0, downloadedFile);
|
||||
this.filesToChooseFrom = chooseableFiles;
|
||||
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
if(!initialized) {
|
||||
dropdownTitle = new GuiString(0, 0, Color.WHITE, REPLAYFILE);
|
||||
|
||||
fileDropdown = new GuiDropdown<GuiEntryListValueEntry<File>>(fontRendererObj, 0, 0, 0, 5);
|
||||
|
||||
int i = 0;
|
||||
for(File file : filesToChooseFrom) {
|
||||
String displayName = FilenameUtils.getName(file.getAbsolutePath()) + " (" + (i == 0 ? ORIGINAL : MODIFIED) + ")";
|
||||
fileDropdown.addElement(new GuiEntryListValueEntry<File>(displayName, file));
|
||||
i++;
|
||||
}
|
||||
|
||||
chooseButton = new GuiAdvancedButton(0, 0, 100, 20, I18n.format("replaymod.gui.load"), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
File file = fileDropdown.getElement(fileDropdown.getSelectionIndex()).getValue();
|
||||
//TODO
|
||||
// ReplayHandler.startReplay(file);
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}, null);
|
||||
|
||||
cancelButton = new GuiAdvancedButton(0, 0, 100, 20, I18n.format("replaymod.gui.cancel"), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// mc.displayGuiScreen(new GuiReplayCenter());
|
||||
}
|
||||
}, null);
|
||||
|
||||
composedElement = new ComposedElement(dropdownTitle, fileDropdown, chooseButton, cancelButton);
|
||||
}
|
||||
|
||||
fileDropdown.width = 200;
|
||||
|
||||
int strWidth = fontRendererObj.getStringWidth(REPLAYFILE);
|
||||
int totWidth = strWidth + fileDropdown.width + 5;
|
||||
|
||||
dropdownTitle.positionX = (this.width-totWidth)/2;
|
||||
fileDropdown.xPosition = dropdownTitle.positionX + strWidth + 5;
|
||||
|
||||
fileDropdown.yPosition = this.height/2 - 10;
|
||||
|
||||
dropdownTitle.positionY = fileDropdown.yPosition + 6;
|
||||
|
||||
cancelButton.xPosition = this.width - 100 - 5;
|
||||
chooseButton.xPosition = cancelButton.xPosition - 100 - 5;
|
||||
|
||||
cancelButton.yPosition = chooseButton.yPosition = this.height - 5 - 20;
|
||||
|
||||
this.initialized = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||
this.drawDefaultBackground();
|
||||
drawCenteredString(fontRendererObj, ChatFormatting.UNDERLINE+TITLE, this.width / 2, 15, Color.WHITE.getRGB());
|
||||
|
||||
String[] lines = eu.crushedpixel.replaymod.utils.StringUtils.splitStringInMultipleRows(MESSAGE, this.width-40);
|
||||
int i = 0;
|
||||
for(String line : lines) {
|
||||
drawString(fontRendererObj, line, 20, 40+(15*i), Color.WHITE.getRGB());
|
||||
i++;
|
||||
}
|
||||
|
||||
composedElement.draw(mc, mouseX, mouseY);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
|
||||
composedElement.mouseClick(mc, mouseX, mouseY, mouseButton);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseReleased(int mouseX, int mouseY, int state) {
|
||||
composedElement.mouseRelease(mc, mouseX, mouseY, state);
|
||||
}
|
||||
}
|
||||
469
src/main/java/com/replaymod/online/gui/GuiUploadFile.java
Executable file
469
src/main/java/com/replaymod/online/gui/GuiUploadFile.java
Executable file
@@ -0,0 +1,469 @@
|
||||
package com.replaymod.online.gui;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import com.replaymod.online.api.ApiClient;
|
||||
import com.replaymod.replay.gui.screen.GuiReplayViewer;
|
||||
import de.johni0702.replaystudio.replay.ReplayFile;
|
||||
import de.johni0702.replaystudio.replay.ReplayMetaData;
|
||||
import de.johni0702.replaystudio.replay.ZipReplayFile;
|
||||
import de.johni0702.replaystudio.studio.ReplayStudio;
|
||||
import com.replaymod.online.api.replay.FileUploader;
|
||||
import com.replaymod.online.api.replay.holders.Category;
|
||||
import eu.crushedpixel.replaymod.gui.GuiConstants;
|
||||
import eu.crushedpixel.replaymod.gui.elements.*;
|
||||
import eu.crushedpixel.replaymod.gui.elements.listeners.ProgressUpdateListener;
|
||||
import eu.crushedpixel.replaymod.registry.ResourceHelper;
|
||||
import eu.crushedpixel.replaymod.utils.ImageUtils;
|
||||
import eu.crushedpixel.replaymod.utils.MouseUtils;
|
||||
import eu.crushedpixel.replaymod.utils.RegexUtils;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
import net.minecraft.client.renderer.texture.DynamicTexture;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.client.settings.GameSettings;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
// TODO: Rewrite using new GUI API
|
||||
public class GuiUploadFile extends GuiScreen implements ProgressUpdateListener {
|
||||
|
||||
private final Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
private final ResourceLocation textureResource;
|
||||
private DynamicTexture dynTex = null;
|
||||
|
||||
private boolean initialized;
|
||||
|
||||
private int columnWidth;
|
||||
private int columnRight;
|
||||
|
||||
private GuiAdvancedTextField name, tags;
|
||||
private GuiToggleButton category;
|
||||
private GuiString serverIP, duration;
|
||||
private GuiAdvancedCheckBox hideServerIP;
|
||||
private GuiTextArea description;
|
||||
|
||||
private ComposedElement content;
|
||||
|
||||
private GuiTextField messageTextField;
|
||||
private GuiAdvancedButton startUploadButton, cancelUploadButton, backButton;
|
||||
private GuiProgressBar progressBar;
|
||||
|
||||
private File replayFile;
|
||||
|
||||
private ReplayMetaData metaData;
|
||||
private BufferedImage thumb;
|
||||
private boolean hasThumbnail;
|
||||
|
||||
private FileUploader uploader;
|
||||
|
||||
private GuiReplayViewer parent;
|
||||
|
||||
private boolean lockUploadButton = false;
|
||||
|
||||
public GuiUploadFile(ApiClient apiClient, File file, GuiReplayViewer parent) {
|
||||
this.parent = parent;
|
||||
|
||||
uploader = new FileUploader(apiClient);
|
||||
|
||||
this.textureResource = new ResourceLocation("upload_thumbs/" + FilenameUtils.getBaseName(file.getAbsolutePath()));
|
||||
dynTex = null;
|
||||
|
||||
boolean correctFile = false;
|
||||
this.replayFile = file;
|
||||
|
||||
ReplayFile archive = null;
|
||||
try {
|
||||
archive = new ZipReplayFile(new ReplayStudio(), file);
|
||||
|
||||
metaData = archive.getMetaData();
|
||||
Optional<BufferedImage> img = archive.getThumb();
|
||||
if(img.isPresent()) {
|
||||
thumb = ImageUtils.scaleImage(img.get(), new Dimension(1280, 720));
|
||||
hasThumbnail = true;
|
||||
}
|
||||
|
||||
archive.close();
|
||||
correctFile = true;
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (archive != null) {
|
||||
archive.close();
|
||||
}
|
||||
} catch (IOException ignored) {}
|
||||
}
|
||||
|
||||
if(!correctFile) {
|
||||
Logger logger = LogManager.getLogger();
|
||||
logger.error("Invalid file provided to upload");
|
||||
parent.display();
|
||||
replayFile = null;
|
||||
return;
|
||||
}
|
||||
|
||||
//If thumb is null, set image to placeholder
|
||||
if(thumb == null) {
|
||||
try {
|
||||
thumb = ImageIO.read(GuiUploadFile.class.getClassLoader().getResourceAsStream("default_thumb.jpg"));
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
if(replayFile == null) {
|
||||
parent.display();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!initialized) {
|
||||
initialized = true;
|
||||
|
||||
int y = 20;
|
||||
|
||||
name = new GuiAdvancedTextField(fontRendererObj, 0, y, 0, 20);
|
||||
name.hint = I18n.format("replaymod.gui.upload.namehint");
|
||||
name.text = FilenameUtils.getBaseName(replayFile.getAbsolutePath());
|
||||
name.setMaxStringLength(30);
|
||||
y+=25;
|
||||
|
||||
int secs = metaData.getDuration() / 1000;
|
||||
String durationString = I18n.format("replaymod.gui.duration") + String.format(": %02dm%02ds", secs / 60, secs % 60);
|
||||
duration = new GuiString(0, y, Color.WHITE, durationString);
|
||||
y+=15;
|
||||
|
||||
hideServerIP = new GuiAdvancedCheckBox(0, y, I18n.format("replaymod.gui.upload.hideip"), false);
|
||||
hideServerIP.enabled = !metaData.isSingleplayer();
|
||||
y+=15;
|
||||
|
||||
serverIP = new GuiString(0, y, Color.GRAY, new Callable<String>() {
|
||||
@Override
|
||||
public String call() throws Exception {
|
||||
if (hideServerIP.isChecked()){
|
||||
return I18n.format("replaymod.gui.iphidden");
|
||||
} else {
|
||||
return metaData.getServerName();
|
||||
}
|
||||
}
|
||||
});
|
||||
y+=15;
|
||||
|
||||
category = new GuiToggleButton(0, 0, y, I18n.format("replaymod.category") + ": ", Category.stringValues());
|
||||
y+=25;
|
||||
|
||||
tags = new GuiAdvancedTextField(fontRendererObj, 0, y, 0, 20);
|
||||
tags.setMaxStringLength(30);
|
||||
tags.hint = I18n.format("replaymod.gui.upload.tagshint");
|
||||
y+=20;
|
||||
|
||||
description = new GuiTextArea(fontRendererObj, 0, name.yPosition, 0, y - name.yPosition, 1000, 100, 1000);
|
||||
}
|
||||
|
||||
columnWidth = Math.min(200, (width - 60) / 3);
|
||||
int columnLeft = width / 2 - columnWidth / 2 * 3 - 10;
|
||||
int columnMiddle = width / 2 - columnWidth / 2;
|
||||
columnRight = width / 2 + columnWidth / 2 + 10;
|
||||
|
||||
name.xPosition = columnLeft;
|
||||
name.width = columnWidth;
|
||||
|
||||
duration.positionX = columnLeft;
|
||||
hideServerIP.xPosition = columnLeft - 1;
|
||||
serverIP.positionX = columnLeft;
|
||||
|
||||
category.xPosition = columnLeft - 1;
|
||||
category.width = columnWidth + 2;
|
||||
|
||||
tags.xPosition = columnLeft;
|
||||
tags.width = columnWidth;
|
||||
|
||||
description.positionX = columnMiddle;
|
||||
description.setWidth(columnWidth);
|
||||
|
||||
List<GuiElement> elements = new ArrayList<GuiElement>(Arrays.asList(
|
||||
name, category, tags, description, serverIP, duration
|
||||
));
|
||||
if (!metaData.isSingleplayer()) {
|
||||
elements.add(hideServerIP);
|
||||
}
|
||||
content = new ComposedElement(elements.toArray(new GuiElement[elements.size()]));
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
List<GuiButton> buttonList = this.buttonList;
|
||||
if(startUploadButton == null) {
|
||||
List<GuiButton> bottomBar = new ArrayList<GuiButton>();
|
||||
startUploadButton = new GuiAdvancedButton(GuiConstants.UPLOAD_START_BUTTON, 0, 0, I18n.format("replaymod.gui.upload.start"));
|
||||
bottomBar.add(startUploadButton);
|
||||
|
||||
cancelUploadButton = new GuiAdvancedButton(GuiConstants.UPLOAD_CANCEL_BUTTON, 0, 0, I18n.format("replaymod.gui.upload.cancel"));
|
||||
cancelUploadButton.enabled = false;
|
||||
bottomBar.add(cancelUploadButton);
|
||||
|
||||
backButton = new GuiAdvancedButton(GuiConstants.UPLOAD_BACK_BUTTON, 0, 0, I18n.format("replaymod.gui.back"));
|
||||
bottomBar.add(backButton);
|
||||
|
||||
int i = 0;
|
||||
for(GuiButton b : bottomBar) {
|
||||
int w = this.width - 30;
|
||||
int w2 = w / bottomBar.size();
|
||||
|
||||
int x = 15 + (w2 * i);
|
||||
b.xPosition = x + 2;
|
||||
b.yPosition = height - 30;
|
||||
b.width = w2 - 4;
|
||||
|
||||
buttonList.add(b);
|
||||
|
||||
i++;
|
||||
}
|
||||
} else {
|
||||
List<GuiButton> bottomBar = new ArrayList<GuiButton>();
|
||||
|
||||
bottomBar.add(startUploadButton);
|
||||
bottomBar.add(cancelUploadButton);
|
||||
bottomBar.add(backButton);
|
||||
|
||||
int i = 0;
|
||||
for(GuiButton b : bottomBar) {
|
||||
int w = this.width - 30;
|
||||
int w2 = w / bottomBar.size();
|
||||
|
||||
int x = 15 + (w2 * i);
|
||||
b.xPosition = x + 2;
|
||||
b.yPosition = height - 30;
|
||||
b.width = w2 - 4;
|
||||
|
||||
buttonList.add(b);
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
if(messageTextField == null) {
|
||||
messageTextField = new GuiTextField(GuiConstants.UPLOAD_INFO_FIELD, fontRendererObj, 20, height - 80, width - 40, 20);
|
||||
messageTextField.setEnabled(true);
|
||||
messageTextField.setFocused(false);
|
||||
messageTextField.setMaxStringLength(Integer.MAX_VALUE);
|
||||
} else {
|
||||
messageTextField.yPosition = height - 80;
|
||||
messageTextField.width = width - 40;
|
||||
}
|
||||
|
||||
if(progressBar == null) {
|
||||
progressBar = new GuiProgressBar(19, height - 52, width - (2*19), 15);
|
||||
} else {
|
||||
progressBar.setBounds(19, height - 52, width - (2*19), 15);
|
||||
}
|
||||
|
||||
validateStartButton();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button) throws IOException {
|
||||
if(!button.enabled) return;
|
||||
if(button.id == GuiConstants.UPLOAD_BACK_BUTTON) {
|
||||
parent.display();
|
||||
} else if(button.id == GuiConstants.UPLOAD_START_BUTTON) {
|
||||
final String name = this.name.getText().trim();
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
String tagsRaw = tags.getText();
|
||||
String[] split = tagsRaw.split(",");
|
||||
List<String> tags = new ArrayList<String>();
|
||||
for(String str : split) {
|
||||
if(!tags.contains(str) && str.length() > 0) {
|
||||
tags.add(str);
|
||||
}
|
||||
}
|
||||
|
||||
Category category = Category.values()[GuiUploadFile.this.category.getValue()];
|
||||
|
||||
String desc = StringUtils.join(description.getText(), '\n');
|
||||
|
||||
if(hideServerIP.isChecked()) {
|
||||
File tmp = File.createTempFile("replay_hidden_ip", "mcpr");
|
||||
|
||||
ReplayMetaData newMetaData = new ReplayMetaData(metaData);
|
||||
newMetaData.setServerName(null);
|
||||
ReplayFile replay = new ZipReplayFile(new ReplayStudio(), replayFile);
|
||||
replay.writeMetaData(newMetaData);
|
||||
replay.saveTo(tmp);
|
||||
|
||||
uploader.uploadFile(GuiUploadFile.this, name, tags, tmp, category, desc);
|
||||
|
||||
FileUtils.deleteQuietly(tmp);
|
||||
} else {
|
||||
uploader.uploadFile(GuiUploadFile.this, name, tags, replayFile, category, desc);
|
||||
}
|
||||
|
||||
ReplayMod.uploadedFileHandler.markAsUploaded(replayFile);
|
||||
} catch(Exception e) {
|
||||
messageTextField.setText(I18n.format("replaymod.gui.unknownerror"));
|
||||
messageTextField.setTextColor(Color.RED.getRGB());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}, "replaymod-file-uploader").start();
|
||||
} else if(button.id == GuiConstants.UPLOAD_CANCEL_BUTTON) {
|
||||
uploader.cancelUploading();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||
this.drawDefaultBackground();
|
||||
|
||||
drawCenteredString(fontRendererObj, I18n.format("replaymod.gui.upload.title"), this.width / 2, 5, Color.WHITE.getRGB());
|
||||
|
||||
//Draw thumbnail
|
||||
if(thumb != null) {
|
||||
if(dynTex == null) {
|
||||
dynTex = new DynamicTexture(thumb);
|
||||
mc.getTextureManager().loadTexture(textureResource, dynTex);
|
||||
dynTex.updateDynamicTexture();
|
||||
ResourceHelper.registerResource(textureResource);
|
||||
}
|
||||
|
||||
mc.getTextureManager().bindTexture(textureResource); //Will be freed by the ResourceHelper
|
||||
int height = columnWidth * 720 / 1280;
|
||||
Gui.drawScaledCustomSizeModalRect(columnRight, 20, 0, 0, 1280, 720, columnWidth, height, 1280, 720);
|
||||
|
||||
if (!hasThumbnail) {
|
||||
KeyBinding keyBinding = ReplayMod.instance.getKeyBindingRegistry().getKeyBindings().get("replaymod.input.thumbnail");
|
||||
String str = I18n.format("replaymod.gui.upload.nothumbnail",
|
||||
keyBinding == null ? "???" : GameSettings.getKeyDisplayString(keyBinding.getKeyCode()));
|
||||
int y = 20 + height + 10;
|
||||
fontRendererObj.drawSplitString(str, columnRight, y, columnWidth, Color.RED.getRGB());
|
||||
}
|
||||
}
|
||||
|
||||
messageTextField.drawTextBox();
|
||||
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
|
||||
progressBar.drawProgressBar();
|
||||
|
||||
startUploadButton.drawOverlay(mc, mouseX, mouseY);
|
||||
|
||||
content.draw(mc, mouseX, mouseY);
|
||||
content.drawOverlay(mc, mouseX, mouseY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
|
||||
super.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
content.mouseClick(mc, mouseX, mouseY, mouseButton);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateScreen() {
|
||||
content.tick(mc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGuiClosed() {
|
||||
ResourceHelper.freeAllResources();
|
||||
Keyboard.enableRepeatEvents(false);
|
||||
super.onGuiClosed();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void keyTyped(char typedChar, int keyCode) throws IOException {
|
||||
org.lwjgl.util.Point mouse = MouseUtils.getMousePos();
|
||||
content.buttonPressed(mc, mouse.getX(), mouse.getY(), typedChar, keyCode);
|
||||
|
||||
if(uploader.isUploading()) {
|
||||
startUploadButton.enabled = false;
|
||||
} else {
|
||||
validateStartButton();
|
||||
}
|
||||
}
|
||||
|
||||
private void validateStartButton() {
|
||||
boolean enabled = true;
|
||||
if(name.getText().trim().length() < 5 || name.getText().trim().length() > 30) {
|
||||
enabled = false;
|
||||
name.setTextColor(Color.RED.getRGB());
|
||||
startUploadButton.hoverText = I18n.format("replaymod.gui.upload.error.name.length");
|
||||
} else if(!RegexUtils.isValid(RegexUtils.ALPHANUMERIC_SPACE_HYPHEN_UNDERSCORE, name.getText())) {
|
||||
enabled = false;
|
||||
name.setTextColor(Color.RED.getRGB());
|
||||
startUploadButton.hoverText = I18n.format("replaymod.gui.upload.error.name");
|
||||
} else if(!RegexUtils.isValid(RegexUtils.ALPHANUMERIC_COMMA, tags.getText())) {
|
||||
enabled = false;
|
||||
tags.setTextColor(Color.RED.getRGB());
|
||||
startUploadButton.hoverText = I18n.format("replaymod.gui.upload.error.tags");
|
||||
} else {
|
||||
name.setTextColor(Color.WHITE.getRGB());
|
||||
tags.setTextColor(Color.WHITE.getRGB());
|
||||
startUploadButton.hoverText = null;
|
||||
}
|
||||
|
||||
if(lockUploadButton) enabled = false;
|
||||
|
||||
startUploadButton.enabled = enabled;
|
||||
}
|
||||
|
||||
public void onStartUploading() {
|
||||
startUploadButton.enabled = false;
|
||||
cancelUploadButton.enabled = true;
|
||||
backButton.enabled = false;
|
||||
category.enabled = false;
|
||||
name.setElementEnabled(false);
|
||||
description.enabled = false;
|
||||
messageTextField.setText(I18n.format("replaymod.gui.upload.uploading"));
|
||||
messageTextField.setTextColor(Color.WHITE.getRGB());
|
||||
}
|
||||
|
||||
public void onFinishUploading(boolean success, String info) {
|
||||
validateStartButton();
|
||||
cancelUploadButton.enabled = false;
|
||||
backButton.enabled = true;
|
||||
category.enabled = true;
|
||||
name.setElementEnabled(true);
|
||||
description.enabled = true;
|
||||
if(success) {
|
||||
messageTextField.setText(I18n.format("replaymod.gui.upload.success"));
|
||||
messageTextField.setTextColor(Color.GREEN.getRGB());
|
||||
startUploadButton.enabled = false;
|
||||
lockUploadButton = true;
|
||||
} else {
|
||||
messageTextField.setText(info);
|
||||
messageTextField.setTextColor(Color.RED.getRGB());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgressChanged(float progress) {
|
||||
if(progressBar != null) progressBar.setProgress(progress);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgressChanged(float progress, String progressString) {}
|
||||
}
|
||||
Reference in New Issue
Block a user