Scoreboard flicker fixed!

This commit is contained in:
Mini-Chiss 2014-07-02 12:38:41 -07:00
parent 558f79fe34
commit 05e116ea0d

View File

@ -1,6 +1,7 @@
package nautilus.game.arcade.scoreboard;
import java.util.ArrayList;
import java.util.HashSet;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
@ -26,7 +27,7 @@ public class GameScoreboard
private Objective _sideObjective;
private ArrayList<ScoreboardElement> _elements = new ArrayList<ScoreboardElement>();
private String _space = " ";
private String[] _current = new String[15];
private String _title;
@ -110,6 +111,7 @@ public class GameScoreboard
_scoreboard.resetScores(line);
}
/*
public void Reset()
{
for (ScoreboardElement elem : _elements)
@ -124,6 +126,7 @@ public class GameScoreboard
_space = " ";
}
*/
public String Clean(String line)
{
@ -166,22 +169,96 @@ public class GameScoreboard
public void WriteBlank()
{
_elements.add(new ScoreboardElementText(_space));
_space += " ";
_elements.add(new ScoreboardElementText(" "));
}
public void Draw()
{
int i = 15;
//System.out.println();
//System.out.println("/////////////////////////");
//Generate Lines
ArrayList<String> newLines = new ArrayList<String>();
for (ScoreboardElement elem : _elements)
{
for (String line : elem.GetLines())
{
GetObjectiveSide().getScore(line).setScore(i--);
//Ensure no duplicate lines
while (true)
{
boolean matched = false;
for (String otherLine : newLines)
{
if (line.equals(otherLine))
{
line += ChatColor.RESET;
matched = true;
}
}
if (!matched)
break;
}
newLines.add(line);
}
}
//Find Changes
HashSet<Integer> toUpdate = new HashSet<Integer>();
HashSet<Integer> toDelete = new HashSet<Integer>();
for (int i=0 ; i<15 ; i++)
{
//Delete Old Excess Row
if (i >= newLines.size())
{
if (_current[i] != null)
{
//System.out.println("Delete: " + i + " [" + _current[i] + "]");
toDelete.add(i);
}
continue;
}
if (i <= 0)
break;
//Update or Add Row
if (_current[i] == null || !_current[i].equals(newLines.get(i)))
{
//System.out.println("Update: " + i + " [" + newLines.get(i) + "]");
toUpdate.add(i);
}
}
//Add/Update Elements
for (int i : toUpdate)
{
//Remove Old Line at Index
if (_current[i] != null)
ResetScore(_current[i]);
//Insert New Line
String newLine = newLines.get(i);
GetObjectiveSide().getScore(newLine).setScore(15-i);
_current[i] = newLine;
}
//Delete Elements
for (int i : toDelete)
{
//Remove Old Line at Index
if (_current[i] != null)
{
ResetScore(_current[i]);
_current[i] = null;
}
}
}
public void Reset()
{
_elements.clear();
}
}