~ubuntu-branches/ubuntu/hardy/bygfoot/hardy

« back to all changes in this revision

Viewing changes to src/treeview.c

  • Committer: Bazaar Package Importer
  • Author(s): Isaac Clerencia
  • Date: 2006-06-04 17:51:19 UTC
  • mfrom: (1.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060604175119-0pbfuhr617031qa9
Tags: 2.0.0-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
   treeview.c
 
3
 
 
4
   Bygfoot Football Manager -- a small and simple GTK2-based
 
5
   football management game.
 
6
 
 
7
   http://bygfoot.sourceforge.net
 
8
 
 
9
   Copyright (C) 2005  Gyözö Both (gyboth@bygfoot.com)
 
10
 
 
11
   This program is free software; you can redistribute it and/or
 
12
   modify it under the terms of the GNU General Public License
 
13
   as published by the Free Software Foundation; either version 2
 
14
   of the License, or (at your option) any later version.
 
15
 
 
16
   This program is distributed in the hope that it will be useful,
 
17
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
18
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
19
   GNU General Public License for more details.
 
20
 
 
21
   You should have received a copy of the GNU General Public License
 
22
   along with this program; if not, write to the Free Software
 
23
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
24
*/
 
25
 
1
26
#include "cup.h"
 
27
#include "file.h"
2
28
#include "finance.h"
3
29
#include "fixture.h"
4
30
#include "free.h"
5
31
#include "game.h"
 
32
#include "game_gui.h"
6
33
#include "language.h"
7
34
#include "league.h"
8
35
#include "live_game.h"
100
127
    gtk_tree_view_set_headers_visible(treeview, TRUE);    
101
128
    gtk_tree_view_set_rules_hint(treeview, TRUE);
102
129
 
 
130
    gtk_tree_view_set_search_column(treeview, 2);
 
131
    gtk_tree_view_set_search_equal_func(treeview,
 
132
                                        treeview_helper_search_equal,
 
133
                                        NULL, NULL);
 
134
 
103
135
    /* Numbering the teams */
104
136
    col = gtk_tree_view_column_new();
105
137
    gtk_tree_view_append_column(treeview, col);
713
745
                            G_TYPE_STRING,
714
746
                            G_TYPE_STRING);
715
747
 
716
 
    fixture_result_to_buf(live_game->fix, buf[0], FALSE);
 
748
    if(live_game->fix != NULL)
 
749
        fixture_result_to_buf(live_game->fix, buf[0], FALSE);
 
750
    else
 
751
        sprintf(
 
752
            buf[0], "%d : %d",
 
753
            g_array_index(live_game->units, LiveGameUnit, live_game->units->len - 1).
 
754
            result[0],
 
755
            g_array_index(live_game->units, LiveGameUnit, live_game->units->len - 1).
 
756
            result[1]);
717
757
    gtk_list_store_append(ls, &iter);
718
 
    gtk_list_store_set(ls, &iter, 0, live_game->fix->teams[0]->name,
 
758
    gtk_list_store_set(ls, &iter, 0, live_game->team_names[0],
719
759
                       1, buf[0],
720
 
                       2, live_game->fix->teams[1]->name,
 
760
                       2, live_game->team_names[1],
721
761
                       -1);
722
762
 
723
763
    for(k=0;k<LIVE_GAME_STAT_ARRAY_END;k++)
759
799
        }
760
800
    }
761
801
 
762
 
    misc_print_grouped_int(live_game->fix->attendance, buf[0]);
 
802
    misc_print_grouped_int(live_game->attendance, buf[0]);
763
803
    sprintf(buf[1], _("Attendance\n%s"), buf[0]);
764
804
    gtk_list_store_append(ls, &iter);
765
805
    gtk_list_store_set(ls, &iter, 0, buf[1], 1, "", 2, "", -1);
906
946
    gchar *symbol[2] = {NULL, NULL};
907
947
    gchar buf_result[SMALL], buf[3][SMALL];
908
948
    gchar *colour_fg = NULL, *colour_bg = NULL;
 
949
    gint user_idx = fixture_user_team_involved(fix);
909
950
 
910
951
    if(fix->clid >= ID_CUP_START &&
911
952
       query_cup_is_international(fix->clid))
912
953
        for(i=0;i<2;i++)
913
954
            symbol[i] = fix->teams[i]->symbol;
914
955
    
915
 
    if(fixture_user_team_involved(fix) != -1)
