You can now Like/Dislike files from the Replay Center
This commit is contained in:
@@ -76,6 +76,7 @@ public class ReplayMod {
|
||||
public static UploadedFileHandler uploadedFileHandler;
|
||||
public static DownloadedFileHandler downloadedFileHandler;
|
||||
public static FavoritedFileHandler favoritedFileHandler;
|
||||
public static RatedFileHandler ratedFileHandler;
|
||||
|
||||
private static Field defaultResourcePacksField;
|
||||
static {
|
||||
@@ -103,8 +104,8 @@ public class ReplayMod {
|
||||
replaySettings.readValues();
|
||||
|
||||
downloadedFileHandler = new DownloadedFileHandler();
|
||||
|
||||
favoritedFileHandler = new FavoritedFileHandler();
|
||||
ratedFileHandler = new RatedFileHandler();
|
||||
|
||||
replayFileAppender = new ReplayFileAppender();
|
||||
replayFileAppender.start();
|
||||
|
||||
@@ -31,6 +31,11 @@ public class ApiError {
|
||||
}
|
||||
|
||||
public String getTranslatedDesc() {
|
||||
return I18n.format(key, (Object[])objects);
|
||||
try {
|
||||
return I18n.format(key, (Object[]) objects);
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
return desc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,5 +23,10 @@ public class Rating {
|
||||
RatingType(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public static RatingType fromBoolean(Boolean rating) {
|
||||
return rating == null ? RatingType.NEUTRAL :
|
||||
(rating ? RatingType.LIKE : RatingType.DISLIKE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package eu.crushedpixel.replaymod.gui.online;
|
||||
import eu.crushedpixel.replaymod.ReplayMod;
|
||||
import eu.crushedpixel.replaymod.api.replay.SearchQuery;
|
||||
import eu.crushedpixel.replaymod.api.replay.holders.FileInfo;
|
||||
import eu.crushedpixel.replaymod.api.replay.holders.Rating;
|
||||
import eu.crushedpixel.replaymod.api.replay.pagination.DownloadedFilePagination;
|
||||
import eu.crushedpixel.replaymod.api.replay.pagination.FavoritedFilePagination;
|
||||
import eu.crushedpixel.replaymod.api.replay.pagination.Pagination;
|
||||
@@ -177,6 +178,19 @@ public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback {
|
||||
favButton.displayString = favorited ? I18n.format("replaymod.gui.center.unfavorite") : I18n.format("replaymod.gui.center.favorite");
|
||||
//if not downloaded, disable favorising
|
||||
favButton.enabled = favorited || downloaded;
|
||||
|
||||
likeButton.enabled = dislikeButton.enabled = downloaded;
|
||||
Rating.RatingType rating = ReplayMod.ratedFileHandler.getRating(info.getId());
|
||||
|
||||
likeButton.displayString = I18n.format("replaymod.gui.like");
|
||||
dislikeButton.displayString = I18n.format("replaymod.gui.dislike");
|
||||
|
||||
if(rating == Rating.RatingType.LIKE) {
|
||||
likeButton.displayString = I18n.format("replaymod.gui.removelike");
|
||||
} else if(rating == Rating.RatingType.DISLIKE) {
|
||||
dislikeButton.displayString = I18n.format("replaymod.gui.removedislike");
|
||||
}
|
||||
|
||||
} else {
|
||||
for(GuiButton b : replayButtonBar) {
|
||||
b.enabled = false;
|
||||
@@ -240,6 +254,36 @@ public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback {
|
||||
}
|
||||
elementSelected(currentList.selected);
|
||||
}
|
||||
} else if(button.id == GuiConstants.CENTER_LIKE_REPLAY_BUTTON) {
|
||||
GuiReplayListEntry entry = (GuiReplayListEntry)currentList.getListEntry(currentList.selected);
|
||||
FileInfo info = entry.getFileInfo();
|
||||
if(info != null) {
|
||||
try {
|
||||
if(ReplayMod.ratedFileHandler.getRating(info.getId()) == Rating.RatingType.LIKE) {
|
||||
ReplayMod.ratedFileHandler.rateFile(info.getId(), Rating.RatingType.NEUTRAL);
|
||||
} else {
|
||||
ReplayMod.ratedFileHandler.rateFile(info.getId(), Rating.RatingType.LIKE);
|
||||
}
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
elementSelected(currentList.selected);
|
||||
}
|
||||
} else if(button.id == GuiConstants.CENTER_DISLIKE_REPLAY_BUTTON) {
|
||||
GuiReplayListEntry entry = (GuiReplayListEntry)currentList.getListEntry(currentList.selected);
|
||||
FileInfo info = entry.getFileInfo();
|
||||
if(info != null) {
|
||||
try {
|
||||
if(ReplayMod.ratedFileHandler.getRating(info.getId()) == Rating.RatingType.DISLIKE) {
|
||||
ReplayMod.ratedFileHandler.rateFile(info.getId(), Rating.RatingType.NEUTRAL);
|
||||
} else {
|
||||
ReplayMod.ratedFileHandler.rateFile(info.getId(), Rating.RatingType.DISLIKE);
|
||||
}
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
elementSelected(currentList.selected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -271,7 +315,7 @@ public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback {
|
||||
|
||||
if(((favButton.isMouseOver() && !favButton.enabled) || (likeButton.isMouseOver() && !likeButton.enabled)
|
||||
|| (dislikeButton.isMouseOver() && !dislikeButton.enabled ))&& currentList.selected != -1) {
|
||||
this.drawString(fontRendererObj, I18n.format("replaymod.gui.center.downloadrequired"), mouseX, mouseY + 4, Color.RED.getRGB());
|
||||
this.drawCenteredString(fontRendererObj, I18n.format("replaymod.gui.center.downloadrequired"), mouseX, mouseY + 4, Color.RED.getRGB());
|
||||
}
|
||||
|
||||
this.drawCenteredString(fontRendererObj, I18n.format("replaymod.gui.replaycenter"), this.width / 2, 5, Color.WHITE.getRGB());
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package eu.crushedpixel.replaymod.registry;
|
||||
|
||||
import eu.crushedpixel.replaymod.ReplayMod;
|
||||
import eu.crushedpixel.replaymod.api.ApiException;
|
||||
import eu.crushedpixel.replaymod.api.replay.holders.FileRating;
|
||||
import eu.crushedpixel.replaymod.api.replay.holders.Rating;
|
||||
import eu.crushedpixel.replaymod.online.authentication.AuthenticationHandler;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class RatedFileHandler {
|
||||
|
||||
private HashMap<Integer, Boolean> rated = new HashMap<Integer, Boolean>();
|
||||
|
||||
boolean retrieved = false;
|
||||
|
||||
public RatedFileHandler() {
|
||||
reloadRatings();
|
||||
}
|
||||
|
||||
public HashMap<Integer, Boolean> getRated() {
|
||||
return rated;
|
||||
}
|
||||
|
||||
public Rating.RatingType getRating(int id) {
|
||||
return Rating.RatingType.fromBoolean(rated.get(id));
|
||||
}
|
||||
|
||||
public void rateFile(int id, Rating.RatingType type) throws IOException, ApiException {
|
||||
if(type == Rating.RatingType.LIKE || type == Rating.RatingType.DISLIKE) {
|
||||
rated.put(id, type == Rating.RatingType.LIKE);
|
||||
} else {
|
||||
rated.remove(id);
|
||||
}
|
||||
ReplayMod.apiClient.rateFile(AuthenticationHandler.getKey(), id, type);
|
||||
}
|
||||
|
||||
public void reloadRatings() {
|
||||
if(AuthenticationHandler.isAuthenticated()) {
|
||||
try {
|
||||
FileRating[] ratings = ReplayMod.apiClient.getRatedFiles(AuthenticationHandler.getKey());
|
||||
rated = new HashMap<Integer, Boolean>();
|
||||
|
||||
for(FileRating fr : ratings) {
|
||||
rated.put(fr.getFileID(), fr.getRating());
|
||||
}
|
||||
|
||||
retrieved = true;
|
||||
} catch(Exception e) {
|
||||
retrieved = false;
|
||||
rated = new HashMap<Integer, Boolean>();
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
retrieved = false;
|
||||
rated = new HashMap<Integer, Boolean>();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -59,6 +59,8 @@ replaymod.gui.load=Load
|
||||
replaymod.gui.download=Download
|
||||
replaymod.gui.like=Like
|
||||
replaymod.gui.dislike=Dislike
|
||||
replaymod.gui.removelike=Remove Like
|
||||
replaymod.gui.removedislike=Remove Dislike
|
||||
replaymod.gui.save=Save
|
||||
replaymod.gui.upload=Upload
|
||||
replaymod.gui.rename=Rename
|
||||
|
||||
Reference in New Issue
Block a user