"Startup leaguges."

This commit is contained in:
gyboth 2005-06-11 16:54:59 +00:00
parent 0d3194bde1
commit 401195ef6e
7 changed files with 154 additions and 186 deletions

View File

@ -178,7 +178,7 @@
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0.05</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
@ -191,77 +191,13 @@
</child>
<child>
<widget class="GtkHBox" id="hbox2">
<widget class="GtkComboBoxEntry" id="comboboxentry_start_league">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child>
<widget class="GtkRadioButton" id="team_selection_radio1">
<property name="border_width">3</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Top league</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="active">False</property>
<property name="inconsistent">False</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkRadioButton" id="team_selection_radio2">
<property name="border_width">3</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Current league</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="active">True</property>
<property name="inconsistent">False</property>
<property name="draw_indicator">True</property>
<property name="group">team_selection_radio1</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkRadioButton" id="team_selection_radio3">
<property name="border_width">3</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Bottom league</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="active">False</property>
<property name="inconsistent">False</property>
<property name="draw_indicator">True</property>
<property name="group">team_selection_radio1</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
</widget>
<packing>
<property name="padding">5</property>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="fill">False</property>
</packing>
</child>
@ -287,7 +223,7 @@
<child>
<widget class="GtkLabel" id="label75">
<property name="visible">True</property>
<property name="label" translatable="yes">Player name</property>
<property name="label" translatable="yes">Username</property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>

View File

