Example #1
0
RuleBoxClass::RuleBoxClass(wxScrolled<wxPanel> *parent, Rule currentRule, uint32_t index, bool isSelected) : wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize) {
	//First get text representation of rule.
	string text = Outputter(PLAINTEXT, currentRule).AsString();
	ruleIndex = index;

	//Now do GUI stuff.
	SetBackgroundColour(wxColour(255,255,255));

	wxFlexGridSizer *mainSizer = new wxFlexGridSizer(2,0,0);
	mainSizer->SetFlexibleDirection(wxHORIZONTAL);
	mainSizer->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_NONE);
	mainSizer->AddGrowableCol(1,0);
	mainSizer->Add(ruleCheckbox = new wxCheckBox(this, wxID_ANY, ""),0,wxALIGN_CENTER_HORIZONTAL|wxLEFT|wxRIGHT|wxTOP|wxBOTTOM,10);
	mainSizer->Add(ruleContent = new wxStaticText(this, wxID_ANY, wxString(text.c_str(), wxConvUTF8)),0,wxEXPAND|wxRIGHT|wxTOP,10);  //Need to convert text that is outputted by BOSS-Common from UTF-8.

	ruleCheckbox->SetValue(currentRule.Enabled());
	ruleContent->Bind(wxEVT_LEFT_DOWN, &RuleBoxClass::OnSelect, this, wxID_ANY);
	if (!currentRule.Enabled())
		ruleContent->Enable(false);
	if (isSelected)
		SetBackgroundColour(wxColour(240,240,240));

	SetSizerAndFit(mainSizer);
	Show();
}
Example #2
0
void RuleListFrameClass::OnToggleRule(wxCommandEvent& event) {
	if (event.GetId() >= 0 && event.GetId() < game.userlist.Rules().size()) {
		uint32_t id = event.GetId();
		bool checked = event.IsChecked();
		Rule rule = game.userlist.RuleAt(id);

		rule.Enabled(checked);
		if (checked && rule.Key() == ADD && game.masterlist.FindItem(rule.Object(), MOD) != game.masterlist.Items().size())
			rule.Key(OVERRIDE);
		game.userlist.Replace(id, rule);
	}
}
Example #3
0
Rule UserRulesEditorFrame::GetRuleFromForm() {
	Rule newRule;
	//First validate.
	//Calling functions need to check for an enabled = false; rule as a failure.
	//Failure description is given in ruleObject.
	string ruleItem = RuleModBox->GetValue().ToUTF8();
	string sortItem = SortModBox->GetValue().ToUTF8();
	string insertItem = InsertModBox->GetValue().ToUTF8();
	if (Item(ruleItem).IsPlugin()) {
		if (SortModsCheckBox->IsChecked()) {
			if (SortModOption->GetValue()) {
				if (SortModOption->GetValue() && SortModBox->IsEmpty())
					throw boss_error(loc::translate("No mod is specified to sort relative to."), BOSS_ERROR_INVALID_SYNTAX);
				else if (!Item(sortItem).IsPlugin())  //Sort object is a group. Error.
					throw boss_error(loc::translate("Cannot sort a plugin relative to a group."), BOSS_ERROR_INVALID_SYNTAX);
			} else if (InsertModOption->GetValue() && !Item(insertItem).IsGroup()) {  //Inserting into a mod. Error.
				if (InsertModBox->IsEmpty())
					throw boss_error(loc::translate("No group is specified to insert into."), BOSS_ERROR_INVALID_SYNTAX);
				else
					throw boss_error(loc::translate("Cannot insert into a plugin."), BOSS_ERROR_INVALID_SYNTAX);
			}
		}
		if (AddMessagesCheckBox->IsChecked() && NewModMessagesBox->IsEmpty())  //Can't add no messages. Error.
			throw boss_error(loc::translate("Cannot add messages when none are given."), BOSS_ERROR_INVALID_SYNTAX);
	} else {  //Rule object is a group, or empty.
		if (RuleModBox->IsEmpty())
			throw boss_error(loc::translate("No rule mod is specified."), BOSS_ERROR_INVALID_SYNTAX);
		if (SortModsCheckBox->IsChecked()) {
			if (SortModOption->GetValue()) {
				if (SortModBox->IsEmpty())  //No sort object specified. Error.
					throw boss_error(loc::translate("No group is specified to sort relative to."), BOSS_ERROR_INVALID_SYNTAX);
				else if (Item(sortItem).IsPlugin())  //Sort object is a plugin. Error.
					throw boss_error(loc::translate("Cannot sort a group relative to a plugin."), BOSS_ERROR_INVALID_SYNTAX);
			} else if (InsertModOption->GetValue())  //Can't insert groups. Error.
				throw boss_error(loc::translate("Cannot insert groups."), BOSS_ERROR_INVALID_SYNTAX);
		}
		if (AddMessagesCheckBox->IsChecked())  //Can't add messages to a group. Error.
			throw boss_error(loc::translate("Cannot add messages to groups."), BOSS_ERROR_INVALID_SYNTAX);
	}
	if (!SortModsCheckBox->IsChecked() && !AddMessagesCheckBox->IsChecked())
		throw boss_error(loc::translate("The rule mod is not being sorted nor having its attached messages altered."), BOSS_ERROR_INVALID_SYNTAX);

	newRule.Enabled(true);
	newRule.Object(ruleItem);
	if (!SortModsCheckBox->IsChecked())
		newRule.Key(FOR);
	else {
		if (Item(newRule.Object()).IsGroup())
			newRule.Key(OVERRIDE);
		else {
			size_t pos = game.masterlist.FindItem(newRule.Object(), MOD);
			if (pos != game.masterlist.Items().size())  //Mod in masterlist.
				newRule.Key(OVERRIDE);
			else
				newRule.Key(ADD);
		}


		if (SortModOption->GetValue()) {
			RuleLine newLine;
			newLine.Object(sortItem);
			if (BeforeAfterChoiceBox->GetSelection() == 0)
				newLine.Key(BEFORE);
			else
				newLine.Key(AFTER);
			vector<RuleLine> lines = newRule.Lines();
			lines.push_back(newLine);
			newRule.Lines(lines);
		} else if (InsertModOption->GetValue()) {
			RuleLine newLine;
			newLine.Object(insertItem);
			if (TopBottomChoiceBox->GetSelection() == 0)
				newLine.Key(TOP);
			else
				newLine.Key(BOTTOM);
			vector<RuleLine> lines = newRule.Lines();
			lines.push_back(newLine);
			newRule.Lines(lines);
		}
	}

	//Now add message lines.
	if (AddMessagesCheckBox->IsChecked()) {
		RuleLine newLine;
		string messages = NewModMessagesBox->GetValue().ToUTF8();
		if (!messages.empty()) {
			//Split messages string by \n characters.
			size_t pos1 = 0, pos2 = string::npos;
			pos2 = messages.find("\n");
			if (pos2 == string::npos)  //No \n characters.
				pos2 = messages.length();
			while (pos2 != string::npos) {
				newLine.Object(trim_copy(messages.substr(pos1,pos2-pos1)));
				if (pos1 == 0 && ReplaceMessagesCheckBox->IsChecked())
					newLine.Key(REPLACE);
				else
					newLine.Key(APPEND);

				if (!newLine.IsObjectMessage())  //Message is formatted incorrectly. Error.
					throw boss_error((format("The message \"%1%\" is formatted incorrectly.") % newLine.Object()).str(), BOSS_ERROR_INVALID_SYNTAX);

				vector<RuleLine> lines = newRule.Lines();
				lines.push_back(newLine);
				newRule.Lines(lines);

				if (pos2 >= messages.length()-1)
					break;
				pos1 = pos2 + 1;
				pos2 = messages.find("\n", pos1);
				if (pos2 == string::npos && pos1 < messages.length()-1)
					pos2 = messages.length();
			}
		}
	}

	return newRule;
}