diff -Nurd -X clean/diff_ignore clean/client/Makefile.am work/client/Makefile.am --- clean/client/Makefile.am Thu Aug 22 22:06:47 2002 +++ work/client/Makefile.am Thu Aug 22 19:30:01 2002 @@ -147,6 +147,8 @@ goto.h \ helpdata.c \ helpdata.h \ + mapctrl_common.c \ + mapctrl_common.h \ mapview_common.c \ mapview_common.h \ messagewin_common.c \ diff -Nurd -X clean/diff_ignore clean/client/agents/agents.c work/client/agents/agents.c --- clean/client/agents/agents.c Thu Aug 22 22:06:47 2002 +++ work/client/agents/agents.c Thu Aug 22 21:34:18 2002 @@ -133,8 +133,6 @@ } } call_list_iterate_end; - set_turn_done_button_state(FALSE); - pcall2 = fc_malloc(sizeof(struct call)); pcall2->agent = agent; @@ -147,6 +145,8 @@ if (DEBUG_TODO_LISTS) { freelog(LOG_NORMAL, "A: adding call"); } + + update_turn_done_button_state(); } /*********************************************************************** @@ -235,9 +235,7 @@ currently_running = FALSE; - if (!agents_busy() && !game.player_ptr->turn_done && !client_is_observer()) { - set_turn_done_button_state(TRUE); - } + update_turn_done_button_state(); } /*********************************************************************** diff -Nurd -X clean/diff_ignore clean/client/civclient.c work/client/civclient.c --- clean/client/civclient.c Thu Aug 22 22:06:47 2002 +++ work/client/civclient.c Thu Aug 22 23:30:29 2002 @@ -90,7 +90,13 @@ int turn_gold_difference; /* TRUE if an end turn request is blocked by busy agents */ -static bool waiting_for_end_turn = FALSE; +bool waiting_for_end_turn = FALSE; + +/* + * TRUE for the time between sending PACKET_TURN_DONE and receiving + * PACKET_NEW_YEAR. + */ +bool turn_done_sent = FALSE; static void client_remove_all_cli_conn(void); @@ -441,11 +447,6 @@ case PACKET_PROCESSING_FINISHED: handle_processing_finished(); - /* This may thaw the agents, which may in turn have been blocking an - * end turn request */ - if (waiting_for_end_turn) { - send_turn_done(); - } break; case PACKET_START_TURN: @@ -478,24 +479,34 @@ { struct packet_generic_message gen_packet; - waiting_for_end_turn = FALSE; + freelog(LOG_DEBUG, "send_turn_done() turn_done_button_state=%d", + get_turn_done_button_state()); - if (agents_busy()) { - waiting_for_end_turn = TRUE; + if (!get_turn_done_button_state()) { /* * The turn done button is disabled but the user may have press * the return key. */ + + if (agents_busy()) { + waiting_for_end_turn = TRUE; + } + return; } + waiting_for_end_turn = FALSE; + turn_done_sent = TRUE; + attribute_flush(); gen_packet.message[0] = '\0'; send_packet_generic_message(&aconnection, PACKET_TURN_DONE, &gen_packet); - set_turn_done_button_state(FALSE); + + update_turn_done_button_state(); } + /************************************************************************** ... **************************************************************************/ @@ -618,6 +629,7 @@ gui_server_connect(); } } + update_turn_done_button_state(); } diff -Nurd -X clean/diff_ignore clean/client/civclient.h work/client/civclient.h --- clean/client/civclient.h Thu Aug 22 22:06:47 2002 +++ work/client/civclient.h Thu Aug 22 21:40:16 2002 @@ -47,6 +47,8 @@ extern char metaserver[512]; extern int server_port; extern bool auto_connect; +extern bool waiting_for_end_turn; +extern bool turn_done_sent; extern int turn_gold_difference; extern int seconds_to_turndone; diff -Nurd -X clean/diff_ignore clean/client/control.c work/client/control.c --- clean/client/control.c Thu Aug 22 22:06:47 2002 +++ work/client/control.c Thu Aug 22 19:30:01 2002 @@ -1348,9 +1348,7 @@ **************************************************************************/ void key_end_turn(void) { - if (!game.player_ptr->turn_done) { - send_turn_done(); - } + send_turn_done(); } /************************************************************************** diff -Nurd -X clean/diff_ignore clean/client/gui-beos/gui_main.c work/client/gui-beos/gui_main.c --- clean/client/gui-beos/gui_main.c Thu Aug 22 22:06:47 2002 +++ work/client/gui-beos/gui_main.c Thu Aug 22 19:30:09 2002 @@ -20,12 +20,6 @@ } void -enable_turn_done_button(void) /* HOOK */ -{ - /* NOT_FINISHED( "enable_turn_done_button" ); */ -} - -void add_net_input(int sock) /* HOOK */ { /* NOT_FINISHED( "add_net_input" ); */ diff -Nurd -X clean/diff_ignore clean/client/gui-gtk/gui_main.c work/client/gui-gtk/gui_main.c --- clean/client/gui-gtk/gui_main.c Thu Aug 22 22:06:47 2002 +++ work/client/gui-gtk/gui_main.c Thu Aug 22 23:19:40 2002 @@ -1044,18 +1044,6 @@ } /************************************************************************** -... -**************************************************************************/ -void enable_turn_done_button(void) -{ - if(game.player_ptr->ai.control && !ai_manual_turn_done) - user_ended_turn(); - - gtk_widget_set_sensitive(turn_done_button, - !game.player_ptr->ai.control || ai_manual_turn_done); -} - -/************************************************************************** user clicked "Turn Done" button **************************************************************************/ static void end_turn_callback(GtkWidget *w, gpointer data) diff -Nurd -X clean/diff_ignore clean/client/gui-gtk/mapview.c work/client/gui-gtk/mapview.c --- clean/client/gui-gtk/mapview.c Thu Aug 22 22:06:47 2002 +++ work/client/gui-gtk/mapview.c Thu Aug 22 23:20:14 2002 @@ -328,28 +328,30 @@ } /************************************************************************** -... + If do_restore is FALSE it will invert the turn done button style. If + called regularly from a timer this will give a blinking turn done + button. If do_restore is TRUE this will reset the turn done button + to the default style. **************************************************************************/ -void update_turn_done_button(int do_restore) +void update_turn_done_button(bool do_restore) { - static int flip; - GdkGC *fore, *back; - - if(game.player_ptr->ai.control && !ai_manual_turn_done) - return; - if((do_restore && flip) || !do_restore) - { - - fore = turn_done_button->style->bg_gc[GTK_STATE_NORMAL]; - back = turn_done_button->style->light_gc[GTK_STATE_NORMAL]; + static bool flip = FALSE; + + if (!get_turn_done_button_state()) { + return; + } - turn_done_button->style->bg_gc[GTK_STATE_NORMAL] = back; - turn_done_button->style->light_gc[GTK_STATE_NORMAL] = fore; + if ((do_restore && flip) || !do_restore) { + GdkGC *fore = turn_done_button->style->bg_gc[GTK_STATE_NORMAL]; + GdkGC *back = turn_done_button->style->light_gc[GTK_STATE_NORMAL]; - gtk_expose_now(turn_done_button); + turn_done_button->style->bg_gc[GTK_STATE_NORMAL] = back; + turn_done_button->style->light_gc[GTK_STATE_NORMAL] = fore; - flip=!flip; - } + gtk_expose_now(turn_done_button); + + flip = !flip; + } } /************************************************************************** diff -Nurd -X clean/diff_ignore clean/client/gui-gtk-2.0/gui_main.c work/client/gui-gtk-2.0/gui_main.c --- clean/client/gui-gtk-2.0/gui_main.c Thu Aug 22 22:06:47 2002 +++ work/client/gui-gtk-2.0/gui_main.c Thu Aug 22 22:01:43 2002 @@ -1157,18 +1157,6 @@ } /************************************************************************** -... -**************************************************************************/ -void enable_turn_done_button(void) -{ - if(game.player_ptr->ai.control && !ai_manual_turn_done) - user_ended_turn(); - - gtk_widget_set_sensitive(turn_done_button, - !game.player_ptr->ai.control || ai_manual_turn_done); -} - -/************************************************************************** user clicked "Turn Done" button **************************************************************************/ static void end_turn_callback(GtkWidget *w, gpointer data) diff -Nurd -X clean/diff_ignore clean/client/gui-mui/gui_main.c work/client/gui-mui/gui_main.c --- clean/client/gui-mui/gui_main.c Thu Aug 22 22:06:47 2002 +++ work/client/gui-mui/gui_main.c Thu Aug 22 19:30:12 2002 @@ -311,16 +311,6 @@ } /**************************************************************** - Enables the Turn Done button -*****************************************************************/ -void enable_turn_done_button(void) -{ - if (game.player_ptr->ai.control && !ai_manual_turn_done) - user_ended_turn(); - set(main_turndone_button, MUIA_Disabled, !(!game.player_ptr->ai.control || ai_manual_turn_done)); -} - -/**************************************************************** Callback for the chatline *****************************************************************/ static void inputline_return(void) /* from chatline.c */ diff -Nurd -X clean/diff_ignore clean/client/gui-stub/gui_main.c work/client/gui-stub/gui_main.c --- clean/client/gui-stub/gui_main.c Thu Aug 22 22:06:47 2002 +++ work/client/gui-stub/gui_main.c Thu Aug 22 19:30:12 2002 @@ -25,12 +25,6 @@ } void -enable_turn_done_button(void) -{ - /* PORTME */ -} - -void add_net_input(int sock) { /* PORTME */ diff -Nurd -X clean/diff_ignore clean/client/gui-win32/gui_main.c work/client/gui-win32/gui_main.c --- clean/client/gui-win32/gui_main.c Thu Aug 22 22:06:47 2002 +++ work/client/gui-win32/gui_main.c Thu Aug 22 19:30:12 2002 @@ -593,19 +593,6 @@ **************************************************************************/ void -enable_turn_done_button(void) -{ - if(game.player_ptr->ai.control && !ai_manual_turn_done) - user_ended_turn(); - EnableWindow(turndone_button,TRUE); -} - - - -/************************************************************************** - -**************************************************************************/ -void add_net_input(int sock) { net_input=sock; diff -Nurd -X clean/diff_ignore clean/client/gui-xaw/gui_main.c work/client/gui-xaw/gui_main.c --- clean/client/gui-xaw/gui_main.c Thu Aug 22 22:06:47 2002 +++ work/client/gui-xaw/gui_main.c Thu Aug 22 22:02:51 2002 @@ -741,19 +741,6 @@ /************************************************************************** ... **************************************************************************/ -void enable_turn_done_button(void) -{ - if(game.player_ptr->ai.control && !ai_manual_turn_done) - user_ended_turn(); - - update_turn_done_button(1); - XtSetSensitive(turn_done_button, - !game.player_ptr->ai.control||ai_manual_turn_done); -} - -/************************************************************************** -... -**************************************************************************/ static void get_net_input(XtPointer client_data, int *fid, XtInputId *id) { input_from_server(*fid); diff -Nurd -X clean/diff_ignore clean/client/include/gui_main_g.h work/client/include/gui_main_g.h --- clean/client/include/gui_main_g.h Thu Aug 22 22:06:47 2002 +++ work/client/include/gui_main_g.h Thu Aug 22 19:30:12 2002 @@ -20,7 +20,6 @@ void ui_init(void); void ui_main(int argc, char *argv[]); void sound_bell(void); -void enable_turn_done_button(void); void add_net_input(int); void remove_net_input(void); diff -Nurd -X clean/diff_ignore clean/client/include/mapctrl_g.h work/client/include/mapctrl_g.h --- clean/client/include/mapctrl_g.h Thu Aug 22 22:06:47 2002 +++ work/client/include/mapctrl_g.h Thu Aug 22 19:30:12 2002 @@ -15,6 +15,8 @@ #include "shared.h" /* bool type */ +#include "mapctrl_common.h" + struct unit; struct city; diff -Nurd -X clean/diff_ignore clean/client/mapctrl_common.c work/client/mapctrl_common.c --- clean/client/mapctrl_common.c Thu Jan 1 01:00:00 1970 +++ work/client/mapctrl_common.c Thu Aug 22 23:22:47 2002 @@ -0,0 +1,77 @@ +/********************************************************************** + Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. +***********************************************************************/ + +#include "agents.h" +#include "civclient.h" +#include "log.h" +#include "mapctrl_g.h" +#include "mapview_g.h" +#include "options.h" + +#include "mapctrl_common.h" + +static bool turn_done_state; +static bool is_turn_done_state_valid = FALSE; + +/************************************************************************** + Return TRUE iff the turn done button is enabled. +**************************************************************************/ +bool get_turn_done_button_state() +{ + if (!is_turn_done_state_valid) { + update_turn_done_button_state(); + } + assert(is_turn_done_state_valid); + + return turn_done_state; +} + +/************************************************************************** + Update the turn done button state. +**************************************************************************/ +void update_turn_done_button_state() +{ + bool new_state; + + if (!is_turn_done_state_valid) { + turn_done_state = FALSE; + is_turn_done_state_valid = TRUE; + set_turn_done_button_state(turn_done_state); + freelog(LOG_DEBUG, "setting turn done button state init %d", + turn_done_state); + } + + new_state = (get_client_state() == CLIENT_GAME_RUNNING_STATE + && !game.player_ptr->turn_done && !agents_busy() + && (!game.player_ptr->ai.control || ai_manual_turn_done) + && !client_is_observer() + && !turn_done_sent); + if (new_state == turn_done_state) { + return; + } + + freelog(LOG_DEBUG, "setting turn done button state from %d to %d", + turn_done_state, new_state); + turn_done_state = new_state; + + set_turn_done_button_state(turn_done_state); + + if (turn_done_state) { + if (waiting_for_end_turn + || (game.player_ptr->ai.control && !ai_manual_turn_done)) { + send_turn_done(); + } else { + update_turn_done_button(TRUE); + } + } +} diff -Nurd -X clean/diff_ignore clean/client/mapctrl_common.h work/client/mapctrl_common.h --- clean/client/mapctrl_common.h Thu Jan 1 01:00:00 1970 +++ work/client/mapctrl_common.h Thu Aug 22 19:30:32 2002 @@ -0,0 +1,22 @@ +/********************************************************************** + Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. +***********************************************************************/ + +#ifndef FC__MAPCTRL_COMMON_H +#define FC__MAPCTRL_COMMON_H + +#include "shared.h" /* bool type */ + +bool get_turn_done_button_state(void); +void update_turn_done_button_state(void); + +#endif /* FC__MAPVIEW_COMMON_H */ diff -Nurd -X clean/diff_ignore clean/client/packhand.c work/client/packhand.c --- clean/client/packhand.c Thu Aug 22 22:06:47 2002 +++ work/client/packhand.c Thu Aug 22 23:25:16 2002 @@ -278,9 +278,6 @@ if(get_client_state()==CLIENT_GAME_RUNNING_STATE) { refresh_overview_canvas(); refresh_overview_viewrect(); - if (!client_is_observer()) { - enable_turn_done_button(); - } player_set_unit_focus_status(game.player_ptr); update_info_label(); /* get initial population right */ @@ -646,11 +643,6 @@ **************************************************************************/ void handle_new_year(struct packet_new_year *ppacket) { - update_turn_done_button(1); - if (!client_is_observer()) { - enable_turn_done_button(); - } - game.year = ppacket->year; /* * The turn was increased in handle_before_new_year() @@ -707,6 +699,9 @@ agents_start_turn(); + turn_done_sent = FALSE; + update_turn_done_button_state(); + if(game.player_ptr->ai.control && !ai_manual_turn_done) { user_ended_turn(); } @@ -1206,6 +1201,9 @@ } } + if (pplayer == game.player_ptr && pplayer->turn_done != pinfo->turn_done) { + update_turn_done_button_state(); + } pplayer->turn_done=pinfo->turn_done; pplayer->nturns_idle=pinfo->nturns_idle; pplayer->is_alive=pinfo->is_alive; @@ -1235,17 +1233,9 @@ update_players_dialog(); update_worklist_report_dialog(); - if(pplayer==game.player_ptr) { - if(get_client_state()==CLIENT_GAME_RUNNING_STATE) { - if (!game.player_ptr->turn_done) { - if (!client_is_observer()) { - enable_turn_done_button(); - } - } else { - update_turn_done_button(1); - } - update_info_label(); - } + if (pplayer == game.player_ptr + && get_client_state() == CLIENT_GAME_RUNNING_STATE) { + update_info_label(); } }