@ -28,6 +28,8 @@ misc_callback_show_team_list(GtkWidget *widget, const gchar *country_file)
xml_country_read(country_file);
treeview_show_team_list(GTK_TREE_VIEW(treeview_startup), FALSE, FALSE);
treeview_show_leagues_combo();
}
/** Start a new game after users and teams are selected. */
@ -54,41 +56,38 @@ misc_callback_start_game(void)
void
misc_callback_add_player(void)
{
GtkToggleButton *team_selection_radio1 =
GTK_TOGGLE_BUTTON(lookup_widget(window.startup, "team_selection_radio1"));
GtkToggleButton *team_selection_radio2 =
GTK_TOGGLE_BUTTON(lookup_widget(window.startup, "team_selection_radio2"));
GtkTreeView *treeview_users =
GTK_TREE_VIEW(lookup_widget(window.startup, "treeview_users"));
GtkTreeView *treeview_startup =
GTK_TREE_VIEW(lookup_widget(window.startup, "treeview_startup"));
GtkEntry *entry_player_name =
GTK_ENTRY(lookup_widget(window.startup, "entry_player_name"));
GTK_ENTRY(lookup_widget(window.startup, "entry_player_name"));
GtkComboBox *combo_leagues =
GTK_COMBO_BOX(lookup_widget(window.startup, "comboboxentry_start_league"));
const gchar *player_name = gtk_entry_get_text(entry_player_name);
User new_user = user_new();
Team *tm = (Team*)treeview_helper_get_pointer(treeview_startup, 2);
gint start_league =
gtk_combo_box_get_active(combo_leagues);
if(strlen(player_name) > 0)
g_string_printf(new_user.name, "%s", player_name);
gtk_entry_set_text(entry_player_name, "");
if(gtk_toggle_button_get_active(team_selection_radio1))
new_user.scout = 1;
else if(gtk_toggle_button_get_active(team_selection_radio2))
new_user.scout = 0;
else
new_user.scout = -1;
new_user.tm = tm;
new_user.team_id = tm->id;
new_user.scout = (start_league == 0 || tm->clid == lig(start_league - 1).id) ? -1 : start_league - 1;
g_array_append_val(users, new_user);
treeview_show_users(treeview_users);
treeview_show_team_list(treeview_startup, FALSE, FALSE);
gtk_combo_box_set_active(GTK_COMBO_BOX(combo_leagues), 0);
if(users->len == 1)
{
gtk_widget_set_sensitive(lookup_widget(window.startup, "team_selection_ok"), TRUE);

View File

@ -42,11 +42,7 @@ create_window_startup (void)
GtkWidget *combo_country;
GtkWidget *hseparator11;
GtkWidget *label4;
GtkWidget *hbox2;
GtkWidget *team_selection_radio1;
GSList *team_selection_radio1_group = NULL;
GtkWidget *team_selection_radio2;
GtkWidget *team_selection_radio3;
GtkWidget *comboboxentry_start_league;
GtkWidget *hseparator12;
GtkWidget *hbox54;
GtkWidget *label75;
@ -145,33 +141,10 @@ create_window_startup (void)
label4 = gtk_label_new (_("Start in"));
gtk_widget_show (label4);
gtk_box_pack_start (GTK_BOX (vbox2), label4, FALSE, FALSE, 0);
gtk_misc_set_alignment (GTK_MISC (label4), 0.05, 0.5);
hbox2 = gtk_hbox_new (FALSE, 0);
gtk_widget_show (hbox2);
gtk_box_pack_start (GTK_BOX (vbox2), hbox2, FALSE, TRUE, 5);
team_selection_radio1 = gtk_radio_button_new_with_mnemonic (NULL, _("Top league"));
gtk_widget_show (team_selection_radio1);
gtk_box_pack_start (GTK_BOX (hbox2), team_selection_radio1, FALSE, FALSE, 0);
gtk_container_set_border_width (GTK_CONTAINER (team_selection_radio1), 3);
gtk_radio_button_set_group (GTK_RADIO_BUTTON (team_selection_radio1), team_selection_radio1_group);
team_selection_radio1_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (team_selection_radio1));
team_selection_radio2 = gtk_radio_button_new_with_mnemonic (NULL, _("Current league"));
gtk_widget_show (team_selection_radio2);
gtk_box_pack_start (GTK_BOX (hbox2), team_selection_radio2, FALSE, FALSE, 0);
gtk_container_set_border_width (GTK_CONTAINER (team_selection_radio2), 3);
gtk_radio_button_set_group (GTK_RADIO_BUTTON (team_selection_radio2), team_selection_radio1_group);
team_selection_radio1_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (team_selection_radio2));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (team_selection_radio2), TRUE);
team_selection_radio3 = gtk_radio_button_new_with_mnemonic (NULL, _("Bottom league"));
gtk_widget_show (team_selection_radio3);
gtk_box_pack_start (GTK_BOX (hbox2), team_selection_radio3, FALSE, FALSE, 0);
gtk_container_set_border_width (GTK_CONTAINER (team_selection_radio3), 3);
gtk_radio_button_set_group (GTK_RADIO_BUTTON (team_selection_radio3), team_selection_radio1_group);
team_selection_radio1_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (team_selection_radio3));
comboboxentry_start_league = gtk_combo_box_entry_new ();
gtk_widget_show (comboboxentry_start_league);
gtk_box_pack_start (GTK_BOX (vbox2), comboboxentry_start_league, FALSE, FALSE, 0);
hseparator12 = gtk_hseparator_new ();
gtk_widget_show (hseparator12);
@ -182,7 +155,7 @@ create_window_startup (void)
gtk_widget_show (hbox54);
gtk_box_pack_start (GTK_BOX (vbox2), hbox54, FALSE, TRUE, 0);
label75 = gtk_label_new (_("Player name"));
label75 = gtk_label_new (_("Username"));
gtk_widget_show (label75);
gtk_box_pack_start (GTK_BOX (hbox54), label75, FALSE, FALSE, 0);
@ -347,10 +320,7 @@ create_window_startup (void)
GLADE_HOOKUP_OBJECT (window_startup, combo_country, "combo_country");
GLADE_HOOKUP_OBJECT (window_startup, hseparator11, "hseparator11");
GLADE_HOOKUP_OBJECT (window_startup, label4, "label4");
GLADE_HOOKUP_OBJECT (window_startup, hbox2, "hbox2");
GLADE_HOOKUP_OBJECT (window_startup, team_selection_radio1, "team_selection_radio1");
GLADE_HOOKUP_OBJECT (window_startup, team_selection_radio2, "team_selection_radio2");
GLADE_HOOKUP_OBJECT (window_startup, team_selection_radio3, "team_selection_radio3");
GLADE_HOOKUP_OBJECT (window_startup, comboboxentry_start_league, "comboboxentry_start_league");
GLADE_HOOKUP_OBJECT (window_startup, hseparator12, "hseparator12");
GLADE_HOOKUP_OBJECT (window_startup, hbox54, "hbox54");
GLADE_HOOKUP_OBJECT (window_startup, label75, "label75");

View File

