~ubuntu-branches/ubuntu/raring/simutrans/raring-proposed

« back to all changes in this revision

Viewing changes to gui/savegame_frame.cc

  • Committer: Package Import Robot
  • Author(s): Ansgar Burchardt
  • Date: 2011-11-03 19:59:02 UTC
  • mfrom: (1.2.7)
  • Revision ID: package-import@ubuntu.com-20111103195902-uopgwf488mfctb75
Tags: 111.0-1
* New upstream release.
* debian/rules: Update get-orig-source target for new upstream release.
* Use xz compression for source and binary packages.
* Use override_* targets to simplify debian/rules.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
#include <string>
17
17
 
18
 
#include <sys/stat.h>
19
18
#include <string.h>
20
19
#include <time.h>
21
20
 
22
21
#include "../pathes.h"
23
22
 
24
23
#include "../simdebug.h"
 
24
#include "../simsys.h"
25
25
#include "../simwin.h"
26
26
#include "../simintr.h"
27
27
 
28
28
#include "../dataobj/umgebung.h"
 
29
#include "../dataobj/translator.h"
29
30
#include "../utils/simstring.h"
30
31
 
31
32
#include "components/list_button.h"
34
35
#define DIALOG_WIDTH (360)
35
36
 
36
37
 
37
 
// we need this trick, with the function pointer.
38
 
// Since during initialisations virtual functions do not work yet
39
 
// in derived classes (since the object in question is not full initialized yet)
40
 
// this functions returns true for files to be added.
41
38
savegame_frame_t::savegame_frame_t(const char *suffix, const char *path, bool only_directories ) :
42
 
        gui_frame_t("Load/Save"),
 
39
gui_frame_t( translator::translate("Load/Save") ),
43
40
        input(),
44
41
        fnlabel("Filename"),
45
42
        scrolly(&button_frame)
47
44
        this->suffix = suffix;
48
45
        this->fullpath = path;
49
46
        this->only_directories = only_directories;
50
 
        use_pak_extension = suffix==NULL  ||  strcmp( suffix, ".sve" )==0;
51
47
        in_action = false;
52
48
 
53
49
        // both NULL is not acceptable
54
50
        assert(suffix!=path);
55
51
 
56
 
        fnlabel.set_pos (koord(10,12));
 
52
        fnlabel.set_pos (koord(10,4));
57
53
        add_komponente(&fnlabel);
58
54
 
59
55
        // Input box for game name
60
56
        tstrncpy(ibuf, "", lengthof(ibuf));
61
57
        input.set_text(ibuf, 128);
62
 
        input.set_pos(koord(75,8));
63
 
        input.set_groesse(koord(DIALOG_WIDTH-75-10-10, 14));
 
58
        input.set_pos(koord(75,2));
 
59
        input.set_groesse(koord(DIALOG_WIDTH-75-scrollbar_t::BAR_SIZE-1, BUTTON_HEIGHT));
64
60
        add_komponente(&input);
65
61
 
66
62
        // needs to be scrollable
67
 
        scrolly.set_pos( koord(0,30) );
68
 
        scrolly.set_show_scroll_x(false);
 
63
        scrolly.set_pos( koord(0,20) );
 
64
        scrolly.set_scroll_amount_y(BUTTON_HEIGHT);
69
65
        scrolly.set_size_corner(false);
70
 
        scrolly.set_groesse( koord(DIALOG_WIDTH-12,30) );
71
 
 
72
 
        // The file entries
73
 
        int y = 0;
74
 
        button_frame.set_groesse( koord( DIALOG_WIDTH-1, y ) );
75
66
        add_komponente(&scrolly);
76
67
 
77
 
        y += 10+30;
78
 
        divider1.set_pos(koord(10,y));
79
 
        divider1.set_groesse(koord(DIALOG_WIDTH-20,0));
80
68
        add_komponente(&divider1);
81
69
 
82
 
        y += 10;
83
 
        savebutton.set_pos(koord(10,y));
84
 
        savebutton.set_groesse(koord(BUTTON_WIDTH, 14));
 
70
        savebutton.set_groesse(koord(BUTTON_WIDTH, BUTTON_HEIGHT));
85
71
        savebutton.set_text("Ok");
86
72
        savebutton.set_typ(button_t::roundbox);
87
73
        savebutton.add_listener(this);
88
74
        add_komponente(&savebutton);
89
75
 
90
 
        cancelbutton.set_pos(koord(DIALOG_WIDTH-BUTTON_WIDTH-10,y));
91
 
        cancelbutton.set_groesse(koord(BUTTON_WIDTH, 14));
 
76
        cancelbutton.set_groesse(koord(BUTTON_WIDTH, BUTTON_HEIGHT));
