]> www.infradead.org Git - users/mchehab/andors-trail.git/commitdiff
Allow selection of conversation replies with keyboard.
authoroskar.wiksten@gmail.com <oskar.wiksten@gmail.com@08aca716-68be-ccc6-4d58-36f5abd142ac>
Wed, 19 Oct 2011 22:26:38 +0000 (22:26 +0000)
committeroskar.wiksten@gmail.com <oskar.wiksten@gmail.com@08aca716-68be-ccc6-4d58-36f5abd142ac>
Wed, 19 Oct 2011 22:26:38 +0000 (22:26 +0000)
Prevent FC when changing maps while animations are running (such as regeneration)

git-svn-id: https://andors-trail.googlecode.com/svn/trunk@188 08aca716-68be-ccc6-4d58-36f5abd142ac

AndorsTrail/res/layout/conversation_statement.xml
AndorsTrail/res/values/authors.xml
AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/ConversationActivity.java
AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/Controller.java
AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/MovementController.java
AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/VisualEffectController.java
AndorsTrail/src/com/gpl/rpg/AndorsTrail/view/MainView.java

index bb41eb7dcdac67757aaeda8e46e295f4360232f1..1476643ce9ee15744cb5d7b24c227f9732d46d58 100644 (file)
@@ -20,5 +20,9 @@
                android:layout_height="wrap_content"
                android:text="Actor: Text"
                android:textSize="@dimen/conversation_textsize"
+               android:shadowDx="1"
+               android:shadowDy="1"
+               android:shadowRadius="1"
+               android:shadowColor="#000"
                />
 </LinearLayout>
index f097a29a1a4e6e554317d61479746900c6ccc504..f1d5bc02b54354a58ab35d785c94a27825ead76c 100644 (file)
@@ -26,6 +26,7 @@
                French translation by LeSanglier and Misty Soul&lt;br /&gt;
                German translation by Bomber and Samuel Plentz&lt;br /&gt;
                English proofreading by taws34&lt;br /&gt;
+               English proofreading and testing by Stephen Stalnaker&lt;br /&gt;
                Hebrew translation by eitanbm&lt;br /&gt;
                Forum moderated by Tim Davis&lt;br /&gt;
                Forum moderated by Josh Kloos&lt;br /&gt;
index f2b10c38db2ee7d9df6abc034354592056bed49d..a0ee817cdb2662b116b0198b84e5442c24684734 100644 (file)
@@ -12,17 +12,21 @@ import android.os.Parcel;
 import android.os.Parcelable;
 import android.text.Spannable;
 import android.text.style.ForegroundColorSpan;
+import android.view.KeyEvent;
 import android.view.View;
 import android.view.ViewGroup;
 import android.view.Window;
 import android.view.View.OnClickListener;
+import android.view.View.OnKeyListener;
 import android.widget.ArrayAdapter;
 import android.widget.Button;
+import android.widget.CompoundButton;
 import android.widget.ImageView;
 import android.widget.ListView;
 import android.widget.RadioButton;
 import android.widget.RadioGroup;
 import android.widget.TextView;
+import android.widget.CompoundButton.OnCheckedChangeListener;
 import android.widget.TextView.BufferType;
 
 import com.gpl.rpg.AndorsTrail.AndorsTrailApplication;
@@ -39,7 +43,7 @@ import com.gpl.rpg.AndorsTrail.model.actor.Player;
 import com.gpl.rpg.AndorsTrail.model.item.Loot;
 import com.gpl.rpg.AndorsTrail.resource.tiles.TileManager;
 
-public final class ConversationActivity extends Activity {
+public final class ConversationActivity extends Activity implements OnKeyListener {
        public static final int ACTIVITYRESULT_ATTACK = Activity.RESULT_FIRST_USER + 1;
        public static final int ACTIVITYRESULT_REMOVE = Activity.RESULT_FIRST_USER + 2;
        private static final int playerConversationColor = Color.argb(255, 0xbb, 0x22, 0x22);
@@ -56,7 +60,7 @@ public final class ConversationActivity extends Activity {
        private ListView statementList;
        private Monster npc;
        private RadioGroup replyGroup;
-       private OnClickListener radioButtonListener;
+       private OnCheckedChangeListener radioButtonListener;
        private boolean displayActors = true;
        
        private final ConversationCollection conversationCollection = new ConversationCollection();
@@ -106,9 +110,9 @@ public final class ConversationActivity extends Activity {
                        }
                });
         
-        radioButtonListener = new OnClickListener() {
+        radioButtonListener = new OnCheckedChangeListener() {
                        @Override
-                       public void onClick(View v) {
+                       public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
                                nextButton.setEnabled(true);
                        }
                };
@@ -120,8 +124,64 @@ public final class ConversationActivity extends Activity {
                });
                
         setPhrase(phraseID);
+        
+        statementList.setOnKeyListener(this);
     }
