mirror of https://github.com/OpenTTD/OpenTTD
(svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
parent
34e2d8f1e1
commit
f2869bb7db
|
@ -23,10 +23,7 @@
|
||||||
#include "gui.h"
|
#include "gui.h"
|
||||||
#include "mixer.h"
|
#include "mixer.h"
|
||||||
#include "sound_func.h"
|
#include "sound_func.h"
|
||||||
#include "viewport_func.h"
|
|
||||||
#include "window_func.h"
|
#include "window_func.h"
|
||||||
#include "window_gui.h"
|
|
||||||
#include "zoom_func.h"
|
|
||||||
|
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "saveload.h"
|
#include "saveload.h"
|
||||||
|
@ -341,8 +338,6 @@ static void LoadIntroGame()
|
||||||
|
|
||||||
_pause_game = 0;
|
_pause_game = 0;
|
||||||
SetLocalPlayer(PLAYER_FIRST);
|
SetLocalPlayer(PLAYER_FIRST);
|
||||||
/* Make sure you can't scroll in the menu */
|
|
||||||
_scrolling_viewport = 0;
|
|
||||||
_cursor.fix_at = false;
|
_cursor.fix_at = false;
|
||||||
MarkWholeScreenDirty();
|
MarkWholeScreenDirty();
|
||||||
|
|
||||||
|
@ -1070,53 +1065,6 @@ static void DoAutosave()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ScrollMainViewport(int x, int y)
|
|
||||||
{
|
|
||||||
if (_game_mode != GM_MENU) {
|
|
||||||
Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
|
|
||||||
assert(w);
|
|
||||||
|
|
||||||
w->viewport->dest_scrollpos_x += ScaleByZoom(x, w->viewport->zoom);
|
|
||||||
w->viewport->dest_scrollpos_y += ScaleByZoom(y, w->viewport->zoom);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Describes all the different arrow key combinations the game allows
|
|
||||||
* when it is in scrolling mode.
|
|
||||||
* The real arrow keys are bitwise numbered as
|
|
||||||
* 1 = left
|
|
||||||
* 2 = up
|
|
||||||
* 4 = right
|
|
||||||
* 8 = down
|
|
||||||
*/
|
|
||||||
static const int8 scrollamt[16][2] = {
|
|
||||||
{ 0, 0}, ///< no key specified
|
|
||||||
{-2, 0}, ///< 1 : left
|
|
||||||
{ 0, -2}, ///< 2 : up
|
|
||||||
{-2, -1}, ///< 3 : left + up
|
|
||||||
{ 2, 0}, ///< 4 : right
|
|
||||||
{ 0, 0}, ///< 5 : left + right = nothing
|
|
||||||
{ 2, -1}, ///< 6 : right + up
|
|
||||||
{ 0, -2}, ///< 7 : right + left + up = up
|
|
||||||
{ 0 ,2}, ///< 8 : down
|
|
||||||
{-2 ,1}, ///< 9 : down + left
|
|
||||||
{ 0, 0}, ///< 10 : down + up = nothing
|
|
||||||
{-2, 0}, ///< 11 : left + up + down = left
|
|
||||||
{ 2, 1}, ///< 12 : down + right
|
|
||||||
{ 0, 2}, ///< 13 : left + right + down = down
|
|
||||||
{ 2, 0}, ///< 14 : right + up + down = right
|
|
||||||
{ 0, 0}, ///< 15 : left + up + right + down = nothing
|
|
||||||
};
|
|
||||||
|
|
||||||
static void HandleKeyScrolling()
|
|
||||||
{
|
|
||||||
if (_dirkeys && !_no_scroll) {
|
|
||||||
int factor = _shift_pressed ? 50 : 10;
|
|
||||||
ScrollMainViewport(scrollamt[_dirkeys][0] * factor, scrollamt[_dirkeys][1] * factor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void GameLoop()
|
void GameLoop()
|
||||||
{
|
{
|
||||||
ProcessAsyncSaveFinish();
|
ProcessAsyncSaveFinish();
|
||||||
|
@ -1128,9 +1076,6 @@ void GameLoop()
|
||||||
RedrawAutosave();
|
RedrawAutosave();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* handle scrolling of the main window */
|
|
||||||
HandleKeyScrolling();
|
|
||||||
|
|
||||||
/* make a screenshot? */
|
/* make a screenshot? */
|
||||||
if (IsScreenshotRequested()) ShowScreenshotResult(MakeScreenshot());
|
if (IsScreenshotRequested()) ShowScreenshotResult(MakeScreenshot());
|
||||||
|
|
||||||
|
@ -1143,12 +1088,6 @@ void GameLoop()
|
||||||
IncreaseSpriteLRU();
|
IncreaseSpriteLRU();
|
||||||
InteractiveRandom();
|
InteractiveRandom();
|
||||||
|
|
||||||
if (_scroller_click_timeout > 3) {
|
|
||||||
_scroller_click_timeout -= 3;
|
|
||||||
} else {
|
|
||||||
_scroller_click_timeout = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
_caret_timer += 3;
|
_caret_timer += 3;
|
||||||
_palette_animation_counter += 8;
|
_palette_animation_counter += 8;
|
||||||
CursorTick();
|
CursorTick();
|
||||||
|
@ -1182,17 +1121,6 @@ void GameLoop()
|
||||||
MusicLoop();
|
MusicLoop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BeforeSaveGame()
|
|
||||||
{
|
|
||||||
const Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
|
|
||||||
|
|
||||||
if (w != NULL) {
|
|
||||||
_saved_scrollpos_x = w->viewport->scrollpos_x;
|
|
||||||
_saved_scrollpos_y = w->viewport->scrollpos_y;
|
|
||||||
_saved_scrollpos_zoom = w->viewport->zoom;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ConvertTownOwner()
|
static void ConvertTownOwner()
|
||||||
{
|
{
|
||||||
for (TileIndex tile = 0; tile != MapSize(); tile++) {
|
for (TileIndex tile = 0; tile != MapSize(); tile++) {
|
||||||
|
@ -1298,20 +1226,8 @@ static bool InitializeWindowsAndCaches()
|
||||||
ResetWindowSystem();
|
ResetWindowSystem();
|
||||||
SetupColorsAndInitialWindow();
|
SetupColorsAndInitialWindow();
|
||||||
|
|
||||||
Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
|
extern void ResetViewportAfterLoadGame();
|
||||||
|
ResetViewportAfterLoadGame();
|
||||||
w->viewport->scrollpos_x = _saved_scrollpos_x;
|
|
||||||
w->viewport->scrollpos_y = _saved_scrollpos_y;
|
|
||||||
w->viewport->dest_scrollpos_x = _saved_scrollpos_x;
|
|
||||||
w->viewport->dest_scrollpos_y = _saved_scrollpos_y;
|
|
||||||
|
|
||||||
ViewPort *vp = w->viewport;
|
|
||||||
vp->zoom = min(_saved_scrollpos_zoom, ZOOM_LVL_MAX);
|
|
||||||
vp->virtual_width = ScaleByZoom(vp->width, vp->zoom);
|
|
||||||
vp->virtual_height = ScaleByZoom(vp->height, vp->zoom);
|
|
||||||
|
|
||||||
DoZoomInOutWindow(ZOOM_NONE, w); // update button status
|
|
||||||
MarkWholeScreenDirty();
|
|
||||||
|
|
||||||
/* Update coordinates of the signs. */
|
/* Update coordinates of the signs. */
|
||||||
UpdateAllStationVirtCoord();
|
UpdateAllStationVirtCoord();
|
||||||
|
|
|
@ -1473,7 +1473,7 @@ static const SaveLoadFormat *GetSavegameFormat(const char *s)
|
||||||
/* actual loader/saver function */
|
/* actual loader/saver function */
|
||||||
void InitializeGame(uint size_x, uint size_y, bool reset_date);
|
void InitializeGame(uint size_x, uint size_y, bool reset_date);
|
||||||
extern bool AfterLoadGame();
|
extern bool AfterLoadGame();
|
||||||
extern void BeforeSaveGame();
|
extern void SaveViewportBeforeSaveGame();
|
||||||
extern bool LoadOldSaveGame(const char *file);
|
extern bool LoadOldSaveGame(const char *file);
|
||||||
|
|
||||||
/** Small helper function to close the to be loaded savegame an signal error */
|
/** Small helper function to close the to be loaded savegame an signal error */
|
||||||
|
@ -1673,7 +1673,7 @@ SaveOrLoadResult SaveOrLoad(const char *filename, int mode, Subdirectory sb)
|
||||||
|
|
||||||
_sl_version = SAVEGAME_VERSION;
|
_sl_version = SAVEGAME_VERSION;
|
||||||
|
|
||||||
BeforeSaveGame();
|
SaveViewportBeforeSaveGame();
|
||||||
SlSaveChunks();
|
SlSaveChunks();
|
||||||
SlWriteFill(); // flush the save buffer
|
SlWriteFill(); // flush the save buffer
|
||||||
|
|
||||||
|
|
|
@ -2756,3 +2756,33 @@ void ResetObjectToPlace()
|
||||||
{
|
{
|
||||||
SetObjectToPlace(SPR_CURSOR_MOUSE, PAL_NONE, VHM_NONE, WC_MAIN_WINDOW, 0);
|
SetObjectToPlace(SPR_CURSOR_MOUSE, PAL_NONE, VHM_NONE, WC_MAIN_WINDOW, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SaveViewportBeforeSaveGame()
|
||||||
|
{
|
||||||
|
const Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
|
||||||
|
|
||||||
|
if (w != NULL) {
|
||||||
|
_saved_scrollpos_x = w->viewport->scrollpos_x;
|
||||||
|
_saved_scrollpos_y = w->viewport->scrollpos_y;
|
||||||
|
_saved_scrollpos_zoom = w->viewport->zoom;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ResetViewportAfterLoadGame()
|
||||||
|
{
|
||||||
|
Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
|
||||||
|
|
||||||
|
w->viewport->scrollpos_x = _saved_scrollpos_x;
|
||||||
|
w->viewport->scrollpos_y = _saved_scrollpos_y;
|
||||||
|
w->viewport->dest_scrollpos_x = _saved_scrollpos_x;
|
||||||
|
w->viewport->dest_scrollpos_y = _saved_scrollpos_y;
|
||||||
|
|
||||||
|
ViewPort *vp = w->viewport;
|
||||||
|
vp->zoom = min(_saved_scrollpos_zoom, ZOOM_LVL_MAX);
|
||||||
|
vp->virtual_width = ScaleByZoom(vp->width, vp->zoom);
|
||||||
|
vp->virtual_height = ScaleByZoom(vp->height, vp->zoom);
|
||||||
|
|
||||||
|
DoZoomInOutWindow(ZOOM_NONE, w); // update button status
|
||||||
|
MarkWholeScreenDirty();
|
||||||
|
}
|
||||||
|
|
|
@ -1021,6 +1021,7 @@ void InitWindowSystem()
|
||||||
_last_z_window = _z_windows;
|
_last_z_window = _z_windows;
|
||||||
_mouseover_last_w = NULL;
|
_mouseover_last_w = NULL;
|
||||||
_no_scroll = 0;
|
_no_scroll = 0;
|
||||||
|
_scrolling_viewport = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1707,6 +1708,55 @@ enum MouseClick {
|
||||||
extern void UpdateTileSelection();
|
extern void UpdateTileSelection();
|
||||||
extern bool VpHandlePlaceSizingDrag();
|
extern bool VpHandlePlaceSizingDrag();
|
||||||
|
|
||||||
|
static void ScrollMainViewport(int x, int y)
|
||||||
|
{
|
||||||
|
if (_game_mode != GM_MENU) {
|
||||||
|
Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
|
||||||
|
assert(w);
|
||||||
|
|
||||||
|
w->viewport->dest_scrollpos_x += ScaleByZoom(x, w->viewport->zoom);
|
||||||
|
w->viewport->dest_scrollpos_y += ScaleByZoom(y, w->viewport->zoom);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Describes all the different arrow key combinations the game allows
|
||||||
|
* when it is in scrolling mode.
|
||||||
|
* The real arrow keys are bitwise numbered as
|
||||||
|
* 1 = left
|
||||||
|
* 2 = up
|
||||||
|
* 4 = right
|
||||||
|
* 8 = down
|
||||||
|
*/
|
||||||
|
static const int8 scrollamt[16][2] = {
|
||||||
|
{ 0, 0}, ///< no key specified
|
||||||
|
{-2, 0}, ///< 1 : left
|
||||||
|
{ 0, -2}, ///< 2 : up
|
||||||
|
{-2, -1}, ///< 3 : left + up
|
||||||
|
{ 2, 0}, ///< 4 : right
|
||||||
|
{ 0, 0}, ///< 5 : left + right = nothing
|
||||||
|
{ 2, -1}, ///< 6 : right + up
|
||||||
|
{ 0, -2}, ///< 7 : right + left + up = up
|
||||||
|
{ 0 ,2}, ///< 8 : down
|
||||||
|
{-2 ,1}, ///< 9 : down + left
|
||||||
|
{ 0, 0}, ///< 10 : down + up = nothing
|
||||||
|
{-2, 0}, ///< 11 : left + up + down = left
|
||||||
|
{ 2, 1}, ///< 12 : down + right
|
||||||
|
{ 0, 2}, ///< 13 : left + right + down = down
|
||||||
|
{ 2, 0}, ///< 14 : right + up + down = right
|
||||||
|
{ 0, 0}, ///< 15 : left + up + right + down = nothing
|
||||||
|
};
|
||||||
|
|
||||||
|
static bool HandleKeyScrolling()
|
||||||
|
{
|
||||||
|
if (_dirkeys && !_no_scroll) {
|
||||||
|
int factor = _shift_pressed ? 50 : 10;
|
||||||
|
ScrollMainViewport(scrollamt[_dirkeys][0] * factor, scrollamt[_dirkeys][1] * factor);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void MouseLoop(MouseClick click, int mousewheel)
|
void MouseLoop(MouseClick click, int mousewheel)
|
||||||
{
|
{
|
||||||
DecreaseWindowCounters();
|
DecreaseWindowCounters();
|
||||||
|
@ -1718,6 +1768,7 @@ void MouseLoop(MouseClick click, int mousewheel)
|
||||||
if (!HandleScrollbarScrolling()) return;
|
if (!HandleScrollbarScrolling()) return;
|
||||||
if (!HandleViewportScroll()) return;
|
if (!HandleViewportScroll()) return;
|
||||||
if (!HandleMouseOver()) return;
|
if (!HandleMouseOver()) return;
|
||||||
|
if (!HandleKeyScrolling()) return;
|
||||||
|
|
||||||
bool scrollwheel_scrolling = _settings.gui.scrollwheel_scrolling == 1 && (_cursor.v_wheel != 0 || _cursor.h_wheel != 0);
|
bool scrollwheel_scrolling = _settings.gui.scrollwheel_scrolling == 1 && (_cursor.v_wheel != 0 || _cursor.h_wheel != 0);
|
||||||
if (click == MC_NONE && mousewheel == 0 && !scrollwheel_scrolling) return;
|
if (click == MC_NONE && mousewheel == 0 && !scrollwheel_scrolling) return;
|
||||||
|
@ -1979,6 +2030,12 @@ void InvalidateWindowClassesData(WindowClass cls, int data)
|
||||||
*/
|
*/
|
||||||
void CallWindowTickEvent()
|
void CallWindowTickEvent()
|
||||||
{
|
{
|
||||||
|
if (_scroller_click_timeout > 3) {
|
||||||
|
_scroller_click_timeout -= 3;
|
||||||
|
} else {
|
||||||
|
_scroller_click_timeout = 0;
|
||||||
|
}
|
||||||
|
|
||||||
for (Window * const *wz = _last_z_window; wz != _z_windows;) {
|
for (Window * const *wz = _last_z_window; wz != _z_windows;) {
|
||||||
(*--wz)->OnTick();
|
(*--wz)->OnTick();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue