Permalink
Browse files

improved stone gallery, show only available stones

  • Loading branch information...
1 parent 462617e commit f4e534d1c5f901e6a257346f20590aebc44fce04 @shlusiak committed Apr 13, 2012
View
@@ -12,6 +12,8 @@
android:id="@+id/stoneGallery"
android:layout_width="match_parent"
android:layout_height="wrap_content"
+ android:unselectedAlpha="0.4"
+ android:animationDuration="500"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true" />
@@ -98,18 +98,11 @@ public void gameStarted() {
for (i = 0; i < Spiel.PLAYER_MAX; i++)
if (spiel.is_local_player(i))
Log.d(tag, "Local player: " + i);
- view.updateView();
+ view.updateView();
}
public void newCurrentPlayer(int player) {
- final Player p = spiel.get_current_player();
- stoneGallery.post(new Runnable() {
- @Override
- public void run() {
- stoneGalleryAdapter.setPlayer(p);
- stoneGalleryAdapter.notifyDataSetChanged();
- }
- });
+ updateStoneGallery(player);
if (!spiel.is_local_player())
return;
@@ -126,6 +119,27 @@ public void run() {
stone.mirror_rotate_to(turn.m_mirror_count, turn.m_rotate_count);
spiel.set_stone(stone, turn.m_stone_number, turn.m_y, turn.m_x);
}
+
+ void updateStoneGallery(int player) {
+ final Player p = (player < 0) ? null : spiel.get_player(player);
+ stoneGallery.post(new Runnable() {
+ @Override
+ public void run() {
+ if (p != null)
+ stoneGalleryAdapter.setPlayer(p);
+ stoneGalleryAdapter.notifyDataSetChanged();
+ }
+ });
+ }
+
+ void updateStoneGallery() {
+ stoneGallery.post(new Runnable() {
+ @Override
+ public void run() {
+ stoneGalleryAdapter.notifyDataSetChanged();
+ }
+ });
+ }
public void chatReceived(final NET_CHAT c) {
if (spiel.current_player() < 0)
@@ -153,6 +167,7 @@ public void gameFinished() {
+ " has " + player.m_stone_count + " stones left and "
+ -player.m_stone_points_left + " points.");
}
+ updateStoneGallery();
spiel.disconnect();
view.updateView();
@@ -161,6 +176,7 @@ public void gameFinished() {
@Override
public void stoneWasSet(NET_SET_STONE s) {
view.updateView();
+ updateStoneGallery();
}
@Override
@@ -172,7 +188,7 @@ public void hintReceived(NET_SET_STONE s) {
@Override
public void stoneUndone(Stone s, Turn t) {
view.updateView();
-
+ updateStoneGallery();
}
@Override
@@ -27,12 +27,29 @@ void setPlayer(Player player) {
public int getCount() {
if (player == null)
return 0;
- return Stone.STONE_COUNT_ALL_SHAPES;
+ int c = 0;
+ for (int i = 0; i < Stone.STONE_COUNT_ALL_SHAPES; i++)
+ if (player.get_stone(i).get_available() > 0)
+ c++;
+ return c;
}
@Override
public Object getItem(int position) {
- return player.get_stone(position);
+ int i = 0;
+ do {
+ while (player.get_stone(i).get_available() == 0) {
+ i++;
+ if (i >= Stone.STONE_COUNT_ALL_SHAPES)
+ return null;
+ }
+ if (position == 0)
+ return player.get_stone(i);
+
+ position--;
+ i++;
+ } while (i < Stone.STONE_COUNT_ALL_SHAPES);
+ return null;
}
@Override
@@ -12,24 +12,24 @@
int player;
Paint blockPaint;
- static final int block_size = 20;
+ static final int block_size = 25;
public SimpleStoneView(Context context, int player, Stone stone) {
super(context);
this.stone = stone;
this.player = player;
int alpha;
- if (stone.get_available() <= 0)
- alpha = 30;
+ if (stone != null && stone.get_available() <= 0)
+ alpha = 40;
else
- alpha = 200;
+ alpha = 240;
blockPaint = new Paint();
switch (player) {
- case 0: blockPaint.setColor(Color.argb(alpha, 0, 30, 190)); break;
- case 1: blockPaint.setColor(Color.argb(alpha, 190, 190, 0)); break;
- case 2: blockPaint.setColor(Color.argb(alpha, 190, 0, 0)); break;
- case 3: blockPaint.setColor(Color.argb(alpha, 0, 190, 0)); break;
+ case 0: blockPaint.setColor(Color.argb(alpha, 0, 50, 230)); break;
+ case 1: blockPaint.setColor(Color.argb(alpha, 230, 230, 0)); break;
+ case 2: blockPaint.setColor(Color.argb(alpha, 230, 0, 0)); break;
+ case 3: blockPaint.setColor(Color.argb(alpha, 0, 230, 0)); break;
}
}
@@ -41,11 +41,16 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
@Override
protected void onDraw(Canvas canvas) {
- //canvas.drawColor(Color.RED);
+ if (stone == null)
+ return;
+
+ int left = (getWidth() - block_size * stone.get_stone_size()) / 2;
+ int top = (getHeight() - block_size * stone.get_stone_size()) / 2;
+
for (int y = 0; y < stone.get_stone_size(); y++)
for (int x = 0; x < stone.get_stone_size(); x++) {
if (stone.get_stone_field(y, x) != Stone.STONE_FIELD_FREE) {
- canvas.drawRect(block_size * x, block_size * y, (block_size) * (x + 1) - 1, (block_size) * (y + 1) - 1, blockPaint);
+ canvas.drawRect(left + block_size * x, top + block_size * y, left + (block_size) * (x + 1) - 1, top + (block_size) * (y + 1) - 1, blockPaint);
}
}

0 comments on commit f4e534d

Please sign in to comment.