2
* Copyright (C) 2002-4 by the Widelands Development Team
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.
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.
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., 675 Mass Ave, Cambridge, MA 02139, USA.
23
#include "editor_main_menu_new_map.h"
24
#include "ui_window.h"
25
#include "ui_textarea.h"
26
#include "ui_button.h"
27
#include "editorinteractive.h"
35
Main_Menu_New_Map::Main_Menu_New_Map
37
Create all the buttons etc...
40
Main_Menu_New_Map::Main_Menu_New_Map(Editor_Interactive *parent)
41
: UIWindow(parent, (parent->get_w()-140)/2, (parent->get_h()-150)/2, 140, 150, "New Map")
46
UITextarea* tt=new UITextarea(this, 0, 0, "New Map Options", Align_Left);
47
tt->set_pos((get_inner_w()-tt->get_w())/2, 5);
54
const int width=get_inner_w()-offsx*2;
59
sprintf(buf, "Width: %i", MAP_DIMENSIONS[m_w]);
60
m_width=new UITextarea(this, posx+spacing+20, posy+7, buf, Align_Left);
61
UIButton* b = new UIButton(this, posx, posy, 20, 20, 1, 0);
62
b->set_pic(g_gr->get_picture(PicMod_UI, "pics/scrollbar_up.png", true));
63
b->clickedid.set(this, &Main_Menu_New_Map::button_clicked);
64
b = new UIButton(this, get_inner_w()-spacing-20, posy, 20, 20, 1, 1);
65
b->set_pic(g_gr->get_picture(PicMod_UI, "pics/scrollbar_down.png", true));
66
b->clickedid.set(this, &Main_Menu_New_Map::button_clicked);
67
posy+=20+spacing+spacing;
69
sprintf(buf, "Height: %i", MAP_DIMENSIONS[m_h]);
70
m_height=new UITextarea(this, posx+spacing+20, posy+7, buf, Align_Left);
71
b = new UIButton(this, posx, posy, 20, 20, 1, 2);
72
b->set_pic(g_gr->get_picture(PicMod_UI, "pics/scrollbar_up.png", true));
73
b->clickedid.set(this, &Main_Menu_New_Map::button_clicked);
74
b = new UIButton(this, get_inner_w()-spacing-20, posy, 20, 20, 1, 3);
75
b->set_pic(g_gr->get_picture(PicMod_UI, "pics/scrollbar_down.png", true));
76
b->clickedid.set(this, &Main_Menu_New_Map::button_clicked);
77
posy+=20+spacing+spacing;
80
m_worlds=new std::vector<std::string>;
81
World::get_all_worlds(m_worlds);
83
assert(m_worlds->size());
85
m_world=new UIButton(this, posx, posy, width, height, 1, 4);
86
m_world->set_title((*m_worlds)[m_currentworld].c_str());
87
m_world->clickedid.set(this, &Main_Menu_New_Map::button_clicked);
88
posy+=height+spacing+spacing+spacing;
90
b=new UIButton(this, posx, posy, width, height, 0, 5);
91
b->set_title("Create Map");
92
b->clickedid.set(this, &Main_Menu_New_Map::button_clicked);
101
Main_Menu_New_Map UIButton functions
103
called, when button get clicked
106
void Main_Menu_New_Map::button_clicked(int n) {
108
case 0: m_w++; break;
109
case 1: m_w--; break;
110
case 2: m_h++; break;
111
case 3: m_h--; break;
114
if(m_currentworld==m_worlds->size()) m_currentworld=0;
115
m_world->set_title((*m_worlds)[m_currentworld].c_str());
119
Map* m_map=m_parent->get_egbase()->get_map();
120
// Clean all the stuff up, so we can load
121
m_parent->get_editor()->cleanup_for_load(true, false);
123
m_map->create_empty_map(MAP_DIMENSIONS[m_w],MAP_DIMENSIONS[m_h],(*m_worlds)[m_currentworld]);
125
// Postload the world which provides all the immovables found on a map
126
m_map->get_world()->postload(m_parent->get_editor());
128
m_parent->get_editor()->postload();
129
m_parent->get_editor()->load_graphics();
131
m_map->recalc_whole_map();
133
m_parent->set_need_save(true);
142
if(m_w>=NUMBER_OF_MAP_DIMENSIONS) m_w=NUMBER_OF_MAP_DIMENSIONS-1;
144
if(m_h>=NUMBER_OF_MAP_DIMENSIONS) m_h=NUMBER_OF_MAP_DIMENSIONS-1;
145
sprintf(buf, "Width: %i", MAP_DIMENSIONS[m_w]);
146
m_width->set_text(buf);
147
sprintf(buf, "Height: %i", MAP_DIMENSIONS[m_h]);
148
m_height->set_text(buf);
153
Main_Menu_New_Map::~Main_Menu_New_Map
155
Unregister from the registry pointer
158
Main_Menu_New_Map::~Main_Menu_New_Map()