1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
#include <string>
#include <stdio.h>
#include "../simdebug.h"
#include "pakselector.h"
#include "../dataobj/umgebung.h"
#include "../simsys.h"
/**
* what to do after loading
*/
void pakselector_t::action(const char *filename)
{
umgebung_t::objfilename = (std::string)filename + "/";
umgebung_t::default_einstellungen.set_with_private_paks( false );
}
bool pakselector_t::del_action(const char *filename)
{
// cannot delete set => use this for selection
umgebung_t::objfilename = (std::string)filename + "/";
umgebung_t::default_einstellungen.set_with_private_paks( true );
return true;
}
const char *pakselector_t::get_info(const char *)
{
return "";
}
/**
* This method is called if an action is triggered
* @author Hj. Malthaner
*/
bool pakselector_t::action_triggered( gui_action_creator_t *komp,value_t v)
{
if(komp == &savebutton) {
savebutton.pressed ^= 1;
return true;
}
else if(komp != &input) {
return savegame_frame_t::action_triggered( komp, v );
}
return false;
}
void pakselector_t::zeichnen(koord p, koord gr)
{
gui_frame_t::zeichnen( p, gr );
display_multiline_text( p.x+10, p.y+gr.y-3*LINESPACE-4,
"To avoid seeing this dialogue define a path by:\n"
" - adding 'pak_file_path = pak/' to your simuconf.tab\n"
" - using '-objects pakxyz/' on the command line", COL_BLACK );
}
bool pakselector_t::check_file( const char *filename, const char * )
{
char buf[1024];
sprintf( buf, "%s/ground.Outside.pak", filename );
if (FILE* const f = fopen(buf, "r")) {
fclose(f);
return true;
}
return false;
}
pakselector_t::pakselector_t() : savegame_frame_t( NULL, umgebung_t::program_dir, true )
{
at_least_one_add = false;
// remove unneccessary buttons
remove_komponente( &input );
remove_komponente( &savebutton );
remove_komponente( &cancelbutton );
remove_komponente( ÷r1 );
fnlabel.set_text( "Choose one graphics set for playing:" );
resize(koord(360-488,0));
}
void pakselector_t::fill_list()
{
// do the search ...
savegame_frame_t::fill_list();
int y = 0;
FOR(slist_tpl<entry>, const& i, entries) {
char path[1024];
sprintf(path,"%saddons/%s", umgebung_t::user_dir, i.button->get_text());
i.del->groesse.x += 150;
i.del->set_text("Load with addons");
i.button->set_pos(koord(150,0) + i.button->get_pos());
if( chdir( path )!=0 ) {
// no addons for this
i.del->set_visible(false);
i.del->disable();
if(entries.get_count()==1) {
// only single entry and no addons => no need to question further ...
umgebung_t::objfilename = (std::string)i.button->get_text() + "/";
}
}
y += D_BUTTON_HEIGHT;
}
chdir( umgebung_t::program_dir );
button_frame.set_groesse( koord( get_fenstergroesse().x-1, y ) );
set_fenstergroesse(koord(get_fenstergroesse().x, D_TITLEBAR_HEIGHT+30+y+3*LINESPACE+4+1));
}
void pakselector_t::set_fenstergroesse(koord groesse)
{
if(groesse.y>display_get_height()-70) {
// too large ...
groesse.y = ((display_get_height()-D_TITLEBAR_HEIGHT-30-3*LINESPACE-4-1)/D_BUTTON_HEIGHT)*D_BUTTON_HEIGHT+D_TITLEBAR_HEIGHT+30+3*LINESPACE+4+1-70;
// position adjustment will be done automatically ... nice!
}
gui_frame_t::set_fenstergroesse(groesse);
groesse = get_fenstergroesse();
sint16 y = 0;
FOR(slist_tpl<entry>, const& i, entries) {
// resize all but delete button
if (i.button->is_visible()) {
button_t* const button1 = i.del;
button1->set_pos( koord( button1->get_pos().x, y ) );
button_t* const button2 = i.button;
button2->set_pos( koord( button2->get_pos().x, y ) );
button2->set_groesse(koord( groesse.x/2-40, D_BUTTON_HEIGHT));
i.label->set_pos(koord(groesse.x / 2 - 40 + 30, y + 2));
y += D_BUTTON_HEIGHT;
}
}
button_frame.set_groesse(koord(groesse.x,y));
scrolly.set_groesse(koord(groesse.x,groesse.y-D_TITLEBAR_HEIGHT-30-3*LINESPACE-4-1));
}
|