92
77
        cancelbutton.set_text("Cancel");
93
78
        cancelbutton.set_typ(button_t::roundbox);
94
79
        cancelbutton.add_listener(this);
95
80
        add_komponente(&cancelbutton);
96
81
 
97
82
        set_focus( &input );
98
 
        set_fenstergroesse(koord(DIALOG_WIDTH, y + 40));
 
83
 
 
84
        set_min_windowsize(koord(2*(BUTTON_WIDTH+scrollbar_t::BAR_SIZE)+BUTTON_SPACER, get_fenstergroesse().y+1));
 
85
        set_fenstergroesse(koord(DIALOG_WIDTH, TITLEBAR_HEIGHT+20+3*BUTTON_HEIGHT+30+1));
 
86
 
 
87
        set_resizemode(diagonal_resize);
 
88
        resize(koord(0,0));
99
89
}
100
90
 
101
91
 
102
 
 
103
 
 
104
92
void savegame_frame_t::fill_list()
105
93
{
106
94
        char searchpath[1024];
112
100
#else
113
101
                sprintf( searchpath, "%s/*%s", SAVE_PATH, suffix==NULL ? "" : suffix );
114
102
#endif
115
 
#ifndef _WIN32
116
 
                mkdir(SAVE_PATH, 0700);
117
 
#else
118
 
                mkdir(SAVE_PATH);
119
 
#endif
 
103
                dr_mkdir(SAVE_PATH);
120
104
                fullpath = SAVE_PATH_X;
121
105
        }
122
106
        else {
183
167
                button_t*    button2 = i->button;
184
168
                gui_label_t* label   = i->label;
185
169
 
186
 
                button1->set_groesse(koord(14, 14));
 
170
                button1->set_groesse(koord(14, BUTTON_HEIGHT));
187
171
                button1->set_text("X");
188
172
                button1->set_pos(koord(5, y));
189
173
                button1->set_tooltip("Delete this file.");
190
174
 
191
175
                button2->set_pos(koord(25, y));
192
 
                button2->set_groesse(koord(140, 14));
 
176
                button2->set_groesse(koord(140, BUTTON_HEIGHT));
193
177
 
194
 
                label->set_pos(koord(170, y+3));
 
178
                label->set_pos(koord(170, y+2));
195
179
 
196
180
                button1->add_listener(this);
197
181
                button2->add_listener(this);
200
184
                button_frame.add_komponente(button2);
201
185
                button_frame.add_komponente(label);
202
186
 
203
 
                y += 14;
 
187
                y += BUTTON_HEIGHT;
204
188
        }
205
189
        // since width was maybe increased, we only set the heigth.
206
190
        button_frame.set_groesse( koord( get_fenstergroesse().x-1, y ) );
207
 
        set_fenstergroesse(koord(get_fenstergroesse().x, y + 90));
 
191
        set_fenstergroesse(koord(get_fenstergroesse().x, TITLEBAR_HEIGHT+12+y+30+1));
208
192
}
209
193
 
210
194
 
