mirror of https://github.com/tstellar/bygfoot.git
Betting, first draft.
This commit is contained in:
parent
79f1fea94e
commit
1b29b6284f
|
@ -0,0 +1,192 @@
|
|||
<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
|
||||
<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">
|
||||
|
||||
<glade-interface>
|
||||
|
||||
<widget class="GtkWindow" id="window_bets">
|
||||
<property name="border_width">5</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="title" translatable="yes"></property>
|
||||
<property name="type">GTK_WINDOW_TOPLEVEL</property>
|
||||
<property name="window_position">GTK_WIN_POS_CENTER</property>
|
||||
<property name="modal">True</property>
|
||||
<property name="default_width">600</property>
|
||||
<property name="default_height">700</property>
|
||||
<property name="resizable">True</property>
|
||||
<property name="destroy_with_parent">False</property>
|
||||
<property name="decorated">True</property>
|
||||
<property name="skip_taskbar_hint">False</property>
|
||||
<property name="skip_pager_hint">False</property>
|
||||
<property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
|
||||
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
|
||||
<signal name="delete_event" handler="on_window_bets_delete_event" last_modification_time="Thu, 27 Oct 2005 17:10:03 GMT"/>
|
||||
|
||||
<child>
|
||||
<widget class="GtkVBox" id="vbox1">
|
||||
<property name="visible">True</property>
|
||||
<property name="homogeneous">False</property>
|
||||
<property name="spacing">3</property>
|
||||
|
||||
<child>
|
||||
<widget class="GtkLabel" id="label1">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">Betting -- Left click on odd to place or remove bet</property>
|
||||
<property name="use_underline">False</property>
|
||||
<property name="use_markup">False</property>
|
||||
<property name="justify">GTK_JUSTIFY_LEFT</property>
|
||||
<property name="wrap">False</property>
|
||||
<property name="selectable">False</property>
|
||||
<property name="xalign">0.5</property>
|
||||
<property name="yalign">0.5</property>
|
||||
<property name="xpad">0</property>
|
||||
<property name="ypad">0</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="padding">0</property>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
</packing>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<widget class="GtkHSeparator" id="hseparator1">
|
||||
<property name="width_request">1</property>
|
||||
<property name="height_request">10</property>
|
||||
<property name="visible">True</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="padding">0</property>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
</packing>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<widget class="GtkHBox" id="hbox1">
|
||||
<property name="visible">True</property>
|
||||
<property name="homogeneous">False</property>
|
||||
<property name="spacing">0</property>
|
||||
|
||||
<child>
|
||||
<widget class="GtkCheckButton" id="checkbutton_bet_all_leagues">
|
||||
<property name="visible">True</property>
|
||||
<property name="tooltip" translatable="yes">Whether to show matches of all leagues. Use the options window to toggle permanently.</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="label" translatable="yes">Show matches from all leagues</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>
|
||||
<signal name="button_press_event" handler="on_checkbutton_bet_all_leagues_button_press_event" last_modification_time="Thu, 27 Oct 2005 19:23:57 GMT"/>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="padding">0</property>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<widget class="GtkCheckButton" id="checkbutton_bet_cups">
|
||||
<property name="visible">True</property>
|
||||
<property name="tooltip" translatable="yes">Whether to show cup matches. Use the options window to toggle permanently.</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="label" translatable="yes">Show matches from cups</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>
|
||||
<signal name="button_press_event" handler="on_checkbutton_bet_cups_button_press_event" last_modification_time="Thu, 27 Oct 2005 19:24:05 GMT"/>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="padding">0</property>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
</packing>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<widget class="GtkCheckButton" id="checkbutton_bet_user_recent">
|
||||
<property name="visible">True</property>
|
||||
<property name="tooltip" translatable="yes">Whether to show only your bets in the recent bets list</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="label" translatable="yes">Show only my recent bets</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>
|
||||
<signal name="button_press_event" handler="on_checkbutton_bet_user_recent_button_press_event" last_modification_time="Thu, 27 Oct 2005 19:45:03 GMT"/>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="padding">0</property>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="padding">0</property>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
</packing>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<widget class="GtkHSeparator" id="hseparator2">
|
||||
<property name="width_request">1</property>
|
||||
<property name="height_request">10</property>
|
||||
<property name="visible">True</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="padding">0</property>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
</packing>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<widget class="GtkTreeView" id="treeview_bets">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="headers_visible">True</property>
|
||||
<property name="rules_hint">False</property>
|
||||
<property name="reorderable">False</property>
|
||||
<property name="enable_search">True</property>
|
||||
<signal name="button_press_event" handler="on_treeview_bets_button_press_event" last_modification_time="Thu, 27 Oct 2005 19:43:51 GMT"/>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="padding">0</property>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<widget class="GtkButton" id="button_bet_close">
|
||||
<property name="visible">True</property>
|
||||
<property name="tooltip" translatable="yes">Esc</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="label">gtk-close</property>
|
||||
<property name="use_stock">True</property>
|
||||
<property name="relief">GTK_RELIEF_NORMAL</property>
|
||||
<property name="focus_on_click">True</property>
|
||||
<signal name="clicked" handler="on_button_bet_close_clicked" last_modification_time="Thu, 27 Oct 2005 17:12:51 GMT"/>
|
||||
<accelerator key="Escape" modifiers="0" signal="clicked"/>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="padding">0</property>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
</child>
|
||||
</widget>
|
||||
|
||||
</glade-interface>
|
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
|
||||
<!DOCTYPE glade-project SYSTEM "http://glade.gnome.org/glade-project-2.0.dtd">
|
||||
|
||||
<glade-project>
|
||||
<name>bygfoot_misc3</name>
|
||||
<program_name>bygfoot_misc3</program_name>
|
||||
<pixmaps_directory>support_files/pixmaps</pixmaps_directory>
|
||||
<gnome_support>FALSE</gnome_support>
|
||||
<output_main_file>FALSE</output_main_file>
|
||||
<output_support_files>FALSE</output_support_files>
|
||||
<output_build_files>FALSE</output_build_files>
|
||||
<backup_source_files>FALSE</backup_source_files>
|
||||
<main_source_file>misc3_interface.c</main_source_file>
|
||||
<main_header_file>misc3_interface.h</main_header_file>
|
||||
<handler_source_file>misc3_callbacks.c</handler_source_file>
|
||||
<handler_header_file>misc3_callbacks.h</handler_header_file>
|
||||
</glade-project>
|
|
@ -0,0 +1,250 @@
|
|||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#include "bet.h"
|
||||
#include "finance.h"
|
||||
#include "fixture.h"
|
||||
#include "game_gui.h"
|
||||
#include "league.h"
|
||||
#include "main.h"
|
||||
#include "maths.h"
|
||||
#include "option.h"
|
||||
#include "player.h"
|
||||
#include "treeview2.h"
|
||||
#include "user.h"
|
||||
|
||||
/** Round a betting odd to a multiple of 0.05. */
|
||||
gfloat
|
||||
bet_round_odd(gfloat odd)
|
||||
{
|
||||
gint local_odd = (gint)rint(odd * 100);
|
||||
|
||||
if(local_odd % 5 == 0)
|
||||
return odd;
|
||||
|
||||
if(local_odd % 5 >= 3)
|
||||
return (gfloat)(local_odd + (5 - local_odd % 5)) / 100;
|
||||
|
||||
return (gfloat)(local_odd - local_odd % 5) / 100;
|
||||
}
|
||||
|
||||
/** Find the bet containing the fixture. */
|
||||
BetMatch*
|
||||
bet_from_fixture(const Fixture *fix)
|
||||
{
|
||||
gint i, j;
|
||||
|
||||
for(i=1;i>=0;i--)
|
||||
for(j=0;j<bets[i]->len;j++)
|
||||
if(g_array_index(bets[i], BetMatch, j).fix == fix)
|
||||
return &g_array_index(bets[i], BetMatch, j);
|
||||
|
||||
main_exit_program(EXIT_BET_ERROR,
|
||||
"bet_from_fixture: bet going with fixture %s %s - %s not found",
|
||||
league_cup_get_name_string(fix->clid),
|
||||
fix->teams[0]->name, fix->teams[0]->name);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/** Manage the bets made by the users. */
|
||||
void
|
||||
bet_update_user_bets(void)
|
||||
{
|
||||
gint i, j, outcome;
|
||||
const BetMatch *bet;
|
||||
|
||||
for(i=0;i<users->len;i++)
|
||||
{
|
||||
g_array_free(usr(i).bets[0], TRUE);
|
||||
usr(i).bets[0] = g_array_new(FALSE, FALSE, sizeof(BetUser));
|
||||
|
||||
for(j=0;j<usr(i).bets[1]->len;j++)
|
||||
{
|
||||
bet = bet_from_fixture(g_array_index(usr(i).bets[1], BetUser, j).fix);
|
||||
|
||||
if(bet->fix->result[0][0] < bet->fix->result[1][0])
|
||||
outcome = 2;
|
||||
else
|
||||
outcome = (bet->fix->result[0][0] == bet->fix->result[1][0]);
|
||||
|
||||
if(outcome == g_array_index(usr(i).bets[1], BetUser, j).outcome)
|
||||
{
|
||||
usr(i).money +=
|
||||
(gint)rint((gfloat)g_array_index(usr(i).bets[1], BetUser, j).wager *
|
||||
bet->odds[outcome]);
|
||||
usr(i).money_in[1][MON_IN_BETS] +=
|
||||
(gint)rint((gfloat)g_array_index(usr(i).bets[1], BetUser, j).wager *
|
||||
bet->odds[outcome]);
|
||||
g_array_index(usr(i).bets[1], BetUser, j).wager =
|
||||
(gint)rint((gfloat)g_array_index(usr(i).bets[1], BetUser, j).wager *
|
||||
bet->odds[outcome]);
|
||||
}
|
||||
else
|
||||
{
|
||||
usr(i).money -=
|
||||
g_array_index(usr(i).bets[1], BetUser, j).wager;
|
||||
usr(i).money_out[1][MON_OUT_BETS] -=
|
||||
g_array_index(usr(i).bets[1], BetUser, j).wager;
|
||||
g_array_index(usr(i).bets[1], BetUser, j).wager *= -1;
|
||||
}
|
||||
|
||||
g_array_append_val(usr(i).bets[0],
|
||||
g_array_index(usr(i).bets[1], BetUser, j));
|
||||
}
|
||||
|
||||
g_array_free(usr(i).bets[1], TRUE);
|
||||
usr(i).bets[1] = g_array_new(FALSE, FALSE, sizeof(BetUser));
|
||||
}
|
||||
}
|
||||
|
||||
/** Calculate the odds for the bet. */
|
||||
void
|
||||
bet_get_odds(BetMatch *bet)
|
||||
{
|
||||
gfloat home_advantage = (bet->fix->home_advantage) ?
|
||||
(const_float("float_game_home_advantage_lower") +
|
||||
const_float("float_game_home_advantage_upper")) / 2 : 0;
|
||||
gfloat av_skill[2] = {0, 0}, skilldiff;
|
||||
gint i, j, better_idx;
|
||||
|
||||
for(i=0;i<2;i++)
|
||||
{
|
||||
for(j=0;j<11;j++)
|
||||
av_skill[i] +=
|
||||
player_get_game_skill(player_of_idx_team(bet->fix->teams[i], j),
|
||||
FALSE);
|
||||
|
||||
av_skill[i] /= 11;
|
||||
}
|
||||
|
||||
av_skill[0] *= (1 + home_advantage);
|
||||
|
||||
skilldiff = ABS(av_skill[0] - av_skill[1]);
|
||||
|
||||
better_idx = 2 * (av_skill[0] < av_skill[1]);
|
||||
|
||||
bet->odds[better_idx] =
|
||||
0.33 + skilldiff * const_float("float_bet_better_factor");
|
||||
bet->odds[2 - better_idx] =
|
||||
0.33 + skilldiff * const_float("float_bet_worse_factor");
|
||||
|
||||
for(i=0;i<2;i++)
|
||||
bet->odds[i * 2] = CLAMP(bet->odds[i * 2],
|
||||
const_float("float_bet_lower_limit"),
|
||||
1 - const_float("float_bet_lower_limit"));
|
||||
|
||||
bet->odds[1] = (1 - bet->odds[0] - bet->odds[2]);
|
||||
bet->odds[1] = CLAMP(bet->odds[1],
|
||||
const_float("float_bet_lower_limit"),
|
||||
1 - const_float("float_bet_lower_limit"));
|
||||
|
||||
for(i=0;i<3;i++)
|
||||
bet->odds[i] =
|
||||
bet_round_odd((1 / bet->odds[i]) *
|
||||
(1 - const_float("float_bet_commission_decrease")));
|
||||
}
|
||||
|
||||
/** Write the bets for the current week round. */
|
||||
void
|
||||
bet_update(void)
|
||||
{
|
||||
gint i;
|
||||
GPtrArray *fixtures = fixture_get_week_list(week, week_round);
|
||||
BetMatch new_bet;
|
||||
|
||||
bet_update_user_bets();
|
||||
|
||||
g_array_free(bets[0], TRUE);
|
||||
bets[0] = g_array_new(FALSE, FALSE, sizeof(BetMatch));
|
||||
|
||||
for(i=0;i<bets[1]->len;i++)
|
||||
g_array_append_val(bets[0],
|
||||
g_array_index(bets[1], BetMatch, i));
|
||||
|
||||
g_array_free(bets[1], TRUE);
|
||||
bets[1] = g_array_new(FALSE, FALSE, sizeof(BetMatch));
|
||||
|
||||
for(i=0;i<fixtures->len;i++)
|
||||
if(fixture_user_team_involved((Fixture*)g_ptr_array_index(fixtures, i)) == -1)
|
||||
{
|
||||
new_bet.fix = (Fixture*)g_ptr_array_index(fixtures, i);
|
||||
bet_get_odds(&new_bet);
|
||||
g_array_append_val(bets[1], new_bet);
|
||||
}
|
||||
|
||||
g_ptr_array_free(fixtures, TRUE);
|
||||
}
|
||||
|
||||
/** Return the user bet if the user betted on the bet or NULL. */
|
||||
BetUser*
|
||||
bet_is_user(const BetMatch *bet)
|
||||
{
|
||||
gint i, j;
|
||||
|
||||
for(i=1;i>=0;i--)
|
||||
for(j=0;j<current_user.bets[i]->len;j++)
|
||||
if(bet->fix == g_array_index(current_user.bets[i], BetUser, j).fix)
|
||||
return &g_array_index(current_user.bets[i], BetUser, j);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/** Place a new bet. */
|
||||
void
|
||||
bet_place(const Fixture *fix, gint outcome, gint wager)
|
||||
{
|
||||
BetUser new_bet;
|
||||
|
||||
if(wager <= 0)
|
||||
return;
|
||||
|
||||
if(wager > BUDGET(cur_user))
|
||||
{
|
||||
game_gui_show_warning(_("You don't have the money."));
|
||||
return;
|
||||
}
|
||||
|
||||
new_bet.fix = fix;
|
||||
new_bet.outcome = outcome;
|
||||
new_bet.wager = wager;
|
||||
|
||||
g_array_append_val(current_user.bets[1], new_bet);
|
||||
|
||||
if(window.bets != NULL)
|
||||
treeview2_show_bets();
|
||||
}
|
||||
|
||||
/** Remove the bet on the given fixture. */
|
||||
void
|
||||
bet_remove(const Fixture *fix)
|
||||
{
|
||||
gint i;
|
||||
|
||||
for(i=0;i<current_user.bets[1]->len;i++)
|
||||
if(g_array_index(current_user.bets[1], BetUser, i).fix == fix)
|
||||
{
|
||||
g_array_remove_index(current_user.bets[1], i);
|
||||
return;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef BET_H
|
||||
#define BET_H
|
||||
|
||||
#include "bet_struct.h"
|
||||
#include "bygfoot.h"
|
||||
#include "fixture_struct.h"
|
||||
|
||||
BetMatch*
|
||||
bet_from_fixture(const Fixture *fix);
|
||||
|
||||
void
|
||||
bet_update_user_bets(void);
|
||||
|
||||
void
|
||||
bet_get_odds(BetMatch *bet);
|
||||
|
||||
void
|
||||
bet_update(void);
|
||||
|
||||
gfloat
|
||||
bet_round_odd(gfloat odd);
|
||||
|
||||
BetUser*
|
||||
bet_is_user(const BetMatch *bet);
|
||||
|
||||
void
|
||||
bet_place(const Fixture *fix, gint outcome, gint wager);
|
||||
|
||||
void
|
||||
bet_remove(const Fixture *fix);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef BET_STRUCT_H
|
||||
#define BET_STRUCT_H
|
||||
|
||||
#include "bygfoot.h"
|
||||
#include "fixture_struct.h"
|
||||
|
||||
/** A struct representing a betting possibility: a fixture plus odds. */
|
||||
typedef struct
|
||||
{
|
||||
/** The match the bet is about. */
|
||||
const Fixture *fix;
|
||||
/** The odds for a win, draw or loss of the first team. */
|
||||
gfloat odds[3];
|
||||
|
||||
} BetMatch;
|
||||
|
||||
/** A struct representing a bet by a user. */
|
||||
typedef struct
|
||||
{
|
||||
/** Match the user betted on. */
|
||||
const Fixture *fix;
|
||||
/** Which outcome he picked. */
|
||||
gint outcome;
|
||||
/** How much he wagered. */
|
||||
gint wager;
|
||||
} BetUser;
|
||||
|
||||
#endif
|
|
@ -0,0 +1,150 @@
|
|||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#include "bet.h"
|
||||
#include "misc3_callbacks.h"
|
||||
#include "misc3_interface.h"
|
||||
#include "option.h"
|
||||
#include "support.h"
|
||||
#include "treeview2.h"
|
||||
#include "treeview_helper.h"
|
||||
#include "user.h"
|
||||
#include "variables.h"
|
||||
#include "window.h"
|
||||
|
||||
gboolean
|
||||
on_window_bets_delete_event (GtkWidget *widget,
|
||||
GdkEvent *event,
|
||||
gpointer user_data)
|
||||
{
|
||||
on_button_bet_close_clicked(NULL, NULL);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
on_button_bet_close_clicked (GtkButton *button,
|
||||
gpointer user_data)
|
||||
{
|
||||
window_destroy(&window.bets, FALSE);
|
||||
}
|
||||
|
||||
gboolean
|
||||
on_checkbutton_bet_all_leagues_button_press_event
|
||||
(GtkWidget *widget,
|
||||
GdkEventButton *event,
|
||||
gpointer user_data)
|
||||
{
|
||||
opt_user_set_int("int_opt_user_bet_show_all_leagues",
|
||||
!opt_user_int("int_opt_user_bet_show_all_leagues"));
|
||||
|
||||
treeview2_show_bets();
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
gboolean
|
||||
on_checkbutton_bet_cups_button_press_event
|
||||
(GtkWidget *widget,
|
||||
GdkEventButton *event,
|
||||
gpointer user_data)
|
||||
{
|
||||
opt_user_set_int("int_opt_user_bet_show_cups",
|
||||
!opt_user_int("int_opt_user_bet_show_cups"));
|
||||
|
||||
treeview2_show_bets();
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
gboolean
|
||||
on_treeview_bets_button_press_event (GtkWidget *widget,
|
||||
GdkEventButton *event,
|
||||
gpointer user_data)
|
||||
{
|
||||
GtkTreePath *path = NULL;
|
||||
GtkTreeViewColumn *col = NULL;
|
||||
GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(widget));
|
||||
GtkTreeIter iter;
|
||||
const BetMatch *bet = NULL;
|
||||
gint col_num = -1;
|
||||
gchar buf[SMALL];
|
||||
|
||||
if(!gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget),
|
||||
event->x, event->y,
|
||||
&path, &col, NULL, NULL))
|
||||
return TRUE;
|
||||
|
||||
if(!gtk_tree_model_get_iter(model, &iter, path))
|
||||
{
|
||||
gtk_tree_path_free(path);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gtk_tree_path_free(path);
|
||||
col_num = treeview_helper_get_col_number_column(col);
|
||||
|
||||
if(col_num == 0 || col_num > 3)
|
||||
return TRUE;
|
||||
|
||||
gtk_tree_model_get(model, &iter, col_num, &bet, -1);
|
||||
|
||||
if(bet == NULL || bet->fix->attendance != -1)
|
||||
return TRUE;
|
||||
|
||||
if(bet_is_user(bet))
|
||||
{
|
||||
bet_remove(bet->fix);
|
||||
treeview2_show_bets();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
sprintf(buf, _("You bet on outcome %d with an odd of %.2f. How much do you wager?"),
|
||||
col_num - 1, bet->odds[col_num - 1]);
|
||||
|
||||
statp = (gpointer)bet->fix;
|
||||
stat1 = STATUS_PLACE_BET;
|
||||
stat2 = col_num - 1;
|
||||
|
||||
window_show_digits(buf, _("Wager"), 0, NULL, -1);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
gboolean
|
||||
on_checkbutton_bet_user_recent_button_press_event
|
||||
(GtkWidget *widget,
|
||||
GdkEventButton *event,
|
||||
gpointer user_data)
|
||||
{
|
||||
opt_user_set_int("int_opt_user_bet_show_my_recent",
|
||||
!opt_user_int("int_opt_user_bet_show_my_recent"));
|
||||
|
||||
treeview2_show_bets();
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef MISC2_CALLBACKS_H
|
||||
#define MISC2_CALLBACKS_H
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
|
||||
gboolean
|
||||
on_window_bets_delete_event (GtkWidget *widget,
|
||||
GdkEvent *event,
|
||||
gpointer user_data);
|
||||
|
||||
void
|
||||
on_button_bet_close_clicked (GtkButton *button,
|
||||
gpointer user_data);
|
||||
gboolean
|
||||
on_checkbutton_bet_all_leagues_button_press_event
|
||||
(GtkWidget *widget,
|
||||
GdkEventButton *event,
|
||||
gpointer user_data);
|
||||
|
||||
gboolean
|
||||
on_checkbutton_bet_cups_button_press_event
|
||||
(GtkWidget *widget,
|
||||
GdkEventButton *event,
|
||||
gpointer user_data);
|
||||
|
||||
gboolean
|
||||
on_treeview_bets_button_press_event (GtkWidget *widget,
|
||||
GdkEventButton *event,
|
||||
gpointer user_data);
|
||||
|
||||
gboolean
|
||||
on_checkbutton_bet_user_recent_button_press_event
|
||||
(GtkWidget *widget,
|
||||
GdkEventButton *event,
|
||||
gpointer user_data);
|
||||
#endif
|
|
@ -0,0 +1,142 @@
|
|||
/*
|
||||
* DO NOT EDIT THIS FILE - it is generated by Glade.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <gdk/gdkkeysyms.h>
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "misc3_callbacks.h"
|
||||
#include "misc3_interface.h"
|
||||
#include "support.h"
|
||||
|
||||
#define GLADE_HOOKUP_OBJECT(component,widget,name) \
|
||||
g_object_set_data_full (G_OBJECT (component), name, \
|
||||
gtk_widget_ref (widget), (GDestroyNotify) gtk_widget_unref)
|
||||
|
||||
#define GLADE_HOOKUP_OBJECT_NO_REF(component,widget,name) \
|
||||
g_object_set_data (G_OBJECT (component), name, widget)
|
||||
|
||||
GtkWidget*
|
||||
create_window_bets (void)
|
||||
{
|
||||
GtkWidget *window_bets;
|
||||
GtkWidget *vbox1;
|
||||
GtkWidget *label1;
|
||||
GtkWidget *hseparator1;
|
||||
GtkWidget *hbox1;
|
||||
GtkWidget *checkbutton_bet_all_leagues;
|
||||
GtkWidget *checkbutton_bet_cups;
|
||||
GtkWidget *checkbutton_bet_user_recent;
|
||||
GtkWidget *hseparator2;
|
||||
GtkWidget *treeview_bets;
|
||||
GtkWidget *button_bet_close;
|
||||
GtkAccelGroup *accel_group;
|
||||
GtkTooltips *tooltips;
|
||||
|
||||
tooltips = gtk_tooltips_new ();
|
||||
|
||||
accel_group = gtk_accel_group_new ();
|
||||
|
||||
window_bets = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||
gtk_container_set_border_width (GTK_CONTAINER (window_bets), 5);
|
||||
gtk_window_set_position (GTK_WINDOW (window_bets), GTK_WIN_POS_CENTER);
|
||||
gtk_window_set_modal (GTK_WINDOW (window_bets), TRUE);
|
||||
gtk_window_set_default_size (GTK_WINDOW (window_bets), 600, 700);
|
||||
|
||||
vbox1 = gtk_vbox_new (FALSE, 3);
|
||||
gtk_widget_show (vbox1);
|
||||
gtk_container_add (GTK_CONTAINER (window_bets), vbox1);
|
||||
|
||||
label1 = gtk_label_new (_("Betting -- Left click on odd to place or remove bet"));
|
||||
gtk_widget_show (label1);
|
||||
gtk_box_pack_start (GTK_BOX (vbox1), label1, FALSE, FALSE, 0);
|
||||
|
||||
hseparator1 = gtk_hseparator_new ();
|
||||
gtk_widget_show (hseparator1);
|
||||
gtk_box_pack_start (GTK_BOX (vbox1), hseparator1, FALSE, FALSE, 0);
|
||||
gtk_widget_set_size_request (hseparator1, 1, 10);
|
||||
|
||||
hbox1 = gtk_hbox_new (FALSE, 0);
|
||||
gtk_widget_show (hbox1);
|
||||
gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, FALSE, 0);
|
||||
|
||||
checkbutton_bet_all_leagues = gtk_check_button_new_with_mnemonic (_("Show matches from all leagues"));
|
||||
gtk_widget_show (checkbutton_bet_all_leagues);
|
||||
gtk_box_pack_start (GTK_BOX (hbox1), checkbutton_bet_all_leagues, TRUE, TRUE, 0);
|
||||
gtk_tooltips_set_tip (tooltips, checkbutton_bet_all_leagues, _("Whether to show matches of all leagues. Use the options window to toggle permanently."), NULL);
|
||||
|
||||
checkbutton_bet_cups = gtk_check_button_new_with_mnemonic (_("Show matches from cups"));
|
||||
gtk_widget_show (checkbutton_bet_cups);
|
||||
gtk_box_pack_start (GTK_BOX (hbox1), checkbutton_bet_cups, FALSE, FALSE, 0);
|
||||
gtk_tooltips_set_tip (tooltips, checkbutton_bet_cups, _("Whether to show cup matches. Use the options window to toggle permanently."), NULL);
|
||||
|
||||
checkbutton_bet_user_recent = gtk_check_button_new_with_mnemonic (_("Show only my recent bets"));
|
||||
gtk_widget_show (checkbutton_bet_user_recent);
|
||||
gtk_box_pack_start (GTK_BOX (hbox1), checkbutton_bet_user_recent, TRUE, TRUE, 0);
|
||||
gtk_tooltips_set_tip (tooltips, checkbutton_bet_user_recent, _("Whether to show only your bets in the recent bets list"), NULL);
|
||||
|
||||
hseparator2 = gtk_hseparator_new ();
|
||||
gtk_widget_show (hseparator2);
|
||||
gtk_box_pack_start (GTK_BOX (vbox1), hseparator2, FALSE, FALSE, 0);
|
||||
gtk_widget_set_size_request (hseparator2, 1, 10);
|
||||
|
||||
treeview_bets = gtk_tree_view_new ();
|
||||
gtk_widget_show (treeview_bets);
|
||||
gtk_box_pack_start (GTK_BOX (vbox1), treeview_bets, TRUE, TRUE, 0);
|
||||
|
||||
button_bet_close = gtk_button_new_from_stock ("gtk-close");
|
||||
gtk_widget_show (button_bet_close);
|
||||
gtk_box_pack_start (GTK_BOX (vbox1), button_bet_close, FALSE, FALSE, 0);
|
||||
gtk_tooltips_set_tip (tooltips, button_bet_close, _("Esc"), NULL);
|
||||
gtk_widget_add_accelerator (button_bet_close, "clicked", accel_group,
|
||||
GDK_Escape, 0,
|
||||
GTK_ACCEL_VISIBLE);
|
||||
|
||||
g_signal_connect ((gpointer) window_bets, "delete_event",
|
||||
G_CALLBACK (on_window_bets_delete_event),
|
||||
NULL);
|
||||
g_signal_connect ((gpointer) checkbutton_bet_all_leagues, "button_press_event",
|
||||
G_CALLBACK (on_checkbutton_bet_all_leagues_button_press_event),
|
||||
NULL);
|
||||
g_signal_connect ((gpointer) checkbutton_bet_cups, "button_press_event",
|
||||
G_CALLBACK (on_checkbutton_bet_cups_button_press_event),
|
||||
NULL);
|
||||
g_signal_connect ((gpointer) checkbutton_bet_user_recent, "button_press_event",
|
||||
G_CALLBACK (on_checkbutton_bet_user_recent_button_press_event),
|
||||
NULL);
|
||||
g_signal_connect ((gpointer) treeview_bets, "button_press_event",
|
||||
G_CALLBACK (on_treeview_bets_button_press_event),
|
||||
NULL);
|
||||
g_signal_connect ((gpointer) button_bet_close, "clicked",
|
||||
G_CALLBACK (on_button_bet_close_clicked),
|
||||
NULL);
|
||||
|
||||
/* Store pointers to all widgets, for use by lookup_widget(). */
|
||||
GLADE_HOOKUP_OBJECT_NO_REF (window_bets, window_bets, "window_bets");
|
||||
GLADE_HOOKUP_OBJECT (window_bets, vbox1, "vbox1");
|
||||
GLADE_HOOKUP_OBJECT (window_bets, label1, "label1");
|
||||
GLADE_HOOKUP_OBJECT (window_bets, hseparator1, "hseparator1");
|
||||
GLADE_HOOKUP_OBJECT (window_bets, hbox1, "hbox1");
|
||||
GLADE_HOOKUP_OBJECT (window_bets, checkbutton_bet_all_leagues, "checkbutton_bet_all_leagues");
|
||||
GLADE_HOOKUP_OBJECT (window_bets, checkbutton_bet_cups, "checkbutton_bet_cups");
|
||||
GLADE_HOOKUP_OBJECT (window_bets, checkbutton_bet_user_recent, "checkbutton_bet_user_recent");
|
||||
GLADE_HOOKUP_OBJECT (window_bets, hseparator2, "hseparator2");
|
||||
GLADE_HOOKUP_OBJECT (window_bets, treeview_bets, "treeview_bets");
|
||||
GLADE_HOOKUP_OBJECT (window_bets, button_bet_close, "button_bet_close");
|
||||
GLADE_HOOKUP_OBJECT_NO_REF (window_bets, tooltips, "tooltips");
|
||||
|
||||
gtk_window_add_accel_group (GTK_WINDOW (window_bets), accel_group);
|
||||
|
||||
return window_bets;
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
/*
|
||||
* DO NOT EDIT THIS FILE - it is generated by Glade.
|
||||
*/
|
||||
|
||||
GtkWidget* create_window_bets (void);
|
Loading…
Reference in New Issue