916
 
        treeview_helper_set_user_colours(usr(fixture_user_team_involved(fix)).tm,
 
956
    if(user_idx != -1)
 
957
        treeview_helper_set_user_colours(usr(user_idx).tm->name,
917
958
                                         &colour_bg, &colour_fg);
918
959
    else
919
960
    {
1122
1163
                colour_bg, colour_fg, i + 1);
1123
1164
 
1124
1165
        treeview_helper_get_table_element_colours(table, i, &colour_fg, &colour_bg, TRUE);
1125
 
        sprintf(buf[1], "<span background='%s' foreground='%s'>%s</span>", 
1126
 
                colour_bg, colour_fg, elem->team->name);
 
1166
        if(debug < 50)
 
1167
            sprintf(buf[1], "<span background='%s' foreground='%s'>%s</span>", 
 
1168
                    colour_bg, colour_fg, elem->team->name);
 
1169
        else
 
1170
            sprintf(buf[1], "<span background='%s' foreground='%s'>%s (%s)</span>", 
 
1171
                    colour_bg, colour_fg, elem->team->name, elem->team->strategy_sid);
1127
1172
 
1128
1173
        gtk_list_store_set(ls, &iter, 1, buf[0], 3, buf[1], -1);
1129
1174
 
1306
1351
    gchar *in_titles[MON_IN_TRANSFERS] =
1307
1352
        {_("Prize money"),
1308
1353
         _("Ticket income"),
1309
 
         _("Sponsorship")};
 
1354
         _("Sponsorship"),
 
1355
         _("Betting")};
1310
1356
    gchar *out_titles[MON_OUT_TRANSFERS] =
1311
1357
        {_("Wages"),
1312
1358
         _("Physio"),
1315
1361
         _("Youth academy"),
1316
1362
         _("Journey costs"),
1317
1363
         /* Money paid to players a user fired. */
1318
 
         _("Compensations")};
 
1364
         _("Compensations"),
 
1365
         _("Betting"),
 
1366
         /* Applying boost costs money. */
 
1367
         _("Boost costs")};
1319
1368
 
1320
1369
    GtkTreeIter iter;
1321
1370
    GtkListStore *ls = 
1326
1375
 
1327
1376
    gtk_list_store_append(ls, &iter);
1328
1377
    /* Finances balance. */
1329
 
    gtk_list_store_set(ls, &iter, 0, _("Bi-weekly balance"), 1, "", 2, "", -1);
 
1378
    if(week > 2)
 
1379
    {
 
1380
        if(week % 2 == 1)
 
1381
            sprintf(buf, _("Bi-weekly balance\n(Week %d and %d)"),
 
1382
                    week - 2, week - 1);
 
1383
        else
 
1384
            sprintf(buf, _("Bi-weekly balance\n(Week %d and %d)"),
 
1385
                    week - 3, week - 2);
 
1386
    }
 
1387
    else
 
1388
        strcpy(buf, _("Bi-weekly balance"));
 
1389
 
 
1390
    gtk_list_store_set(ls, &iter, 0, buf, 1, "", 2, "", -1);
1330
1391
 
1331
1392
    for(i=0;i<MON_IN_TRANSFERS;i++)
1332
1393
        if(in[i] != 0)
1545
1606
    if(opp == NULL)
1546
1607
        return NULL;
1547
1608
    
 
1609
    ls = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING);
 
1610
 
1548
1611
    if(fix->clid < ID_CUP_START)
1549
1612
        strcpy(buf, league_cup_get_name_string(fix->clid));
1550
1613
    else
1988
2051
        gtk_list_store_set(ls, &iter,
1989
2052
                           0, g_array_index(current_user.history, UserHistory, i).season,
1990
2053
                           1, g_array_index(current_user.history, UserHistory, i).week,
1991
 
                           2, team_of_id(g_array_index(current_user.history, UserHistory, i).team_id)->name,
 
2054
                           2, g_array_index(current_user.history, UserHistory, i).team_name,
1992
2055
                           4, buf, -1);
1993
2056
 
1994
2057
    }
2077
2140
    gchar *colour_fg = NULL, *colour_bg = NULL;
2078
2141
    
2079
2142
    gtk_list_store_append(ls, &iter);
2080
 
    treeview_helper_insert_icon(ls, &iter, 0, league_from_clid(league_stat->clid)->symbol);
 
