2005-10-20 17:45:00 +02:00
/*
2005-11-26 17:52:51 +01:00
window . c
2005-10-20 17:45:00 +02:00
Bygfoot Football Manager - - a small and simple GTK2 - based
football management game .
http : //bygfoot.sourceforge.net
Copyright ( C ) 2005 Gyözö Both ( gyboth @ bygfoot . com )
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
of the License , 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 .
You should have received a copy of the GNU General Public License
along with this program ; if not , write to the Free Software
Foundation , Inc . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 , USA .
*/
2005-06-15 21:13:35 +02:00
# include "callbacks.h"
2005-11-26 17:52:51 +01:00
# include "debug.h"
2005-01-09 21:21:22 +01:00
# include "file.h"
2005-03-17 21:26:01 +01:00
# include "finance.h"
2008-11-07 21:43:38 +01:00
# include "fixture.h"
2005-01-09 21:21:22 +01:00
# include "free.h"
2005-03-03 13:46:48 +01:00
# include "game_gui.h"
2005-03-17 21:26:01 +01:00
# include "gui.h"
2004-12-30 17:48:19 +01:00
# include "interface.h"
2005-11-01 22:20:24 +01:00
# include "language.h"
2005-06-05 12:39:29 +02:00
# include "league.h"
# include "live_game.h"
2005-06-14 22:04:37 +02:00
# include "load_save.h"
2005-04-09 21:18:28 +02:00
# include "main.h"
2005-11-02 22:04:19 +01:00
# include "maths.h"
2008-05-02 15:00:05 +02:00
# include "misc.h"
2005-06-14 22:04:37 +02:00
# include "misc_callback_func.h"
2004-12-30 17:48:19 +01:00
# include "misc_interface.h"
2005-03-08 09:25:46 +01:00
# include "misc2_interface.h"
2005-10-27 23:10:15 +02:00
# include "misc3_interface.h"
2005-03-03 13:46:48 +01:00
# include "option.h"
2005-03-23 20:03:26 +01:00
# include "option_gui.h"
# include "options_interface.h"
2004-12-30 17:48:19 +01:00
# include "support.h"
2007-01-18 18:40:28 +01:00
# include "training.h"
# include "training_interface.h"
2005-06-15 18:44:53 +02:00
# include "transfer.h"
2005-05-07 16:19:52 +02:00
# include "treeview.h"
2005-08-20 21:39:36 +02:00
# include "treeview2.h"
2005-05-07 16:19:52 +02:00
# include "treeview_helper.h"
2005-03-03 13:46:48 +01:00
# include "user.h"
2005-01-09 21:21:22 +01:00
# include "window.h"
2004-12-23 13:58:39 +01:00
2006-02-15 13:03:48 +01:00
/** Show the splash screen window. */
void
window_show_splash ( void )
{
2008-11-25 14:50:07 +01:00
# ifdef DEBUG
printf ( " window_show_splash \n " ) ;
# endif
2006-02-15 13:03:48 +01:00
window_create ( WINDOW_SPLASH ) ;
treeview_show_contributors (
GTK_TREE_VIEW ( lookup_widget ( window . splash , " treeview_splash_contributors " ) ) ) ;
window_load_hint_number ( ) ;
window_splash_show_hint ( ) ;
}
/** Show the hint determined by the hint counter in the splash window. */
void
window_splash_show_hint ( void )
{
2008-11-25 14:50:07 +01:00
# ifdef DEBUG
printf ( " window_splash_show_hint \n " ) ;
# endif
2006-02-15 13:03:48 +01:00
gchar buf [ SMALL ] ;
gtk_label_set_text (
GTK_LABEL ( lookup_widget ( window . splash , " label_splash_hint " ) ) ,
g_array_index ( hints . list , Option , counters [ COUNT_HINT_NUMBER ] ) . string_value ) ;
sprintf ( buf , " (%d/%d) " , counters [ COUNT_HINT_NUMBER ] + 1 ,
hints . list - > len ) ;
gtk_label_set_text (
GTK_LABEL ( lookup_widget ( window . splash , " label_splash_hintcounter " ) ) ,
buf ) ;
}
/** Load the index of the hint to show in the splash screen. */
void
window_load_hint_number ( void )
{
2008-11-25 14:50:07 +01:00
# ifdef DEBUG
printf ( " window_load_hint_number \n " ) ;
# endif
2006-02-15 13:03:48 +01:00
gchar filename [ SMALL ] ;
gchar dir [ SMALL ] ;
FILE * fil ;
file_get_bygfoot_dir ( dir ) ;
sprintf ( filename , " %s%shint_num " ,
dir , G_DIR_SEPARATOR_S ) ;
fil = fopen ( filename , " r " ) ;
if ( fil = = NULL )
{
counters [ COUNT_HINT_NUMBER ] = 0 ;
return ;
}
fscanf ( fil , " %d " , & counters [ COUNT_HINT_NUMBER ] ) ;
fclose ( fil ) ;
2006-02-21 11:20:20 +01:00
if ( counters [ COUNT_HINT_NUMBER ] < 0 | |
counters [ COUNT_HINT_NUMBER ] > = hints . list - > len )
{
g_warning ( " Hint counter out of bounds: %d (bounds 0 and %d). \n " ,
counters [ COUNT_HINT_NUMBER ] , hints . list - > len - 1 ) ;
counters [ COUNT_HINT_NUMBER ] = 0 ;
}
2006-02-15 13:03:48 +01:00
}
/** Save the index of the current hint. */
void
window_save_hint_number ( void )
{
2008-11-25 14:50:07 +01:00
# ifdef DEBUG
printf ( " window_save_hint_number \n " ) ;
# endif
2006-02-15 13:03:48 +01:00
gchar filename [ SMALL ] ;
gchar dir [ SMALL ] ;
FILE * fil ;
file_get_bygfoot_dir ( dir ) ;
sprintf ( filename , " %s%shint_num " ,
dir , G_DIR_SEPARATOR_S ) ;
fil = fopen ( filename , " w " ) ;
if ( fil = = NULL )
return ;
fprintf ( fil , " %d " , counters [ COUNT_HINT_NUMBER ] ) ;
fclose ( fil ) ;
}
2005-11-02 22:04:19 +01:00
/** Show the window with the progress bar,
sometimes with a nice picture . */
void
window_show_progress ( gint pictype )
{
2008-11-25 14:50:07 +01:00
# ifdef DEBUG
printf ( " window_show_progress \n " ) ;
# endif
2005-11-02 22:04:19 +01:00
GPtrArray * pics = NULL ;
const gchar * picdir = NULL ;
gchar buf [ SMALL ] ;
2005-11-26 17:52:51 +01:00
gchar * buf2 = NULL ;
2005-11-02 22:04:19 +01:00
GtkImage * image = NULL ;
2009-01-09 15:32:34 +01:00
if ( sett_int ( " int_opt_goto_mode " ) )
return ;
2005-11-02 22:04:19 +01:00
window_create ( WINDOW_PROGRESS ) ;
if ( pictype = = PIC_TYPE_NONE | |
! opt_int ( " int_opt_progressbar_pics " ) )
return ;
image = GTK_IMAGE ( lookup_widget ( window . progress ,
" image_match " ) ) ;
switch ( pictype )
{
default :
g_warning ( " window_show_progress: unknown picture type %d " ,
pictype ) ;
break ;
case PIC_TYPE_SAVE :
gtk_image_set_from_stock ( image , GTK_STOCK_FLOPPY ,
GTK_ICON_SIZE_DIALOG ) ;
break ;
case PIC_TYPE_LOAD :
gtk_image_set_from_stock ( image , GTK_STOCK_OPEN ,
GTK_ICON_SIZE_DIALOG ) ;
break ;
case PIC_TYPE_MATCHPIC :
2005-11-26 17:52:51 +01:00
if ( debug_egg_forwards_boost_style ( ) )
{
buf2 = file_find_support_file ( " soccerbabes.jpg " , FALSE ) ;
if ( buf2 ! = NULL )
{
gtk_image_set_from_file ( image , buf2 ) ;
g_free ( buf2 ) ;
}
2005-11-02 22:04:19 +01:00
}
2005-11-26 17:52:51 +01:00
if ( buf2 = = NULL )
{
picdir = file_get_first_support_dir_suffix ( " pics " ) ;
if ( picdir = = NULL )
return ;
pics = file_dir_get_contents ( picdir , " match " , " " ) ;
if ( pics - > len ! = 0 )
{
sprintf ( buf , " %s%s%s " , picdir , G_DIR_SEPARATOR_S ,
( gchar * ) g_ptr_array_index ( pics , math_rndi ( 0 , pics - > len - 1 ) ) ) ;
gtk_image_set_from_file ( image , buf ) ;
}
free_gchar_array ( & pics ) ;
}
2005-11-02 22:04:19 +01:00
break ;
}
}
2005-10-27 23:10:15 +02:00
/** Show the betting window. */
void
window_show_bets ( void )
{
2008-11-25 14:50:07 +01:00
# ifdef DEBUG
printf ( " window_show_bets \n " ) ;
# endif
2005-10-27 23:10:15 +02:00
window_create ( WINDOW_BETS ) ;
gtk_toggle_button_set_active (
GTK_TOGGLE_BUTTON ( lookup_widget ( window . bets , " checkbutton_bet_all_leagues " ) ) ,
opt_user_int ( " int_opt_user_bet_show_all_leagues " ) ) ;
gtk_toggle_button_set_active (
GTK_TOGGLE_BUTTON ( lookup_widget ( window . bets , " checkbutton_bet_cups " ) ) ,
opt_user_int ( " int_opt_user_bet_show_cups " ) ) ;
gtk_toggle_button_set_active (
GTK_TOGGLE_BUTTON ( lookup_widget ( window . bets , " checkbutton_bet_user_recent " ) ) ,
opt_user_int ( " int_opt_user_bet_show_my_recent " ) ) ;
treeview2_show_bets ( ) ;
}
2005-05-22 15:33:24 +02:00
/** Show the help/about window.
@ param page Which notebook page to display . */
void
window_show_help ( gint page )
{
2008-11-25 14:50:07 +01:00
# ifdef DEBUG
printf ( " window_show_help \n " ) ;
# endif
2005-05-22 15:33:24 +02:00
gchar buf [ SMALL ] ;
window_create ( WINDOW_HELP ) ;
2007-01-18 18:40:28 +01:00
sprintf ( buf , " <span %s>Bygfoot Football Manager %s</span> \n (c) %s Győző Both (gyboth@bygfoot.com) \n http://bygfoot.sourceforge.net " , const_app ( " string_help_window_program_name_attribute " ) , VERS , YEAR ) ;
2005-05-24 20:31:07 +02:00
gtk_label_set_markup ( GTK_LABEL ( lookup_widget ( window . help , " label_about " ) ) , buf ) ;
2005-05-22 15:33:24 +02:00
2006-02-15 13:03:48 +01:00
treeview_show_contributors (
GTK_TREE_VIEW ( lookup_widget ( window . help , " treeview_contributors " ) ) ) ;
2005-05-22 15:33:24 +02:00
2005-05-24 20:31:07 +02:00
game_gui_set_help_labels ( ) ;
2005-05-22 15:33:24 +02:00
gtk_notebook_set_current_page ( GTK_NOTEBOOK ( lookup_widget ( window . help , " notebook1 " ) ) , page ) ;
}
2008-12-08 14:46:11 +01:00
static void
is_capital_sensitive ( GtkCellLayout * cell_layout ,
GtkCellRenderer * cell ,
GtkTreeModel * tree_model ,
GtkTreeIter * iter ,
gpointer data )
{
gboolean sensitive ;
sensitive = ! gtk_tree_model_iter_has_child ( tree_model , iter ) ;
g_object_set ( cell , " sensitive " , sensitive , NULL ) ;
}
2004-12-23 13:58:39 +01:00
/**
Show the country selection window . All files with prefix
' country_ ' from $ HOME / . bygfoot / definitions are appended to a combo box .
*/
void
window_show_startup ( void )
{
2008-11-25 14:50:07 +01:00
# ifdef DEBUG
printf ( " window_show_startup \n " ) ;
# endif
2004-12-23 13:58:39 +01:00
GtkWidget * window_startup =
2004-12-30 17:48:19 +01:00
window_create ( WINDOW_STARTUP ) ;
2004-12-23 13:58:39 +01:00
GtkWidget * combo_country =
lookup_widget ( window_startup , " combo_country " ) ;
2005-04-09 21:18:28 +02:00
GPtrArray * country_files = NULL ;
2005-05-07 16:19:52 +02:00
GtkTreeModel * model = NULL ;
GtkCellRenderer * renderer = NULL ;
2008-12-17 15:39:10 +01:00
gchar * last_country = file_load_text_from_saves ( " last_country " ) ;
2004-12-23 13:58:39 +01:00
2005-04-09 21:18:28 +02:00
country_files = file_get_country_files ( ) ;
2004-12-23 13:58:39 +01:00
2005-04-09 21:18:28 +02:00
if ( country_files - > len = = 0 )
2005-10-24 22:50:48 +02:00
main_exit_program ( EXIT_NO_COUNTRY_FILES ,
" Didn't find any country definition files in the support directories. " ) ;
2004-12-23 13:58:39 +01:00
2005-05-07 16:19:52 +02:00
gtk_cell_layout_clear ( GTK_CELL_LAYOUT ( combo_country ) ) ;
renderer = gtk_cell_renderer_pixbuf_new ( ) ;
gtk_cell_layout_pack_start ( GTK_CELL_LAYOUT ( combo_country ) , renderer , FALSE ) ;
gtk_cell_layout_set_attributes ( GTK_CELL_LAYOUT ( combo_country ) , renderer , " pixbuf " , 0 , NULL ) ;
renderer = treeview_helper_cell_renderer_text_new ( ) ;
gtk_cell_layout_pack_start ( GTK_CELL_LAYOUT ( combo_country ) , renderer , TRUE ) ;
gtk_cell_layout_set_attributes ( GTK_CELL_LAYOUT ( combo_country ) , renderer , " text " , 1 , NULL ) ;
2005-11-01 22:20:24 +01:00
language_pick_country ( country_files ) ;
2005-08-26 14:41:37 +02:00
model = treeview_create_country_list ( country_files ) ;
gtk_combo_box_set_model ( GTK_COMBO_BOX ( combo_country ) , model ) ;
2008-12-08 14:46:11 +01:00
gtk_cell_layout_set_cell_data_func ( GTK_CELL_LAYOUT ( combo_country ) ,
renderer ,
is_capital_sensitive ,
NULL , NULL ) ;
2005-08-26 14:41:37 +02:00
g_object_unref ( model ) ;
2008-12-17 16:31:07 +01:00
if ( country . sid ! = NULL )
misc_callback_show_team_list ( combo_country , country . sid ) ;
else if ( last_country ! = NULL )
2008-12-17 15:39:10 +01:00
misc_callback_show_team_list ( combo_country , last_country ) ;
else
misc_callback_show_team_list ( combo_country , ( const gchar * ) g_ptr_array_index ( country_files , country_files - > len - 1 ) ) ;
2008-12-17 16:31:07 +01:00
if ( last_country ! = NULL )
g_free ( last_country ) ;
2008-12-17 15:39:10 +01:00
//gtk_combo_box_set_active(GTK_COMBO_BOX(combo_country), country_index);
2004-12-23 13:58:39 +01:00
2005-10-05 21:59:37 +02:00
free_gchar_array ( & country_files ) ;
2004-12-23 13:58:39 +01:00
}
2005-04-04 12:36:04 +02:00
/** Show the file selection window. */
void
window_show_file_sel ( void )
{
2008-11-25 14:50:07 +01:00
# ifdef DEBUG
printf ( " window_show_file_sel \n " ) ;
# endif
2005-04-04 12:36:04 +02:00
gchar buf [ SMALL ] ;
const gchar * home = g_get_home_dir ( ) ;
2005-06-14 22:04:37 +02:00
gchar * filename = NULL ;
2005-06-20 14:46:57 +02:00
GtkFileFilter * filter ;
2005-08-20 21:39:36 +02:00
gboolean mm_file_exists = FALSE ;
2005-04-04 12:36:04 +02:00
2005-06-14 22:04:37 +02:00
window_create ( WINDOW_FILE_CHOOSER ) ;
2005-08-26 14:41:37 +02:00
if ( stat5 ! = STATUS_LOAD_GAME & &
2006-02-15 13:03:48 +01:00
stat5 ! = STATUS_LOAD_GAME_SPLASH )
2005-06-14 22:04:37 +02:00
gtk_file_chooser_set_action ( GTK_FILE_CHOOSER ( window . file_chooser ) ,
GTK_FILE_CHOOSER_ACTION_SAVE ) ;
else
gtk_file_chooser_set_action ( GTK_FILE_CHOOSER ( window . file_chooser ) ,
GTK_FILE_CHOOSER_ACTION_OPEN ) ;
2005-04-04 12:36:04 +02:00
2005-06-20 14:46:57 +02:00
filter = gtk_file_filter_new ( ) ;
2005-08-26 14:41:37 +02:00
if ( stat5 = = STATUS_SAVE_GAME | |
stat5 = = STATUS_LOAD_GAME | |
2006-02-15 13:03:48 +01:00
stat5 = = STATUS_LOAD_GAME_SPLASH )
2005-08-20 21:39:36 +02:00
{
gtk_file_filter_set_name ( filter , _ ( " Bygfoot Save Files " ) ) ;
gtk_file_filter_add_pattern ( filter , " *.zip " ) ;
gtk_file_filter_add_pattern ( filter , " last_save " ) ;
}
else
{
gtk_file_filter_set_name ( filter , _ ( " Bygfoot Memorable Matches " ) ) ;
gtk_file_filter_add_pattern ( filter , " *.bmm.zip " ) ;
}
2005-06-20 14:46:57 +02:00
gtk_file_chooser_add_filter ( GTK_FILE_CHOOSER ( window . file_chooser ) , filter ) ;
filter = gtk_file_filter_new ( ) ;
gtk_file_filter_set_name ( filter , _ ( " All Files " ) ) ;
gtk_file_filter_add_pattern ( filter , " * " ) ;
gtk_file_chooser_add_filter ( GTK_FILE_CHOOSER ( window . file_chooser ) , filter ) ;
2005-08-26 14:41:37 +02:00
if ( ( stat5 = = STATUS_SAVE_GAME | |
stat5 = = STATUS_LOAD_GAME | |
2006-02-15 13:03:48 +01:00
stat5 = = STATUS_LOAD_GAME_SPLASH ) & &
2005-10-09 11:35:44 +02:00
save_file ! = NULL )
2005-08-26 14:41:37 +02:00
gtk_file_chooser_set_filename ( GTK_FILE_CHOOSER ( window . file_chooser ) ,
2005-10-09 11:35:44 +02:00
save_file ) ;
else if ( users - > len > 0 & & current_user . mmatches_file ! = NULL )
2005-06-14 22:04:37 +02:00
gtk_file_chooser_set_filename ( GTK_FILE_CHOOSER ( window . file_chooser ) ,
2005-10-09 11:35:44 +02:00
current_user . mmatches_file ) ;
2005-04-04 12:36:04 +02:00
else
{
2005-07-25 06:35:53 +02:00
if ( os_is_unix )
2005-09-18 12:02:10 +02:00
sprintf ( buf , " %s%s%s%ssaves " , home , G_DIR_SEPARATOR_S ,
HOMEDIRNAME , G_DIR_SEPARATOR_S ) ;
2005-07-25 06:35:53 +02:00
else
{
gchar * pwd = g_get_current_dir ( ) ;
2005-09-18 12:02:10 +02:00
sprintf ( buf , " %s%ssaves " , pwd , G_DIR_SEPARATOR_S ) ;
2005-07-25 06:35:53 +02:00
g_free ( pwd ) ;
2005-08-04 14:37:50 +02:00
}
2005-09-18 12:02:10 +02:00
gtk_file_chooser_set_current_folder (
GTK_FILE_CHOOSER ( window . file_chooser ) , buf ) ;
2005-06-14 22:04:37 +02:00
}
if ( gtk_dialog_run ( GTK_DIALOG ( window . file_chooser ) ) = = GTK_RESPONSE_OK )
{
filename = gtk_file_chooser_get_filename ( GTK_FILE_CHOOSER ( window . file_chooser ) ) ;
2005-08-20 21:39:36 +02:00
if ( stat5 = = STATUS_LOAD_GAME )
2005-09-29 15:41:16 +02:00
load_save_load_game ( filename , FALSE ) ;
2006-02-15 13:03:48 +01:00
else if ( stat5 = = STATUS_LOAD_GAME_SPLASH )
2005-06-14 22:04:37 +02:00
misc_callback_startup_load ( filename ) ;
2005-08-20 21:39:36 +02:00
else if ( stat5 = = STATUS_SAVE_GAME )
2005-06-14 22:04:37 +02:00
load_save_save_game ( filename ) ;
2005-08-20 21:39:36 +02:00
else if ( stat5 = = STATUS_SELECT_MM_FILE_LOAD )
{
mm_file_exists = g_file_test ( filename , G_FILE_TEST_EXISTS ) ;
if ( ( mm_file_exists & & g_str_has_suffix ( filename , " .bmm.zip " ) ) | |
! mm_file_exists )
{
if ( mm_file_exists )
2005-08-21 21:58:51 +02:00
user_mm_load_file ( filename , NULL ) ;
2005-08-20 21:39:36 +02:00
else
2005-08-21 21:58:51 +02:00
user_mm_set_filename ( filename , NULL ) ;
2005-08-20 21:39:36 +02:00
window_show_mmatches ( ) ;
}
else
2005-08-28 10:56:36 +02:00
game_gui_show_warning ( _ ( " Not a valid Bygfoot Memorable Matches filename. " ) ) ;
2005-08-20 21:39:36 +02:00
}
else if ( stat5 = = STATUS_SELECT_MM_FILE_ADD )
{
2005-08-21 21:58:51 +02:00
user_mm_set_filename ( filename , NULL ) ;
2005-10-09 11:35:44 +02:00
mm_file_exists = g_file_test ( current_user . mmatches_file ,
2005-08-20 21:39:36 +02:00
G_FILE_TEST_EXISTS ) ;
user_mm_add_last_match ( mm_file_exists , TRUE ) ;
}
2005-08-21 21:58:51 +02:00
else if ( stat5 = = STATUS_SELECT_MM_FILE_IMPORT )
{
user_mm_import_file ( filename ) ;
window_show_mmatches ( ) ;
}
else if ( stat5 = = STATUS_SELECT_MM_FILE_EXPORT )
user_mm_export_file ( filename ) ;
2005-06-14 22:04:37 +02:00
2005-08-20 21:39:36 +02:00
if ( stat5 = = STATUS_LOAD_GAME | |
2006-02-15 13:03:48 +01:00
stat5 = = STATUS_LOAD_GAME_SPLASH )
2005-06-15 21:13:35 +02:00
{
cur_user = 0 ;
on_button_back_to_main_clicked ( NULL , NULL ) ;
setsav1 ;
}
2005-06-14 22:04:37 +02:00
g_free ( filename ) ;
2005-04-04 12:36:04 +02:00
}
2005-06-14 22:04:37 +02:00
2006-03-26 16:14:45 +02:00
window_destroy ( & window . file_chooser ) ;
2005-04-04 12:36:04 +02:00
}
2005-08-20 21:39:36 +02:00
/** Show window with memorable matches list. */
void
window_show_mmatches ( void )
{
2008-11-25 14:50:07 +01:00
# ifdef DEBUG
printf ( " window_show_mmatches \n " ) ;
# endif
2005-08-20 21:39:36 +02:00
if ( window . mmatches = = NULL )
window_create ( WINDOW_MMATCHES ) ;
treeview2_show_mmatches ( ) ;
gtk_entry_set_text ( GTK_ENTRY ( lookup_widget ( window . mmatches , " entry_mm_file " ) ) ,
2005-10-09 11:35:44 +02:00
current_user . mmatches_file ) ;
2005-08-20 21:39:36 +02:00
}
2005-03-23 20:03:26 +01:00
/** Show the options window. */
void
window_show_options ( void )
{
2008-11-25 14:50:07 +01:00
# ifdef DEBUG
printf ( " window_show_options \n " ) ;
# endif
2005-03-23 20:03:26 +01:00
window_create ( WINDOW_OPTIONS ) ;
option_gui_set_up_window ( ) ;
}
2005-03-27 19:59:57 +02:00
/** Show the player list context menu, triggered by 'event'. */
void
window_show_menu_player ( GdkEvent * event )
{
2008-11-25 14:50:07 +01:00
# ifdef DEBUG
printf ( " window_show_menu_player \n " ) ;
# endif
2005-03-27 19:59:57 +02:00
if ( window . menu_player ! = NULL )
2006-03-26 16:14:45 +02:00
window_destroy ( & window . menu_player ) ;
2005-03-27 19:59:57 +02:00
window . menu_player = create_menu_player ( ) ;
gtk_menu_popup ( GTK_MENU ( window . menu_player ) , NULL , NULL , NULL , NULL ,
( ( GdkEventButton * ) event ) - > button , gdk_event_get_time ( event ) ) ;
}
2005-07-08 11:26:00 +02:00
/** Show the youth academy context menu, triggered by 'event'. */
void
window_show_menu_youth ( GdkEvent * event )
{
2008-11-25 14:50:07 +01:00
# ifdef DEBUG
printf ( " window_show_menu_youth \n " ) ;
# endif
2005-07-08 11:26:00 +02:00
if ( window . menu_youth ! = NULL )
2006-03-26 16:14:45 +02:00
window_destroy ( & window . menu_youth ) ;
2005-07-08 11:26:00 +02:00
window . menu_youth = create_menu_youth ( ) ;
gtk_menu_popup ( GTK_MENU ( window . menu_youth ) , NULL , NULL , NULL , NULL ,
( ( GdkEventButton * ) event ) - > button , gdk_event_get_time ( event ) ) ;
}
2005-03-17 21:26:01 +01:00
/** Show the digits window with the labels and values set
according to the arguments . */
void
2005-05-30 17:54:20 +02:00
window_show_digits ( const gchar * text_main , const gchar * text1 , gint value1 ,
2008-11-08 13:46:12 +01:00
const gchar * text2 , gint value2 , gboolean show_alr )
2005-03-17 21:26:01 +01:00
{
2008-11-25 14:50:07 +01:00
# ifdef DEBUG
printf ( " window_show_digits \n " ) ;
# endif
2005-03-17 21:26:01 +01:00
GtkLabel * label_main , * label_1 , * label_2 ;
GtkSpinButton * spinbutton1 , * spinbutton2 ;
window_create ( WINDOW_DIGITS ) ;
label_main = GTK_LABEL ( lookup_widget ( window . digits , " label_main " ) ) ;
label_1 = GTK_LABEL ( lookup_widget ( window . digits , " label_1 " ) ) ;
label_2 = GTK_LABEL ( lookup_widget ( window . digits , " label_2 " ) ) ;
spinbutton1 = GTK_SPIN_BUTTON ( lookup_widget ( window . digits , " spinbutton1 " ) ) ;
spinbutton2 = GTK_SPIN_BUTTON ( lookup_widget ( window . digits , " spinbutton2 " ) ) ;
2005-07-08 11:26:00 +02:00
if ( stat1 = = STATUS_GET_LOAN | |
stat1 = = STATUS_PAY_LOAN )
2005-03-17 21:26:01 +01:00
gtk_spin_button_set_range ( spinbutton1 , ( gdouble ) 1 , ( gdouble ) value1 ) ;
2005-07-08 11:26:00 +02:00
else if ( stat1 = = STATUS_SET_YA_PERCENTAGE )
gtk_spin_button_set_range ( spinbutton2 , ( gdouble ) 0 ,
( gdouble ) const_int ( " int_youth_academy_max_percentage " ) ) ;
2005-03-17 21:26:01 +01:00
gtk_spin_button_set_value ( spinbutton1 , ( gdouble ) value1 ) ;
gtk_spin_button_set_value ( spinbutton2 , ( gdouble ) value2 ) ;
gtk_label_set_text ( label_main , text_main ) ;
if ( text1 ! = NULL )
gtk_label_set_text ( label_1 , text1 ) ;
else
gtk_widget_hide ( GTK_WIDGET ( label_1 ) - > parent ) ;
if ( text2 ! = NULL )
gtk_label_set_text ( label_2 , text2 ) ;
else
gtk_widget_hide ( GTK_WIDGET ( label_2 ) - > parent ) ;
2008-11-08 13:46:12 +01:00
if ( show_alr )
gtk_widget_show ( lookup_widget ( window . digits , " button_digits_alr " ) ) ;
2005-03-17 21:26:01 +01:00
}
/** Show the stadium window for the current user. */
void
window_show_stadium ( void )
{
2008-11-25 14:50:07 +01:00
# ifdef DEBUG
printf ( " window_show_stadium \n " ) ;
# endif
2005-03-17 21:26:01 +01:00
gchar buf [ SMALL ] ;
2005-03-18 23:03:23 +01:00
const Team * tm = current_user . tm ;
2005-03-17 21:26:01 +01:00
GtkLabel * label_capacity ,
2005-06-21 15:33:16 +02:00
* label_stadium_status , * label_average_attendance ,
* label_name ;
2005-04-07 18:44:33 +02:00
GtkProgressBar * progressbar_safety ,
* progressbar_average_attendance ;
gfloat average_attendance_perc = 0 ;
2008-10-28 16:27:28 +01:00
GtkSpinButton * spin_ticket_price ;
2005-03-17 21:26:01 +01:00
window_create ( WINDOW_STADIUM ) ;
label_capacity = GTK_LABEL ( lookup_widget ( window . stadium , " label_capacity " ) ) ;
label_stadium_status = GTK_LABEL ( lookup_widget ( window . stadium , " label_stadium_status " ) ) ;
2005-04-07 18:44:33 +02:00
label_average_attendance = GTK_LABEL ( lookup_widget ( window . stadium , " label_average_attendance " ) ) ;
2005-06-21 15:33:16 +02:00
label_name = GTK_LABEL ( lookup_widget ( window . stadium , " label_stadium_name " ) ) ;
2005-03-17 21:26:01 +01:00
2008-10-28 16:27:28 +01:00
spin_ticket_price = GTK_SPIN_BUTTON ( lookup_widget ( window . stadium , " spin_ticket_price " ) ) ;
gtk_spin_button_set_value ( spin_ticket_price , tm - > stadium . ticket_price ) ;
2008-10-30 23:05:20 +01:00
/* Set the lower bound to constant_ticket_price-(1/constant_ticket_attendance)
+ 1 So that we can ' t divide by 0 or negative numbers */
gfloat lower_bound = const_int ( " int_team_stadium_ticket_price " ) - ( 1 / const_float ( " float_team_stadium_price_attendance_factor " ) ) + 1 ;
gtk_spin_button_set_range ( spin_ticket_price , lower_bound , 100 ) ;
2008-10-28 14:13:45 +01:00
2005-03-17 21:26:01 +01:00
progressbar_safety = GTK_PROGRESS_BAR ( lookup_widget ( window . stadium , " progressbar_safety " ) ) ;
2005-04-07 18:44:33 +02:00
progressbar_average_attendance = GTK_PROGRESS_BAR ( lookup_widget ( window . stadium , " progressbar_average_attendance " ) ) ;
2005-03-17 21:26:01 +01:00
gui_label_set_text_from_int ( label_capacity , tm - > stadium . capacity , FALSE ) ;
2005-04-07 18:44:33 +02:00
gui_label_set_text_from_int ( label_average_attendance , tm - > stadium . average_attendance , FALSE ) ;
2005-06-21 15:33:16 +02:00
if ( tm - > stadium . name ! = NULL )
2005-10-09 11:35:44 +02:00
gtk_label_set_text ( label_name , tm - > stadium . name ) ;
2005-06-22 17:07:34 +02:00
else
gtk_widget_hide ( GTK_WIDGET ( label_name ) ) ;
2005-03-17 21:26:01 +01:00
2005-04-07 18:44:33 +02:00
if ( tm - > stadium . games > 0 )
average_attendance_perc =
( gfloat ) ( tm - > stadium . average_attendance * tm - > stadium . games ) /
( gfloat ) tm - > stadium . possible_attendance ;
2005-03-17 21:26:01 +01:00
gtk_progress_bar_set_fraction ( progressbar_safety , tm - > stadium . safety ) ;
2005-04-07 18:44:33 +02:00
gtk_progress_bar_set_fraction ( progressbar_average_attendance , average_attendance_perc ) ;
2005-03-17 21:26:01 +01:00
sprintf ( buf , " %d%% " , ( gint ) rint ( tm - > stadium . safety * 100 ) ) ;
gtk_progress_bar_set_text ( progressbar_safety , buf ) ;
2005-04-07 18:44:33 +02:00
sprintf ( buf , " %d%% " , ( gint ) rint ( average_attendance_perc * 100 ) ) ;
gtk_progress_bar_set_text ( progressbar_average_attendance , buf ) ;
2005-03-18 23:03:23 +01:00
if ( current_user . counters [ COUNT_USER_STADIUM_CAPACITY ] +
current_user . counters [ COUNT_USER_STADIUM_SAFETY ] ! = 0 )
2005-03-17 21:26:01 +01:00
{
sprintf ( buf , _ ( " Improvement in progress. \n %d seats and %d%% safety still to be done. \n Expected finish: %d weeks. " ) ,
2005-03-18 23:03:23 +01:00
current_user . counters [ COUNT_USER_STADIUM_CAPACITY ] ,
current_user . counters [ COUNT_USER_STADIUM_SAFETY ] ,
2005-03-17 21:26:01 +01:00
MAX ( finance_get_stadium_improvement_duration (
2005-03-18 23:03:23 +01:00
( gfloat ) current_user . counters [ COUNT_USER_STADIUM_CAPACITY ] , TRUE ) ,
2005-03-17 21:26:01 +01:00
finance_get_stadium_improvement_duration (
2005-03-18 23:03:23 +01:00
( gfloat ) current_user . counters [ COUNT_USER_STADIUM_SAFETY ] / 100 , FALSE ) ) ) ;
2005-03-17 21:26:01 +01:00
gtk_label_set_text ( label_stadium_status , buf ) ;
}
else
gtk_label_set_text ( label_stadium_status , _ ( " No improvements currently in progress. " ) ) ;
}
2005-03-27 19:59:57 +02:00
gboolean
window_show ( gpointer window )
{
2008-11-25 14:50:07 +01:00
# ifdef DEBUG
printf ( " window_show \n " ) ;
# endif
2005-03-27 19:59:57 +02:00
gtk_widget_show ( ( GtkWidget * ) window ) ;
return FALSE ;
}
2005-03-20 21:49:55 +01:00
/** Show the window where the user can select between yes and no.
2005-05-30 17:54:20 +02:00
@ param text The text shown in the window . */
2005-03-20 21:49:55 +01:00
void
2005-05-30 17:54:20 +02:00
window_show_yesno ( const gchar * text )
2005-03-20 21:49:55 +01:00
{
2008-11-25 14:50:07 +01:00
# ifdef DEBUG
printf ( " window_show_yesno \n " ) ;
# endif
2005-03-20 21:49:55 +01:00
window_create ( WINDOW_YESNO ) ;
gtk_label_set_text ( GTK_LABEL ( lookup_widget ( window . yesno , " label_yesno " ) ) , text ) ;
}
2005-05-30 17:54:20 +02:00
/** Show the transfer dialog (yes/no/later).
@ param text The text to put into the label . */
void
window_show_transfer_dialog ( const gchar * text )
{
2008-11-25 14:50:07 +01:00
# ifdef DEBUG
printf ( " window_show_transfer_dialog \n " ) ;
# endif
2005-05-30 17:54:20 +02:00
window_create ( WINDOW_TRANSFER_DIALOG ) ;
gtk_label_set_text ( GTK_LABEL ( lookup_widget ( window . transfer_dialog , " label_transfer_dialog " ) ) , text ) ;
}
2005-09-28 18:41:32 +02:00
/** Set up the spinbuttons and boost/style images in the
live window . */
2005-05-28 16:34:14 +02:00
void
2005-09-28 18:41:32 +02:00
window_live_set_up ( void )
2005-05-28 16:34:14 +02:00
{
2008-11-25 14:50:07 +01:00
# ifdef DEBUG
printf ( " window_live_set_up \n " ) ;
# endif
2005-08-29 10:31:00 +02:00
GtkSpinButton * sb_speed =
GTK_SPIN_BUTTON ( lookup_widget ( window . live , " spinbutton_speed " ) ) ;
2005-09-18 12:02:10 +02:00
gfloat user_option = ( gfloat ) option_int ( " int_opt_user_live_game_speed " ,
& usr ( stat2 ) . options ) ;
gtk_spin_button_set_range (
sb_speed , 0 , - rint ( ( gfloat ) ( const_int ( " int_game_gui_live_game_speed_max " ) - 10 ) /
( gfloat ) ( const_int ( " int_game_gui_live_game_speed_grad " ) ) ) ) ;
gtk_spin_button_set_value ( sb_speed , user_option ) ;
2005-08-29 10:31:00 +02:00
2005-05-28 16:34:14 +02:00
gtk_spin_button_set_value (
GTK_SPIN_BUTTON ( lookup_widget ( window . live , " spinbutton_verbosity " ) ) ,
( gfloat ) option_int ( " int_opt_user_live_game_verbosity " , & usr ( stat2 ) . options ) ) ;
2005-09-28 18:41:32 +02:00
2005-10-09 12:07:06 +02:00
game_gui_write_meters ( usr ( stat2 ) . tm ) ;
2005-05-28 16:34:14 +02:00
}
2005-09-18 12:02:10 +02:00
/** Save main window size and position into a file.*/
void
window_main_save_geometry ( void )
{
2008-11-25 14:50:07 +01:00
# ifdef DEBUG
printf ( " window_main_save_geometry \n " ) ;
# endif
2005-09-18 12:02:10 +02:00
gchar filename [ SMALL ] ;
2006-02-15 13:03:48 +01:00
gchar dir [ SMALL ] ;
2005-09-18 12:02:10 +02:00
FILE * fil = NULL ;
gint width , height , pos_x , pos_y , paned_pos ;
2006-02-15 13:03:48 +01:00
file_get_bygfoot_dir ( dir ) ;
2005-09-18 12:02:10 +02:00
2006-02-15 13:03:48 +01:00
sprintf ( filename , " %s%swindow_settings " ,
dir , G_DIR_SEPARATOR_S ) ;
2005-09-18 12:02:10 +02:00
if ( window . main ! = NULL & & file_my_fopen ( filename , " w " , & fil , FALSE ) )
{
gtk_window_get_size ( GTK_WINDOW ( window . main ) , & width , & height ) ;
gtk_window_get_position ( GTK_WINDOW ( window . main ) , & pos_x , & pos_y ) ;
paned_pos = gtk_paned_get_position (
GTK_PANED ( lookup_widget ( window . main , " hpaned2 " ) ) ) ;
fprintf ( fil , " int_window_settings_width \t %d \n " , width ) ;
fprintf ( fil , " int_window_settings_height \t %d \n " , height ) ;
fprintf ( fil , " int_window_settings_pos_x \t %d \n " , pos_x ) ;
fprintf ( fil , " int_window_settings_pos_y \t %d \n " , pos_y ) ;
fprintf ( fil , " int_window_settings_paned_pos \t %d \n " , paned_pos ) ;
fclose ( fil ) ;
}
}
/** Set the main window geometry according to the file
settings . */
void
window_main_load_geometry ( void )
{
2008-11-25 14:50:07 +01:00
# ifdef DEBUG
printf ( " window_main_load_geometry \n " ) ;
# endif
2005-09-18 12:02:10 +02:00
gchar filename [ SMALL ] ;
2006-02-15 13:03:48 +01:00
gchar dir [ SMALL ] ;
2005-09-18 12:02:10 +02:00
OptionList optionlist ;
2006-02-15 13:03:48 +01:00
file_get_bygfoot_dir ( dir ) ;
2005-09-18 12:02:10 +02:00
2006-02-15 13:03:48 +01:00
sprintf ( filename , " %s%swindow_settings " ,
dir , G_DIR_SEPARATOR_S ) ;
2005-09-18 12:02:10 +02:00
if ( g_file_test ( filename , G_FILE_TEST_EXISTS ) )
{
optionlist . list = NULL ;
optionlist . datalist = NULL ;
2009-03-10 21:58:34 +01:00
file_load_opt_file ( filename , & optionlist , FALSE ) ;
2005-09-18 12:02:10 +02:00
gtk_window_resize ( GTK_WINDOW ( window . main ) ,
option_int ( " int_window_settings_width " , & optionlist ) ,
option_int ( " int_window_settings_height " , & optionlist ) ) ;
gtk_window_move ( GTK_WINDOW ( window . main ) ,
option_int ( " int_window_settings_pos_x " , & optionlist ) ,
option_int ( " int_window_settings_pos_y " , & optionlist ) ) ;
gtk_paned_set_position ( GTK_PANED ( lookup_widget ( window . main , " hpaned2 " ) ) ,
option_int ( " int_window_settings_paned_pos " , & optionlist ) ) ;
free_option_list ( & optionlist , FALSE ) ;
}
}
2004-12-30 17:48:19 +01:00
/** Create and show a window. Which one depends on the argument.
@ param window_type An integer telling us which window to
create .
2005-03-08 09:25:46 +01:00
@ param count_popups Whether this window adds to the popup
counter that determines when the main window gets ( in ) sensitive .
2004-12-30 17:48:19 +01:00
@ return The pointer to the new window .
@ see # Windows */
GtkWidget *
window_create ( gint window_type )
{
2005-03-10 21:59:39 +01:00
gchar buf [ SMALL ] ;
2005-03-03 13:46:48 +01:00
GtkWidget * wind = NULL ;
2005-01-09 21:21:22 +01:00
2005-03-10 21:59:39 +01:00
sprintf ( buf , " Bygfoot Football Manager %s " , VERS ) ;
2004-12-30 17:48:19 +01:00
switch ( window_type )
{
default :
2005-10-24 22:50:48 +02:00
main_exit_program ( EXIT_INT_NOT_FOUND ,
" window_create: unknown window type %d \n " , window_type ) ;
2005-03-08 09:25:46 +01:00
break ;
case WINDOW_MAIN :
2005-03-03 13:46:48 +01:00
if ( window . main = = NULL )
2005-01-09 21:21:22 +01:00
{
2005-03-03 13:46:48 +01:00
window . main = create_main_window ( ) ;
wind = window . main ;
2005-09-18 12:02:10 +02:00
window_main_load_geometry ( ) ;
2005-12-01 12:50:54 +01:00
window . paned_pos =
gtk_paned_get_position (
GTK_PANED ( lookup_widget ( window . main , " hpaned2 " ) ) ) ;
2005-07-08 11:26:00 +02:00
game_gui_print_message ( _ ( " Welcome to Bygfoot %s " ) , VERS ) ;
2005-06-15 10:58:26 +02:00
sprintf ( buf , " Bygfoot Football Manager %s " , VERS ) ;
2005-01-09 21:21:22 +01:00
}
else
2005-03-03 13:46:48 +01:00
wind = window . main ;
2005-03-24 19:04:31 +01:00
if ( opt_int ( " int_opt_maximize_main_window " ) )
gtk_window_maximize ( GTK_WINDOW ( wind ) ) ;
2004-12-30 17:48:19 +01:00
break ;
case WINDOW_STARTUP :
2005-03-03 13:46:48 +01:00
if ( window . startup ! = NULL )
g_warning ( " window_create: called on already existing window \n " ) ;
else
window . startup = create_window_startup ( ) ;
wind = window . startup ;
2004-12-30 17:48:19 +01:00
break ;
2005-01-09 21:21:22 +01:00
case WINDOW_LIVE :
2005-03-03 13:46:48 +01:00
if ( window . live ! = NULL )
g_warning ( " window_create: called on already existing window \n " ) ;
else
window . live = create_window_live ( ) ;
2006-03-26 16:14:45 +02:00
if ( ( ( LiveGame * ) statp ) - > fix ! = NULL )
strcpy ( buf , league_cup_get_name_string ( ( ( LiveGame * ) statp ) - > fix - > clid ) ) ;
2005-03-03 13:46:48 +01:00
wind = window . live ;
2005-09-28 18:41:32 +02:00
window_live_set_up ( ) ;
2005-03-03 13:46:48 +01:00
break ;
2005-03-08 09:25:46 +01:00
case WINDOW_WARNING :
if ( window . warning ! = NULL )
g_warning ( " window_create: called on already existing window \n " ) ;
else
window . warning = create_window_warning ( ) ;
wind = window . warning ;
2005-06-18 16:45:29 +02:00
strcpy ( buf , _ ( " Erm... " ) ) ;
2005-03-10 21:59:39 +01:00
break ;
case WINDOW_PROGRESS :
if ( window . progress ! = NULL )
g_warning ( " window_create: called on already existing window \n " ) ;
else
window . progress = create_window_progress ( ) ;
wind = window . progress ;
strcpy ( buf , " " ) ;
2005-03-08 09:25:46 +01:00
break ;
2005-03-17 21:26:01 +01:00
case WINDOW_DIGITS :
if ( window . digits ! = NULL )
g_warning ( " window_create: called on already existing window \n " ) ;
else
window . digits = create_window_digits ( ) ;
2005-10-27 23:10:15 +02:00
2005-03-17 21:26:01 +01:00
wind = window . digits ;
strcpy ( buf , _ ( " Numbers... " ) ) ;
break ;
case WINDOW_STADIUM :
if ( window . stadium ! = NULL )
g_warning ( " window_create: called on already existing window \n " ) ;
else
window . stadium = create_window_stadium ( ) ;
wind = window . stadium ;
strcpy ( buf , _ ( " Your stadium " ) ) ;
break ;
2005-03-18 23:03:23 +01:00
case WINDOW_JOB_OFFER :
if ( window . job_offer ! = NULL )
g_warning ( " window_create: called on already existing window \n " ) ;
else
window . job_offer = create_window_job_offer ( ) ;
wind = window . job_offer ;
strcpy ( buf , _ ( " Job offer " ) ) ;
break ;
2005-03-20 21:49:55 +01:00
case WINDOW_YESNO :
if ( window . yesno ! = NULL )
g_warning ( " window_create: called on already existing window \n " ) ;
else
window . yesno = create_window_yesno ( ) ;
wind = window . yesno ;
strcpy ( buf , " ??? " ) ;
break ;
2005-03-23 20:03:26 +01:00
case WINDOW_OPTIONS :
if ( window . options ! = NULL )
g_warning ( " window_create: called on already existing window \n " ) ;
else
window . options = create_window_options ( ) ;
wind = window . options ;
2005-06-18 16:45:29 +02:00
strcpy ( buf , _ ( " Options " ) ) ;
2005-03-23 20:03:26 +01:00
break ;
2005-03-24 14:00:01 +01:00
case WINDOW_FONT_SEL :
if ( window . font_sel ! = NULL )
g_warning ( " window_create: called on already existing window \n " ) ;
else
window . font_sel = create_window_font_sel ( ) ;
wind = window . font_sel ;
2005-06-18 16:45:29 +02:00
strcpy ( buf , _ ( " Select font " ) ) ;
2005-03-24 14:00:01 +01:00
break ;
2005-06-14 22:04:37 +02:00
case WINDOW_FILE_CHOOSER :
if ( window . file_chooser ! = NULL )
2005-04-04 12:36:04 +02:00
g_warning ( " window_create: called on already existing window \n " ) ;
else
2005-06-14 22:04:37 +02:00
window . file_chooser = create_window_file_chooser ( ) ;
wind = window . file_chooser ;
2005-04-04 12:36:04 +02:00
break ;
2005-03-25 11:54:54 +01:00
case WINDOW_CONTRACT :
if ( window . contract ! = NULL )
g_warning ( " window_create: called on already existing window \n " ) ;
else
window . contract = create_window_contract ( ) ;
wind = window . contract ;
2005-06-18 16:45:29 +02:00
strcpy ( buf , _ ( " Contract offer " ) ) ;
2005-03-25 11:54:54 +01:00
break ;
2005-03-27 19:59:57 +02:00
case WINDOW_USER_MANAGEMENT :
if ( window . user_management ! = NULL )
g_warning ( " window_create: called on already existing window \n " ) ;
else
window . user_management = create_window_user_management ( ) ;
wind = window . user_management ;
2005-06-18 16:45:29 +02:00
strcpy ( buf , _ ( " User management " ) ) ;
2005-03-27 19:59:57 +02:00
break ;
2005-05-13 20:20:47 +02:00
case WINDOW_DEBUG :
if ( window . wdebug ! = NULL )
g_warning ( " window_create: called on already existing window \n " ) ;
else
window . wdebug = create_window_debug ( ) ;
wind = window . wdebug ;
strcpy ( buf , " Bygfoot debug window " ) ;
break ;
2005-05-22 15:33:24 +02:00
case WINDOW_HELP :
if ( window . help ! = NULL )
g_warning ( " window_create: called on already existing window \n " ) ;
else
window . help = create_window_help ( ) ;
wind = window . help ;
break ;
2005-05-30 17:54:20 +02:00
case WINDOW_TRANSFER_DIALOG :
if ( window . transfer_dialog ! = NULL )
g_warning ( " window_create: called on already existing window \n " ) ;
else
window . transfer_dialog = create_window_transfer_dialog ( ) ;
wind = window . transfer_dialog ;
2005-06-18 16:45:29 +02:00
strcpy ( buf , _ ( " Transfer offer " ) ) ;
2005-05-30 17:54:20 +02:00
break ;
2005-06-20 14:46:57 +02:00
case WINDOW_SPONSORS :
if ( window . sponsors ! = NULL )
g_warning ( " window_create: called on already existing window \n " ) ;
else
window . sponsors = create_window_sponsors ( ) ;
wind = window . sponsors ;
strcpy ( buf , _ ( " Sponsorship offers " ) ) ;
break ;
2005-08-20 21:39:36 +02:00
case WINDOW_MMATCHES :
if ( window . mmatches ! = NULL )
g_warning ( " window_create: called on already existing window \n " ) ;
else
window . mmatches = create_window_mmatches ( ) ;
wind = window . mmatches ;
strcpy ( buf , _ ( " Memorable matches " ) ) ;
break ;
2005-10-27 23:10:15 +02:00
case WINDOW_BETS :
if ( window . bets ! = NULL )
g_warning ( " window_create: called on already existing window \n " ) ;
else
window . bets = create_window_bets ( ) ;
wind = window . bets ;
strcpy ( buf , _ ( " Betting " ) ) ;
break ;
2006-02-15 13:03:48 +01:00
case WINDOW_SPLASH :
if ( window . splash ! = NULL )
g_warning ( " window_create: called on already existing window \n " ) ;
else
window . splash = create_window_splash ( ) ;
wind = window . splash ;
break ;
2008-11-07 09:38:55 +01:00
case WINDOW_TRAINING_CAMP :
if ( window . training_camp ! = NULL )
g_warning ( " window_create: called on already existing window \n " ) ;
else
window . training_camp = create_window_training_camp ( ) ;
wind = window . training_camp ;
strcpy ( buf , _ ( " Training camp " ) ) ;
break ;
case WINDOW_ALR :
if ( window . alr ! = NULL )
g_warning ( " window_create: called on already existing window \n " ) ;
else
window . alr = create_window_alr ( ) ;
wind = window . alr ;
strcpy ( buf , _ ( " Automatic loan repayment " ) ) ;
break ;
2008-12-06 18:07:03 +01:00
case WINDOW_NEWS :
if ( window . news ! = NULL )
g_warning ( " window_create: called on already existing window \n " ) ;
else
window . news = create_window_news ( ) ;
wind = window . news ;
2008-12-17 18:36:18 +01:00
strcpy ( buf , _ ( " Bygfoot News " ) ) ;
2008-12-06 18:07:03 +01:00
break ;
2009-03-09 21:20:26 +01:00
case WINDOW_CONSTANTS :
if ( window . constants ! = NULL )
g_warning ( " window_create: called on already existing window \n " ) ;
else
window . constants = create_window_constants ( ) ;
wind = window . constants ;
strcpy ( buf , _ ( " Bygfoot constants " ) ) ;
break ;
2005-03-03 13:46:48 +01:00
}
2004-12-30 17:48:19 +01:00
2005-06-14 22:04:37 +02:00
if ( window_type ! = WINDOW_FILE_CHOOSER )
gtk_window_set_title ( GTK_WINDOW ( wind ) , buf ) ;
2005-04-13 15:01:59 +02:00
2006-02-15 13:03:48 +01:00
if ( window_type ! = WINDOW_PROGRESS & & window_type ! = WINDOW_SPLASH )
2005-04-13 15:01:59 +02:00
g_timeout_add ( 20 , ( GSourceFunc ) window_show , ( gpointer ) wind ) ;
else
gtk_widget_show ( wind ) ;
2004-12-30 17:48:19 +01:00
2005-03-03 13:46:48 +01:00
return wind ;
2004-12-30 17:48:19 +01:00
}
2005-01-09 21:21:22 +01:00
/** Destroy a window widget and set the popups and
main window sensitivity correctly .
2005-03-08 09:25:46 +01:00
@ param window The window we destroy .
@ param count_popups Whether this window adds to the popup
counter that determines when the main window gets ( in ) sensitive . */
2005-01-09 21:21:22 +01:00
void
2006-03-26 16:14:45 +02:00
window_destroy ( GtkWidget * * wind )
2005-01-09 21:21:22 +01:00
{
2008-11-25 14:50:07 +01:00
# ifdef DEBUG
printf ( " window_destroy \n " ) ;
# endif
2005-03-03 13:46:48 +01:00
if ( * wind = = NULL )
2005-01-09 21:21:22 +01:00
return ;
2006-02-15 13:03:48 +01:00
if ( * wind = = window . splash )
{
counters [ COUNT_HINT_NUMBER ] =
( counters [ COUNT_HINT_NUMBER ] + 1 ) % hints . list - > len ;
window_save_hint_number ( ) ;
}
2005-03-03 13:46:48 +01:00
gtk_widget_destroy ( * wind ) ;
2005-01-09 21:21:22 +01:00
2005-03-03 13:46:48 +01:00
* wind = NULL ;
2005-01-09 21:21:22 +01:00
}
2007-01-18 18:40:28 +01:00
/* Show the training camp window for the current user. */
void
window_show_training_camp ( void )
{
2008-11-25 14:50:07 +01:00
# ifdef DEBUG
printf ( " window_show_training_camp \n " ) ;
# endif
2007-01-18 18:40:28 +01:00
GtkEntry * tfCosts ;
GtkWidget * rb_camp1 ;
GtkWidget * rb_camp2 ;
GtkWidget * rb_camp3 ;
GtkLabel * l_costs ;
GtkLabel * l_recreation ;
GtkLabel * l_training ;
GtkLabel * l_camp_points ;
GtkHScale * hs_recreation ;
GtkHScale * hs_training ;
GtkHScale * hs_camp_points ;
gchar buf [ SMALL ] ;
window_create ( WINDOW_TRAINING_CAMP ) ;
// Initialize entry costs
2008-05-02 15:00:05 +02:00
misc_print_grouped_int (
math_round_integer ( finance_wage_unit ( current_user . tm ) * const_float ( " float_training_camp_factor1 " ) , - 2 ) ,
buf ) ;
2007-01-18 18:40:28 +01:00
tfCosts = GTK_ENTRY ( lookup_widget ( window . training_camp , " tf_costs " ) ) ;
gtk_entry_set_text ( tfCosts , buf ) ;
// Initialize radio group camp
rb_camp1 = GTK_WIDGET ( lookup_widget ( window . training_camp , " rb_camp1 " ) ) ;
rb_camp2 = GTK_WIDGET ( lookup_widget ( window . training_camp , " rb_camp2 " ) ) ;
rb_camp3 = GTK_WIDGET ( lookup_widget ( window . training_camp , " rb_camp3 " ) ) ;
2008-05-03 17:03:30 +02:00
if ( opt_user_int ( " int_opt_user_training_camp_hotel " ) = = TRAINING_CAMP_HOTEL_GOOD )
gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( rb_camp1 ) , TRUE ) ;
else if ( opt_user_int ( " int_opt_user_training_camp_hotel " ) = = TRAINING_CAMP_HOTEL_FIRST )
gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( rb_camp2 ) , TRUE ) ;
else
gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( rb_camp3 ) , TRUE ) ;
2007-01-18 18:40:28 +01:00
//Initialize labels
l_costs = GTK_LABEL ( lookup_widget ( window . training_camp , " l_costs " ) ) ;
l_recreation = GTK_LABEL ( lookup_widget ( window . training_camp , " l_recreation " ) ) ;
l_training = GTK_LABEL ( lookup_widget ( window . training_camp , " l_training " ) ) ;
l_camp_points = GTK_LABEL ( lookup_widget ( window . training_camp , " l_camp_points " ) ) ;
gtk_misc_set_alignment ( GTK_MISC ( l_costs ) , 0.0 , 0.5 ) ;
gtk_misc_set_alignment ( GTK_MISC ( l_recreation ) , 0.0 , 0.5 ) ;
gtk_misc_set_alignment ( GTK_MISC ( l_training ) , 0.0 , 0.5 ) ;
gtk_misc_set_alignment ( GTK_MISC ( l_camp_points ) , 0.0 , 0.5 ) ;
//Initialize hScales
hs_recreation = GTK_HSCALE ( lookup_widget ( window . training_camp , " hs_recreation " ) ) ;
hs_training = GTK_HSCALE ( lookup_widget ( window . training_camp , " hs_training " ) ) ;
hs_camp_points = GTK_HSCALE ( lookup_widget ( window . training_camp , " hs_camp_points " ) ) ;
gtk_range_set_range ( GTK_RANGE ( hs_recreation ) , CAMP_SCALE_MIN , CAMP_SCALE_MAX ) ;
gtk_range_set_range ( GTK_RANGE ( hs_training ) , CAMP_SCALE_MIN , CAMP_SCALE_MAX ) ;
gtk_range_set_range ( GTK_RANGE ( hs_camp_points ) , CAMP_SCALE_MIN , CAMP_SCALE_MAX ) ;
2008-05-03 17:03:30 +02:00
gtk_range_set_value ( GTK_RANGE ( hs_recreation ) , opt_user_int ( " int_opt_user_training_camp_recreation " ) ) ;
gtk_range_set_value ( GTK_RANGE ( hs_training ) ,
CAMP_SCALE_MAX - opt_user_int ( " int_opt_user_training_camp_recreation " ) ) ;
gtk_range_set_value ( GTK_RANGE ( hs_camp_points ) , CAMP_SCALE_MIN ) ;
2007-01-18 18:40:28 +01:00
gtk_scale_set_digits ( GTK_SCALE ( hs_recreation ) , 0 ) ;
gtk_scale_set_digits ( GTK_SCALE ( hs_training ) , 0 ) ;
gtk_scale_set_digits ( GTK_SCALE ( hs_camp_points ) , 0 ) ;
2007-02-12 17:07:44 +01:00
gtk_widget_set_sensitive ( GTK_WIDGET ( hs_recreation ) , FALSE ) ;
gtk_widget_set_sensitive ( GTK_WIDGET ( hs_training ) , FALSE ) ;
2007-01-18 18:40:28 +01:00
gtk_widget_set_sensitive ( GTK_WIDGET ( hs_camp_points ) , FALSE ) ;
2007-02-12 17:07:44 +01:00
GdkColor color ;
2007-02-12 22:22:07 +01:00
//gtk_widget_modify_fg(GTK_WIDGET(hs_recreation), GTK_STATE_INSENSITIVE , NULL);
//gtk_widget_modify_fg(GTK_WIDGET(hs_training), GTK_STATE_INSENSITIVE , NULL);
//gtk_widget_modify_fg(GTK_WIDGET(hs_camp_points), GTK_STATE_INSENSITIVE , NULL);
//gtk_widget_modify_bg(GTK_WIDGET(hs_recreation), GTK_STATE_NORMAL, NULL);
2007-02-12 17:07:44 +01:00
gdk_color_parse ( " black " , & color ) ;
gtk_widget_modify_fg ( GTK_WIDGET ( hs_recreation ) , GTK_STATE_INSENSITIVE , & color ) ;
2007-02-12 22:22:07 +01:00
gtk_widget_modify_fg ( GTK_WIDGET ( hs_training ) , GTK_STATE_INSENSITIVE , & color ) ;
gtk_widget_modify_fg ( GTK_WIDGET ( hs_camp_points ) , GTK_STATE_INSENSITIVE , & color ) ;
2007-02-12 17:07:44 +01:00
gtk_widget_modify_bg ( GTK_WIDGET ( hs_recreation ) , GTK_STATE_NORMAL , & color ) ;
2007-02-12 22:22:07 +01:00
gtk_widget_modify_bg ( GTK_WIDGET ( hs_training ) , GTK_STATE_NORMAL , & color ) ;
gtk_widget_modify_bg ( GTK_WIDGET ( hs_camp_points ) , GTK_STATE_NORMAL , & color ) ;
2007-01-18 18:40:28 +01:00
}
2007-09-24 20:41:57 +02:00
2008-11-07 09:38:55 +01:00
/** Create and set up the debt repayment window. */
void
window_show_alr ( void )
{
2008-11-25 14:50:07 +01:00
# ifdef DEBUG
printf ( " window_show_alr \n " ) ;
# endif
2008-11-09 10:36:55 +01:00
gchar weekly_installment [ SMALL ] ,
debt [ SMALL ] ;
2008-11-07 09:38:55 +01:00
window_create ( WINDOW_ALR ) ;
2008-11-09 10:36:55 +01:00
misc_print_grouped_int ( current_user . alr_weekly_installment , weekly_installment ) ;
misc_print_grouped_int ( - current_user . debt , debt ) ;
2008-11-07 09:38:55 +01:00
gui_label_set_text_from_int ( GTK_LABEL ( lookup_widget ( window . alr , " label_current_start_week " ) ) ,
current_user . alr_start_week , FALSE ) ;
2008-11-09 10:36:55 +01:00
gtk_label_set_text ( GTK_LABEL ( lookup_widget ( window . alr , " label_current_weekly_installment " ) ) , weekly_installment ) ;
gtk_label_set_text ( GTK_LABEL ( lookup_widget ( window . alr , " label_alr_debt " ) ) , debt ) ;
2008-11-07 09:38:55 +01:00
gtk_spin_button_set_range ( GTK_SPIN_BUTTON ( lookup_widget ( window . alr , " spinbutton_start_week " ) ) ,
2008-11-08 13:46:12 +01:00
week + 1 , MIN ( week + current_user . counters [ COUNT_USER_LOAN ] , fixture_get_last_scheduled_week ( ) ) ) ;
2008-11-07 09:38:55 +01:00
gtk_spin_button_set_range ( GTK_SPIN_BUTTON ( lookup_widget ( window . alr , " spinbutton_weekly_installment " ) ) ,
2008-11-08 13:46:12 +01:00
0 , - current_user . debt * powf ( 1 + current_user . debt_interest , const_int ( " int_finance_payback_weeks " ) ) + 1 ) ;
2008-11-07 09:38:55 +01:00
}
2008-12-08 14:46:11 +01:00
2009-03-09 21:20:26 +01:00
/** Show the window where the user can edit constants determining
gameplay behaviour . */
void
window_show_constants ( void )
{
window_create ( WINDOW_CONSTANTS ) ;
treeview2_show_constants ( ) ;
}