bsnes/higan/target-tomoko/tools/state-manager.cpp

122 lines
3.8 KiB
C++
Raw Normal View History

StateManager::StateManager(TabFrame* parent) : TabFrameItem(parent) {
setIcon(Icon::Application::FileManager);
setText("State Manager");
layout.setMargin(5);
stateList.append(TableViewHeader().setVisible()
.append(TableViewColumn().setText("Slot").setForegroundColor({0, 128, 0}).setAlignment(1.0))
.append(TableViewColumn().setText("Description").setExpandable())
);
for(auto slot : range(Slots)) {
stateList.append(TableViewItem()
.append(TableViewCell().setText(1 + slot))
.append(TableViewCell())
);
}
stateList.onActivate([&] { doLoad(); });
stateList.onChange([&] { doChangeSelected(); });
descriptionLabel.setText("Description:");
descriptionValue.onChange([&] { doChangeDescription(); });
saveButton.setText("Save").onActivate([&] { doSave(); });
loadButton.setText("Load").onActivate([&] { doLoad(); });
resetButton.setText("Reset").onActivate([&] { doReset(); });
eraseButton.setText("Erase").onActivate([&] { doErase(); });
doUpdateControls();
}
auto StateManager::doUpdateControls() -> void {
vector<uint8_t> buffer;
if(auto item = stateList.selected()) {
buffer = file::read(program->stateName(1 + item.offset(), true));
}
if(buffer.size() >= 584) {
descriptionValue.setEnabled(true);
loadButton.setEnabled(true);
eraseButton.setEnabled(true);
} else {
descriptionValue.setEnabled(false).setText("");
loadButton.setEnabled(false);
eraseButton.setEnabled(false);
}
}
auto StateManager::doChangeSelected() -> void {
vector<uint8_t> buffer;
if(auto item = stateList.selected()) {
buffer = file::read(program->stateName(1 + item.offset(), true));
if(buffer.size() >= 584) {
string description;
description.reserve(512);
memory::copy(description.get(), buffer.data() + 72, 512);
description.resize(description.length());
descriptionValue.setEnabled(true).setText(description);
return doUpdateControls();
}
}
descriptionValue.setEnabled(false).setText("");
doUpdateControls();
}
auto StateManager::doRefresh() -> void {
for(auto slot : range(Slots)) {
auto buffer = file::read(program->stateName(1 + slot, true));
if(buffer.size() >= 584) {
string description;
description.reserve(512);
memory::copy(description.get(), buffer.data() + 72, 512);
description.resize(description.length());
stateList.item(slot).cell(1).setText(description).setForegroundColor({0, 0, 0});
} else {
stateList.item(slot).cell(1).setText("(empty)").setForegroundColor({128, 128, 128});
}
}
}
auto StateManager::doChangeDescription() -> void {
if(auto item = stateList.selected()) {
auto buffer = file::read(program->stateName(1 + item.offset(), true));
if(buffer.size() >= 584) {
string description = descriptionValue.text();
description.reserve(512);
memory::copy(buffer.data() + 72, description.data(), 512);
file::write(program->stateName(1 + item.offset(), true), buffer);
doRefresh();
doUpdateControls();
}
}
}
auto StateManager::doLoad() -> void {
if(auto item = stateList.selected()) {
program->loadState(1 + item.offset(), true);
}
}
auto StateManager::doSave() -> void {
if(auto item = stateList.selected()) {
program->saveState(1 + item.offset(), true);
doRefresh();
doUpdateControls();
descriptionValue.setText("").setFocused();
}
}
auto StateManager::doReset() -> void {
Update to v094r23 release. byuu says: The library window is gone, and replaced with hiro::BrowserWindow::openFolder(). This gives navigation capabilities to game loading, and it also completes our slotted cart selection code. As an added bonus, it's less code this way, too. I also set the window size to consistent sizes between all emulated systems, so that switching between SFC and GB don't cause the window size to keep changing, and so that the scaling size is consistent (eg at normal scale, GB @ 3x is closer to SNES @ 2x.) This means black borders in GB/GBA mode, but it doesn't look that bad, and it's not like many people ever use these modes anyway. Finally, added the placeholder tabs for video, audio and timing. I don't intend to add the timing calculator code to v095 (it might be better as a separate tool), but I'll add the ability to set video/audio rates, at least. Glitch 1: despite selecting the first item in the BrowserDialog list, if you press enter when the window appears, it doesn't activate the item until you press an arrow key first. Glitch 2: in Game Boy mode, if you set the 4x window size, it's not honoring the full requested height because the viewport is smaller than the window. 8+ years of trying to get GTK+ and Qt to simply set the god damned window size I ask for, and I still can't get them to do it reliably. Remaining issues: - finish configuration panels (video, audio, timing) - fix ruby driver compilation on Windows - add DIP switch selection window (NSS) [I may end up punting this one to v096]
2015-05-30 11:39:09 +00:00
if(MessageDialog().setParent(*toolsManager).setText("Permanently erase all slots?").question() == "Yes") {
for(auto slot : range(Slots)) file::remove(program->stateName(1 + slot, true));
doRefresh();
doUpdateControls();
}
}
auto StateManager::doErase() -> void {
if(auto item = stateList.selected()) {
file::remove(program->stateName(1 + item.offset(), true));
doRefresh();
doUpdateControls();
}
}