Update of /cvsroot/arianne/stendhal/src/games/stendhal/client
In directory vz-cvs-4.sog:/tmp/cvs-serv21720/src/games/stendhal/client
Modified Files:
GameScreen.java
Log Message:
Keep the offline icon always on screen. cleaning
Index: GameScreen.java
===================================================================
RCS file: /cvsroot/arianne/stendhal/src/games/stendhal/client/GameScreen.java,v
retrieving revision 1.219
retrieving revision 1.220
diff -C2 -d -r1.219 -r1.220
*** GameScreen.java 17 Nov 2012 19:24:31 -0000 1.219
--- GameScreen.java 19 Nov 2012 16:37:35 -0000 1.220
***************
*** 58,62 ****
GameObjects.GameObjectListener, StendhalClient.ZoneChangeListener {
/**
! * serial version uid
*/
private static final long serialVersionUID = -4070406295913030925L;
--- 58,62 ----
GameObjects.GameObjectListener, StendhalClient.ZoneChangeListener {
/**
! * serial version uid.
*/
private static final long serialVersionUID = -4070406295913030925L;
***************
*** 82,86 ****
* A scale factor for panning delta (to allow non-float precision).
*/
! protected static final int PAN_SCALE = 8;
/**
* Speed factor for centering the screen. Smaller is faster,
--- 82,86 ----
* A scale factor for panning delta (to allow non-float precision).
*/
! private static final int PAN_SCALE = 8;
/**
* Speed factor for centering the screen. Smaller is faster,
***************
*** 88,91 ****
--- 88,96 ----
*/
private static final int PAN_INERTIA = 15;
+ /**
+ * Space at the right and bottom of the screen next to the off line
+ * indicator icon.
+ */
+ private static final int OFFLINE_MARGIN = 10;
private static final Sprite offlineIcon;
***************
*** 97,101 ****
* Static game layers.
*/
! protected StaticGameLayers gameLayers;
/** Entity views container. */
--- 102,106 ----
* Static game layers.
*/
! private StaticGameLayers gameLayers;
/** Entity views container. */
***************
*** 103,109 ****
/** Actual width of the world in world units. */
! protected int ww;
/** Actual height of the world in world units. */
! protected int wh;
/**
--- 108,114 ----
/** Actual width of the world in world units. */
! private int ww;
/** Actual height of the world in world units. */
! private int wh;
/**
***************
*** 133,136 ****
--- 138,144 ----
private boolean offline;
+ /**
+ * Off line indicator counter.
+ */
private int blinkOffline;
***************
*** 208,213 ****
x = 0;
y = 0;
! svx = sw / -2;
! svy = sh / -2;
dvx = 0;
dvy = 0;
--- 216,221 ----
x = 0;
y = 0;
! svx = -sw / 2;
! svy = -sh / 2;
dvx = 0;
dvy = 0;
***************
*** 249,257 ****
double yScale = sh / screenSize.getHeight();
// Scale by the dimension that needs more scaling
! if (Math.abs(xScale) > Math.abs(yScale)) {
! scale = xScale;
! } else {
! scale = yScale;
! }
} else {
sw = Math.min(sw, screenSize.width);
--- 257,261 ----
double yScale = sh / screenSize.getHeight();
// Scale by the dimension that needs more scaling
! scale = Math.max(xScale, yScale);
} else {
sw = Math.min(sw, screenSize.width);
***************
*** 308,317 ****
/** @return screen width in world units. */
private int getViewWidth() {
! return (int) Math.ceil((sw / SIZE_UNIT_PIXELS / scale));
}
/** @return screen height in world units .*/
private int getViewHeight() {
! return (int) Math.ceil((sh / SIZE_UNIT_PIXELS / scale));
}
--- 312,321 ----
/** @return screen width in world units. */
private int getViewWidth() {
! return (int) Math.ceil(sw / (SIZE_UNIT_PIXELS * scale));
}
/** @return screen height in world units .*/
private int getViewHeight() {
! return (int) Math.ceil(sh / (SIZE_UNIT_PIXELS * scale));
}
***************
*** 327,331 ****
/**
! * Get the achievement box factory
*
* @return factory
--- 331,335 ----
/**
! * Get the achievement box factory.
*
* @return factory
***************
*** 385,389 ****
final int sx = convertWorldXToScaledScreen(x) - getScreenViewX() + SIZE_UNIT_PIXELS / 2;
! final int sy = convertWorldYToScaledScreen(y) - getScreenViewY() + (SIZE_UNIT_PIXELS / 2);
if ((sx < 0) || (sx >= sw) || (sy < -SIZE_UNIT_PIXELS) || (sy > sh)) {
--- 389,393 ----
final int sx = convertWorldXToScaledScreen(x) - getScreenViewX() + SIZE_UNIT_PIXELS / 2;
! final int sy = convertWorldYToScaledScreen(y) - getScreenViewY() + SIZE_UNIT_PIXELS / 2;
if ((sx < 0) || (sx >= sw) || (sy < -SIZE_UNIT_PIXELS) || (sy > sh)) {
***************
*** 393,416 ****
center();
} else {
! /*
! * Calculate the target speed. The farther away, the faster.
! */
! final int dux = dvx / PAN_INERTIA;
! final int duy = dvy / PAN_INERTIA;
!
! final int tspeed = ((dux * dux) + (duy * duy)) * PAN_SCALE;
!
! if (speed > tspeed) {
! speed = (speed + speed + tspeed) / 3;
!
! /*
! * Don't stall
! */
! if ((dvx != 0) || (dvy != 0)) {
! speed = Math.max(speed, 1);
! }
! } else if (speed < tspeed) {
! speed += 2;
! }
/*
--- 397,401 ----
center();
} else {
! calculatePanningSpeed();
/*
***************
*** 452,455 ****
--- 437,464 ----
}
}
+
+ /**
+ * Calculate the target speed for moving the view position. The farther
+ * away, the faster.
+ */
+ private void calculatePanningSpeed() {
+ final int dux = dvx / PAN_INERTIA;
+ final int duy = dvy / PAN_INERTIA;
+
+ final int tspeed = ((dux * dux) + (duy * duy)) * PAN_SCALE;
+
+ if (speed > tspeed) {
+ speed = (2 * speed + tspeed) / 3;
+
+ /*
+ * Don't stall
+ */
+ if ((dvx != 0) || (dvy != 0)) {
+ speed = Math.max(speed, 1);
+ }
+ } else if (speed < tspeed) {
+ speed += 2;
+ }
+ }
/**
***************
*** 591,606 ****
drawText(g2d);
// Offline
! if (offline && (blinkOffline > 0)) {
! offlineIcon.draw(g2d, 560, 420);
! }
! if (blinkOffline < -10) {
! blinkOffline = 20;
! } else {
! blinkOffline--;
}
-
- graphics.dispose();
}
--- 600,628 ----
drawText(g2d);
+ paintOffLineIfNeeded(g2d);
+
+ graphics.dispose();
+ }
+
+ /**
+ * Draw the offline indicator, blinking, if the client is offline.
+ *
+ * @param g graphics
+ */
+ private void paintOffLineIfNeeded(Graphics g) {
// Offline
! if (offline) {
! if (blinkOffline > 0) {
! offlineIcon.draw(g, getWidth() - offlineIcon.getWidth() - OFFLINE_MARGIN,
! getHeight() - offlineIcon.getHeight() - OFFLINE_MARGIN);
! }
! // Show for 20 screen draws, hide for 12
! if (blinkOffline < -10) {
! blinkOffline = 20;
! } else {
! blinkOffline--;
! }
}
}
***************
*** 691,697 ****
*
* @param sprite
! * @param x
! * @param y
! * @param textLength
*/
public void addTextBox(Sprite sprite, double x, double y, int textLength) {
--- 713,719 ----
*
* @param sprite
! * @param x x coordinate
! * @param y y coordinate
! * @param textLength length of the text in characters
*/
public void addTextBox(Sprite sprite, double x, double y, int textLength) {
***************
*** 718,722 ****
if ((item.getX() == sx) && (item.getY() == sy)) {
found = true;
! sy += (SIZE_UNIT_PIXELS / scale / 2);
sy = keepSpriteOnMapY(sprite, sy);
break;
--- 740,744 ----
if ((item.getX() == sx) && (item.getY() == sy)) {
found = true;
! sy += SIZE_UNIT_PIXELS / 2;
sy = keepSpriteOnMapY(sprite, sy);
break;
***************
*** 740,744 ****
* Try to keep a sprite on the map. Adjust the Y coordinate.
*
! * @param sprite
* @param sy suggested Y coordinate on screen
* @return new Y coordinate
--- 762,766 ----
* Try to keep a sprite on the map. Adjust the Y coordinate.
*
! * @param sprite sprite to keep on the map
* @param sy suggested Y coordinate on screen
* @return new Y coordinate
***************
*** 761,765 ****
* Try to keep a sprite on the map. Adjust the X coordinate.
*
! * @param sprite
* @param sx suggested X coordinate on screen
* @return new X coordinate
--- 783,787 ----
* Try to keep a sprite on the map. Adjust the X coordinate.
*
! * @param sprite sprite to keep on the map
* @param sx suggested X coordinate on screen
* @return new X coordinate
***************
*** 904,908 ****
/**
! * Convert a world x coordinate to <emph>raw</raw> (native resolution)
* screen x coordinate.
*
--- 926,930 ----
/**
! * Convert a world x coordinate to <em>raw</em> (native resolution)
* screen x coordinate.
*
***************
*** 915,919 ****
/**
! * Convert a world y coordinate to <emph>raw</raw> (native resolution)
* screen y coordinate.
*
--- 937,941 ----
/**
! * Convert a world y coordinate to <em>raw</em> (native resolution)
* screen y coordinate.
*
***************
*** 1019,1027 ****
/**
! * Draw a box for a reached achievement with given title, description and category
*
! * @param title
! * @param description
! * @param category
*/
public void addAchievementBox(String title, String description,
--- 1041,1050 ----
/**
! * Draw a box for a reached achievement with given title, description and
! * category.
*
! * @param title title of the achievement
! * @param description achievement description
! * @param category achievement category
*/
public void addAchievementBox(String title, String description,
***************
*** 1041,1046 ****
* dependent on the text length.
*
! * @param sprite
! * @param textLength
* @param priority importance of the message to keep it above others
*/
--- 1064,1069 ----
* dependent on the text length.
*
! * @param sprite text box sprite
! * @param textLength text length in characters
* @param priority importance of the message to keep it above others
*/
***************
*** 1080,1084 ****
/**
! * Switch to spell casting triggered by a key event
* @param e triggering key event
*/
--- 1103,1108 ----
/**
! * Switch to spell casting triggered by a key event.
! *
* @param e triggering key event
*/
***************
*** 1087,1091 ****
// only if a spell was found switch to spell casting
// i.e. Ctrl + 9 was issued, but player only has 8 spell would return null
! if(spell != null) {
switchToSpellCastingState(spell);
}
--- 1111,1115 ----
// only if a spell was found switch to spell casting
// i.e. Ctrl + 9 was issued, but player only has 8 spell would return null
! if (spell != null) {
switchToSpellCastingState(spell);
}
***************
*** 1093,1097 ****
/**
! * Switch to spell casting with an already chosen spell
*
* @param spell the chosen spell
--- 1117,1121 ----
/**
! * Switch to spell casting with an already chosen spell.
*
* @param spell the chosen spell
***************
*** 1103,1106 ****
--- 1127,1136 ----
}
+ /**
+ * Find spell corresponding to a key.
+ *
+ * @param e key
+ * @return spell, or <code>null</code> if the key does not match any spell
+ */
private RPObject findSpell(KeyEvent e) {
RPObject player = StendhalClient.get().getPlayer();
***************
*** 1109,1113 ****
Integer counter = Integer.valueOf(1);
for (RPObject spell : slot) {
! if(counter.equals(position)) {
return spell;
}
--- 1139,1143 ----
Integer counter = Integer.valueOf(1);
for (RPObject spell : slot) {
! if (counter.equals(position)) {
return spell;
}
|