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>
French translation by LeSanglier and Misty Soul<br />
German translation by Bomber and Samuel Plentz<br />
English proofreading by taws34<br />
+ English proofreading and testing by Stephen Stalnaker<br />
Hebrew translation by eitanbm<br />
Forum moderated by Tim Davis<br />
Forum moderated by Josh Kloos<br />
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;
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);
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();
}
});
- radioButtonListener = new OnClickListener() {
+ radioButtonListener = new OnCheckedChangeListener() {
@Override
- public void onClick(View v) {
+ public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
nextButton.setEnabled(true);
}
};
});
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)) {
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);
}
return false;
}
+
private Reply getSelectedReply() {
for (int i = 0; i < phrase.replies.length; ++i) {
final View v = replyGroup.getChildAt(i);
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));
}
protected void onPostExecute(Void result) {
super.onPostExecute(result);
view.mainActivity.clearMessages();
- view.mainActivity.mainview.notifyMapChanged();
+ view.mainActivity.mainview.notifyMapChanged(model);
stopMovement();
view.gameRoundController.resume();
}
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);
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() {
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;
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);
);
if (model.currentMap != null) {
- notifyMapChanged();
+ notifyMapChanged(model);
}
redrawAll(REDRAW_ALL_SURFACE_CHANGED);
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);
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;
}
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) {
}
}
- 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);
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);
}
}