I had fallen into a sketchy pattern in GamePlayerList and my hashCode() implementation, and this
works fine (better, really) with a Dictionary and pure object equality, so lets just do that. git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@481 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
@@ -21,6 +21,8 @@
|
|||||||
|
|
||||||
package com.threerings.flex {
|
package com.threerings.flex {
|
||||||
|
|
||||||
|
import flash.utils.Dictionary;
|
||||||
|
|
||||||
import mx.collections.ArrayCollection;
|
import mx.collections.ArrayCollection;
|
||||||
import mx.collections.Sort;
|
import mx.collections.Sort;
|
||||||
|
|
||||||
@@ -30,8 +32,6 @@ import mx.core.ClassFactory;
|
|||||||
import mx.core.ScrollPolicy;
|
import mx.core.ScrollPolicy;
|
||||||
|
|
||||||
import com.threerings.util.Comparable;
|
import com.threerings.util.Comparable;
|
||||||
import com.threerings.util.Hashable;
|
|
||||||
import com.threerings.util.HashMap;
|
|
||||||
|
|
||||||
public class PlayerList extends VBox
|
public class PlayerList extends VBox
|
||||||
{
|
{
|
||||||
@@ -69,13 +69,13 @@ public class PlayerList extends VBox
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The PlayerList is meant to include data that is at least as complicated as a Name, so to
|
* The PlayerList is meant to include data that is at least as complicated as a Name, so to
|
||||||
* keep things simple and extendable, we require Hashables. This allows the issue of passing
|
* keep things simple and extendable, we require Comparable. This allows the issue of passing
|
||||||
* the NameLabelCreator into the player renderer to be kept simple and straightforward and still
|
* the NameLabelCreator into the player renderer to be kept simple and straightforward and still
|
||||||
* allow efficient item updating.
|
* allow efficient item updating.
|
||||||
*/
|
*/
|
||||||
public function addItem (value :Hashable) :void
|
public function addItem (value :Comparable) :void
|
||||||
{
|
{
|
||||||
var currentValue :Array = _values.get(value) as Array;
|
var currentValue :Array = _values[value] as Array;
|
||||||
if (currentValue != null) {
|
if (currentValue != null) {
|
||||||
currentValue[1] = value;
|
currentValue[1] = value;
|
||||||
// this is the same array already contained in the list, so the proper renderer should
|
// this is the same array already contained in the list, so the proper renderer should
|
||||||
@@ -83,26 +83,28 @@ public class PlayerList extends VBox
|
|||||||
_players.itemUpdated(currentValue);
|
_players.itemUpdated(currentValue);
|
||||||
} else {
|
} else {
|
||||||
currentValue = [_labelCreator, value];
|
currentValue = [_labelCreator, value];
|
||||||
_values.put(value, currentValue);
|
_values[value] = currentValue;
|
||||||
_players.addItem(currentValue);
|
_players.addItem(currentValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function removeItem (value :Hashable) :void
|
public function removeItem (value :Comparable) :void
|
||||||
{
|
{
|
||||||
var currentValue :Array = _values.remove(value) as Array;
|
var currentValue :Array = _values[value] as Array;
|
||||||
if (currentValue != null) {
|
if (currentValue != null) {
|
||||||
_players.removeItemAt(_players.getItemIndex(currentValue));
|
_players.removeItemAt(_players.getItemIndex(currentValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delete _values[value];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notify the list that this value has changed internally, and the renderer should be told to
|
* Notify the list that this value has changed internally, and the renderer should be told to
|
||||||
* redraw its contents.
|
* redraw its contents.
|
||||||
*/
|
*/
|
||||||
public function itemUpdated (value :Hashable) :void
|
public function itemUpdated (value :Comparable) :void
|
||||||
{
|
{
|
||||||
var currentValue :Array = _values.get(value) as Array;
|
var currentValue :Array = _values[value] as Array;
|
||||||
if (currentValue != null) {
|
if (currentValue != null) {
|
||||||
currentValue[1] = value;
|
currentValue[1] = value;
|
||||||
_players.itemUpdated(currentValue);
|
_players.itemUpdated(currentValue);
|
||||||
@@ -133,7 +135,7 @@ public class PlayerList extends VBox
|
|||||||
protected var _labelCreator :NameLabelCreator;
|
protected var _labelCreator :NameLabelCreator;
|
||||||
protected var _list :AmbidextrousList;
|
protected var _list :AmbidextrousList;
|
||||||
protected var _players :ArrayCollection = new ArrayCollection();
|
protected var _players :ArrayCollection = new ArrayCollection();
|
||||||
protected var _values :HashMap = new HashMap();
|
protected var _values :Dictionary = new Dictionary();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user