Skip to content

Commit 413ba23

Browse files
FlamefireFlow86
authored andcommitted
Add option to jump by specific number of GFs to jump window
Closes #1861
1 parent 696db30 commit 413ba23

4 files changed

Lines changed: 81 additions & 30 deletions

File tree

libs/s25main/ingameWindows/IngameWindow.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ class IngameWindow : public Window
5555
glArchivItem_Bitmap* background, bool modal = false,
5656
CloseBehavior closeBehavior = CloseBehavior::Regular, Window* parent = nullptr);
5757

58-
/// setzt den Hintergrund.
58+
/// Set background image
5959
void SetBackground(glArchivItem_Bitmap* background) { this->background = background; }
60-
/// liefert den Hintergrund.
60+
/// Get background image
6161
glArchivItem_Bitmap* GetBackground() const { return background; }
6262

63-
/// setzt den Fenstertitel.
63+
/// Set window title
6464
void SetTitle(const std::string& title) { this->title_ = title; }
65-
/// liefert den Fenstertitel.
65+
/// Get window title
6666
const std::string& GetTitle() const { return title_; }
6767

6868
void Resize(const Extent& newSize) override;
@@ -78,14 +78,14 @@ class IngameWindow : public Window
7878
/// Set the position for the window after adjusting newPos so the window is in the visible area
7979
void SetPos(DrawPoint newPos, bool saveRestorePos = true);
8080

81-
/// merkt das Fenster zum Schließen vor.
81+
/// Queue the window for closing, will be done in next draw cycle
8282
virtual void Close();
83-
/// soll das Fenster geschlossen werden.
83+
/// Return if the window will be closes
8484
bool ShouldBeClosed() const { return closeme; }
8585

86-
/// minimiert das Fenster.
86+
/// Minimize window (only title bar and bottom border remains)
8787
void SetMinimized(bool minimized = true);
88-
/// ist das Fenster minimiert?
88+
/// Return whether the window is minimized
8989
bool IsMinimized() const { return isMinimized_; }
9090

9191
void SetPinned(bool pinned = true);
@@ -109,12 +109,12 @@ class IngameWindow : public Window
109109
/// Called when not minimized after the frame and background have been drawn
110110
virtual void DrawContent() {}
111111

112-
/// Verschiebt Fenster in die Bildschirmmitte
112+
/// Move window to center of screen
113113
void MoveToCenter();
114-
/// Verschiebt Fenster neben die Maus
114+
/// Move window next to current cursor position
115115
void MoveNextToMouse();
116116

117-
/// Weiterleitung von Nachrichten erlaubt oder nicht?
117+
/// Return if events (mouse move...) should be passed to controls of the window
118118
bool IsMessageRelayAllowed() const override;
119119

120120
void SaveOpenStatus(bool isOpen) const;

libs/s25main/ingameWindows/iwSkipGFs.cpp

Lines changed: 66 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,91 @@
55
#include "iwSkipGFs.h"
66
#include "Loader.h"
77
#include "controls/ctrlEdit.h"
8+
#include "helpers/Range.h"
89
#include "network/GameClient.h"
910
#include "gameData/const_gui_ids.h"
1011
#include "s25util/StringConversion.h"
1112
#include "s25util/colors.h"
1213

