void BattleroomListCtrl::SetBattle(IBattle* battle)
{
	if (m_battle != NULL) {
		for (unsigned int i = 0; i < side_vector.size(); i++) {
			m_sides->Destroy(side_vector[i]); // delete side;
			Disconnect(BRLIST_SIDE + i, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(BattleroomListCtrl::OnSideSelect));
		}
	}

	m_data.clear();
	side_vector.clear();

	if ((battle != NULL) && m_sides) {
		try {
			const wxArrayString sides = lslTowxArrayString(LSL::usync().GetSides(battle->GetHostModName()));
			for (unsigned int i = 0; i < sides.GetCount(); i++) {
				wxMenuItem* side = new wxMenuItem(m_sides, BRLIST_SIDE + i, sides[i], wxEmptyString, wxITEM_NORMAL);
				m_sides->Append(side);
				side_vector.push_back(side);
				Connect(BRLIST_SIDE + i, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(BattleroomListCtrl::OnSideSelect));
			}
		} catch (...) {
		}
	}
	m_battle = battle;
}
void BattleRoomTab::OnSetModDefaultPreset(wxCommandEvent& /*unused*/)
{
	if (!m_battle)
		return;
	wxArrayString choices = lslTowxArrayString(m_battle->GetPresetList());
	int result = wxGetSingleChoiceIndex(_("Pick an existing option set from the list"), _("Set game default preset"), choices);
	if (result < 0)
		return;
	sett().SetModDefaultPresetName(TowxString(m_battle->GetHostModName()), choices[result]);
}
void BattleRoomTab::OnDeletePreset(wxCommandEvent& /*unused*/)
{
	if (!m_battle)
		return;
	wxArrayString choices = lslTowxArrayString(m_battle->GetPresetList());
	int result = wxGetSingleChoiceIndex(_("Pick an existing option set from the list"), _("Delete preset"), choices);
	if (result < 0)
		return;
	m_battle->DeletePreset(STD_STRING(choices[result]));
}
void BattleRoomTab::ReloadMaplist()
{
	if (!m_battle)
		return;
	m_map_combo->Clear();

	const wxArrayString maplist = lslTowxArrayString(LSL::usync().GetMapList());
	size_t nummaps = maplist.Count();
	for (size_t i = 0; i < nummaps; i++)
		m_map_combo->Insert(maplist[i], i);
	m_map_combo->SetValue(TowxString(m_battle->GetHostMapName()));
}
Beispiel #5
0
void SinglePlayerTab::ReloadModlist()
{
	m_mod_pick->Clear();
	m_mod_pick->Append(lslTowxArrayString(LSL::usync().GetGameList()));
	m_mod_pick->Insert(_("-- Select one --"), m_mod_pick->GetCount());
	if (m_battle.GetHostGameName().empty()) {
		m_mod_pick->SetSelection(m_mod_pick->GetCount() - 1);
	} else {
		m_mod_pick->SetStringSelection(TowxString(m_battle.GetHostGameName()));
		if (m_mod_pick->GetStringSelection().empty()) {
			SetMod(m_mod_pick->GetCount() - 1);
		}
	}
}
void BattleroomListCtrl::UpdateUser(User& user)
{
	if (!user.BattleStatus().spectator)
		icons().SetColourIcon(user.BattleStatus().colour);
	try {
		wxArrayString sides = lslTowxArrayString(LSL::usync().GetSides(m_battle->GetHostModName()));
		if (user.BattleStatus().side < (long)sides.GetCount()) {
			user.SetSideiconIndex(icons().GetSideIcon(m_battle->GetHostModName(), user.BattleStatus().side));
		}
	} catch (...) {
	}
	int index = GetIndexFromData(&user);
	UpdateUser(index);
}
Beispiel #7
0
void SinglePlayerTab::ReloadMaplist()
{
	m_map_pick->Clear();
	m_map_pick->Append(lslTowxArrayString(LSL::usync().GetMapList()));
	m_map_pick->Insert(_("-- Select one --"), m_map_pick->GetCount());
	if (m_battle.GetHostMapName().empty()) {
		m_map_pick->SetSelection(m_map_pick->GetCount() - 1);
		m_addbot_btn->Enable(false);
	} else {
		m_map_pick->SetStringSelection(TowxString(m_battle.GetHostMapName()));
		if (m_map_pick->GetStringSelection().IsEmpty()) {
			SetMap(m_mod_pick->GetCount() - 1);
		}
	}
}
void AddBotDialog::ShowAIInfo()
{
	m_add_btn->Enable(m_ai->GetStringSelection() != wxEmptyString);
	m_ai_infos_lst->DeleteAllItems();
	const wxArrayString info = lslTowxArrayString(LSL::usync().GetAIInfos(GetAIType()));
	int count = info.GetCount();
	for (int i = 0; i < count; i = i + 3) {
		long index = m_ai_infos_lst->InsertItem(i, info[i]);
		m_ai_infos_lst->SetItem(index, 0, info[i]);
		m_ai_infos_lst->SetItem(index, 1, info[i + 1]);
	}
	m_ai_infos_lst->SetColumnWidth(0, wxLIST_AUTOSIZE);
	m_ai_infos_lst->SetColumnWidth(1, wxLIST_AUTOSIZE);
	Layout();
	SetSize(wxDefaultSize);
}
void BattleOptionsTab::ReloadRestrictions()
{
	if ( !m_battle ) return;
	m_allowed_list->Clear();
	m_restrict_list->Clear();
	if ( m_battle->GetHostModName().empty() )
        return;

	try {
		wxArrayString items = lslTowxArrayString(LSL::usync().GetUnitsList(m_battle->GetHostModName()));
		m_allowed_list->Append(items);
	} catch ( ... ) {}
	std::map<std::string, int> units = m_battle->RestrictedUnits();

	for ( std::map<std::string, int>::const_iterator itor = units.begin(); itor != units.end(); ++itor )
		Restrict( TowxString(itor->first), itor->second );
}
void MapSelectDialog::OnInit(wxInitDialogEvent& /*unused*/)
{
	slLogDebugFunc("");

	AppendSortKeys(m_horizontal_choice);
	AppendSortKeys(m_vertical_choice);

	m_horizontal_choice->SetSelection(sett().GetHorizontalSortkeyIndex());
	m_vertical_choice->SetSelection(sett().GetVerticalSortkeyIndex());

	m_horizontal_direction_button->SetLabel(m_horizontal_direction ? _T(">") : _T("<"));
	m_vertical_direction_button->SetLabel(m_vertical_direction ? _T("ᴠ") : _T("ᴧ"));

	m_maps = lslTowxArrayString(LSL::usync().GetMapList());
	LoadAll();

	UpdateSortAndFilter();

	m_filter_text->SetFocus();
}
Beispiel #11
0
void BattleRoomTab::RegenerateOptionsList()
{
	long pos = 0;
	m_opts_list->DeleteAllItems();
	m_opts_list->InsertItem(pos, _("Size"));
	m_opt_list_map.clear();
	m_opt_list_map[_("Size")] = pos;
	pos++;
	m_opts_list->InsertItem(pos, _("Windspeed"));
	m_opt_list_map[_("Windspeed")] = pos;
	pos++;
	m_opts_list->InsertItem(pos, _("Tidal strength"));
	m_opt_list_map[_("Tidal strength")] = pos;
	pos++;
	m_opts_list->InsertItem(pos, wxEmptyString);
	pos++;
	pos = AddMMOptionsToList(pos, LSL::Enum::EngineOption);
	// AddMMOptionsToList already increments pos by itself
	m_opts_list->InsertItem(pos, wxEmptyString);
	pos++;
	m_mod_opts_index = pos;
	pos = AddMMOptionsToList(m_mod_opts_index, LSL::Enum::ModOption);
	// AddMMOptionsToList already increments pos by itself
	m_opts_list->InsertItem(pos, wxEmptyString);
	pos++;
	m_map_opts_index = pos;
	pos = AddMMOptionsToList(m_map_opts_index, LSL::Enum::MapOption);
	m_side_sel->Clear();
	if (m_battle != NULL) {
		try {
			const wxArrayString sides = lslTowxArrayString(LSL::usync().GetSides(m_battle->GetHostModName()));
			for (unsigned int i = 0; i < sides.GetCount(); i++) {
				m_side_sel->Append(sides[i], icons().GetBitmap(icons().GetSideIcon(m_battle->GetHostModName(), i)));
			}
			wxSize s = m_side_sel->GetEffectiveMinSize();
			s.SetWidth(s.GetWidth() + 16); // HACK without this additional place, the image overflows the text on wxGtk
			m_side_sel->SetMinSize(s);
		} catch (...) {
		}
	}
}
void AddBotDialog::ReloadAIList()
{
	try {
		m_ais = lslTowxArrayString(LSL::usync().GetAIList(m_battle.GetHostGameName()));
	} catch (...) {
	}

	m_ai->Clear();
	for (unsigned int i = 0; i < m_ais.GetCount(); i++)
		m_ai->Append(RefineAIName(m_ais[i]));
	if (m_ais.GetCount() > 0) {
		m_ai->SetStringSelection(sett().GetLastAI());
		if (m_ai->GetStringSelection() == wxEmptyString)
			m_ai->SetSelection(0);
	} else {
		customMessageBox(SL_MAIN_ICON, _("No AI bots found in your Spring installation."), _("No bot-libs found"), wxOK);
	}
	m_add_btn->Enable(m_ai->GetStringSelection() != wxEmptyString);
	ShowAIInfo();
	ShowAIOptions();
}
SingleOptionDialog::SingleOptionDialog(IBattle& battle, const wxString& optiontag)
    : m_battle(battle)
    , m_tag(optiontag)
    , m_checkbox(NULL)
    , m_combobox(NULL)
    , m_spinctrl(NULL)
    , m_textctrl(NULL)
    , m_cancel_button(NULL)
    , m_ok_button(NULL)
{
	LSL::OptionsWrapper& optWrap = m_battle.CustomBattleOptions();
	LSL::Enum::GameOption optFlag = (LSL::Enum::GameOption)FromwxString(optiontag.BeforeFirst('_'));
	const auto key = STD_STRING(optiontag.AfterFirst('_'));
	LSL::Enum::OptionType type = optWrap.GetSingleOptionType(key);
	Create((wxWindow*)&ui().mw(), wxID_ANY, _("Change option"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE, _T( "OptionDialog" ));
	if (!optWrap.keyExists(key, optFlag, false, type)) {
		EndModal(wxID_CANCEL);
		return;
	}

	wxBoxSizer* m_main_sizer = new wxBoxSizer(wxVERTICAL);

	// wxStaticText* m_labelctrl = wxStaticText();

	switch (type) {
		case LSL::Enum::opt_bool: {
			const auto opt = optWrap.m_opts[optFlag].bool_map[key];
			m_checkbox = new wxCheckBox(this, wxID_ANY, TowxString(opt.name));
			m_checkbox->SetToolTip(opt.description);
			m_checkbox->SetValue(opt.value);
			m_main_sizer->Add(m_checkbox, 0, wxEXPAND);
			break;
		}
		case LSL::Enum::opt_float: {
			const auto opt = optWrap.m_opts[optFlag].float_map[key];
			m_spinctrl = new wxSpinCtrlDouble(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize,
							  wxSP_ARROW_KEYS, double(opt.min), double(opt.max),
							  double(opt.value), double(opt.stepping), TowxString(opt.key));
			m_spinctrl->SetToolTip(opt.description);
			m_main_sizer->Add(m_spinctrl, 0, wxEXPAND);
			break;
		}
		case LSL::Enum::opt_string: {
			const auto opt = optWrap.m_opts[optFlag].string_map[key];
			m_textctrl = new wxTextCtrl(this, wxID_ANY, TowxString(opt.value), wxDefaultPosition,
						    wxDefaultSize, 0, wxDefaultValidator, TowxString(opt.key));
			m_textctrl->SetToolTip(opt.description);
			m_main_sizer->Add(m_textctrl, 0, wxEXPAND);
			break;
		}
		case LSL::Enum::opt_list: {
			const auto opt = optWrap.m_opts[optFlag].list_map[key];
			const int temp = int(opt.cbx_choices.size() - 1);
			const int index = LSL::Util::Clamp(opt.cur_choice_index, 0, temp);
			m_combobox = new wxComboBox(this, wxID_ANY, TowxString(opt.cbx_choices[index]), wxDefaultPosition, wxDefaultSize,
						    lslTowxArrayString(opt.cbx_choices), wxCB_READONLY, wxDefaultValidator);
			std::string tooltip = opt.description + "\n";
			for (const auto itor : opt.listitems) {
				tooltip += "\n" + itor.name + ": " + itor.desc;
			}
			m_combobox->SetToolTip(tooltip);
			m_main_sizer->Add(m_combobox, 0, wxEXPAND);
			break;
		}
		default: {
			EndModal(wxID_CANCEL);
			return;
		}
	}

	wxSize __SpacerSize_1 = wxDLG_UNIT(this, wxSize(0, 0));
	m_main_sizer->Add(__SpacerSize_1.GetWidth(), __SpacerSize_1.GetHeight(), 0, wxALL | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 5);
	wxStaticLine* m_separator1 = new wxStaticLine(this, wxID_ANY, wxDefaultPosition, wxSize(10, -1), wxLI_HORIZONTAL, _T( "ID_STATICLINE1" ));
	m_main_sizer->Add(m_separator1, 0, wxALL | wxEXPAND | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 5);
	wxBoxSizer* m_buttons_sizer = new wxBoxSizer(wxHORIZONTAL);
	m_cancel_button = new wxButton(this, ID_CANCEL, _("Cancel"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T( "ID_CANCEL" ));
	m_buttons_sizer->Add(m_cancel_button, 0, wxALL | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL, 5);
	m_buttons_sizer->Add(0, 0, 1, wxALL | wxEXPAND | wxSHAPED | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 0);
	m_ok_button = new wxButton(this, ID_OK, _("Ok"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T( "ID_OK" ));
	m_buttons_sizer->Add(m_ok_button, 0, wxALL | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL, 5);
	m_main_sizer->Add(m_buttons_sizer, 0, wxALL | wxEXPAND | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 0);


	m_main_sizer->Fit(this);
	m_main_sizer->SetSizeHints(this);

	SetSizer(m_main_sizer);
	Layout();

	Connect(ID_CANCEL, wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&SingleOptionDialog::OnCancel);
	Connect(ID_OK, wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&SingleOptionDialog::OnOk);
}
Beispiel #14
0
std::string GetBestMatch(const std::vector<std::string>& a, const std::string& s, double* distance)
{
	auto arr = lslTowxArrayString(a);
	return STD_STRING(GetBestMatch(arr, TowxString(s), distance));
}
int BattleroomMMOptionsTab::setupOptionsSectionSizer(const LSL::mmOptionSection& section,
						     wxBoxSizer* parent_sizer, LSL::Enum::GameOption optFlag)
{
	if (!m_battle)
		return -1;
	const int col_gap = 35;
	wxString pref = wxString::Format(_T("%d%s"), optFlag, wxsep.c_str());
	LSL::OptionsWrapper optWrap = m_battle->CustomBattleOptions();
	bool enable = m_battle->IsFounderMe();
	wxFlexGridSizer* cbxSizer = new wxFlexGridSizer(4, 2, 10, 10);
	wxFlexGridSizer* spinSizer = new wxFlexGridSizer(4, 10, 10);
	wxFlexGridSizer* textSizer = new wxFlexGridSizer(4, 10, 10);
	wxFlexGridSizer* chkSizer = new wxFlexGridSizer(4, 10, 10);

	const int b_gap = 1;

	int total_count = 0;
	int ctrl_count = 0;
	for (const auto i : optWrap.m_opts[optFlag].bool_map) {
		if (i.second.section == section.key) {
			LSL::mmOptionBool current = i.second;
			wxCheckBox* temp = new wxCheckBox(this, BOOL_START_ID + ctrl_count, TowxString(current.name));
			temp->SetToolTip(current.description);
			m_name_info_map[pref + TowxString(current.key)] = TowxString(current.description);
			temp->SetName(pref + TowxString(current.key));
			m_chkbox_map[pref + TowxString(current.key)] = temp;
			temp->SetValue(current.value);
			temp->Enable(enable);
			wxBoxSizer* ct_sizer = new wxBoxSizer(wxHORIZONTAL);
			ct_sizer->Add(temp, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, b_gap);
			ct_sizer->Add(getButton(BOOL_START_ID + ctrl_count, pref + TowxString(current.key)), 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, col_gap);
			chkSizer->Add(ct_sizer);
			ctrl_count++;
		}
	}

	total_count += ctrl_count;
	ctrl_count = 0;
	for (const auto it : optWrap.m_opts[optFlag].float_map) {
		//	    wxString seckey = it.second.section;
		//	    wxString kkey = section.key ;
		if (it.second.section == section.key) {
			const LSL::mmOptionFloat current = it.second;
			wxSpinCtrlDouble* tempspin = new wxSpinCtrlDouble(this, FLOAT_START_ID + ctrl_count, _T(""),
									  wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, double(current.min), double(current.max),
									  double(current.value), double(current.stepping), TowxString(current.key));
			tempspin->SetSnapToTicks(true);
			tempspin->SetToolTip(current.description);
			const wxString pref_key = pref + TowxString(current.key);
			m_name_info_map[pref_key] = TowxString(current.description);
			tempspin->Enable(enable);
			tempspin->SetName(pref_key);
			m_spinctrl_map[pref_key] = tempspin;
			wxStaticText* tempst = new wxStaticText(this, -1, TowxString(current.name));
			m_statictext_map[pref_key] = tempst;
			spinSizer->Add(tempst, 0, wxALIGN_CENTER_VERTICAL);
			wxBoxSizer* ct_sizer = new wxBoxSizer(wxHORIZONTAL);
			ct_sizer->Add(tempspin, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, b_gap);
			ct_sizer->Add(getButton(FLOAT_START_ID + ctrl_count, pref_key), 0, wxRIGHT, col_gap);
			spinSizer->Add(ct_sizer);
			ctrl_count++;
		}
	}

	total_count += ctrl_count;
	ctrl_count = 0;
	for (const auto it : optWrap.m_opts[optFlag].list_map) {
		if (it.second.section == section.key) {
			LSL::mmOptionList current = it.second;

			const int temp = int(current.cbx_choices.size() - 1);
			const int index = LSL::Util::Clamp(current.cur_choice_index, 0, temp);
			wxComboBox* tempchoice = new wxComboBox(this, LIST_START_ID + ctrl_count,
								TowxString(current.cbx_choices[index]), wxDefaultPosition,
								wxDefaultSize,
								lslTowxArrayString(current.cbx_choices),
								wxCB_READONLY, wxDefaultValidator);
			wxString tooltip = TowxString(current.description + std::string("\n"));
			for (const auto itor : current.listitems) {
				tooltip += TowxString(std::string("\n") + itor.name + std::string(": ") + itor.desc);
			}
			tempchoice->SetToolTip(tooltip);
			const wxString pref_key = pref + TowxString(current.key);
			m_name_info_map[pref_key] = tooltip;
			tempchoice->SetName(pref_key);
			tempchoice->Enable(enable);
			m_combox_map[pref_key] = tempchoice;
			wxStaticText* tempst = new wxStaticText(this, -1, TowxString(current.name));
			m_statictext_map[pref_key] = tempst;
			cbxSizer->Add(tempst, 0, wxALIGN_CENTER_VERTICAL);
			wxBoxSizer* ct_sizer = new wxBoxSizer(wxHORIZONTAL);
			ct_sizer->Add(tempchoice, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, b_gap);
			ct_sizer->Add(getButton(LIST_START_ID + ctrl_count, pref_key), 0, wxRIGHT, col_gap);
			cbxSizer->Add(ct_sizer);

			ctrl_count++;
		}
	}

	total_count += ctrl_count;
	ctrl_count = 0;
	for (const auto it : optWrap.m_opts[optFlag].string_map) {
		if (it.second.section == section.key) {
			const LSL::mmOptionString current = it.second;
			wxTextCtrl* temptext = new wxTextCtrl(this, STRING_START_ID + ctrl_count, TowxString(current.value), wxDefaultPosition,
							      wxDefaultSize, 0, wxDefaultValidator, TowxString(current.key));
			temptext->SetToolTip(current.description);
			const wxString pref_key = pref + TowxString(current.key);
			m_name_info_map[pref_key] = TowxString(current.description);
			temptext->SetName(pref_key);
			temptext->Enable(enable);
			m_textctrl_map[pref_key] = temptext;
			wxStaticText* tempst = new wxStaticText(this, -1, TowxString(current.name));
			m_statictext_map[pref_key] = tempst;
			textSizer->Add(tempst, 0, wxALIGN_CENTER_VERTICAL);
			wxBoxSizer* ct_sizer = new wxBoxSizer(wxHORIZONTAL);
			ct_sizer->Add(temptext, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, b_gap);
			ct_sizer->Add(getButton(STRING_START_ID + ctrl_count, pref_key), 0, wxRIGHT, col_gap);
			textSizer->Add(ct_sizer);

			ctrl_count++;
		}
	}
	total_count += ctrl_count;

	parent_sizer->Add(chkSizer, 0, wxALL, chkSizer->GetChildren().size() > 0 ? 5 : 0);
	parent_sizer->Add(spinSizer, 0, wxALL, spinSizer->GetChildren().size() > 0 ? 5 : 0);
	parent_sizer->Add(cbxSizer, 0, wxALL, cbxSizer->GetChildren().size() > 0 ? 5 : 0);
	parent_sizer->Add(textSizer, 0, wxALL, textSizer->GetChildren().size() > 0 ? 5 : 0);

	return total_count;
}