2143
    treeview_helper_insert_icon(ls, &iter, 0, 
 
2144
                                league_stat->league_symbol);
2081
2145
    gtk_list_store_set(ls, &iter, 1, const_int("int_treeview_helper_int_empty"),
2082
 
                       2, league_cup_get_name_string(league_stat->clid), 3, "", 4, "", 5, "", -1);
 
2146
                       2, league_stat->league_name, 3, "", 4, "", 5, "", -1);
2083
2147
 
2084
2148
    for(i=0;i<2;i++)
2085
2149
    {
2099
2163
                    g_array_index(teams[i], Stat, j).value1,
2100
2164
                    g_array_index(teams[i], Stat, j).value2);
2101
2165
            
2102
 
            treeview_helper_set_user_colours(team_of_id(g_array_index(teams[i], Stat, j).team_id),
2103
 
                                             &colour_bg, &colour_fg);
 
2166
            treeview_helper_set_user_colours(
 
2167
                g_array_index(teams[i], Stat, j).team_name,
 
2168
                &colour_bg, &colour_fg);
2104
2169
 
2105
2170
            sprintf(buf2, "<span background='%s' foreground='%s'>%s</span>",
2106
 
                    colour_bg, colour_fg, team_of_id(g_array_index(teams[i], Stat, j).team_id)->name);
 
2171
                    colour_bg, colour_fg, 
 
2172
                    g_array_index(teams[i], Stat, j).team_name);
2107
2173
            
2108
2174
            gtk_list_store_append(ls, &iter);
2109
2175
            gtk_list_store_set(ls, &iter, 0, NULL, 1, j + 1,
2141
2207
                        100 * (1 - (gfloat)g_array_index(players[i], Stat, j).value1 /
2142
2208
                               (gfloat)g_array_index(players[i], Stat, j).value3) : 0);
2143
2209
 
2144
 
            treeview_helper_set_user_colours(team_of_id(g_array_index(players[i], Stat, j).team_id),
2145
 
                                             &colour_bg, &colour_fg);
 
2210
            treeview_helper_set_user_colours(
 
2211
                g_array_index(players[i], Stat, j).team_name,
 
2212
                &colour_bg, &colour_fg);
2146
2213
            sprintf(buf3, "<span background='%s' foreground='%s'>%s (%s)</span>",
2147
2214
                    colour_bg, colour_fg,
2148
2215
                    g_array_index(players[i], Stat, j).value_string,
2149
 
                    team_of_id(g_array_index(players[i], Stat, j).team_id)->name);
 
2216
                    g_array_index(players[i], Stat, j).team_name);
2150
2217
            sprintf(buf4, "%d", g_array_index(players[i], Stat, j).value1);
2151
2218
 
2152
2219
            gtk_list_store_append(ls, &iter);
2248
2315
    }
2249
2316
}
2250
2317
 
2251
 
/** Show the season history of the specified season
2252
 
    and the specified page. Page is either a page of league stats
 
2318
/** Show the season history with given index in the season_stats array
 
2319
    and the specified page. 
 
2320
    @param page Either a page of league stats
2253
2321
    (if != -1) or -1 which means we show the champions. */
2254
2322
void
2255
 
treeview_show_season_history(gint page, gint season_number)
 
