|
5 | 5 | #include "iwSkipGFs.h" |
6 | 6 | #include "Loader.h" |
7 | 7 | #include "controls/ctrlEdit.h" |
| 8 | +#include "helpers/Range.h" |
8 | 9 | #include "network/GameClient.h" |
9 | 10 | #include "gameData/const_gui_ids.h" |
10 | 11 | #include "s25util/StringConversion.h" |
11 | 12 | #include "s25util/colors.h" |
12 | 13 |
|
| 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 | + |
13 | 33 | 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"), |
15 | 35 | LOADER.GetImageN("resource", 41)), |
16 | 36 | gwv(gwv) |
17 | 37 | { |
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); |
20 | 43 |
|
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); |
23 | 46 | 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); |
24 | 60 |
|
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 | + } |
27 | 71 | } |
28 | 72 |
|
29 | | -void iwSkipGFs::SkipGFs() |
| 73 | +void iwSkipGFs::SkipGFs(const unsigned edtCtrlId) |
30 | 74 | { |
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); |
33 | 79 | } |
34 | 80 |
|
35 | | -void iwSkipGFs::Msg_ButtonClick(const unsigned /*ctrl_id*/) |
| 81 | +void iwSkipGFs::Msg_ButtonClick(const unsigned ctrlId) |
36 | 82 | { |
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 | + } |
38 | 90 | } |
39 | 91 |
|
40 | | -void iwSkipGFs::Msg_EditEnter(const unsigned /*ctrl_id*/) |
| 92 | +void iwSkipGFs::Msg_EditEnter(const unsigned ctrlId) |
41 | 93 | { |
42 | | - SkipGFs(); |
| 94 | + SkipGFs(ctrlId); |
43 | 95 | } |
0 commit comments