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.
20
#include "editor_increase_resources_tool.h"
21
#include "editor_decrease_resources_tool.h"
22
#include "editor_set_resources_tool.h"
25
#include "editorinteractive.h"
27
#include "overlay_manager.h"
30
=============================
32
class Editor_Set_Resources_Tool
34
=============================
39
Editor_Set_Resources_Tool::handle_click_impl()
41
sets the resources of the current to a fixed value
44
int Editor_Set_Resources_Tool::handle_click_impl(FCoords& fc, Map* map, Editor_Interactive* parent)
46
MapRegion mrc(map, fc, parent->get_fieldsel_radius());
50
Field* f=map->get_field(c);
52
int res=f->get_resources();
53
int amount=f->get_resources_amount();
54
int max_amount=map->get_world()->get_resource(m_cur_res)->get_max_amount();
57
if(amount<0) amount=0;
58
if(amount>max_amount) amount=max_amount;
60
if(Editor_Change_Resource_Tool_Callback(c,map,m_cur_res)) {
61
// Ok, we're doing something. First remove the current overlays
63
str=map->get_world()->get_resource(res)->get_editor_pic(f->get_resources_amount());
64
int picid=g_gr->get_picture(PicMod_Menu, str.c_str(), true);
65
map->get_overlay_manager()->remove_overlay(c,picid);
68
f->set_resources(0,0);
69
f->set_starting_res_amount(0);
71
f->set_resources(m_cur_res,amount);
72
f->set_starting_res_amount(amount);
74
str=map->get_world()->get_resource(m_cur_res)->get_editor_pic(amount);
75
int picid=g_gr->get_picture(PicMod_Menu, str.c_str(), true);
76
map->get_overlay_manager()->register_overlay(c,picid,4);
77
map->recalc_for_field_area(c,0);
81
return parent->get_fieldsel_radius();