2323
treeview_show_season_history(gint page, gint idx)
2256
2324
{
2257
2325
    gchar buf[SMALL];
2258
2326
    GtkTreeView *treeview = GTK_TREE_VIEW(lookup_widget(window.main, "treeview_right"));
2260
2328
        gtk_list_store_new(6, GDK_TYPE_PIXBUF, G_TYPE_INT, G_TYPE_STRING, G_TYPE_STRING,
2261
2329
                           G_TYPE_STRING, G_TYPE_STRING);
2262
2330
    GtkTreeIter iter;
2263
 
    SeasonStat *stat = &g_array_index(season_stats, SeasonStat, season_number);
 
2331
    SeasonStat *stat = &g_array_index(season_stats, SeasonStat, idx);
2264
2332
 
2265
2333
    treeview_helper_clear(treeview);
2266
2334
 
2267
2335
    treeview_set_up_league_stats(treeview);
2268
2336
 
2269
 
    sprintf(buf, _("Season %d"), season_number + 1);
 
2337
    sprintf(buf, _("Season %d"), stat->season_number);
2270
2338
    gtk_list_store_append(model, &iter);
2271
2339
    gtk_list_store_set(model, &iter, 0, NULL,
2272
2340
                       1, const_int("int_treeview_helper_int_empty"),
2273
2341
                       2, buf, -1);
2274
2342
 
2275
2343
    if(page != -1)
2276
 
        treeview_create_league_stats(model, 
2277
 
                                     &g_array_index(stat->league_stats, LeagueStat, page));
 
2344
        treeview_create_league_stats(
 
2345
            model, &g_array_index(stat->league_stats, LeagueStat, page));
2278
2346
    else
2279
 
        treeview_create_season_history_champions(model, stat->league_champs,
2280
 
                                                 stat->cup_champs);
 
2347
        treeview_create_season_history_champions(
 
2348
            model, stat->league_champs, stat->cup_champs);
2281
2349
 
2282
2350
    gtk_tree_view_set_model(treeview, GTK_TREE_MODEL(model));
2283
2351
    g_object_unref(model);
2310
2378
 
2311
2379
/** Show the list of contributors in the help window.*/
2312
2380
void
2313
 
treeview_show_contributors(const OptionList *help_list)
 
2381
treeview_show_contributors(GtkTreeView *treeview)
2314
2382
{
2315
 
    GtkTreeView *treeview = GTK_TREE_VIEW(lookup_widget(window.help, "treeview_contributors"));
 
2383
    gchar *help_file = file_find_support_file("bygfoot_help", TRUE);
 
2384
    OptionList help_list;
2316
2385
    GtkListStore *ls = gtk_list_store_new(1, G_TYPE_STRING);
2317
2386
    GtkTreeIter iter;
2318
2387
    GtkTreeViewColumn   *col;
2320
2389
    gint i;
2321
2390
    gchar buf[SMALL];
2322
2391
 
 
2392
 
 
2393
    if(help_file == NULL)
 
2394
    {
 
2395
        game_gui_show_warning(_("Didn't find file 'bygfoot_help'."));
 
2396
        return;
 
2397
    }
 
2398
 
 
2399
    help_list.list = NULL;
 
2400
    help_list.datalist = NULL;
 
2401
    file_load_opt_file(help_file, &help_list);
 
2402
 
2323
2403
    gtk_tree_selection_set_mode(gtk_tree_view_get_selection(treeview),
2324
2404
                                GTK_SELECTION_NONE);
2325
2405
    gtk_tree_view_set_rules_hint(treeview, FALSE);
2332
2412
    gtk_tree_view_column_add_attribute(col, renderer,
2333
2413
                                       "markup", 0);
2334
2414
 
2335
 
    for(i=0;i<help_list->list->len;i++)
 
2415
    for(i=0;i<help_list.list->len;i++)
2336
2416
    {
2337
2417
        gtk_list_store_append(ls, &iter);
2338
2418
        
2339
 
        if(g_str_has_prefix(g_array_index(help_list->list, Option, i).name,
 
2419
        if(g_str_has_prefix(g_array_index(help_list.list, Option, i).name,
2340
2420
                            "string_contrib_title"))
2341
2421
        {
2342
2422
            sprintf(buf, "\n<span %s>%s</span>", 
2343
2423
                    const_app("string_help_window_title_attribute"),
2344
 
                    g_array_index(help_list->list, Option, i).string_value);
 
2424
                    g_array_index(help_list.list, Option, i).string_value);
2345
2425
            gtk_list_store_set(ls, &iter, 0, buf, -1);
2346
2426
        }
2347
 
        else if(g_str_has_prefix(g_array_index(help_list->list, Option, i).name,
 
2427
        else if(g_str_has_prefix(g_array_index(help_list.list, Option, i).name,
2348
2428
                                 "string_contrib_"))
2349
2429
        {
2350
 
            strcpy(buf, g_array_index(help_list->list, Option, i).string_value);
 
2430
            strcpy(buf, g_array_index(help_list.list, Option, i).string_value);
2351
2431
            gtk_list_store_set(ls, &iter, 0, buf, -1);
2352
2432
        }
2353
2433
 
2355
2435
 
2356
2436
    gtk_tree_view_set_model(treeview, GTK_TREE_MODEL(ls));
2357
2437
    g_object_unref(ls);
 
2438
 
 
2439
    g_free(help_file);
 
2440
    free_option_list(&help_list, FALSE);
2358
2441
}
2359
2442
 
2360
2443
GtkTreeModel*