211
 
 
212
195
savegame_frame_t::~savegame_frame_t()
213
196
{
214
197
        for (slist_tpl<entry>::const_iterator i = entries.begin(), end = entries.end(); i != end; ++i) {
221
204
}
222
205
 
223
206
 
224
 
 
225
207
// sets the current filename in the input box
226
208
void savegame_frame_t::set_filename(const char *fn)
227
209
{
238
220
}
239
221
 
240
222
 
241
 
 
242
223
void savegame_frame_t::add_file(const char *filename, const char *pak, const bool no_cutting_suffix )
243
224
{
244
225
        button_t * button = new button_t();
253
234
        button->set_no_translate(true);
254
235
        button->set_text(name); // to avoid translation
255
236
 
256
 
        const std::string compare_to = umgebung_t::objfilename.size()>0  ?  umgebung_t::objfilename.substr( 0, umgebung_t::objfilename.size()-1 ) + " -"  :  std::string();
 
237
        std::string const compare_to = !umgebung_t::objfilename.empty() ? umgebung_t::objfilename.substr(0, umgebung_t::objfilename.size() - 1) + " -" : std::string();
257
238
        // sort by date descending:
258
239
        slist_tpl<entry>::iterator i = entries.begin();
259
240
        slist_tpl<entry>::iterator end = entries.end();
294
275
}
295
276
 
296
277
 
297
 
// true, if this is a croorect file
 
278
// true, if this is a correct file
298
279
bool savegame_frame_t::check_file( const char *filename, const char *suffix )
299
280
{
300
281
        // assume truth, if there is no pattern to compare
313
294
        if(komp == &input || komp == &savebutton) {
314
295
                // Save/Load Button or Enter-Key pressed
315
296
                //---------------------------------------
316
 
 
317
297
                if (strstr(ibuf,"net:")==ibuf) {
318
298
                        tstrncpy(buf,ibuf,lengthof(buf));
319
299
                }
320
300
                else {
321
 
                        tstrncpy(buf, SAVE_PATH_X, lengthof(buf));
 
301
                        if(fullpath) {
 
302
                                tstrncpy(buf, fullpath, lengthof(buf));
 
303
                        }
 
304
                        else {
 
305
                                buf[0] = 0;
 
306
                        }
322
307
                        strcat(buf, ibuf);
323
 
                        strcat(buf, suffix);
 
308
                        if (suffix) {
 
309
                                strcat(buf, suffix);
 
310
                        }
324
311
                }
325
312
                set_focus( NULL );
326
313
                action(buf);
345
332
                                        tstrncpy(buf, fullpath, lengthof(buf));
346
333
                                }
347
334
                                strcat(buf, i->button->get_text());
348
 
                                if(fullpath) {
 
335
                                if(suffix) {
349
336
                                        strcat(buf, suffix);
350
337
                                }
351
338
 
381
368
}
382
369
 
383
370
 
384
 
 
385
 
 
386
371
/**
387
372
 * Bei Scrollpanes _muss_ diese Methode zum setzen der Groesse
388
373
 * benutzt werden.
390
375
 */
391
376
void savegame_frame_t::set_fenstergroesse(koord groesse)
392
377
{
393
 
        if(groesse.y>display_get_height()-64) {
 
378
        if(groesse.y>display_get_height()-70) {
394
379
                // too large ...
395
 
                groesse.y = display_get_height()-64;
 
380
                groesse.y = ((display_get_height()-TITLEBAR_HEIGHT-12-30-1)/BUTTON_HEIGHT)*BUTTON_HEIGHT+TITLEBAR_HEIGHT+12+30+1-70;
396
381
                // position adjustment will be done automatically ... nice!
397
382
        }
398
383
        gui_frame_t::set_fenstergroesse(groesse);
399
 
        input.set_groesse(koord(groesse.x-75-10-10, 14));
 
384
        groesse = get_fenstergroesse();
 
385
 
 
386
        input.set_groesse(koord(groesse.x-75-scrollbar_t::BAR_SIZE-1, BUTTON_HEIGHT));
400
387
 
401
388
        sint16 y = 0;
402
389
        for (slist_tpl<entry>::const_iterator i = entries.begin(), end = entries.end(); i != end; ++i) {
407
394
                        button_t*    button2 = i->button;
408
395
                        gui_label_t* label   = i->label;
409
396
                        button2->set_pos( koord( button2->get_pos().x, y ) );
410
 
                        button2->set_groesse(koord( groesse.x/2-40, 14));
411
 
                        label->set_pos(koord(groesse.x/2-40+30, y));
412
 
                        y += 14;
 
397
                        button2->set_groesse(koord( groesse.x/2-40, BUTTON_HEIGHT));
 
398
                        label->set_pos(koord(groesse.x/2-40+30, y+2));
 
399
                        y += BUTTON_HEIGHT;
413
400
                }
414
401
        }
415
402
 
416
 
        button_frame.set_groesse( koord( groesse.x, y ) );
417
 
        scrolly.set_groesse( koord(groesse.x,groesse.y-30-40-8) );
418
 
 
419
 
        divider1.set_pos(koord(10,groesse.y-44));
420
 
        divider1.set_groesse(koord(groesse.x-20,0));
421
 
        savebutton.set_pos(koord(10,groesse.y-34));
422
 
        cancelbutton.set_pos(koord(groesse.x-BUTTON_WIDTH-10,groesse.y-34));
 
403
        button_frame.set_groesse(koord(groesse.x,y));
 
404
        scrolly.set_groesse(koord(groesse.x,groesse.y-TITLEBAR_HEIGHT-12-30-1));
 
405
 
 
406
        divider1.set_pos(koord(4,groesse.y-36));
 
407
        divider1.set_groesse(koord(groesse.x-8-1,0));
 
408
 
 
409
        savebutton.set_pos(koord(scrollbar_t::BAR_SIZE,groesse.y-BUTTON_HEIGHT-2-16-1));
 
410
        cancelbutton.set_pos(koord(groesse.x-BUTTON_WIDTH-scrollbar_t::BAR_SIZE,groesse.y-BUTTON_HEIGHT-2-16-1));
423
411
}
424
412
 
425
413
 
426
 
 
427
 
 
428
414
bool savegame_frame_t::infowin_event(const event_t *ev)
429
415
{
430
416
        if(ev->ev_class == INFOWIN  &&  ev->ev_code == WIN_OPEN  &&  entries.empty()) {