~ubuntu-branches/ubuntu/trusty/lordsawar/trusty

« back to all changes in this revision

Viewing changes to src/gui/splash-window.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Barry deFreese, Barry deFreese
  • Date: 2008-12-20 13:52:12 UTC
  • mfrom: (1.1.6 upstream) (5.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20081220135212-noeb2w3y98ebo7o9
Tags: 0.1.4-1
[ Barry deFreese ]
* New upstream release.
* Move 0.0.8-2.1 changelog entry to correct point in changelog.
* Make lordsawar-data suggest lordsawar.
* Update my e-mail address.
* Add build-depends on intltool, uuid-dev, and libboost-dev.
* Don't install locales since there are no translations currently.
* Add simple man page for new lordsawar-pbm binary.
* Drop gcc4.3 patches as they have been fixed upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
#include <gtkmm/stock.h>
31
31
 
32
32
#include "splash-window.h"
33
 
#include "game-window.h"
 
33
#include "driver.h"
34
34
 
35
35
#include "game-preferences-dialog.h"
36
36
#include "load-scenario-dialog.h"
 
37
#include "new-campaign-dialog.h"
37
38
#include "glade-helpers.h"
38
 
#include "../Configuration.h"
39
 
#include "../defs.h"
40
 
#include "../sound.h"
41
 
#include "../File.h"
42
 
#include "../GameScenario.h"
43
 
#include "../playerlist.h"
44
 
#include "game-lobby-dialog.h"
 
39
#include "Configuration.h"
 
40
#include "defs.h"
 
41
#include "sound.h"
 
42
#include "File.h"
 
43
#include "GameScenario.h"
 
44
#include "playerlist.h"
45
45
#include "network-game-selector-dialog.h"
46
 
//#include "../netggz.h"
 
46
//#include "netggz.h"
47
47
#include "gtksdl.h"
 
48
#include "main-preferences-dialog.h"
 
49
#include "timed-message-dialog.h"
48
50
 
49
51
namespace
50
52
{
55
57
}
56
58
SplashWindow::SplashWindow()
57
59
{
 
60
  network_game_nickname = "";
58
61
  sdl_inited = false;
59
62
#if 0
60
63
    d_networkcancelled = false;
67
70
    Gtk::Window *w = 0;
68
71
    xml->get_widget("window", w);
69
72
    window.reset(w);
 
73
    decorate(window.get(), File::getMiscFile("various/back.bmp"));
 
74
    window_closed.connect(sigc::mem_fun(this, &SplashWindow::on_window_closed));
70
75
 
71
76
    xml->get_widget("sdl_container", sdl_container);
72
77
    w->signal_delete_event().connect(
85
90
                         sigc::mem_fun(*this, &SplashWindow::on_new_game_clicked));
86
91
    xml->connect_clicked("load_game_button",
87
92
                         sigc::mem_fun(*this, &SplashWindow::on_load_game_clicked));
 
93
    xml->connect_clicked("new_campaign_button",
 
94
                         sigc::mem_fun(*this, &SplashWindow::on_new_campaign_clicked));
88
95
    xml->connect_clicked("load_scenario_button",
89
96
                         sigc::mem_fun(*this, &SplashWindow::on_load_scenario_clicked));
90
97
    xml->connect_clicked("quit_button",
92
99
 
93
100
    xml->connect_clicked("new_network_game_button",
94
101
                         sigc::mem_fun(*this, &SplashWindow::on_new_network_game_clicked));
 
102
    xml->connect_clicked("new_pbm_game_button",
 
103
                         sigc::mem_fun(*this, &SplashWindow::on_new_pbm_game_clicked));
 
104
    xml->connect_clicked("preferences_button",
 
105
                         sigc::mem_fun(*this, &SplashWindow::on_preferences_clicked));
95
106
    Sound::getInstance()->playMusic("intro");
96
107
 
97
108
    if (Configuration::s_autosave_policy == 1)
144
155
    window->hide();
145
156
}
146
157
 
 
158
    
 
159
void SplashWindow::on_window_closed()
 
160
{
 
161
  hide();
 
162
  quit_requested.emit();
 
163
}
 
164
 
147
165
bool SplashWindow::on_delete_event(GdkEventAny *e)
148
166
{
149
167
    quit_requested.emit();
165
183
 
166
184
void SplashWindow::on_new_game_clicked()
167
185
{
168
 
    GamePreferencesDialog d;
 
186
    GamePreferencesDialog d(GameScenario::HOTSEAT);
169
187
    
170
188
    d.set_parent_window(*window.get());
171
189
    d.game_started.connect(sigc::mem_fun(*this, &SplashWindow::on_game_started));
208
226
  dialog.reset(d);
209
227
  xml->get_widget("client_radiobutton", client_radiobutton);
210
228
  dialog->set_transient_for(*window.get());
 
229
  Gtk::Entry *nick_entry;
 
230
  xml->get_widget("nick_entry", nick_entry);
 
231
  std::string nick;
 
232
  if (getenv("USER"))
 
233
    nick = getenv("USER");
 
234
  else if (network_game_nickname != "")
 
235
    nick = network_game_nickname;
 
236
  else
 
237
    nick = "guest";
 
238
  nick_entry->set_text(nick);
 
239
  nick_entry->set_activates_default(true);
211
240
  int response = dialog->run();
 
241
  dialog->hide();
212
242
  if (response == 0) //we hit okay
213
243
    {
 
244
      network_game_nickname = nick_entry->get_text();
214
245
      if (client_radiobutton->get_active() == true)
215
246
        {
216
 
          Gtk::MessageDialog mdialog(*window.get(), "not implemented yet.");
217
 
          mdialog.show_all();
218
 
          mdialog.run();
219
247
          NetworkGameSelectorDialog ngsd;
220
248
          ngsd.game_selected.connect(sigc::mem_fun(*this, &SplashWindow::on_network_game_selected));
221
249
          ngsd.run();
222
 
          //okay, we're a client.
223
 
          //ask which ip
224
 
          //go get the file
225
 
          //std::string filename;
226
 
          //launch lobby.. emit something?
227
 
          //GameLobbyDialog gld(filename, false);
228
 
          //return gld.run();
229
250
        }
230
251
      else
231
252
        {
232
 
          Gtk::MessageDialog mdialog(*window.get(), "not implemented yet.");
233
 
          mdialog.show_all();
234
 
          mdialog.run();
235
253
          //okay, we're a server.
236
 
          GamePreferencesDialog gpd;
 
254
          GamePreferencesDialog gpd(GameScenario::NETWORKED);
237
255
    
238
256
          gpd.set_parent_window(*window.get());
 
257
          gpd.set_title(_("New Networked Game"));
239
258
          gpd.game_started.connect(sigc::mem_fun(*this, &SplashWindow::on_network_game_created));
240
 
          gpd.run();
 
259
          gpd.run(network_game_nickname);
 
260
          gpd.hide();
241
261
          return;
242
262
        }
243
263
    }
244
264
 
245
265
}
246
266
 
 
267
void SplashWindow::on_new_pbm_game_clicked()
 
268
{
 
269
  GamePreferencesDialog gpd(GameScenario::PLAY_BY_MAIL);
 
270
    
 
271
  gpd.set_parent_window(*window.get());
 
272
  gpd.set_title(_("New Play By Mail game"));
 
273
  gpd.game_started.connect(sigc::mem_fun(*this, &SplashWindow::on_pbm_game_created));
 
274
  gpd.run();
 
275
  gpd.hide();
 
276
}
 
277
 
247
278
void SplashWindow::on_load_scenario_clicked()
248
279
{
249
280
    LoadScenarioDialog d;
255
286
    std::string filename = d.get_scenario_filename();
256
287
    if (!filename.empty())
257
288
      {
 
289
        d.hide();
258
290
        GamePreferencesDialog gp(filename);
259
291
        gp.set_parent_window(*window.get());
260
292
        gp.game_started.connect(sigc::mem_fun(*this, &SplashWindow::on_game_started));
264
296
        //load_requested.emit(filename);
265
297
}
266
298
 
 
299
void SplashWindow::on_new_campaign_clicked()
 
300
{
 
301
    NewCampaignDialog d;
 
302
    
 
303
    d.set_parent_window(*window.get());
 
304
    
 
305
    d.run();
 
306
    
 
307
    std::string filename = d.get_campaign_filename();
 
308
    if (!filename.empty())
 
309
      {
 
310
        d.hide();
 
311
        GamePreferencesDialog gp(filename, true);
 
312
        gp.set_parent_window(*window.get());
 
313
        gp.game_started.connect(sigc::mem_fun(*this, &SplashWindow::on_campaign_started));
 
314
    
 
315
        gp.run();
 
316
      } 
 
317
        //load_requested.emit(filename);
 
318
}
 
319
 
267
320
void SplashWindow::on_network_game_selected(std::string ip, unsigned short port)
268
321
{
269
 
  //go get the file!
270
 
  //download it into a file called network.sav, and then:
271
 
  std::string filename = File::getSavePath() + "network.sav";
272
 
  new_network_game_requested.emit(filename, false);
273
 
}
274
 
 
275
 
void SplashWindow::on_network_game_created(GameParameters g)
276
 
{
277
 
  std::string filename;
278
 
  if (g.map_path.empty()) 
279
 
    {
280
 
      // construct new random scenario if we're not going to load the game
281
 
      std::string path = GameWindow::create_and_dump_scenario("random.map", g);
282
 
      g.map_path = path;
283
 
    }
284
 
 
285
 
    bool broken = false;
286
 
    GameScenario* game_scenario = new GameScenario(g.map_path, broken);
287
 
 
288
 
    if (broken)
289
 
      {
290
 
        //on_message_requested("Corrupted saved game file.");
291
 
        return;
292
 
      }
293
 
 
294
 
    if (game_scenario->getRound() == 0)
295
 
      {
296
 
        Playerlist::getInstance()->syncPlayers(g.players);
297
 
        game_scenario->setupFog(g.hidden_map);
298
 
        game_scenario->setupCities(g.quick_start);
299
 
        game_scenario->setupDiplomacy(g.diplomacy);
300
 
        game_scenario->nextRound();
301
 
      }
302
 
 
303
 
    filename = File::getSavePath() + "network.sav";
304
 
    game_scenario->saveGame(filename);
305
 
    delete game_scenario;
306
 
    new_network_game_requested.emit(filename, true);
 
322
  new_remote_network_game_requested.emit(ip, port, network_game_nickname);
307
323
}
308
324
 
309
325
void SplashWindow::on_game_started(GameParameters g)
310
326
{
311
 
    new_game_requested.emit(g);
 
327
  new_game_requested.emit(g);
 
328
}
 
329
 
 
330
void SplashWindow::on_campaign_started(GameParameters g)
 
331
{
 
332
  new_campaign_requested.emit(g);
312
333
}
313
334
 
314
335
 
489
510
      sdl_initialized.emit();
490
511
    }
491
512
}
 
513
 
 
514
void SplashWindow::on_network_game_created(GameParameters g)
 
515
{
 
516
  new_hosted_network_game_requested.emit(g, LORDSAWAR_PORT, 
 
517
                                         network_game_nickname);
 
518
}
 
519
 
 
520
void SplashWindow::on_pbm_game_created(GameParameters g)
 
521
{
 
522
  new_pbm_game_requested.emit(g);
 
523
}
 
524
    
 
525
void SplashWindow::on_preferences_clicked()
 
526
{
 
527
  bool saved = Configuration::s_decorated;
 
528
  MainPreferencesDialog d;
 
529
  d.set_parent_window(*window.get());
 
530
  d.run();
 
531
  d.hide();
 
532
  if (saved != Configuration::s_decorated)
 
533
    {
 
534
      TimedMessageDialog dialog(*window.get(), _("Please exit the program and restart it for the changes to take effect."), 30);
 
535
      dialog.run();
 
536
    }
 
537
}