mirror of https://github.com/mgba-emu/mgba.git
GBA: Cheat set disabling
This commit is contained in:
parent
ca6b2e7b09
commit
8c7d5b5b86
|
@ -424,6 +424,7 @@ void GBACheatSetInit(struct GBACheatSet* set, const char* name) {
|
|||
} else {
|
||||
set->name = 0;
|
||||
}
|
||||
set->enabled = true;
|
||||
}
|
||||
|
||||
void GBACheatSetDeinit(struct GBACheatSet* set) {
|
||||
|
@ -693,6 +694,7 @@ bool GBACheatParseFile(struct GBACheatDevice* device, struct VFile* vf) {
|
|||
struct GBACheatSet* set = 0;
|
||||
struct GBACheatSet* newSet;
|
||||
int gsaVersion = 0;
|
||||
bool nextDisabled = false;
|
||||
while (true) {
|
||||
size_t i = 0;
|
||||
ssize_t bytesRead = vf->readline(vf, cheat, sizeof(cheat));
|
||||
|
@ -712,6 +714,8 @@ bool GBACheatParseFile(struct GBACheatDevice* device, struct VFile* vf) {
|
|||
} while (isspace(cheat[i]));
|
||||
newSet = malloc(sizeof(*set));
|
||||
GBACheatSetInit(newSet, &cheat[i]);
|
||||
newSet->enabled = !nextDisabled;
|
||||
nextDisabled = false;
|
||||
if (set) {
|
||||
GBACheatAddSet(device, set);
|
||||
newSet->gsaVersion = set->gsaVersion;
|
||||
|
@ -732,12 +736,19 @@ bool GBACheatParseFile(struct GBACheatDevice* device, struct VFile* vf) {
|
|||
if (strncasecmp(&cheat[i], "GSAv", 4) == 0 || strncasecmp(&cheat[i], "PARv", 4) == 0) {
|
||||
i += 4;
|
||||
gsaVersion = atoi(&cheat[i]);
|
||||
break;
|
||||
}
|
||||
if (strcasecmp(&cheat[i], "disabled") == 0) {
|
||||
nextDisabled = true;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (!set) {
|
||||
set = malloc(sizeof(*set));
|
||||
GBACheatSetInit(set, 0);
|
||||
set->enabled = !nextDisabled;
|
||||
nextDisabled = false;
|
||||
_setGameSharkVersion(set, gsaVersion);
|
||||
}
|
||||
GBACheatAddLine(set, cheat);
|
||||
|
@ -779,6 +790,9 @@ bool GBACheatAddLine(struct GBACheatSet* cheats, const char* line) {
|
|||
}
|
||||
|
||||
void GBACheatRefresh(struct GBACheatDevice* device, struct GBACheatSet* cheats) {
|
||||
if (!cheats->enabled) {
|
||||
return;
|
||||
}
|
||||
bool condition = true;
|
||||
int conditionRemaining = 0;
|
||||
_patchROM(device, cheats);
|
||||
|
|
|
@ -163,6 +163,7 @@ struct GBACheatSet {
|
|||
int remainingAddresses;
|
||||
|
||||
char* name;
|
||||
bool enabled;
|
||||
struct StringList lines;
|
||||
};
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ QVariant CheatsModel::data(const QModelIndex& index, int role) const {
|
|||
case Qt::EditRole:
|
||||
return cheats->name ? cheats->name : tr("(untitled)");
|
||||
case Qt::CheckStateRole:
|
||||
return Qt::Checked;
|
||||
return cheats->enabled ? Qt::Checked : Qt::Unchecked;
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
|
@ -67,9 +67,12 @@ bool CheatsModel::setData(const QModelIndex& index, const QVariant& value, int r
|
|||
cheats->name = nullptr;
|
||||
}
|
||||
cheats->name = strdup(value.toString().toLocal8Bit().constData());
|
||||
emit dataChanged(index, index);
|
||||
return true;
|
||||
case Qt::CheckStateRole:
|
||||
return false;
|
||||
cheats->enabled = value == Qt::Checked;
|
||||
emit dataChanged(index, index);
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
@ -108,7 +111,7 @@ Qt::ItemFlags CheatsModel::flags(const QModelIndex &index) const {
|
|||
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
||||
}
|
||||
|
||||
return Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
||||
return Qt::ItemIsUserCheckable | Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
||||
}
|
||||
|
||||
int CheatsModel::columnCount(const QModelIndex& parent) const {
|
||||
|
|
Loading…
Reference in New Issue