2005-01-09 21:21:22 +01:00
|
|
|
#include "file.h"
|
2005-03-17 21:26:01 +01:00
|
|
|
#include "finance.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"
|
|
|
|
#include "misc_interface.h"
|
2005-03-08 09:25:46 +01:00
|
|
|
#include "misc2_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"
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
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");
|
|
|
|
gchar country_dir[SMALL];
|
|
|
|
GPtrArray *dir_contents = NULL;
|
|
|
|
GList *combo_strings = NULL;
|
|
|
|
gint i;
|
|
|
|
|
2005-01-09 21:21:22 +01:00
|
|
|
file_get_definitions_dir(country_dir);
|
2004-12-23 13:58:39 +01:00
|
|
|
|
|
|
|
dir_contents = file_dir_get_contents((const gchar*)country_dir, "country_");
|
|
|
|
|
|
|
|
for(i=0;i<dir_contents->len;i++)
|
|
|
|
combo_strings = g_list_append(combo_strings,
|
|
|
|
((GString*)g_ptr_array_index(dir_contents, i))->str);
|
|
|
|
|
|
|
|
gtk_combo_set_popdown_strings(GTK_COMBO(combo_country), combo_strings);
|
|
|
|
|
2004-12-30 17:48:19 +01:00
|
|
|
free_g_string_array(&dir_contents);
|
2004-12-23 13:58:39 +01:00
|
|
|
}
|
|
|
|
|
2005-03-23 20:03:26 +01:00
|
|
|
|
|
|
|
/** Show the options window. */
|
|
|
|
void
|
|
|
|
window_show_options(void)
|
|
|
|
{
|
|
|
|
window_create(WINDOW_OPTIONS);
|
|
|
|
|
|
|
|
option_gui_set_up_window();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-03-17 21:26:01 +01:00
|
|
|
/** Show the digits window with the labels and values set
|
|
|
|
according to the arguments. */
|
|
|
|
void
|
|
|
|
window_show_digits(gchar *text_main, gchar* text1, gint value1, gchar* text2, gint value2)
|
|
|
|
{
|
|
|
|
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"));
|
|
|
|
|
|
|
|
if(stat0 == STATUS_GET_LOAN ||
|
|
|
|
stat0 == STATUS_PAY_LOAN)
|
|
|
|
gtk_spin_button_set_range(spinbutton1, (gdouble)1, (gdouble)value1);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Show the stadium window for the current user. */
|
|
|
|
void
|
|
|
|
window_show_stadium(void)
|
|
|
|
{
|
|
|
|
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,
|
|
|
|
*label_costs_capacity, *label_costs_safety,
|
|
|
|
*label_duration_capacity, *label_duration_safety,
|
|
|
|
*label_stadium_status;
|
|
|
|
GtkSpinButton *spinbutton_capacity, *spinbutton_safety;
|
|
|
|
GtkProgressBar *progressbar_safety;
|
|
|
|
|
|
|
|
window_create(WINDOW_STADIUM);
|
|
|
|
|
|
|
|
label_capacity = GTK_LABEL(lookup_widget(window.stadium, "label_capacity"));
|
|
|
|
label_costs_capacity = GTK_LABEL(lookup_widget(window.stadium, "label_costs_capacity"));
|
|
|
|
label_costs_safety = GTK_LABEL(lookup_widget(window.stadium, "label_costs_safety"));
|
|
|
|
label_duration_capacity = GTK_LABEL(lookup_widget(window.stadium, "label_duration_capacity"));
|
|
|
|
label_duration_safety = GTK_LABEL(lookup_widget(window.stadium, "label_duration_safety"));
|
|
|
|
label_stadium_status = GTK_LABEL(lookup_widget(window.stadium, "label_stadium_status"));
|
|
|
|
|
|
|
|
spinbutton_capacity = GTK_SPIN_BUTTON(lookup_widget(window.stadium, "spinbutton_capacity"));
|
|
|
|
spinbutton_safety = GTK_SPIN_BUTTON(lookup_widget(window.stadium, "spinbutton_safety"));
|
|
|
|
|
|
|
|
progressbar_safety = GTK_PROGRESS_BAR(lookup_widget(window.stadium, "progressbar_safety"));
|
|
|
|
|
|
|
|
gui_label_set_text_from_int(label_capacity, tm->stadium.capacity, FALSE);
|
|
|
|
gui_label_set_text_from_int(label_costs_capacity,
|
|
|
|
(gint)rint(finance_wage_unit(tm) *
|
|
|
|
const_float("float_stadium_improvement_wage_unit_factor_seats")),
|
|
|
|
FALSE);
|
|
|
|
gui_label_set_text_from_int(label_costs_safety,
|
|
|
|
(gint)rint(finance_wage_unit(tm) *
|
|
|
|
(const_float("float_stadium_improvement_wage_unit_factor_safety") /
|
|
|
|
100)), FALSE);
|
|
|
|
gui_label_set_text_from_int(label_duration_capacity, 1, FALSE);
|
|
|
|
gui_label_set_text_from_int(label_duration_safety, 1, FALSE);
|
|
|
|
|
|
|
|
gtk_spin_button_set_value(spinbutton_capacity,
|
|
|
|
(gdouble)const_int("int_stadium_improvement_base_seats"));
|
|
|
|
gtk_spin_button_set_value(spinbutton_safety,
|
|
|
|
const_float("float_stadium_improvement_base_safety") * 100);
|
|
|
|
|
|
|
|
gtk_progress_bar_set_fraction(progressbar_safety, tm->stadium.safety);
|
|
|
|
|
|
|
|
sprintf(buf, "%d%%", (gint)rint(tm->stadium.safety * 100));
|
|
|
|
gtk_progress_bar_set_text(progressbar_safety, 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.\nExpected 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-20 21:49:55 +01:00
|
|
|
/** Show the window where the user can select between yes and no.
|
|
|
|
@param text The text shown in the window.
|
|
|
|
@param checkbutton Whether to show the checkbutton. */
|
|
|
|
void
|
|
|
|
window_show_yesno(gchar *text, gboolean checkbutton)
|
|
|
|
{
|
|
|
|
window_create(WINDOW_YESNO);
|
|
|
|
|
|
|
|
gtk_label_set_text(GTK_LABEL(lookup_widget(window.yesno, "label_yesno")), text);
|
|
|
|
|
|
|
|
if(!checkbutton)
|
|
|
|
gtk_widget_hide(lookup_widget(window.yesno, "checkbutton_yesno"));
|
|
|
|
}
|
|
|
|
|
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-08 09:25:46 +01:00
|
|
|
gint old_popups_active = popups_active;
|
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-03-08 09:25:46 +01:00
|
|
|
g_warning("window_create: unknown window type %d\n", window_type);
|
|
|
|
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;
|
|
|
|
game_gui_print_message("Welcome to Bygfoot "VERS);
|
2005-01-09 21:21:22 +01:00
|
|
|
}
|
|
|
|
else
|
2005-03-03 13:46:48 +01:00
|
|
|
wind = window.main;
|
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
|
2005-03-08 09:25:46 +01:00
|
|
|
{
|
|
|
|
popups_active++;
|
2005-03-03 13:46:48 +01:00
|
|
|
window.startup = create_window_startup();
|
2005-03-08 09:25:46 +01:00
|
|
|
}
|
2005-03-03 13:46:48 +01:00
|
|
|
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
|
2005-03-08 09:25:46 +01:00
|
|
|
{
|
|
|
|
popups_active++;
|
2005-03-03 13:46:48 +01:00
|
|
|
window.live = create_window_live();
|
2005-03-08 09:25:46 +01:00
|
|
|
}
|
2005-03-10 21:59:39 +01:00
|
|
|
strcpy(buf, "Bygfoot Live game");
|
2005-03-03 13:46:48 +01:00
|
|
|
wind = window.live;
|
2005-01-10 16:24:15 +01:00
|
|
|
gtk_spin_button_set_value(
|
2005-03-03 13:46:48 +01:00
|
|
|
GTK_SPIN_BUTTON(lookup_widget(wind, "spinbutton_speed")),
|
2005-03-23 20:03:26 +01:00
|
|
|
(gfloat)option_int("int_opt_user_live_game_speed", &usr(stat2).options));
|
2005-03-03 13:46:48 +01:00
|
|
|
break;
|
|
|
|
case WINDOW_STARTUP_USERS:
|
|
|
|
if(window.startup_users != NULL)
|
|
|
|
g_warning("window_create: called on already existing window\n");
|
|
|
|
else
|
2005-03-08 09:25:46 +01:00
|
|
|
{
|
|
|
|
popups_active++;
|
2005-03-03 13:46:48 +01:00
|
|
|
window.startup_users = create_window_startup_users();
|
2005-03-08 09:25:46 +01:00
|
|
|
}
|
2005-03-10 21:59:39 +01:00
|
|
|
strcpy(buf, "Users");
|
2005-03-03 13:46:48 +01:00
|
|
|
wind = window.startup_users;
|
2005-01-09 21:21:22 +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-03-10 21:59:39 +01:00
|
|
|
strcpy(buf, "Erm...");
|
|
|
|
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
|
|
|
|
{
|
|
|
|
popups_active++;
|
|
|
|
window.digits = create_window_digits();
|
|
|
|
}
|
|
|
|
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
|
|
|
|
{
|
|
|
|
popups_active++;
|
|
|
|
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
|
|
|
|
{
|
|
|
|
popups_active++;
|
|
|
|
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
|
|
|
|
{
|
|
|
|
popups_active++;
|
|
|
|
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
|
|
|
|
{
|
|
|
|
popups_active++;
|
|
|
|
window.options = create_window_options();
|
|
|
|
}
|
|
|
|
wind = window.options;
|
|
|
|
strcpy(buf, "Options");
|
|
|
|
break;
|
2005-03-03 13:46:48 +01:00
|
|
|
}
|
2004-12-30 17:48:19 +01:00
|
|
|
|
2005-03-10 21:59:39 +01:00
|
|
|
gtk_window_set_title(GTK_WINDOW(wind), buf);
|
2005-03-03 13:46:48 +01:00
|
|
|
gtk_widget_show(wind);
|
2004-12-30 17:48:19 +01:00
|
|
|
|
2005-03-11 18:18:51 +01:00
|
|
|
if(popups_active != old_popups_active &&
|
|
|
|
window.main != NULL)
|
2005-03-03 13:46:48 +01:00
|
|
|
gtk_widget_set_sensitive(window.main, FALSE);
|
2005-01-09 21:21:22 +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
|
2005-03-08 09:25:46 +01:00
|
|
|
window_destroy(GtkWidget **wind, gboolean count_popups)
|
2005-01-09 21:21:22 +01:00
|
|
|
{
|
2005-03-03 13:46:48 +01:00
|
|
|
if(*wind == NULL)
|
2005-01-09 21:21:22 +01:00
|
|
|
return;
|
|
|
|
|
2005-03-08 09:25:46 +01:00
|
|
|
if(*wind != window.main && count_popups)
|
2005-01-09 21:21:22 +01:00
|
|
|
{
|
|
|
|
popups_active--;
|
|
|
|
|
2005-03-03 13:46:48 +01:00
|
|
|
if(popups_active == 0 && window.main != NULL)
|
|
|
|
gtk_widget_set_sensitive(window.main, TRUE);
|
2005-01-09 21:21:22 +01:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|