-       
+    
+    private int getSelectedReplyIndex() {
+       for (int i = 0; i < phrase.replies.length; ++i) {
+                       final View v = replyGroup.getChildAt(i);
+                       if (v == null) continue;
+                       final RadioButton rb = (RadioButton) v;
+                       if (rb.isChecked()) return i;
+       }
+       return -1;
+    }
+    
+    private void setSelectedReplyIndex(int i) {
+       if (phrase.replies == null) return;
+       if (phrase.replies.length <= 0) return;
+       if (i < 0) i = 0;
+       else if (i >= phrase.replies.length) i = phrase.replies.length - 1;
+       
+       View v = replyGroup.getChildAt(i);
+               if (v == null) return;
+               RadioButton rb = (RadioButton) v;
+               rb.setChecked(true);
+    }
+       @Override
+       public boolean onKey(View arg0, int keyCode, KeyEvent event) {
+               if (event.getAction() != KeyEvent.ACTION_DOWN) return false;
+               int selectedReplyIndex = getSelectedReplyIndex();
+               
+               switch (keyCode) {
+               case KeyEvent.KEYCODE_DPAD_UP:
+                       --selectedReplyIndex;
+                       setSelectedReplyIndex(selectedReplyIndex);
+                       return true;
+               case KeyEvent.KEYCODE_DPAD_DOWN:
+                       ++selectedReplyIndex;
+                       setSelectedReplyIndex(selectedReplyIndex);
+                       return true;
+               case KeyEvent.KEYCODE_SPACE:
+               case KeyEvent.KEYCODE_ENTER:
+               case KeyEvent.KEYCODE_DPAD_CENTER:
+                       if (nextButton.isEnabled()) nextButton.performClick();
+                       return true;
+               case KeyEvent.KEYCODE_1: setSelectedReplyIndex(0); return true;
+               case KeyEvent.KEYCODE_2: setSelectedReplyIndex(1); return true;
+               case KeyEvent.KEYCODE_3: setSelectedReplyIndex(2); return true;
+               case KeyEvent.KEYCODE_4: setSelectedReplyIndex(3); return true;
+               case KeyEvent.KEYCODE_5: setSelectedReplyIndex(4); return true;
+               case KeyEvent.KEYCODE_6: setSelectedReplyIndex(5); return true;
+               case KeyEvent.KEYCODE_7: setSelectedReplyIndex(6); return true;
+               case KeyEvent.KEYCODE_8: setSelectedReplyIndex(7); return true;
+               case KeyEvent.KEYCODE_9: setSelectedReplyIndex(8); return true;
+               default: return false;
+               }
+       }
+    
     public void setPhrase(String phraseID) {
                this.phraseID = phraseID;
        if (phraseID.equalsIgnoreCase(ConversationCollection.PHRASE_CLOSE)) {
@@ -200,8 +260,9 @@ public final class ConversationActivity extends Activity {
                RadioButton rb = new RadioButton(this);
                rb.setLayoutParams(layoutParams);
                rb.setText(r.text);
-               rb.setOnClickListener(radioButtonListener);
+               rb.setOnCheckedChangeListener(radioButtonListener);
                rb.setTag(r);
+               rb.setShadowLayer(1, 1, 1, Color.BLACK);
                replyGroup.addView(rb, layoutParams);
     }
        
@@ -211,6 +272,7 @@ public final class ConversationActivity extends Activity {
                return false;
        }
        
+       
        private Reply getSelectedReply() {
                for (int i = 0; i < phrase.replies.length; ++i) {
                        final View v = replyGroup.getChildAt(i);
index 640be4cbdefb29edffab2c6b84a6580ee2c00abd..378daea4c705a1aef05276bce24a312914ac1701 100644 (file)
@@ -72,7 +72,7 @@ public final class Controller {
                final MainActivity act = view.mainActivity;
                MovementController.respawnPlayer(act.getResources(), world);
                act.updateStatus();
-               act.mainview.notifyMapChanged();
+               act.mainview.notifyMapChanged(world.model);
                act.message(act.getResources().getString(R.string.combat_hero_dies, lostExp));
        }
        
index 79e49f1c4c931b20abe3f06ead9c8607569e8929..273bba6ef86983f6d64a99a29149f5736e05e3bd 100644 (file)
@@ -49,7 +49,7 @@ public final class MovementController implements TimedMessageTask.Callback {
                        protected void onPostExecute(Void result) {
                                super.onPostExecute(result);
                                view.mainActivity.clearMessages();
-                               view.mainActivity.mainview.notifyMapChanged();
+                               view.mainActivity.mainview.notifyMapChanged(model);
                                stopMovement();
                                view.gameRoundController.resume();
                        }
@@ -213,7 +213,7 @@ public final class MovementController implements TimedMessageTask.Callback {
        player.lastPosition.set(player.position);
        player.position.set(newPosition);
        view.combatController.setCombatSelection(null, null);
-               view.mainActivity.mainview.notifyPlayerMoved();
+               view.mainActivity.mainview.notifyPlayerMoved(newPosition);
                
                if (handleEvents) {
                        MapObject o = currentMap.getEventObjectAt(newPosition);
index 506d6a191d68c45897ac1e7c1d2e1dc0efd6c29c..393c45929fc17672c74979a87e471cf8241c61a1 100644 (file)
@@ -48,7 +48,8 @@ public final class VisualEffectController {
                        if (frame >= beginFadeAtFrame && displayText != null) {
                                this.textPaint.setAlpha(255 * (effect.lastFrame - frame) / (effect.lastFrame - beginFadeAtFrame)); 
                        }
-                       view.redrawAreaWithEffect(area, this, tileID, textYOffset, this.textPaint);
+                       area.topLeft.y = position.y - 1;
+                       view.redrawAreaWithEffect(this, tileID, textYOffset, this.textPaint);
                }
 
                protected void onCompleted() {
@@ -68,7 +69,7 @@ public final class VisualEffectController {
                
                public final Coord position;
                public final String displayText;
-               private final CoordRect area;
+               public final CoordRect area;
                private final Paint textPaint = new Paint();
                private final int beginFadeAtFrame;
                private final VisualEffectCompletedCallback callback;
index 762c80e494b29236c39b6310e40cd921315a305c..596b590174e658bc306a8faf55a84385e8f550a4 100644 (file)
@@ -53,7 +53,10 @@ public final class MainView extends SurfaceView implements SurfaceHolder.Callbac
        private final CoordRect p1x1 = new CoordRect(new Coord(), new Size(1,1));
        private boolean hasSurface = false;
        
+       private PredefinedMap currentMap;
+       private LayeredTileMap currentTileMap;
        private TileCollection tiles;
+       private final Coord playerPosition = new Coord();
 
        public MainView(Context context, AttributeSet attr) {
                super(context, attr);
@@ -113,7 +116,7 @@ public final class MainView extends SurfaceView implements SurfaceHolder.Callbac
                        );
                
        if (model.currentMap != null) {
-               notifyMapChanged();
+               notifyMapChanged(model);
        }
        
        redrawAll(REDRAW_ALL_SURFACE_CHANGED);
@@ -175,8 +178,7 @@ public final class MainView extends SurfaceView implements SurfaceHolder.Callbac
                if (!hasSurface) return;
                //if (!preferences.optimizedDrawing) area = mapViewArea;
         
-               final PredefinedMap currentMap = model.currentMap;
-        boolean b = currentMap.isOutside(area);
+               boolean b = currentMap.isOutside(area);
         if (b) return;
                                
                calculateRedrawRect(area);
@@ -204,12 +206,12 @@ public final class MainView extends SurfaceView implements SurfaceHolder.Callbac
                return true;
        }
        private final Rect redrawRect = new Rect();
-       public void redrawAreaWithEffect(CoordRect area, final VisualEffectAnimation effect, int tileID, int textYOffset, Paint textPaint) {
+       public void redrawAreaWithEffect(final VisualEffectAnimation effect, int tileID, int textYOffset, Paint textPaint) {
+               CoordRect area = effect.area;
                if (!hasSurface) return;
                if (shouldRedrawEverythingForVisualEffect()) area = mapViewArea;
                
-               final PredefinedMap currentMap = model.currentMap;
-        if (currentMap.isOutside(area)) return;
+               if (currentMap.isOutside(area)) return;
                
                calculateRedrawRect(area);
                Canvas c = null;
@@ -263,10 +265,8 @@ public final class MainView extends SurfaceView implements SurfaceHolder.Callbac
        }
        
        private void doDrawRect(Canvas canvas, CoordRect area) {
-       final LayeredTileMap currentTileMap = model.currentTileMap;
-       final PredefinedMap currentMap = model.currentMap;
-       
-        drawMapLayer(canvas, area, currentTileMap.layers[LayeredTileMap.LAYER_GROUND]);
+               
+       drawMapLayer(canvas, area, currentTileMap.layers[LayeredTileMap.LAYER_GROUND]);
         tryDrawMapLayer(canvas, area, currentTileMap, LayeredTileMap.LAYER_OBJECTS);
         
         for (Loot l : currentMap.groundBags) {
@@ -275,7 +275,7 @@ public final class MainView extends SurfaceView implements SurfaceHolder.Callbac
                }
                }
         
-               drawFromMapPosition(canvas, area, model.player.position, model.player.actorTraits.iconID);
+               drawFromMapPosition(canvas, area, playerPosition, model.player.actorTraits.iconID);
                for (MonsterSpawnArea a : currentMap.spawnAreas) {
                        for (Monster m : a.monsters) {
                                drawFromMapPosition(canvas, area, m.rectPosition, m.actorTraits.iconID);
@@ -339,39 +339,44 @@ public final class MainView extends SurfaceView implements SurfaceHolder.Callbac
                canvas.drawText(e.displayText, x, y, textPaint);
     }
     
-       public void notifyMapChanged() {
-               Size mapViewSize = new Size(
-                       Math.min(screenSizeTileCount.width, model.currentMap.size.width)
-                       ,Math.min(screenSizeTileCount.height, model.currentMap.size.height)
+       public void notifyMapChanged(ModelContainer model) {
+               synchronized (holder) {
+                       currentMap = model.currentMap;
+                       currentTileMap = model.currentTileMap;
+                       Size mapViewSize = new Size(
+                       Math.min(screenSizeTileCount.width, currentMap.size.width)
+                       ,Math.min(screenSizeTileCount.height, currentMap.size.height)
                        );
-               mapViewArea = new CoordRect(mapTopLeft, mapViewSize);
                
-               tiles = world.tileManager.currentMapTiles;
+                       mapViewArea = new CoordRect(mapTopLeft, mapViewSize);
+                       
+                       tiles = world.tileManager.currentMapTiles;
+               }
                
                clearCanvas();
            
-               recalculateMapTopLeft();
+               recalculateMapTopLeft(model.player.position);
                redrawAll(REDRAW_ALL_MAP_CHANGED);
        }
        
-       private void recalculateMapTopLeft() {
-               mapTopLeft.set(0, 0);
-               
-               final PredefinedMap currentMap = model.currentMap;
-               final Coord playerpos = model.player.position;
-               
-       if (currentMap.size.width > screenSizeTileCount.width) {
-               mapTopLeft.x = Math.max(0, playerpos.x - mapViewArea.size.width/2);
-               mapTopLeft.x = Math.min(mapTopLeft.x, currentMap.size.width - mapViewArea.size.width);
-       }
-       if (currentMap.size.height > screenSizeTileCount.height) {
-               mapTopLeft.y = Math.max(0, playerpos.y - mapViewArea.size.height/2);
-               mapTopLeft.y = Math.min(mapTopLeft.y, currentMap.size.height - mapViewArea.size.height);
-       }
+       private void recalculateMapTopLeft(Coord playerPosition) {
+               synchronized (holder) { 
+                       this.playerPosition.set(playerPosition);
+                       mapTopLeft.set(0, 0);
+                       
+               if (currentMap.size.width > screenSizeTileCount.width) {
+                       mapTopLeft.x = Math.max(0, playerPosition.x - mapViewArea.size.width/2);
+                       mapTopLeft.x = Math.min(mapTopLeft.x, currentMap.size.width - mapViewArea.size.width);
+               }
+               if (currentMap.size.height > screenSizeTileCount.height) {
+                       mapTopLeft.y = Math.max(0, playerPosition.y - mapViewArea.size.height/2);
+                       mapTopLeft.y = Math.min(mapTopLeft.y, currentMap.size.height - mapViewArea.size.height);
+               }
+               }
        }
        
-       public void notifyPlayerMoved() {
-               recalculateMapTopLeft();
+       public void notifyPlayerMoved(Coord newPosition) {
+               recalculateMapTopLeft(newPosition);
                redrawAll(REDRAW_ALL_PLAYER_MOVED);
        }
 }