14+
namespace {
15+
enum
16+
{
17+
ID_lblToGf,
18+
ID_edtToGf,
19+
ID_btToGf,
20+
ID_lblByGf,
21+
ID_edtByGf,
22+
ID_btByGf,
23+
ID_btJumpPresetStart, // Must be last, one per jump preset
24+
};
25+
constexpr std::array jumpPresets = {
26+
100,
27+
1000,
28+
5000,
29+
10000,
30+
};
31+
} // namespace
32+
1333
iwSkipGFs::iwSkipGFs(GameWorldView& gwv)
14-
: IngameWindow(CGI_SKIPGFS, IngameWindow::posLastOrCenter, Extent(300, 110), _("Skip GameFrames"),
34+
: IngameWindow(CGI_SKIPGFS, IngameWindow::posLastOrCenter, Extent(300, 120), _("Skip GameFrames"),
1535
LOADER.GetImageN("resource", 41)),
1636
gwv(gwv)
1737
{
18-
// Text vor Editfeld
19-
AddText(0, DrawPoint(50, 36), _("to GameFrame:"), COLOR_YELLOW, FontStyle{}, NormalFont);
38+
constexpr auto lblWidth = 135;
39+
const auto edtOffset = contentOffset.x + lblWidth;
40+
constexpr auto spacing = 5;
41+
constexpr Extent edtSize(100, 20);
42+
Extent btSize(GetIwSize().x - edtOffset - edtSize.x - spacing, edtSize.y);
2043

21-
// Editfeld zum Eingeben des Ziel-GF
22-
ctrlEdit* edit = AddEdit(1, DrawPoint(126, 32), Extent(120, 20), TextureColor::Grey, NormalFont);
44+
DrawPoint curPos(edtOffset, 28);
45+
ctrlEdit* edit = AddEdit(ID_edtToGf, curPos, edtSize, TextureColor::Grey, NormalFont);
2346
edit->SetFocus();
47+
curPos.x -= spacing;
48+
AddText(ID_lblToGf, curPos + DrawPoint(0, 4), _("to GameFrame:"), COLOR_YELLOW, FontStyle::RIGHT, NormalFont);
49+
curPos.x += edtSize.x + spacing * 2;
50+
AddTextButton(ID_btToGf, curPos, btSize, TextureColor::Green2, "->|", NormalFont);
51+
52+
curPos.x = edtOffset;
53+
curPos.y += edtSize.y + 5;
54+
55+
AddEdit(ID_edtByGf, curPos, edtSize, TextureColor::Grey, NormalFont);
56+
curPos.x -= spacing;
57+
AddText(ID_lblByGf, curPos + DrawPoint(0, 4), _("by GameFrames:"), COLOR_YELLOW, FontStyle::RIGHT, NormalFont);
58+
curPos.x += edtSize.x + spacing * 2;
59+
AddTextButton(ID_btByGf, curPos, btSize, TextureColor::Green2, "-->", NormalFont);
2460

25-
// OK-Button
26-
AddTextButton(2, DrawPoint(110, 65), Extent(80, 22), TextureColor::Green2, _("OK"), NormalFont);
61+
curPos.x = contentOffset.x + spacing;
62+
curPos.y += edtSize.y + 5;
63+
const auto availWidth = GetIwSize().x - spacing * 2;
64+
btSize.x = (availWidth - spacing * (jumpPresets.size() - 1)) / jumpPresets.size();
65+
for(auto i : helpers::range(jumpPresets.size()))
66+
{
67+
AddTextButton(ID_btJumpPresetStart + i, curPos, btSize, TextureColor::Green1,
68+
"+" + std::to_string(jumpPresets[i]), NormalFont);
69+
curPos.x += btSize.x + spacing;
70+
}
2771
}
2872

29-
void iwSkipGFs::SkipGFs()
73+
void iwSkipGFs::SkipGFs(const unsigned edtCtrlId)
3074
{
31-
int gf = s25util::fromStringClassicDef(GetCtrl<ctrlEdit>(1)->GetText(), 0);
32-
GAMECLIENT.SkipGF(gf, gwv);
75+
int targetGF = s25util::fromStringClassicDef(GetCtrl<ctrlEdit>(edtCtrlId)->GetText(), 0);
76+
if(edtCtrlId == ID_edtByGf)
77+
targetGF += GAMECLIENT.GetGFNumber();
78+
GAMECLIENT.SkipGF(targetGF, gwv);
3379
}
3480

35-
void iwSkipGFs::Msg_ButtonClick(const unsigned /*ctrl_id*/)
81+
void iwSkipGFs::Msg_ButtonClick(const unsigned ctrlId)
3682
{
37-
SkipGFs();
83+
if(ctrlId < ID_btJumpPresetStart)
84+
SkipGFs((ctrlId == ID_btByGf) ? ID_edtByGf : ID_edtToGf);
85+
else
86+
{
87+
const unsigned targetGF = GAMECLIENT.GetGFNumber() + jumpPresets[ctrlId - ID_btJumpPresetStart];
88+
GAMECLIENT.SkipGF(targetGF, gwv);
89+
}
3890
}
3991

40-
void iwSkipGFs::Msg_EditEnter(const unsigned /*ctrl_id*/)
92+
void iwSkipGFs::Msg_EditEnter(const unsigned ctrlId)
4193
{
42-
SkipGFs();
94+
SkipGFs(ctrlId);
4395
}

libs/s25main/ingameWindows/iwSkipGFs.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ class iwSkipGFs : public IngameWindow
1616
private:
1717
GameWorldView& gwv;
1818

19-
/// Teilt dem GameClient den Wert mit
20-
void SkipGFs();
19+
void SkipGFs(unsigned edtCtrlId);
2120

22-
void Msg_ButtonClick(unsigned ctrl_id) override;
23-
void Msg_EditEnter(unsigned ctrl_id) override;
21+
void Msg_ButtonClick(unsigned ctrlId) override;
22+
void Msg_EditEnter(unsigned ctrlId) override;
2423
};

libs/s25main/network/GameClient.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1381,7 +1381,7 @@ void GameClient::ExecuteGameFrame()
13811381
// Check remaining time until next GF
13821382
if(framesinfo.frameTime >= framesinfo.gf_length)
13831383
{
1384-
// This can happen, if we don't call this method in intervalls less than gf_length or gf_length has changed
1384+
// This can happen, if we don't call this method in intervals less than gf_length or gf_length has changed
13851385
// TODO: Run multiple GFs per call.
13861386
// For now just make sure it is less than gf_length by skipping some simulation time,
13871387
// until we are only a bit less than 1 GF behind

0 commit comments

Comments
 (0)