@ -180,7 +180,8 @@ treeview_show_team_list(GtkTreeView *treeview, gboolean show_cup_teams,
@param max The size of the attribute array.
@param separator Whether we draw a blank line after the 11th player. */
GtkTreeModel*
treeview_create_player_list(GPtrArray *players, gint *attributes, gint max, gboolean show_separator)
treeview_create_player_list(GPtrArray *players, gint *attributes, gint max,
gboolean show_separator, gboolean sortable)
{
gint i, j;
GtkListStore *ls;
@ -212,7 +213,7 @@ treeview_create_player_list(GPtrArray *players, gint *attributes, gint max, gboo
gtk_list_store_set(ls, &iter, j + 1, g_ptr_array_index(players, i), -1);
}
if(!show_separator)
if(sortable)
{
for(i=0;i<max;i++)
if(attributes[i] == PLAYER_LIST_ATTRIBUTE_POS ||
@ -234,7 +235,7 @@ treeview_create_player_list(GPtrArray *players, gint *attributes, gint max, gboo
/** Set up the tree view for a player list */
void
treeview_set_up_player_list (GtkTreeView *treeview, gint *attributes, gint max,
gboolean show_separator)
gboolean show_separator, gboolean sortable)
{
gint i;
GtkTreeViewColumn *col;
@ -294,7 +295,7 @@ treeview_set_up_player_list (GtkTreeView *treeview, gint *attributes, gint max,
NULL);
}
if(!show_separator &&
if(sortable &&
(attributes[i] == PLAYER_LIST_ATTRIBUTE_POS ||
attributes[i] == PLAYER_LIST_ATTRIBUTE_SKILL ||
attributes[i] == PLAYER_LIST_ATTRIBUTE_GOALS ||
@ -323,6 +324,7 @@ treeview_show_player_list(GtkTreeView *treeview, GPtrArray *players, PlayerListA
gint columns = math_sum_int_array(attribute.on_off, PLAYER_LIST_ATTRIBUTE_END);
gint attributes[columns];
GtkTreeModel *model = NULL;
gboolean sortable = (treeview != GTK_TREE_VIEW(lookup_widget(window.main, "player_list1")));
treeview_helper_clear(treeview);
@ -330,9 +332,9 @@ treeview_show_player_list(GtkTreeView *treeview, GPtrArray *players, PlayerListA
if(attribute.on_off[i])
attributes[cnt++] = i;
treeview_set_up_player_list(treeview, attributes, columns, show_separator);
treeview_set_up_player_list(treeview, attributes, columns, show_separator, sortable);
model = treeview_create_player_list(players, attributes, columns, show_separator);
model = treeview_create_player_list(players, attributes, columns, show_separator, sortable);
gtk_tree_view_set_model(treeview, model);
g_object_unref(model);
@ -572,14 +574,14 @@ treeview_create_users(void)
2, usr(i).tm->name->str,
-1);
if(stat0 == STATUS_TEAM_SELECTION && usr(i).scout != 0)
if(stat0 == STATUS_TEAM_SELECTION)
{
if(usr(i).scout == 1)
if(usr(i).scout == -1)
gtk_list_store_set(ls, &iter, 3,
lig(0).name->str, -1);
league_from_clid(usr(i).tm->clid)->name->str, -1);
else
gtk_list_store_set(ls, &iter, 3,
lig(ligs->len - 1).name->str, -1);
lig(usr(i).scout).name->str, -1);
}
else
gtk_list_store_set(ls, &iter, 3,
@ -2238,3 +2240,51 @@ treeview_show_contributors(const OptionList *help_list)
gtk_tree_view_set_model(treeview, GTK_TREE_MODEL(ls));
g_object_unref(ls);
}
GtkTreeModel*
treeview_create_league_list(void)
{
gint i;
GtkListStore *ls = gtk_list_store_new(2, G_TYPE_INT, G_TYPE_STRING);
GtkTreeIter iter;
gtk_list_store_append(ls, &iter);
gtk_list_store_set(ls, &iter, 0, 0, 1, _("Current league"), -1);
for(i=0;i<ligs->len;i++)
{
gtk_list_store_append(ls, &iter);
gtk_list_store_set(ls, &iter, 0, i + 1, 1, lig(i).name->str, -1);
}
return GTK_TREE_MODEL(ls);
}
/** Show the league list in the combo box
in the startup window. */
void
treeview_show_leagues_combo(void)
{
GtkTreeModel *model = treeview_create_league_list();
GtkComboBox *combo_leagues =
GTK_COMBO_BOX(lookup_widget(window.startup, "comboboxentry_start_league"));
GtkCellRenderer *renderer = NULL;
gtk_combo_box_set_model(combo_leagues, model);
g_object_unref(model);
if(gtk_combo_box_entry_get_text_column(GTK_COMBO_BOX_ENTRY(combo_leagues)) == -1)
gtk_combo_box_entry_set_text_column(GTK_COMBO_BOX_ENTRY(combo_leagues), 1);
gtk_cell_layout_clear(GTK_CELL_LAYOUT(combo_leagues));
renderer = treeview_helper_cell_renderer_text_new();
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo_leagues), renderer, FALSE);
gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo_leagues), renderer, "text", 0, NULL);
renderer = treeview_helper_cell_renderer_text_new();
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo_leagues), renderer, TRUE);
gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo_leagues), renderer, "text", 1, NULL);
gtk_combo_box_set_active(GTK_COMBO_BOX(combo_leagues), 0);
}

View File

@ -20,10 +20,12 @@ treeview_show_team_list(GtkTreeView *treeview, gboolean show_cup_teams,
gboolean show_user_teams);
GtkTreeModel*
treeview_create_player_list(GPtrArray *players, gint *attributes, gint max, gboolean show_separator);
treeview_create_player_list(GPtrArray *players, gint *attributes, gint max,
gboolean show_separator, gboolean sortable);
void
treeview_set_up_player_list (GtkTreeView *treeview, gint *attributes, gint max, gboolean show_separator);
treeview_set_up_player_list (GtkTreeView *treeview, gint *attributes, gint max,
gboolean show_separator, gboolean sortable);
void
treeview_show_player_list(GtkTreeView *treeview, GPtrArray *players, PlayerListAttribute attribute,
@ -199,4 +201,10 @@ treeview_create_country_list(const GPtrArray *country_list);
void
treeview_show_contributors(const OptionList *help_list);
GtkTreeModel*
treeview_create_league_list(void);
void
treeview_show_leagues_combo(void);
#endif

View File

@ -360,49 +360,58 @@ treeview_helper_player_compare(GtkTreeModel *model,
gtk_tree_model_get(model, a, 4, &pl1, -1);
gtk_tree_model_get(model, b, 4, &pl2, -1);
switch(type)
if(pl1 == NULL && pl2 == NULL)
return_value = 0;
else if(pl1 == NULL)
return_value = 1;
else if(pl2 == NULL)
return_value = -1;
else
{
default:
g_warning("treeview_player_compare: unknown type %d.\n", type);
break;
case PLAYER_LIST_ATTRIBUTE_POS:
return_value = misc_int_compare(pl1->pos, pl2->pos);
break;
case PLAYER_LIST_ATTRIBUTE_GOALS:
if(pl1->pos == 0 && pl2->pos == 0)
return_value = misc_int_compare(player_games_goals_get(pl2, pl2->team->clid, PLAYER_VALUE_GOALS),
player_games_goals_get(pl1, pl1->team->clid, PLAYER_VALUE_GOALS));
else if(pl1->pos == 0 || pl2->pos == 0)
return_value = (pl1->pos == 0) ? 1 : -1;
else
return_value = misc_int_compare(player_games_goals_get(pl1, pl1->team->clid, PLAYER_VALUE_GOALS),
player_games_goals_get(pl2, pl2->team->clid, PLAYER_VALUE_GOALS));
break;
case PLAYER_LIST_ATTRIBUTE_SHOTS:
return_value = misc_int_compare(player_games_goals_get(pl1, pl1->team->clid, PLAYER_VALUE_SHOTS),
player_games_goals_get(pl2, pl2->team->clid, PLAYER_VALUE_SHOTS));
break;
case PLAYER_LIST_ATTRIBUTE_GAMES:
return_value = misc_int_compare(player_games_goals_get(pl1, pl1->team->clid, PLAYER_VALUE_GAMES),
player_games_goals_get(pl2, pl2->team->clid, PLAYER_VALUE_GAMES));
break;
case PLAYER_LIST_ATTRIBUTE_SKILL:
return_value = misc_float_compare(pl1->skill, pl2->skill);
break;
case PLAYER_LIST_ATTRIBUTE_AGE:
return_value = misc_float_compare(pl1->age, pl2->age);
break;
case PLAYER_LIST_ATTRIBUTE_ETAL:
return_value = misc_float_compare(pl1->etal[current_user.scout % 10],
pl2->etal[current_user.scout % 10]);
break;
case PLAYER_LIST_ATTRIBUTE_VALUE:
return_value = misc_int_compare(pl1->value, pl2->value);
break;
case PLAYER_LIST_ATTRIBUTE_WAGE:
return_value = misc_int_compare(pl1->wage, pl2->wage);
break;
switch(type)
{
default:
g_warning("treeview_player_compare: unknown type %d.\n", type);
break;
case PLAYER_LIST_ATTRIBUTE_POS:
return_value = misc_int_compare(pl1->pos, pl2->pos);
break;
case PLAYER_LIST_ATTRIBUTE_GOALS:
if(pl1->pos == 0 && pl2->pos == 0)
return_value = misc_int_compare(player_games_goals_get(pl2, pl2->team->clid, PLAYER_VALUE_GOALS),
player_games_goals_get(pl1, pl1->team->clid, PLAYER_VALUE_GOALS));
else if(pl1->pos == 0 || pl2->pos == 0)
return_value = (pl1->pos == 0) ? 1 : -1;
else
return_value = misc_int_compare(player_games_goals_get(pl1, pl1->team->clid, PLAYER_VALUE_GOALS),
player_games_goals_get(pl2, pl2->team->clid, PLAYER_VALUE_GOALS));
break;
case PLAYER_LIST_ATTRIBUTE_SHOTS:
return_value = misc_int_compare(player_games_goals_get(pl1, pl1->team->clid, PLAYER_VALUE_SHOTS),
player_games_goals_get(pl2, pl2->team->clid, PLAYER_VALUE_SHOTS));
break;
case PLAYER_LIST_ATTRIBUTE_GAMES:
return_value = misc_int_compare(player_games_goals_get(pl1, pl1->team->clid, PLAYER_VALUE_GAMES),
player_games_goals_get(pl2, pl2->team->clid, PLAYER_VALUE_GAMES));
break;
case PLAYER_LIST_ATTRIBUTE_SKILL:
return_value = misc_float_compare(pl1->skill, pl2->skill);
break;
case PLAYER_LIST_ATTRIBUTE_AGE:
return_value = misc_float_compare(pl1->age, pl2->age);
break;
case PLAYER_LIST_ATTRIBUTE_ETAL:
return_value = misc_float_compare(pl1->etal[current_user.scout % 10],
pl2->etal[current_user.scout % 10]);
break;
case PLAYER_LIST_ATTRIBUTE_VALUE:
return_value = misc_int_compare(pl1->value, pl2->value);
break;
case PLAYER_LIST_ATTRIBUTE_WAGE:
return_value = misc_int_compare(pl1->wage, pl2->wage);
break;
}
}
return return_value;

View File

@ -41,30 +41,26 @@ void
user_set_up_team_new_game(User *user)
{
gchar buf[SMALL];
gint rndom, max, lig_idx = -1;
gint rndom;
if(user->scout == 0)
if(user->scout == -1)
{
user_set_up_team(user);
user_history_add(user, USER_HISTORY_START_GAME, user->tm->id, user->tm->clid, -1, "");
}
else
{
if(user->scout == 1 &&
lig(0).id != user->tm->clid)
lig_idx = 0;
else if(lig(ligs->len - 1).id != user->tm->clid)
lig_idx = ligs->len - 1;
max = lig(lig_idx).teams->len - 1;
rndom = math_rndi(0, max);
sprintf(buf, "%s", g_array_index(lig(lig_idx).teams, Team, rndom).name->str);
g_string_printf(g_array_index(lig(lig_idx).teams, Team, rndom).name, "%s",
rndom = math_rndi(0, lig(user->scout).teams->len - 1);
while(team_is_user(&g_array_index(lig(user->scout).teams, Team, rndom)) != -1)
rndom = math_rndi(0, lig(user->scout).teams->len - 1);
sprintf(buf, "%s", g_array_index(lig(user->scout).teams, Team, rndom).name->str);
g_string_printf(g_array_index(lig(user->scout).teams, Team, rndom).name, "%s",
user->tm->name->str);
g_string_printf(user->tm->name, "%s", buf);
user->tm = &g_array_index(lig(lig_idx).teams, Team, rndom);
user->team_id = g_array_index(lig(lig_idx).teams, Team, rndom).id;
user->tm = &g_array_index(lig(user->scout).teams, Team, rndom);
user->team_id = g_array_index(lig(user->scout).teams, Team, rndom).id;
user_history_add(user, USER_HISTORY_START_GAME, user->tm->id, user->tm->clid, -1, "");