int BattleroomMMOptionsTab<BattleType>::setupOptionsSectionSizer(const mmOptionSection& section,
    wxBoxSizer* parent_sizer, OptionsWrapper::GameOption optFlag)
{
	if ( !m_battle ) return -1;
    const int col_gap = 35;
	wxString pref = wxFormat( _T("%d%s") ) % optFlag % wxsep;
	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 (SpringUnitSync::OptionMapBoolIter i = optWrap.m_opts[optFlag].bool_map.begin(); i != optWrap.m_opts[optFlag].bool_map.end();++i)
    {
        if ( i->second.section == section.key )
        {
			mmOptionBool current = i->second;
			wxCheckBox* temp = new wxCheckBox(this,BOOL_START_ID+ctrl_count,current.name);
			temp->SetToolTip(TE(current.description));
			m_name_info_map[pref+current.key] = current.description;
			temp->SetName(pref+current.key);
			m_chkbox_map[pref+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+current.key), 0, wxRIGHT| wxALIGN_CENTER_VERTICAL, col_gap);
			chkSizer->Add( ct_sizer );
			ctrl_count++;
        }
	}

    total_count += ctrl_count;
	ctrl_count = 0;
	for ( SpringUnitSync::OptionMapFloatIter it = optWrap.m_opts[optFlag].float_map.begin(); it != optWrap.m_opts[optFlag].float_map.end(); ++it)
	{
	    wxString seckey = it->second.section;
	    wxString kkey = section.key ;
        if ( it->second.section == section.key )
        {
			mmOptionFloat current = it->second;
			SlSpinCtrlDouble<ThisType>* tempspin = new SlSpinCtrlDouble<ThisType>();
			tempspin->Create(this, FLOAT_START_ID+ctrl_count, _T(""),
					wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, double(current.min), double(current.max),
					double(current.value),double(current.stepping), current.key);
            tempspin->SetSnapToTicks( true );
			tempspin->SetToolTip(TE(current.description));
			m_name_info_map[pref+current.key] = current.description;
			tempspin->Enable(enable);
			tempspin->SetName(pref+current.key);
			m_spinctrl_map[pref+current.key] = tempspin;
			 wxStaticText* tempst = new wxStaticText(this,-1,current.name);
			 m_statictext_map[pref+current.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+current.key), 0, wxRIGHT , col_gap);
			spinSizer->Add( ct_sizer );
			ctrl_count++;
        }
	}

    total_count += ctrl_count;
	ctrl_count = 0;
	for ( SpringUnitSync::OptionMapListIter it = optWrap.m_opts[optFlag].list_map.begin(); it != optWrap.m_opts[optFlag].list_map.end(); ++it)
	{
	    if ( it->second.section == section.key )
        {
            mmOptionList current = it->second;

            int temp = int(current.cbx_choices.GetCount()-1);
            int index = clamp(current.cur_choice_index,0,temp);
            wxComboBox* tempchoice = new wxComboBox(this, LIST_START_ID+ctrl_count, current.cbx_choices[index], wxDefaultPosition,
                    wxDefaultSize, current.cbx_choices, wxCB_READONLY, wxDefaultValidator);
						wxString tooltip = current.description + _T("\n");
						for ( ListItemVec::const_iterator itor = current.listitems.begin(); itor != current.listitems.end(); ++itor )
						{
							tooltip+= _T("\n") + itor->name + _T(": ") + itor->desc;
						}
            tempchoice->SetToolTip(TE(tooltip));
            m_name_info_map[pref+current.key] = tooltip;
            tempchoice->SetName(pref+current.key);
            tempchoice->Enable(enable);
            m_combox_map[pref+current.key] = tempchoice;
            wxStaticText* tempst = new wxStaticText(this,-1,current.name);
            m_statictext_map[pref+current.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+current.key), 0,  wxRIGHT, col_gap);
            cbxSizer->Add( ct_sizer );

            ctrl_count++;
        }
	}

    total_count += ctrl_count;
	ctrl_count = 0;
	for ( SpringUnitSync::OptionMapStringIter it = optWrap.m_opts[optFlag].string_map.begin(); it != optWrap.m_opts[optFlag].string_map.end(); ++it)
	{
	    if ( it->second.section == section.key )
        {
            mmOptionString current = it->second;
            wxTextCtrl* temptext = new wxTextCtrl(this, STRING_START_ID+ctrl_count, current.value, wxDefaultPosition,
                    wxDefaultSize, 0, wxDefaultValidator, current.key);
            temptext->SetToolTip(TE(current.description));
            m_name_info_map[pref+current.key] = current.description;
            temptext->SetName(pref+current.key);
            temptext->Enable(enable);
            m_textctrl_map[pref+current.key] = temptext;
            wxStaticText* tempst = new wxStaticText(this,-1,current.name);
            m_statictext_map[pref+current.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+current.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;

}