Add hotkeys to remember locations and scroll back to them

This commit is contained in:
dP
2020-05-20 00:19:52 +03:00
parent 1d2c2925d1
commit 9fe35a49a1
6 changed files with 119 additions and 2 deletions

View File

@@ -80,6 +80,7 @@ This is usable for any OpenTTD servers
- Rename "New CB borders" zone to "CB town limit" and switch it to a new colored highlight. Remove old "CB borders" zone.
- In CB modes added CB town limit to outer town zones highlight (red border).
- Show engine id in build window in newgrf developer mode.
- Add hotkeys (unset by default) to remember locations and scroll back to them.
- Fixed automatic funding and advertisement wasting money.
- Fixed crash on selecting tram station build tool.
- Fixed zoning hotkeys.

View File

@@ -620,6 +620,8 @@ citymania/base64.h
citymania/base64.cpp
citymania/highlight.hpp
citymania/highlight.cpp
citymania/locations.hpp
citymania/locations.cpp
citymania/minimap.hpp
citymania/minimap.cpp
citymania/station_ui.hpp

View File

@@ -0,0 +1,65 @@
#include "../stdafx.h"
#include "../viewport_func.h"
#include "../window_func.h"
#include "../window_gui.h"
#include "../window_type.h"
#include "../zoom_func.h"
#include "../zoom_type.h"
#include "locations.hpp"
#include "../safeguards.h"
namespace citymania {
struct Location {
ZoomLevel zoom;
int32 scrollpos_x = 0;
int32 scrollpos_y = 0;
};
Location _locations[NUM_LOCATIONS];
void SaveLocation(uint slot) {
assert(slot < NUM_LOCATIONS);
auto &loc = _locations[slot];
Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
auto vp = w->viewport;
loc.zoom = vp->zoom;
loc.scrollpos_x = vp->scrollpos_x;
loc.scrollpos_y = vp->scrollpos_y;
}
void LoadLocation(uint slot) {
assert(slot < NUM_LOCATIONS);
auto &loc = _locations[slot];
if (!loc.scrollpos_y && !loc.scrollpos_x) return;
Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
auto vp = w->viewport;
vp->zoom = loc.zoom;
vp->follow_vehicle = INVALID_VEHICLE;
vp->dest_scrollpos_x = loc.scrollpos_x;
vp->dest_scrollpos_y = loc.scrollpos_y;
vp->virtual_width = ScaleByZoom(vp->width, vp->zoom);
vp->virtual_height = ScaleByZoom(vp->height, vp->zoom);
}
EventState HandleToolbarHotkey(int hotkey) {
if (hotkey >= CM_MTHK_LOCATIONS_GOTO_START && hotkey < CM_MTHK_LOCATIONS_GOTO_END) {
LoadLocation(hotkey - CM_MTHK_LOCATIONS_GOTO_START);
return ES_HANDLED;
}
if (hotkey >= CM_MTHK_LOCATIONS_SET_START && hotkey < CM_MTHK_LOCATIONS_SET_END) {
SaveLocation(hotkey - CM_MTHK_LOCATIONS_SET_START);
return ES_HANDLED;
}
return ES_NOT_HANDLED;
}
} // namespace citymania

View File

