Skip to content

Commit c3e2599

Browse files
authored
add MenuHandler::temp_replay (#2802)
1 parent e677985 commit c3e2599

5 files changed

Lines changed: 18 additions & 12 deletions

File tree

gframe/menu_handler.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
232232
break;
233233
}
234234
case BUTTON_LOAD_REPLAY: {
235+
int start_turn = 1;
235236
if(open_file) {
236237
ReplayMode::cur_replay.OpenReplay(open_file_name);
237238
open_file = false;
@@ -243,6 +244,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
243244
myswprintf(replay_path, L"./replay/%ls", mainGame->lstReplayList->getListItem(selected));
244245
if (!ReplayMode::cur_replay.OpenReplay(replay_path))
245246
break;
247+
start_turn = std::wcstol(mainGame->ebRepStartTurn->getText(), nullptr, 10);
246248
}
247249
mainGame->ClearCardInfo();
248250
mainGame->wCardImg->setVisible(true);
@@ -257,7 +259,6 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
257259
mainGame->dField.Clear();
258260
mainGame->HideElement(mainGame->wReplay);
259261
mainGame->device->setEventReceiver(&mainGame->dField);
260-
unsigned int start_turn = std::wcstol(mainGame->ebRepStartTurn->getText(), nullptr, 10);
261262
if(start_turn == 1)
262263
start_turn = 0;
263264
ReplayMode::StartReplay(start_turn);
@@ -526,27 +527,27 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
526527
break;
527528
wchar_t replay_path[256]{};
528529
myswprintf(replay_path, L"./replay/%ls", mainGame->lstReplayList->getListItem(sel));
529-
if (!ReplayMode::cur_replay.OpenReplay(replay_path)) {
530+
if (!temp_replay.OpenReplay(replay_path)) {
530531
mainGame->stReplayInfo->setText(L"Error");
531532
break;
532533
}
533534
wchar_t infobuf[256]{};
534535
std::wstring repinfo;
535536
time_t curtime;
536-
if(ReplayMode::cur_replay.pheader.flag & REPLAY_UNIFORM)
537-
curtime = ReplayMode::cur_replay.pheader.start_time;
537+
if(temp_replay.pheader.flag & REPLAY_UNIFORM)
538+
curtime = temp_replay.pheader.start_time;
538539
else
539-
curtime = ReplayMode::cur_replay.pheader.seed;
540+
curtime = temp_replay.pheader.seed;
540541
std::wcsftime(infobuf, sizeof infobuf / sizeof infobuf[0], L"%Y/%m/%d %H:%M:%S\n", std::localtime(&curtime));
541542
repinfo.append(infobuf);
542-
if (ReplayMode::cur_replay.pheader.flag & REPLAY_SINGLE_MODE) {
543+
if (temp_replay.pheader.flag & REPLAY_SINGLE_MODE) {
543544
wchar_t path[256]{};
544-
BufferIO::DecodeUTF8(ReplayMode::cur_replay.script_name.c_str(), path);
545+
BufferIO::DecodeUTF8(temp_replay.script_name.c_str(), path);
545546
repinfo.append(path);
546547
repinfo.append(L"\n");
547548
}
548-
const auto& player_names = ReplayMode::cur_replay.players;
549-
if(ReplayMode::cur_replay.pheader.flag & REPLAY_TAG)
549+
const auto& player_names = temp_replay.players;
550+
if(temp_replay.pheader.flag & REPLAY_TAG)
550551
myswprintf(infobuf, L"%ls\n%ls\n===VS===\n%ls\n%ls\n", player_names[0].c_str(), player_names[1].c_str(), player_names[2].c_str(), player_names[3].c_str());
551552
else
552553
myswprintf(infobuf, L"%ls\n===VS===\n%ls\n", player_names[0].c_str(), player_names[1].c_str());

gframe/menu_handler.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define MENU_HANDLER_H
33

44
#include <irrlicht.h>
5+
#include "replay.h"
56

67
namespace ygo {
78

@@ -10,7 +11,7 @@ class MenuHandler: public irr::IEventReceiver {
1011
bool OnEvent(const irr::SEvent& event) override;
1112
irr::s32 prev_operation{ 0 };
1213
int prev_sel{ -1 };
13-
14+
Replay temp_replay;
1415
};
1516

1617
}

gframe/replay.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,11 @@ void Replay::Reset() {
227227
script_name.clear();
228228
}
229229
void Replay::SkipInfo(){
230-
data_position += info_offset;
230+
if (data_position == 0)
231+
data_position += info_offset;
232+
}
233+
bool Replay::IsReplaying() const {
234+
return is_replaying;
231235
}
232236
bool Replay::ReadInfo() {
233237
int player_count = (pheader.flag & REPLAY_TAG) ? 4 : 2;

gframe/replay.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class Replay {
8181
void Rewind();
8282
void Reset();
8383
void SkipInfo();
84+
bool IsReplaying() const;
8485

8586
FILE* fp{ nullptr };
8687
#ifdef _WIN32

gframe/replay_mode.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ class ReplayMode {
2525
public:
2626
static Replay cur_replay;
2727

28-
public:
2928
static bool StartReplay(int skipturn);
3029
static void StopReplay(bool is_exiting = false);
3130
static void SwapField();

0 commit comments

Comments
 (0)