1 /* Battle Tanks Game
2 * Copyright (C) 2006-2009 Battle Tanks team
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19 /*
20 * Additional rights can be granted beyond the GNU General Public License
21 * on the terms provided in the Exception. If you modify this file,
22 * you may extend this exception to your version of the file,
23 * but you are not obligated to do so. If you do not wish to provide this
24 * exception without modification, you must delete this exception statement
25 * from your version and license this file solely under the GPL without exception.
26 */
27
28 #include "add_tileset_dialog.h"
29 #include "tmx/tileset_list.h"
30 #include "mrt/fs_node.h"
31
AddTilesetDialog(const int w,const int h)32 AddTilesetDialog::AddTilesetDialog(const int w, const int h) :
33 ScrollList("menu/background_box_dark.png", "small", w, h) {}
34
init(const std::string & fname,TilesetList & tilesets,const std::vector<std::string> & all_tilesets)35 const bool AddTilesetDialog::init(const std::string &fname, TilesetList &tilesets, const std::vector<std::string> &all_tilesets) {
36 _tileset.clear();
37
38 std::string dir = mrt::FSNode::get_dir(fname);
39 LOG_DEBUG(("map file: %s base dir: %s", fname.c_str(), dir.c_str()));
40
41 clear();
42 _tilesets.clear();
43
44 bool found = false;
45 for(size_t i = 0; i < all_tilesets.size(); ++i) {
46 const std::string tileset = mrt::FSNode::relative_path(dir, all_tilesets[i]);
47 //LOG_DEBUG(("tileset: %s", tileset.c_str()));
48 if (!tilesets.exists(tileset)) {
49 _tilesets.push_back(tileset);
50 append(mrt::FSNode::get_filename(tileset, false));
51 found = true;
52 }
53 }
54
55 return found;
56 }
57
onKey(const SDL_keysym sym)58 bool AddTilesetDialog::onKey(const SDL_keysym sym) {
59 switch(sym.sym) {
60 case SDLK_KP_ENTER:
61 case SDLK_RETURN:
62 {
63 //adding tileset.
64 _tileset = _tilesets[get()];
65 LOG_DEBUG(("adding tileset #%d (%s)", get(), _tileset.c_str()));
66 }
67 case SDLK_ESCAPE:
68 hide();
69 return true;
70
71 default:
72 return ScrollList::onKey(sym);
73 }
74 }
75
getTileset()76 const std::string AddTilesetDialog::getTileset() {
77 std::string r = _tileset;
78 _tileset.clear();
79 return r;
80 }
81