[Freeciv-Dev] (PR#2608) replace key_move_xxx with key_unit_move
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Jason Short via RT wrote:
> rwetmore@xxxxxxxxxxxx via RT wrote:
> Now gui_to_map_dir and map_to_gui_dir are both provided, in
> mapview_common. Eventually they may move into climap.[ch] (once these
> fies exist).
Umm, did I say climap.[ch] didn't exist?
This patch is identical to v2, I've just moved the functions into climap.
Ross, can you live with this?
jason
? client/mapview_common.c-clip_mapview_window
? client/gui-gtk/diff
Index: client/climap.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/climap.c,v
retrieving revision 1.1
diff -u -r1.1 climap.c
--- client/climap.c 2003/01/05 15:34:04 1.1
+++ client/climap.c 2003/01/27 22:41:12
@@ -19,6 +19,7 @@
#include "shared.h"
#include "climap.h"
+#include "tilespec.h" /* is_isometric */
/***************************************************************
pplayer is only used in the server
@@ -57,4 +58,38 @@
enum known_type tile_get_known(int x, int y)
{
return (enum known_type) map_get_tile(x, y)->known;
+}
+
+/**************************************************************************
+ Convert the given GUI direction into a map direction.
+
+ GUI directions correspond to the current viewing interface, so that
+ DIR8_NORTH is up on the mapview. map directions correspond to the
+ underlying map tiles, so that DIR8_NORTH means moving with a vector of
+ (0,-1). Neither necessarily corresponds to "north" on the underlying
+ world (once iso-maps are possible).
+
+ See also map_to_gui_dir().
+**************************************************************************/
+enum direction8 gui_to_map_dir(enum direction8 gui_dir)
+{
+ if (is_isometric) {
+ return dir_ccw(gui_dir);
+ } else {
+ return gui_dir;
+ }
+}
+
+/**************************************************************************
+ Convert the given GUI direction into a map direction.
+
+ See also gui_to_map_dir().
+**************************************************************************/
+enum direction8 map_to_gui_dir(enum direction8 map_dir)
+{
+ if (is_isometric) {
+ return dir_cw(map_dir);
+ } else {
+ return map_dir;
+ }
}
Index: client/climap.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/climap.h,v
retrieving revision 1.1
diff -u -r1.1 climap.h
--- client/climap.h 2003/01/05 15:34:04 1.1
+++ client/climap.h 2003/01/27 22:41:12
@@ -14,8 +14,12 @@
#ifndef FC__CLIMAP_H
#define FC__CLIMAP_H
+#include "map.h" /* enum direction8 */
#include "terrain.h" /* enum known_type */
enum known_type tile_get_known(int x, int y);
+
+enum direction8 gui_to_map_dir(enum direction8 gui_dir);
+enum direction8 map_to_gui_dir(enum direction8 map_dir);
#endif
Index: client/control.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/control.c,v
retrieving revision 1.91
diff -u -r1.91 control.c
--- client/control.c 2003/01/16 21:04:25 1.91
+++ client/control.c 2003/01/27 22:41:13
@@ -1407,75 +1407,15 @@
}
/**************************************************************************
-...
+ Move the focus unit in the given direction. Here directions are
+ defined according to the GUI, so that north is "up" in the interface.
**************************************************************************/
-void key_move_north(void)
+void key_unit_move(enum direction8 gui_dir)
{
- if(get_unit_in_focus())
- request_move_unit_direction(punit_focus, DIR8_NORTH);
-}
-
-/**************************************************************************
-...
-**************************************************************************/
-void key_move_north_east(void)
-{
- if(get_unit_in_focus())
- request_move_unit_direction(punit_focus, DIR8_NORTHEAST);
-}
-
-/**************************************************************************
-...
-**************************************************************************/
-void key_move_east(void)
-{
- if(get_unit_in_focus())
- request_move_unit_direction(punit_focus, DIR8_EAST);
-}
-
-/**************************************************************************
-...
-**************************************************************************/
-void key_move_south_east(void)
-{
- if(get_unit_in_focus())
- request_move_unit_direction(punit_focus, DIR8_SOUTHEAST);
-}
-
-/**************************************************************************
-...
-**************************************************************************/
-void key_move_south(void)
-{
- if(get_unit_in_focus())
- request_move_unit_direction(punit_focus, DIR8_SOUTH);
-}
-
-/**************************************************************************
-...
-**************************************************************************/
-void key_move_south_west(void)
-{
- if(get_unit_in_focus())
- request_move_unit_direction(punit_focus, DIR8_SOUTHWEST);
-}
-
-/**************************************************************************
-...
-**************************************************************************/
-void key_move_west(void)
-{
- if(get_unit_in_focus())
- request_move_unit_direction(punit_focus, DIR8_WEST);
-}
-
-/**************************************************************************
-...
-**************************************************************************/
-void key_move_north_west(void)
-{
- if(get_unit_in_focus())
- request_move_unit_direction(punit_focus, DIR8_NORTHWEST);
+ if (get_unit_in_focus()) {
+ enum direction8 map_dir = gui_to_map_dir(gui_dir);
+ request_move_unit_direction(get_unit_in_focus(), map_dir);
+ }
}
/**************************************************************************
Index: client/control.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/control.h,v
retrieving revision 1.30
diff -u -r1.30 control.h
--- client/control.h 2002/11/22 18:52:12 1.30
+++ client/control.h 2003/01/27 22:41:13
@@ -116,14 +116,7 @@
void key_fog_of_war_toggle(void);
void key_end_turn(void);
void key_map_grid_toggle(void);
-void key_move_north(void);
-void key_move_north_east(void);
-void key_move_east(void);
-void key_move_south_east(void);
-void key_move_south(void);
-void key_move_south_west(void);
-void key_move_west(void);
-void key_move_north_west(void);
+void key_unit_move(enum direction8 gui_dir);
void key_unit_airbase(void);
void key_unit_auto_attack(void);
void key_unit_auto_explore(void);
Index: client/gui-gtk/gui_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/gui_main.c,v
retrieving revision 1.125
diff -u -r1.125 gui_main.c
--- client/gui-gtk/gui_main.c 2003/01/27 22:27:58 1.125
+++ client/gui-gtk/gui_main.c 2003/01/27 22:41:14
@@ -246,111 +246,63 @@
return keypress;
}
- if (is_isometric && !client_is_observer()) {
+ if (!client_is_observer()) {
switch (ev->keyval) {
case GDK_Up:
case GDK_KP_Up:
case GDK_8:
- case GDK_KP_8: key_move_north_west(); break;
+ case GDK_KP_8:
+ key_unit_move(DIR8_NORTH);
+ break;
case GDK_Page_Up:
case GDK_KP_Page_Up:
case GDK_9:
- case GDK_KP_9: key_move_north(); break;
+ case GDK_KP_9:
+ key_unit_move(DIR8_NORTHEAST);
+ break;
case GDK_Right:
case GDK_KP_Right:
case GDK_6:
- case GDK_KP_6: key_move_north_east(); break;
+ case GDK_KP_6:
+ key_unit_move(DIR8_EAST);
+ break;
case GDK_Page_Down:
case GDK_KP_Page_Down:
case GDK_3:
- case GDK_KP_3: key_move_east(); break;
+ case GDK_KP_3:
+ key_unit_move(DIR8_SOUTHEAST);
+ break;
case GDK_Down:
case GDK_KP_Down:
case GDK_2:
- case GDK_KP_2: key_move_south_east(); break;
+ case GDK_KP_2:
+ key_unit_move(DIR8_SOUTH);
+ break;
case GDK_End:
case GDK_KP_End:
case GDK_1:
- case GDK_KP_1: key_move_south(); break;
+ case GDK_KP_1:
+ key_unit_move(DIR8_SOUTHWEST);
+ break;
case GDK_Left:
case GDK_KP_Left:
case GDK_4:
- case GDK_KP_4: key_move_south_west(); break;
+ case GDK_KP_4:
+ key_unit_move(DIR8_WEST);
+ break;
case GDK_Home:
- case GDK_KP_Home:
- case GDK_7:
- case GDK_KP_7: key_move_west(); break;
-
- case GDK_KP_Begin:
- case GDK_5:
- case GDK_KP_5:
- focus_to_next_unit();
- break;
-
- case GDK_Return:
- case GDK_KP_Enter:
- key_end_turn();
- break;
-
- case GDK_Escape:
- key_cancel_action();
- break;
-
- case GDK_t:
- key_city_workers(w, ev);
- break;
-
- default:
- return FALSE;
- }
- } else if (!client_is_observer()) {
- switch (ev->keyval) {
- case GDK_Up:
- case GDK_KP_Up:
- case GDK_8:
- case GDK_KP_8: key_move_north(); break;
-
- case GDK_Page_Up:
- case GDK_KP_Page_Up:
- case GDK_9:
- case GDK_KP_9: key_move_north_east(); break;
-
- case GDK_Right:
- case GDK_KP_Right:
- case GDK_6:
- case GDK_KP_6: key_move_east(); break;
-
- case GDK_Page_Down:
- case GDK_KP_Page_Down:
- case GDK_3:
- case GDK_KP_3: key_move_south_east(); break;
-
- case GDK_Down:
- case GDK_KP_Down:
- case GDK_2:
- case GDK_KP_2: key_move_south(); break;
-
- case GDK_End:
- case GDK_KP_End:
- case GDK_1:
- case GDK_KP_1: key_move_south_west(); break;
-
- case GDK_Left:
- case GDK_KP_Left:
- case GDK_4:
- case GDK_KP_4: key_move_west(); break;
-
- case GDK_Home:
case GDK_KP_Home:
case GDK_7:
- case GDK_KP_7: key_move_north_west(); break;
+ case GDK_KP_7:
+ key_unit_move(DIR8_NORTHWEST);
+ break;
case GDK_KP_Begin:
case GDK_Return:
Index: client/gui-gtk-2.0/gui_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/gui_main.c,v
retrieving revision 1.38
diff -u -r1.38 gui_main.c
--- client/gui-gtk-2.0/gui_main.c 2003/01/27 22:27:58 1.38
+++ client/gui-gtk-2.0/gui_main.c 2003/01/27 22:41:15
@@ -338,111 +338,63 @@
return keypress;
}
- if (is_isometric && !client_is_observer()) {
+ if (!client_is_observer()) {
switch (ev->keyval) {
case GDK_Up:
case GDK_KP_Up:
case GDK_8:
- case GDK_KP_8: key_move_north_west(); break;
+ case GDK_KP_8:
+ key_unit_move(DIR8_NORTH);
+ break;
case GDK_Page_Up:
case GDK_KP_Page_Up:
case GDK_9:
- case GDK_KP_9: key_move_north(); break;
+ case GDK_KP_9:
+ key_unit_move(DIR8_NORTHEAST);
+ break;
case GDK_Right:
case GDK_KP_Right:
case GDK_6:
- case GDK_KP_6: key_move_north_east(); break;
+ case GDK_KP_6:
+ key_unit_move(DIR8_EAST);
+ break;
case GDK_Page_Down:
case GDK_KP_Page_Down:
case GDK_3:
- case GDK_KP_3: key_move_east(); break;
+ case GDK_KP_3:
+ key_unit_move(DIR8_SOUTHEAST);
+ break;
case GDK_Down:
case GDK_KP_Down:
case GDK_2:
- case GDK_KP_2: key_move_south_east(); break;
+ case GDK_KP_2:
+ key_unit_move(DIR8_SOUTH);
+ break;
case GDK_End:
case GDK_KP_End:
case GDK_1:
- case GDK_KP_1: key_move_south(); break;
+ case GDK_KP_1:
+ key_unit_move(DIR8_SOUTHWEST);
+ break;
case GDK_Left:
case GDK_KP_Left:
case GDK_4:
- case GDK_KP_4: key_move_south_west(); break;
+ case GDK_KP_4:
+ key_unit_move(DIR8_WEST);
+ break;
case GDK_Home:
- case GDK_KP_Home:
- case GDK_7:
- case GDK_KP_7: key_move_west(); break;
-
- case GDK_KP_Begin:
- case GDK_5:
- case GDK_KP_5:
- focus_to_next_unit();
- break;
-
- case GDK_Return:
- case GDK_KP_Enter:
- key_end_turn();
- break;
-
- case GDK_Escape:
- key_cancel_action();
- break;
-
- case GDK_t:
- key_city_workers(w, ev);
- break;
-
- default:
- return FALSE;
- }
- } else if (!client_is_observer()) {
- switch (ev->keyval) {
- case GDK_Up:
- case GDK_KP_Up:
- case GDK_8:
- case GDK_KP_8: key_move_north(); break;
-
- case GDK_Page_Up:
- case GDK_KP_Page_Up:
- case GDK_9:
- case GDK_KP_9: key_move_north_east(); break;
-
- case GDK_Right:
- case GDK_KP_Right:
- case GDK_6:
- case GDK_KP_6: key_move_east(); break;
-
- case GDK_Page_Down:
- case GDK_KP_Page_Down:
- case GDK_3:
- case GDK_KP_3: key_move_south_east(); break;
-
- case GDK_Down:
- case GDK_KP_Down:
- case GDK_2:
- case GDK_KP_2: key_move_south(); break;
-
- case GDK_End:
- case GDK_KP_End:
- case GDK_1:
- case GDK_KP_1: key_move_south_west(); break;
-
- case GDK_Left:
- case GDK_KP_Left:
- case GDK_4:
- case GDK_KP_4: key_move_west(); break;
-
- case GDK_Home:
case GDK_KP_Home:
case GDK_7:
- case GDK_KP_7: key_move_north_west(); break;
+ case GDK_KP_7:
+ key_unit_move(DIR8_NORTHWEST);
+ break;
case GDK_KP_Begin:
case GDK_Return:
Index: client/gui-mui/gui_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/gui_main.c,v
retrieving revision 1.69
diff -u -r1.69 gui_main.c
--- client/gui-mui/gui_main.c 2003/01/01 11:51:33 1.69
+++ client/gui-mui/gui_main.c 2003/01/27 22:41:15
@@ -343,36 +343,31 @@
{
if (*value)
{
- if (is_isometric)
- {
- switch (*value)
- {
- case UNIT_NORTH: key_move_north_west(); break;
- case UNIT_SOUTH: key_move_south_east(); break;
- case UNIT_EAST: key_move_north_east(); break;
- case UNIT_WEST: key_move_south_west(); break;
- case UNIT_NORTH_EAST: key_move_north(); break;
- case UNIT_NORTH_WEST: key_move_west(); break;
- case UNIT_SOUTH_EAST: key_move_east(); break;
- case UNIT_SOUTH_WEST: key_move_south();break;
- }
- } else
- {
- switch (*value)
- {
- case UNIT_NORTH: key_move_north(); break;
- case UNIT_SOUTH: key_move_south(); break;
- case UNIT_EAST: key_move_east(); break;
- case UNIT_WEST: key_move_west(); break;
- case UNIT_NORTH_EAST: key_move_north_east(); break;
- case UNIT_NORTH_WEST: key_move_north_west(); break;
- case UNIT_SOUTH_EAST: key_move_south_east(); break;
- case UNIT_SOUTH_WEST: key_move_south_west();break;
- }
- }
-
- switch (*value)
- {
+ switch (*value) {
+ case UNIT_NORTH:
+ key_unit_move(DIR8_NORTH);
+ break;
+ case UNIT_SOUTH:
+ key_unit_move(DIR8_SOUTH);
+ break;
+ case UNIT_EAST:
+ key_unit_move(DIR8_EAST);
+ break;
+ case UNIT_WEST:
+ key_unit_move(DIR8_WEST);
+ break;
+ case UNIT_NORTH_EAST:
+ key_unit_move(DIR8_NORTHEAST);
+ break;
+ case UNIT_NORTH_WEST:
+ key_unit_move(DIR8_NORTHWEST);
+ break;
+ case UNIT_SOUTH_EAST:
+ key_unit_move(DIR8_SOUTHEAST);
+ break;
+ case UNIT_SOUTH_WEST:
+ key_unit_move(DIR8_SOUTHWEST);
+ break;
case UNIT_POPUP_CITY:
{
struct unit *punit;
Index: client/gui-sdl/gui_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-sdl/gui_main.c,v
retrieving revision 1.8
diff -u -r1.8 gui_main.c
--- client/gui-sdl/gui_main.c 2003/01/19 20:05:54 1.8
+++ client/gui-sdl/gui_main.c 2003/01/27 22:41:16
@@ -239,42 +239,42 @@
break;
case SDLK_UP:
case SDLK_KP8:
- key_move_north_west();
+ key_unit_move(DIR8_NORTH);
break;
case SDLK_PAGEUP:
case SDLK_KP9:
- key_move_north();
+ key_unit_move(DIR8_NORTHEAST);
break;
case SDLK_RIGHT:
case SDLK_KP6:
- key_move_north_east();
+ key_unit_move(DIR8_EAST);
break;
case SDLK_PAGEDOWN:
case SDLK_KP3:
- key_move_east();
+ key_unit_move(DIR8_SOUTHEAST);
break;
case SDLK_DOWN:
case SDLK_KP2:
- key_move_south_east();
+ key_unit_move(DIR8_SOUTH);
break;
case SDLK_END:
case SDLK_KP1:
- key_move_south();
+ key_unit_move(DIR8_SOUTHWEST);
break;
case SDLK_LEFT:
case SDLK_KP4:
- key_move_south_west();
+ key_unit_move(DIR8_WEST);
break;
case SDLK_HOME:
case SDLK_KP7:
- key_move_west();
+ key_unit_move(DIR8_NORTHWEST);
break;
case SDLK_KP5:
Index: client/gui-win32/menu.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/menu.c,v
retrieving revision 1.14
diff -u -r1.14 menu.c
--- client/gui-win32/menu.c 2003/01/23 21:39:32 1.14
+++ client/gui-win32/menu.c 2003/01/27 22:41:16
@@ -469,32 +469,34 @@
**************************************************************************/
static void handle_numpad(int code)
{
- if (is_isometric) {
- switch (code)
- {
- case IDM_NUMPAD_BASE+1: key_move_south(); break;
- case IDM_NUMPAD_BASE+2: key_move_south_east(); break;
- case IDM_NUMPAD_BASE+3: key_move_east(); break;
- case IDM_NUMPAD_BASE+4: key_move_south_west(); break;
- case IDM_NUMPAD_BASE+5: focus_to_next_unit(); break;
- case IDM_NUMPAD_BASE+6: key_move_north_east(); break;
- case IDM_NUMPAD_BASE+7: key_move_west(); break;
- case IDM_NUMPAD_BASE+8: key_move_north_west(); break;
- case IDM_NUMPAD_BASE+9: key_move_north(); break;
- }
- } else {
- switch (code)
- {
- case IDM_NUMPAD_BASE+1: key_move_south_west(); break;
- case IDM_NUMPAD_BASE+2: key_move_south(); break;
- case IDM_NUMPAD_BASE+3: key_move_south_east(); break;
- case IDM_NUMPAD_BASE+4: key_move_west(); break;
- case IDM_NUMPAD_BASE+5: focus_to_next_unit(); break;
- case IDM_NUMPAD_BASE+6: key_move_east(); break;
- case IDM_NUMPAD_BASE+7: key_move_north_west(); break;
- case IDM_NUMPAD_BASE+8: key_move_north(); break;
- case IDM_NUMPAD_BASE+9: key_move_north_east(); break;
- }
+ switch (code) {
+ case IDM_NUMPAD_BASE + 1:
+ key_unit_move(DIR8_SOUTHWEST);
+ break;
+ case IDM_NUMPAD_BASE + 2:
+ key_unit_move(DIR8_SOUTH);
+ break;
+ case IDM_NUMPAD_BASE + 3:
+ key_unit_move(DIR8_SOUTHEAST);
+ break;
+ case IDM_NUMPAD_BASE + 4:
+ key_unit_move(DIR8_WEST);
+ break;
+ case IDM_NUMPAD_BASE + 5:
+ focus_to_next_unit();
+ break;
+ case IDM_NUMPAD_BASE + 6:
+ key_unit_move(DIR8_EAST);
+ break;
+ case IDM_NUMPAD_BASE + 7:
+ key_unit_move(DIR8_NORTHWEST);
+ break;
+ case IDM_NUMPAD_BASE + 8:
+ key_unit_move(DIR8_NORTH);
+ break;
+ case IDM_NUMPAD_BASE + 9:
+ key_unit_move(DIR8_NORTHEAST);
+ break;
}
}
Index: client/gui-xaw/actions.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/actions.c,v
retrieving revision 1.13
diff -u -r1.13 actions.c
--- client/gui-xaw/actions.c 2003/01/01 11:51:34 1.13
+++ client/gui-xaw/actions.c 2003/01/27 22:41:16
@@ -153,42 +153,42 @@
static void xaw_key_move_north(Widget w, XEvent *event, String *argv, Cardinal
*argc)
{
- key_move_north();
+ key_unit_move(DIR8_NORTH);
}
static void xaw_key_move_north_east(Widget w, XEvent *event, String *argv,
Cardinal *argc)
{
- key_move_north_east();
+ key_unit_move(DIR8_NORTHEAST);
}
static void xaw_key_move_east(Widget w, XEvent *event, String *argv, Cardinal
*argc)
{
- key_move_east();
+ key_unit_move(DIR8_EAST);
}
static void xaw_key_move_south_east(Widget w, XEvent *event, String *argv,
Cardinal *argc)
{
- key_move_south_east();
+ key_unit_move(DIR8_SOUTHEAST);
}
static void xaw_key_move_south(Widget w, XEvent *event, String *argv, Cardinal
*argc)
{
- key_move_south();
+ key_unit_move(DIR8_SOUTH);
}
static void xaw_key_move_south_west(Widget w, XEvent *event, String *argv,
Cardinal *argc)
{
- key_move_south_west();
+ key_unit_move(DIR8_SOUTHWEST);
}
static void xaw_key_move_west(Widget w, XEvent *event, String *argv, Cardinal
*argc)
{
- key_move_west();
+ key_unit_move(DIR8_WEST);
}
static void xaw_key_move_north_west(Widget w, XEvent *event, String *argv,
Cardinal *argc)
{
- key_move_north_west();
+ key_unit_move(DIR8_NORTHWEST);
}
static void xaw_key_open_city_report(Widget w, XEvent *event, String *argv,
Cardinal *argc)
|
|