Skip to content

Commit 251adc4

Browse files
committed
add gui for the new stuff
1 parent 2e19faa commit 251adc4

4 files changed

Lines changed: 46 additions & 17 deletions

File tree

src/recorder.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
Recorder::Recorder() : m_width(1280), m_height(720), m_fps(60) {}
77

8-
const float extra_length_at_the_end = 3.f;
9-
108
void Recorder::start(const std::string& path) {
119
m_recording = true;
1210
m_finished_level = false;
@@ -24,7 +22,8 @@ void Recorder::start(const std::string& path) {
2422
auto sfx_volume = gm->m_fEffectsVolume;
2523
if (play_layer->m_level->songID == 0)
2624
song_file = CCFileUtils::sharedFileUtils()->fullPathForFilename(song_file.c_str(), false);
27-
std::thread([&, path, song_file, fade_in, fade_out, bg_volume, sfx_volume]() {
25+
auto is_testmode = play_layer->m_isTestMode;
26+
std::thread([&, path, song_file, fade_in, fade_out, bg_volume, sfx_volume, is_testmode]() {
2827
std::stringstream stream;
2928
stream << "ffmpeg -y -f rawvideo -pix_fmt rgb24 -s " << m_width << "x" << m_height << " -r " << m_fps
3029
<< " -i - ";
@@ -53,7 +52,7 @@ void Recorder::start(const std::string& path) {
5352
return;
5453
}
5554
std::cout << "should be done now!" << std::endl;
56-
if (!std::filesystem::exists(song_file)) return;
55+
if (!m_include_audio || !std::filesystem::exists(song_file)) return;
5756
std::cout << "sike" << std::endl;
5857
char buffer[MAX_PATH];
5958
if (!GetTempFileNameA(std::filesystem::temp_directory_path().string().c_str(), "rec", 0, buffer)) {
@@ -68,10 +67,10 @@ void Recorder::start(const std::string& path) {
6867
stream << "ffmpeg -y -ss " << m_song_start_offset << " -i \"" << song_file
6968
<< "\" -i \"" << path << "\" -t " << total_time << " -c:v copy "
7069
<< "-filter:a \"volume=" << bg_volume << "[0:a]";
71-
if (fade_in)
70+
if (fade_in && !is_testmode)
7271
stream << ";[0:a]afade=t=in:d=2[0:a]";
73-
if (fade_out)
74-
stream << ";[0:a]afade=t=out:d=2:st=" << (total_time - extra_length_at_the_end - 3.5f) << "[0:a]";
72+
if (fade_out && m_finished_level)
73+
stream << ";[0:a]afade=t=out:d=2:st=" << (total_time - m_after_end_duration - 3.5f) << "[0:a]";
7574
std::cout << "in " << fade_in << " out " << fade_out << std::endl;
7675
stream << "\" \"" << temp_path << "\"";
7776
std::cout << "executing: " << stream.str() << std::endl;
@@ -150,7 +149,7 @@ void Recorder::capture_frame() {
150149
}
151150

152151
void Recorder::handle_recording(gd::PlayLayer* play_layer, float dt) {
153-
if (!play_layer->m_hasLevelCompleteMenu || m_after_end_extra_time < extra_length_at_the_end) {
152+
if (!play_layer->m_hasLevelCompleteMenu || m_after_end_extra_time < m_after_end_duration) {
154153
if (play_layer->m_hasLevelCompleteMenu) {
155154
m_after_end_extra_time += dt;
156155
m_finished_level = true;

src/recorder.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,11 @@ class Recorder {
5858
double m_last_frame_t, m_extra_t;
5959
bool m_until_end = true;
6060
std::string m_codec = "", m_bitrate = "30M", m_extra_args = "";
61+
float m_after_end_duration = 3.f;
6162
float m_after_end_extra_time;
6263
float m_song_start_offset;
6364
bool m_finished_level;
65+
bool m_include_audio = true;
6466

6567
void start(const std::string& path);
6668
void stop();

src/recorder_layer.cpp

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ bool RecorderLayer::init() {
1818

1919
const CCPoint top_left = win_size / 2.f - ccp(window_size.width / 2.f, -window_size.height / 2.f);
2020

21+
registerWithTouchDispatcher();
22+
CCDirector::sharedDirector()->getTouchDispatcher()->incrementForcePrio(2);
23+
2124
m_pButtonMenu = CCMenu::create();
2225
m_pButtonMenu->setPosition({0, 0});
2326
auto menu = m_pButtonMenu; // sorry m_pButtonMenu is too much to type
@@ -51,41 +54,64 @@ bool RecorderLayer::init() {
5154
menu->addChild(toggler);
5255
layer->addChild(label);
5356

57+
toggler = gd::CCMenuItemToggler::create(check_off_sprite, check_on_sprite, this, menu_selector(RecorderLayer::on_toggle_include_audio));
58+
toggler->setPosition(top_left + ccp(30.f, -100.f));
59+
toggler->toggle(rs.recorder.m_include_audio);
60+
menu->addChild(toggler);
61+
layer->addChild(NodeFactory<CCLabelBMFont>::start("Include audio", "bigFont.fnt")
62+
.setScale(0.7f)
63+
.setPosition(top_left + ccp(55.f, -100.f))
64+
.setAnchorPoint(ccp(0, 0.5f)));
65+
5466
auto input = NumberInputNode::create(CCSize(70.f, 30.f));
5567
input->set_value(rs.recorder.m_width);
56-
input->setPosition(top_left + ccp(49.f, -104.f));
68+
input->setPosition(top_left + ccp(49.f, -138.f));
5769
input->input_node->setMaxLabelScale(0.73f);
5870
input->callback = [&rs](auto input) {
5971
rs.recorder.m_width = input->get_value();
6072
};
6173
layer->addChild(input);
6274

6375
layer->addChild(NodeFactory<CCLabelBMFont>::start("x", "bigFont.fnt")
64-
.setPosition(top_left + ccp(93.5f, -104.f))
76+
.setPosition(top_left + ccp(93.5f, -138.f))
6577
.setScale(0.5f));
6678

6779
input = NumberInputNode::create(CCSize(70.f, 30.f));
6880
input->set_value(rs.recorder.m_height);
69-
input->setPosition(top_left + ccp(137.f, -104.f));
81+
input->setPosition(top_left + ccp(137.f, -138.f));
7082
input->input_node->setMaxLabelScale(0.73f);
7183
input->callback = [&rs](auto input) {
7284
rs.recorder.m_height = input->get_value();
7385
};
7486
layer->addChild(input);
7587

7688
layer->addChild(NodeFactory<CCLabelBMFont>::start("@", "bigFont.fnt")
77-
.setPosition(top_left + ccp(185.5f, -104.f))
89+
.setPosition(top_left + ccp(185.5f, -138.f))
7890
.setScale(0.5f));
7991

8092
input = NumberInputNode::create(CCSize(50.f, 30.f));
8193
input->set_value(rs.recorder.m_fps);
82-
input->setPosition(top_left + ccp(225.f, -104.f));
94+
input->setPosition(top_left + ccp(225.f, -138.f));
8395
input->input_node->setMaxLabelScale(0.73f);
8496
input->callback = [&rs](auto input) {
8597
rs.recorder.m_fps = input->get_value();
8698
};
8799
layer->addChild(input);
88100

101+
input = NumberInputNode::create(CCSize(50.f, 30.f));
102+
input->set_value(rs.recorder.m_after_end_duration);
103+
input->setPosition(top_left + ccp(346.f, -65.f));
104+
input->input_node->setMaxLabelScale(0.73f);
105+
input->callback = [&rs](auto input) {
106+
rs.recorder.m_after_end_duration = static_cast<float>(input->get_value());
107+
};
108+
layer->addChild(input);
109+
layer->addChild(NodeFactory<CCLabelBMFont>::start("seconds to render after", "bigFont.fnt")
110+
.setPosition(top_left + ccp(346.f, -45.f))
111+
.setScale(0.224f));
112+
113+
layer->addChild(NodeFactory<CCNode>::start().setPosition(top_left));
114+
89115
const std::string broad_filter = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.,;-_=+@!\":0123456789$[](){} ";
90116

91117
auto text_input = TextInputNode::create(CCSize(60.f, 30.f), 1.f, "chatFont.fnt");
@@ -122,9 +148,6 @@ bool RecorderLayer::init() {
122148
layer->addChild(NodeFactory<CCLabelBMFont>::start("Bitrate", "bigFont.fnt").setPosition(top_left + ccp(291.5f, -152.f)).setScale(0.4f));
123149
layer->addChild(NodeFactory<CCLabelBMFont>::start("Codec", "bigFont.fnt").setPosition(top_left + ccp(359.5f, -152.f)).setScale(0.4f));
124150

125-
registerWithTouchDispatcher();
126-
CCDirector::sharedDirector()->getTouchDispatcher()->incrementForcePrio(2);
127-
128151
auto close_btn = gd::CCMenuItemSpriteExtra::create(
129152
CCSprite::createWithSpriteFrameName("GJ_closeBtn_001.png"),
130153
this,
@@ -173,4 +196,8 @@ void RecorderLayer::on_toggle_recorder(CCObject* obj) {
173196

174197
void RecorderLayer::on_toggle_until_end(CCObject* obj) {
175198
ReplaySystem::get_instance().recorder.m_until_end = !static_cast<gd::CCMenuItemToggler*>(obj)->isOn();
176-
}
199+
}
200+
201+
void RecorderLayer::on_toggle_include_audio(CCObject* obj) {
202+
ReplaySystem::get_instance().recorder.m_include_audio = !static_cast<gd::CCMenuItemToggler*>(obj)->isOn();
203+
}

src/recorder_layer.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ class RecorderLayer : public gd::FLAlertLayer {
2020
void on_close(CCObject*);
2121
void on_toggle_recorder(CCObject*);
2222
void on_toggle_until_end(CCObject*);
23+
void on_toggle_include_audio(CCObject*);
2324
};

0 commit comments

Comments
 (0)