Added code to display remaining piecen count for each player.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@374 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: PlayerInfoView.java,v 1.1 2001/10/17 23:27:52 mdb Exp $
|
||||
// $Id: PlayerInfoView.java,v 1.2 2001/10/18 18:10:57 mdb Exp $
|
||||
|
||||
package com.threerings.venison;
|
||||
|
||||
@@ -12,6 +12,10 @@ import javax.swing.JPanel;
|
||||
|
||||
import com.threerings.presents.dobj.AttributeChangeListener;
|
||||
import com.threerings.presents.dobj.AttributeChangedEvent;
|
||||
import com.threerings.presents.dobj.SetListener;
|
||||
import com.threerings.presents.dobj.ElementAddedEvent;
|
||||
import com.threerings.presents.dobj.ElementUpdatedEvent;
|
||||
import com.threerings.presents.dobj.ElementRemovedEvent;
|
||||
|
||||
import com.threerings.crowd.client.PlaceView;
|
||||
import com.threerings.crowd.data.PlaceObject;
|
||||
@@ -21,7 +25,8 @@ import com.threerings.crowd.data.PlaceObject;
|
||||
* score.
|
||||
*/
|
||||
public class PlayerInfoView
|
||||
extends JPanel implements PlaceView, AttributeChangeListener
|
||||
extends JPanel
|
||||
implements PlaceView, AttributeChangeListener, SetListener
|
||||
{
|
||||
/**
|
||||
* Constructs a new player info panel, ready for insertion into a
|
||||
@@ -43,9 +48,10 @@ public class PlayerInfoView
|
||||
_venobj = (VenisonObject)plobj;
|
||||
_venobj.addListener(this);
|
||||
|
||||
// we need a score labels array so that we can keep track of the
|
||||
// score labels
|
||||
// we need score and piecen labels arrays so that we can keep
|
||||
// track of per player information
|
||||
_scoreLabels = new JLabel[_venobj.players.length];
|
||||
_piecenLabels = new JLabel[_venobj.players.length];
|
||||
|
||||
// now that we're here, we can add an entry for every player
|
||||
for (int i = 0; i < _venobj.players.length; i++) {
|
||||
@@ -56,6 +62,8 @@ public class PlayerInfoView
|
||||
if (_venobj.scores.length == _venobj.players.length) {
|
||||
updateScores();
|
||||
}
|
||||
|
||||
// update the piecen count
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,18 +75,25 @@ public class PlayerInfoView
|
||||
|
||||
// create a label for their username
|
||||
c.fill = GridBagConstraints.HORIZONTAL;
|
||||
c.weightx = 1.0;
|
||||
c.weightx = 1.0; // use up extra space on this label
|
||||
JLabel unlabel = new JLabel(username);
|
||||
unlabel.setForeground(Feature.PIECEN_COLOR_MAP[idx]);
|
||||
add(unlabel, c);
|
||||
|
||||
// create a label for their score
|
||||
c.weightx = 0.0;
|
||||
c.weightx = 0.0; // size label to its preferred width
|
||||
c.ipadx = 5; // 5 pixels between this label and its neighbors
|
||||
c.fill = GridBagConstraints.NONE;
|
||||
c.gridwidth = GridBagConstraints.REMAINDER;
|
||||
_scoreLabels[idx] = new JLabel("0");
|
||||
_scoreLabels[idx].setForeground(Color.black);
|
||||
add(_scoreLabels[idx], c);
|
||||
|
||||
// create a label for their piecen count
|
||||
c.gridwidth = GridBagConstraints.REMAINDER;
|
||||
c.ipadx = 0; // turn off padding
|
||||
_piecenLabels[idx] = new JLabel("(0)");
|
||||
_piecenLabels[idx].setForeground(Feature.PIECEN_COLOR_MAP[idx]);
|
||||
add(_piecenLabels[idx], c);
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
@@ -98,6 +113,23 @@ public class PlayerInfoView
|
||||
}
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public void elementAdded (ElementAddedEvent event)
|
||||
{
|
||||
updatePiecenCount();
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public void elementUpdated (ElementUpdatedEvent event)
|
||||
{
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public void elementRemoved (ElementRemovedEvent event)
|
||||
{
|
||||
updatePiecenCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the scores from the game object and updates the view.
|
||||
*/
|
||||
@@ -108,9 +140,24 @@ public class PlayerInfoView
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the count of remaining piecens for all of the players.
|
||||
*/
|
||||
protected void updatePiecenCount ()
|
||||
{
|
||||
for (int i = 0; i < _venobj.scores.length; i++) {
|
||||
int pcount = TileUtil.countPiecens(_venobj.piecens, i);
|
||||
int pleft = VenisonCodes.PIECENS_PER_PLAYER - pcount;
|
||||
_piecenLabels[i].setText("(" + pleft + ")");
|
||||
}
|
||||
}
|
||||
|
||||
/** A reference to the game object. */
|
||||
protected VenisonObject _venobj;
|
||||
|
||||
/** References to our score label components. */
|
||||
protected JLabel[] _scoreLabels;
|
||||
|
||||
/** References to our piecen label components. */
|
||||
protected JLabel[] _piecenLabels;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user