Skip to content

Commit

Permalink
Merge pull request #4688 from kuronekochomusuke/reportUpdateLag
Browse files Browse the repository at this point in the history
only reload report tabs that have changed
  • Loading branch information
SJuliez authored Aug 6, 2023
2 parents 00e4c51 + fc5cfb5 commit b1fdfe7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
3 changes: 1 addition & 2 deletions megamek/src/megamek/client/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -1195,7 +1195,6 @@ protected void receiveAttack(Packet c) {
}
}


// Should be private?
public String receiveReport(Vector<Report> v) {
if (v == null) {
Expand All @@ -1209,7 +1208,7 @@ public String receiveReport(Vector<Report> v) {

Set<Integer> set = new HashSet<>();
//find id stored in spans and extract it
Pattern p = Pattern.compile("<span id=(.*?)span>");
Pattern p = Pattern.compile("<span id=(.*?)></span>");
Matcher m = p.matcher(report.toString());

// add all instances to a hashset to prevent duplicates
Expand Down
2 changes: 1 addition & 1 deletion megamek/src/megamek/client/ui/swing/ClientGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ public void showPlayerList() {
public void miniReportDisplayAddReportPages() {
ignoreHotKeys = true;
if (getMiniReportDisplay() != null) {
getMiniReportDisplay().addReportPages();
getMiniReportDisplay().addReportPages(client.getGame().getPhase());
}
ignoreHotKeys = false;
}
Expand Down
21 changes: 17 additions & 4 deletions megamek/src/megamek/client/ui/swing/MiniReportDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import megamek.client.ui.Messages;
import megamek.client.ui.swing.util.BASE64ToolKit;
import megamek.client.ui.swing.util.UIUtil;
import megamek.common.enums.GamePhase;
import megamek.common.preference.ClientPreferences;
import megamek.common.preference.IPreferenceChangeListener;
import megamek.common.preference.PreferenceChangeEvent;
Expand Down Expand Up @@ -295,11 +296,23 @@ private JScrollPane loadHtmlScrollPane(String t) {
return new JScrollPane(ta);
}

public void addReportPages() {
public void addReportPages(GamePhase phase) {
int numRounds = currentClient.getGame().getRoundCount();
tabs.removeAll();
int startIndex = 1;

// only reload what has changed
if (numRounds < 2 || phase.isVictory()) {
tabs.removeAll();
} else if (tabs.getTabCount() > 1) {
tabs.removeTabAt(tabs.getTabCount() - 1);
// don't remove on round change
if (tabs.getTabCount() == numRounds) {
tabs.removeTabAt(tabs.getTabCount() - 1);
}
startIndex = tabs.getTabCount() + 1;
}

for (int round = 1; round <= numRounds; round++) {
for (int round = startIndex; round <= numRounds; round++) {
String text = currentClient.receiveReport(currentClient.getGame().getReports(round));
tabs.add(Messages.getString("MiniReportDisplay.Round") + " " + round, loadHtmlScrollPane(text));
}
Expand Down Expand Up @@ -360,7 +373,7 @@ public void gamePhaseChange(GamePhaseChangeEvent e) {
default:
if ((!e.getNewPhase().equals((e.getOldPhase())))
&& ((e.getNewPhase().isReport()) || ((e.getNewPhase().isOnMap()) && (tabs.getTabCount() == 0)))){
addReportPages();
addReportPages(e.getNewPhase());
updatePlayerChoice();
updateEntityChoice();
}
Expand Down

0 comments on commit b1fdfe7

Please sign in to comment.