///////////////////////////////////////////////////////////////////////////// // Name: abridge.cpp // tag: the aBridge main application // Author: David Roundy // Modified by: // Copyright: (c) 2001 David Roundy // Licence: GPL //--------------------------------------------------------------------------- // Last modified: Sept 9 2001 /* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ ///////////////////////////////////////////////////////////////////////////// // For compilers that support precompilation, includes . #include #ifndef WX_PRECOMP #include #include #include #include #include #endif #include "speech.h" #include "irc.h" #include "room.h" #include "table.h" #include "globals.h" #include "preferences.h" #include "prefmacros.h" #include "playerdata.h" #include "random.h" #include "abridgemenus.h" #include "debug.h" #ifdef wx_x #include "cards.xbm" #endif BEGIN_EVENT_TABLE(aBridgeApp, wxApp) EVT_MENU(EXIT, aBridgeApp::Exit) EVT_MENU(ABOUT, aBridgeApp::About) EVT_MENU(PREFERENCES, aBridgeApp::Preferences) END_EVENT_TABLE() static wxString my_player_name = "John Doe"; // Create a new application object IMPLEMENT_APP (aBridgeApp) bool aBridgeApp::OnInit() { // Seed the random number generator with the time. srand(wxGetUTCTime()); init_speech(); wxInitAllImageHandlers(); // First, find out the player's name! my_player_name = AskPlayerName(); // Set up the IRC object! SetUpIrc(); if (my_player_name.IsSameAs("")) { DebugMsg("I think someone cancelled..."); return false; } wxBusyCursor(); wxSleep(1); wxEndBusyCursor(); aBridgeRoom* frame = new aBridgeRoom(0,"aBridge Lobby",-1, -1, 820, 450, m_irc, "#abridge"); // Show the frame frame->Show(TRUE); SetTopWindow(frame); return TRUE; } void aBridgeApp::SetUpIrc() { // Start up the IRC object itself... m_irc = new Irc(); wxString hostname = _(DEFAULT_SERVER); if (GetAskServer() || hostname.IsSameAs("")) { hostname = wxGetTextFromUser( _("Enter the address of the IRC server:"), _("Connect..."), hostname); } if (!hostname.IsSameAs("")) { m_irc->Connect(hostname, 6667, player_name()); } else { my_player_name = ""; // A flag to exit immediately, someone hit cancel. DebugMsg("Aaaack bad server name!"); } // I want to wait here for connection... } wxString aBridgeApp::AskPlayerName() { // First, creating the global config object, once and for all! wxConfig *config = new wxConfig("abridge",wxEmptyString,".abridgerc"); config->Set(config); wxString the_name = GetPlayerName(); if (GetAskName()) { the_name = wxGetTextFromUser( _("What is your name?"), _("Player name..."), the_name); if (the_name.IsSameAs("")) { DebugMsg("You cancelled on player name input"); } else { DebugMsg("You entered player name '" + the_name + "'"); wxConfig::Get()->Write("/Player/Name", the_name); wxConfig::Get()->Flush(); } } return the_name; } void aBridgeApp::Exit(wxCommandEvent&) { // For some reason this seems to work all right on Mac even doing nothing // here... GetTopWindow()->Close(); } void aBridgeApp::About(wxCommandEvent&) { DebugMsg("I'm in abridge app right now..."); wxMessageBox("aBridge " VERSION "\n\n" "A free software game written using the wxWindows\n" "portable C++ GUI toolkit.\n\n" "http://www.abridgegame.org\n" "Author: David Roundy (c) 2001,2002\n", "About aBridge", wxOK, GetTopWindow()); } void aBridgeApp::Preferences(wxCommandEvent&) { aBridgePreferences *prefs = new aBridgePreferences((wxFrame *)GetTopWindow()); prefs->Show(true); } wxString player_name() { return my_player_name; } unsigned long Random() { return rand(); }