~ubuntu-branches/ubuntu/precise/widelands/precise-backports

« back to all changes in this revision

Viewing changes to src/editor/ui_menus/editor_main_menu_new_map.cc

  • Committer: Bazaar Package Importer
  • Author(s): Martin Quinson
  • Date: 2005-02-14 10:41:12 UTC
  • Revision ID: james.westby@ubuntu.com-20050214104112-6v08iux9fptxpva9
Tags: upstream-build9
Import upstream version build9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2002-4 by the Widelands Development 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., 675 Mass Ave, Cambridge, MA 02139, USA.
 
17
 *
 
18
 */
 
19
 
 
20
#include <string>
 
21
#include <stdio.h>
 
22
#include <vector>
 
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"
 
28
#include "map.h"
 
29
#include "world.h"
 
30
#include "error.h"
 
31
#include "editor.h"
 
32
 
 
33
/*
 
34
===============
 
35
Main_Menu_New_Map::Main_Menu_New_Map
 
36
 
 
37
Create all the buttons etc...
 
38
===============
 
39
*/
 
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")
 
42
{
 
43
   m_parent=parent;
 
44
 
 
45
   // Caption
 
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);
 
48
 
 
49
   // UIButtons
 
50
   char buf[250];
 
51
   const int offsx=5;
 
52
   const int offsy=30;
 
53
   const int spacing=5;
 
54
   const int width=get_inner_w()-offsx*2;
 
55
   const int height=20;
 
56
   int posx=offsx;
 
57
   int posy=offsy;
 
58
   m_w=0; m_h=0;
 
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;
 
68
 
 
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;
 
78
 
 
79
   // get all worlds
 
80
   m_worlds=new std::vector<std::string>;
 
81
   World::get_all_worlds(m_worlds);
 
82
 
 
83
   assert(m_worlds->size());
 
84
   m_currentworld=0;
 
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;
 
89
 
 
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);
 
93
   posy+=height+spacing;
 
94
 
 
95
 
 
96
   }
 
97
 
 
98
 
 
99
/*
 
100
===========
 
101
Main_Menu_New_Map UIButton functions
 
102
 
 
103
called, when button get clicked
 
104
===========
 
105
*/
 
106
void Main_Menu_New_Map::button_clicked(int n) {
 
107
   switch(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;
 
112
      case 4:
 
113
              ++m_currentworld;
 
114
              if(m_currentworld==m_worlds->size()) m_currentworld=0;
 
115
              m_world->set_title((*m_worlds)[m_currentworld].c_str());
 
116
              break;
 
117
      case 5:
 
118
              {
 
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);
 
122
 
 
123
                 m_map->create_empty_map(MAP_DIMENSIONS[m_w],MAP_DIMENSIONS[m_h],(*m_worlds)[m_currentworld]);
 
124
 
 
125
                 // Postload the world which provides all the immovables found on a map
 
126
                 m_map->get_world()->postload(m_parent->get_editor());
 
127
 
 
128
                 m_parent->get_editor()->postload();
 
129
                 m_parent->get_editor()->load_graphics();
 
130
 
 
131
                 m_map->recalc_whole_map();
 
132
 
 
133
                 m_parent->set_need_save(true);
 
134
 
 
135
                 die();
 
136
                 return ;
 
137
              }
 
138
   }
 
139
 
 
140
   char buf[200];
 
141
   if(m_w<0) m_w=0;
 
142
   if(m_w>=NUMBER_OF_MAP_DIMENSIONS) m_w=NUMBER_OF_MAP_DIMENSIONS-1;
 
143
   if(m_h<0) m_h=0;
 
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);
 
149
}
 
150
 
 
151
/*
 
152
===============
 
153
Main_Menu_New_Map::~Main_Menu_New_Map
 
154
 
 
155
Unregister from the registry pointer
 
156
===============
 
157
*/
 
158
Main_Menu_New_Map::~Main_Menu_New_Map()
 
159
{
 
160
   delete m_worlds;
 
161
}
 
162
 
 
163