39
40
InteractiveBase& ibase)
40
41
: UI::Panel(&parent, x, y, 10, 10),
44
43
pic_map_spot_(g_gr->images().get("images/wui/overlays/map_spot.png")),
44
minimap_layers_(flags),
48
/** MiniMap::View::set_view_pos(int32_t x, int32_t y)
50
* Set the view point marker to a new position.
52
* Args: x, y new view point coordinates, in screen coordinates
54
void MiniMap::View::set_view_pos(const int32_t x, const int32_t y) {
55
viewx_ = x / kTriangleWidth;
56
viewy_ = y / kTriangleHeight;
48
void MiniMap::View::set_view(const Rectf& view_area) {
49
view_area_ = view_area;
59
52
void MiniMap::View::draw(RenderTarget& dst) {
60
minimap_image_ = draw_minimap(ibase_.egbase(), ibase_.get_player(),
61
(*flags_) & (MiniMapLayer::Zoom2) ?
62
Point((viewx_ - get_w() / 4), (viewy_ - get_h() / 4)) :
63
Point((viewx_ - get_w() / 2), (viewy_ - get_h() / 2)),
64
*flags_ | MiniMapLayer::ViewWindow);
65
dst.blit(Point(), minimap_image_.get());
53
minimap_image_ = draw_minimap(ibase_.egbase(), ibase_.get_player(), view_area_, *minimap_type_,
54
*minimap_layers_ | MiniMapLayer::ViewWindow);
55
dst.blit(Vector2f(), minimap_image_.get());
74
64
if (btn != SDL_BUTTON_LEFT)
77
// calculates the coordinates corresponding to the mouse position
79
if (*flags_ & MiniMapLayer::Zoom2)
80
c = Widelands::Coords(viewx_ + 1 - (get_w() / 2 - x) / 2, viewy_ + 1 - (get_h() / 2 - y) / 2);
82
c = Widelands::Coords(viewx_ + 1 - get_w() / 2 + x, viewy_ + 1 - get_h() / 2 + y);
84
ibase_.egbase().map().normalize_coords(c);
86
dynamic_cast<MiniMap&>(*get_parent()).warpview(c.x * kTriangleWidth, c.y * kTriangleHeight);
67
dynamic_cast<MiniMap&>(*get_parent())
68
.warpview(minimap_pixel_to_mappixel(ibase_.egbase().map(), Vector2i(x, y), view_area_,
69
*minimap_type_, *minimap_layers_ & MiniMapLayer::Zoom2));
90
73
bool MiniMap::View::handle_mouserelease(uint8_t const btn, int32_t, int32_t) {
91
74
return btn == SDL_BUTTON_LEFT;
130
113
MiniMap::MiniMap(InteractiveBase& ibase, Registry* const registry)
131
114
: UI::UniqueWindow(&ibase, "minimap", registry, 0, 0, _("Map")),
132
view_(*this, ®istry->flags, 0, 0, 0, 0, ibase),
115
view_(*this, ®istry->minimap_layers, ®istry->minimap_type, 0, 0, 0, 0, ibase),
134
117
button_terrn(this,
221
204
void MiniMap::toggle(MiniMapLayer const button) {
222
*view_.flags_ = MiniMapLayer(*view_.flags_ ^ button);
205
*view_.minimap_layers_ = MiniMapLayer(*view_.minimap_layers_ ^ button);
223
206
if (button == MiniMapLayer::Zoom2)
225
208
update_button_permpressed();
228
211
void MiniMap::resize() {
229
view_.set_zoom(*view_.flags_ & MiniMapLayer::Zoom2 ? 2 : 1);
212
view_.set_zoom(*view_.minimap_layers_ & MiniMapLayer::Zoom2 ? 2 : 1);
230
213
set_inner_size(view_.get_w(), view_.get_h() + number_of_button_rows() * but_h());
231
button_terrn.set_pos(Point(but_w() * 0, view_.get_h() + but_h() * 0));
214
button_terrn.set_pos(Vector2i(but_w() * 0, view_.get_h() + but_h() * 0));
232
215
button_terrn.set_size(but_w(), but_h());
233
button_owner.set_pos(Point(but_w() * 1, view_.get_h() + but_h() * 0));
216
button_owner.set_pos(Vector2i(but_w() * 1, view_.get_h() + but_h() * 0));
234
217
button_owner.set_size(but_w(), but_h());
235
button_flags.set_pos(Point(but_w() * 2, view_.get_h() + but_h() * 0));
218
button_flags.set_pos(Vector2i(but_w() * 2, view_.get_h() + but_h() * 0));
236
219
button_flags.set_size(but_w(), but_h());
237
button_roads.set_pos(Point(but_w() * 0, view_.get_h() + but_h() * 1));
220
button_roads.set_pos(Vector2i(but_w() * 0, view_.get_h() + but_h() * 1));
238
221
button_roads.set_size(but_w(), but_h());
239
button_bldns.set_pos(Point(but_w() * 1, view_.get_h() + but_h() * 1));
222
button_bldns.set_pos(Vector2i(but_w() * 1, view_.get_h() + but_h() * 1));
240
223
button_bldns.set_size(but_w(), but_h());
241
button_zoom.set_pos(Point(but_w() * 2, view_.get_h() + but_h() * 1));
224
button_zoom.set_pos(Vector2i(but_w() * 2, view_.get_h() + but_h() * 1));
242
225
button_zoom.set_size(but_w(), but_h());
243
226
move_inside_parent();
246
// Makes the buttons reflect the selected layers
247
229
void MiniMap::update_button_permpressed() {
248
button_terrn.set_perm_pressed(*view_.flags_ & MiniMapLayer::Terrain);
249
button_owner.set_perm_pressed(*view_.flags_ & MiniMapLayer::Owner);
250
button_flags.set_perm_pressed(*view_.flags_ & MiniMapLayer::Flag);
251
button_roads.set_perm_pressed(*view_.flags_ & MiniMapLayer::Road);
252
button_bldns.set_perm_pressed(*view_.flags_ & MiniMapLayer::Building);
253
button_zoom.set_perm_pressed(*view_.flags_ & MiniMapLayer::Zoom2);
230
button_terrn.set_perm_pressed(*view_.minimap_layers_ & MiniMapLayer::Terrain);
231
button_owner.set_perm_pressed(*view_.minimap_layers_ & MiniMapLayer::Owner);
232
button_flags.set_perm_pressed(*view_.minimap_layers_ & MiniMapLayer::Flag);
233
button_roads.set_perm_pressed(*view_.minimap_layers_ & MiniMapLayer::Road);
234
button_bldns.set_perm_pressed(*view_.minimap_layers_ & MiniMapLayer::Building);
235
button_zoom.set_perm_pressed(*view_.minimap_layers_ & MiniMapLayer::Zoom2);