@@ -0,0 +1,45 @@
#ifndef CITYMANIA_LOCATIONS_HPP
#define CITYMANIA_LOCATIONS_HPP
namespace citymania {
static const uint NUM_LOCATIONS = 9;
#define CM_MTHK_LOCATIONS_START 240
static const int CM_MTHK_LOCATIONS_GOTO_START = CM_MTHK_LOCATIONS_START;
static const int CM_MTHK_LOCATIONS_GOTO_END = CM_MTHK_LOCATIONS_GOTO_START + NUM_LOCATIONS;
static const int CM_MTHK_LOCATIONS_SET_START = CM_MTHK_LOCATIONS_GOTO_END;
static const int CM_MTHK_LOCATIONS_SET_END = CM_MTHK_LOCATIONS_SET_START + NUM_LOCATIONS;
// #define CM_MTHK_LOCATIONS_GOTO_START (CM_MTHK_LOCATIONS_START)
// #define CM_MTHK_LOCATIONS_GOTO_END (CM_MTHK_LOCATIONS_GOTO_START + NUM_LOCATIONS)
// #define CM_MTHK_LOCATIONS_SET_START (CM_MTHK_LOCATIONS_GOTO_END)
// #define CM_MTHK_LOCATIONS_SET_END (CM_MTHK_LOCATIONS_SET_START + NUM_LOCATIONS)
#define CM_LOCATION_HOTKEYS_DECL \
Hotkey((uint16)0, "cm_goto_location_1", CM_MTHK_LOCATIONS_START), \
Hotkey((uint16)0, "cm_goto_location_2", CM_MTHK_LOCATIONS_START + 1), \
Hotkey((uint16)0, "cm_goto_location_3", CM_MTHK_LOCATIONS_START + 2), \
Hotkey((uint16)0, "cm_goto_location_4", CM_MTHK_LOCATIONS_START + 3), \
Hotkey((uint16)0, "cm_goto_location_5", CM_MTHK_LOCATIONS_START + 4), \
Hotkey((uint16)0, "cm_goto_location_6", CM_MTHK_LOCATIONS_START + 5), \
Hotkey((uint16)0, "cm_goto_location_7", CM_MTHK_LOCATIONS_START + 6), \
Hotkey((uint16)0, "cm_goto_location_8", CM_MTHK_LOCATIONS_START + 7), \
Hotkey((uint16)0, "cm_goto_location_9", CM_MTHK_LOCATIONS_START + 8), \
Hotkey((uint16)0, "cm_set_location_1", CM_MTHK_LOCATIONS_START + 9), \
Hotkey((uint16)0, "cm_set_location_2", CM_MTHK_LOCATIONS_START + 10), \
Hotkey((uint16)0, "cm_set_location_3", CM_MTHK_LOCATIONS_START + 11), \
Hotkey((uint16)0, "cm_set_location_4", CM_MTHK_LOCATIONS_START + 12), \
Hotkey((uint16)0, "cm_set_location_5", CM_MTHK_LOCATIONS_START + 13), \
Hotkey((uint16)0, "cm_set_location_6", CM_MTHK_LOCATIONS_START + 14), \
Hotkey((uint16)0, "cm_set_location_7", CM_MTHK_LOCATIONS_START + 15), \
Hotkey((uint16)0, "cm_set_location_8", CM_MTHK_LOCATIONS_START + 16), \
Hotkey((uint16)0, "cm_set_location_9", CM_MTHK_LOCATIONS_START + 17)
EventState HandleToolbarHotkey(int hotkey);
} // namespace citymania
#endif /* CITYMANIA_MINIMAP_HPP */

View File

@@ -83,4 +83,4 @@ const byte _openttd_revision_tagged = 1;
const uint32 _openttd_newgrf_version = 1 << 28 | 10 << 24 | 0 << 20 | 1 << 19 | 28004;
const char _citymania_version[] = "20200519-master-mf9699294a9 19.05.20";
const char _citymania_version[] = "20200519-master-m1d2c2925d1 19.05.20";

View File

@@ -60,6 +60,8 @@
#include "zoning.h"
#include "watch_gui.h"
#include "citymania/locations.hpp"
#include "safeguards.h"
@@ -2100,6 +2102,7 @@ enum MainToolbarHotkeys {
MTHK_SETTINGS_ADV,
MTHK_NEWGRF,
MTHK_LANDINFO,
CM_LOCATION_HOTKEYS,
};
/** Main toolbar. */
@@ -2215,7 +2218,7 @@ struct MainToolbarWindow : Window {
case MTHK_SETTINGS_ADV: ShowGameSettings(); break;
case MTHK_NEWGRF: ShowNewGRFSettings(!_networking && _settings_client.gui.UserIsAllowedToChangeNewGRFs(), true, true, &_grfconfig); break;
case MTHK_LANDINFO: _last_started_action = PlaceLandBlockInfo(); break;
default: return ES_NOT_HANDLED;
default: return citymania::HandleToolbarHotkey(hotkey);
}
return ES_HANDLED;
}
@@ -2367,6 +2370,7 @@ static Hotkey maintoolbar_hotkeys[] = {
Hotkey((uint16)0, "newgrf_window", MTHK_NEWGRF),
Hotkey((uint16)0, "sign_list", MTHK_SIGN_LIST),
Hotkey((uint16)0, "land_info", MTHK_LANDINFO),
CM_LOCATION_HOTKEYS_DECL,
HOTKEY_LIST_END
};
HotkeyList MainToolbarWindow::hotkeys("maintoolbar", maintoolbar_hotkeys);