Exemplo n.º 1
0
void BattleroomListCtrl::OnAllySelect(wxCommandEvent& event)
{
	slLogDebugFunc("");
	int ally = event.GetId() - BRLIST_ALLY;
	if (m_sel_user)
		m_battle->ForceAlly(*m_sel_user, ally);
}
Exemplo n.º 2
0
void BattleroomListCtrl::OnSideSelect(wxCommandEvent& event)
{
	slLogDebugFunc("");
	int side = event.GetId() - BRLIST_SIDE;
	if (m_sel_user)
		m_battle->ForceSide(*m_sel_user, side);
}
Exemplo n.º 3
0
void BattleroomListCtrl::OnTeamSelect(wxCommandEvent& event)
{
	slLogDebugFunc("");
	int team = event.GetId() - BRLIST_TEAM;
	if (m_sel_user)
		m_battle->ForceTeam(*m_sel_user, team);
}
Exemplo n.º 4
0
void ServerEvents::OnStartHostedBattle(int battleid)
{
	slLogDebugFunc("");
	IBattle& battle = m_serv.GetBattle(battleid);
	battle.SetInGame(true);
	battle.StartSpring();
}
Exemplo n.º 5
0
void abstract_panel::OnTextUpdate(wxCommandEvent& event)
{

	settingsChanged = true;
	int eventID = event.GetId();

	if (eventID == ID_RES_CHOICES_LBOX_X || eventID == ID_RES_CHOICES_LBOX_Y) {
		wxTextCtrl* textField = (wxTextCtrl*)event.GetEventObject();
		wxString wxStr = textField->GetValue();
		long* res = new long;
		bool success = (wxStr.ToLong(res));

		switch (eventID) {
			case ID_RES_CHOICES_LBOX_X: {
				// TODO: input validation?
				if (success)
					(intSettings)[RC_TEXT[0].key] = int((*res));
			} break;
			case ID_RES_CHOICES_LBOX_Y: {
				// TODO: input validation?
				if (success)
					(intSettings)[RC_TEXT[1].key] = int((*res));
			} break;

			default:
				slLogDebugFunc("unhandled case val");
				break;
		}
	}
}
Exemplo n.º 6
0
void ServerEvents::OnUserQuit(const std::string& nick)
{
	slLogDebugFunc("");
	try {
		User& user = m_serv.GetUser(nick);
		IBattle* userbattle = user.GetBattle();
		if (userbattle) {
			int battleid = userbattle->GetID();
			try {
				if (&userbattle->GetFounder() == &user) {
					for (int i = 0; i < int(userbattle->GetNumUsers()); i++) {
						User& battleuser = userbattle->GetUser(i);
						OnUserLeftBattle(battleid, battleuser.GetNick());
					}
					OnBattleClosed(battleid);
				} else
					OnUserLeftBattle(battleid, user.GetNick());
			} catch (...) {
			}
		}
		ui().OnUserOffline(user);
		m_serv._RemoveUser(nick);
		if (useractions().DoActionOnUser(UserActions::ActNotifLogin, TowxString(nick)))
			actNotifBox(SL_MAIN_ICON, TowxString(nick) + _(" just went offline"));
	} catch (std::runtime_error& except) {
	}
}
Exemplo n.º 7
0
void ServerEvents::OnHostedBattle(int battleid)
{
	slLogDebugFunc("");
	try {
		IBattle& battle = m_serv.GetBattle(battleid);

		if (battle.GetBattleType() == BT_Played) {
			battle.CustomBattleOptions().loadOptions(LSL::Enum::MapOption, battle.GetHostMapName());
			battle.CustomBattleOptions().loadOptions(LSL::Enum::ModOption, battle.GetHostGameName());
		} else {
			battle.GetBattleFromScript(true);
		}


		const std::string presetname = STD_STRING(sett().GetModDefaultPresetName(TowxString(battle.GetHostGameName())));
		if (!presetname.empty()) {
			battle.LoadOptionsPreset(presetname);
		}

		battle.LoadMapDefaults(battle.GetHostMapName());

		m_serv.SendHostInfo(IBattle::HI_Send_All_opts);

		ui().OnHostedBattle(battle);
	} catch (assert_exception) {
	}
}
Exemplo n.º 8
0
void ChatPanel::CreatePopup()
{
	if (m_popup_menu != NULL)
		return;
	slLogDebugFunc("");
	m_popup_menu = new ChatPanelMenu(this);
}
Exemplo n.º 9
0
void ServerEvents::OnUserJoinedBattle(int battleid, const std::string& nick, const std::string& userScriptPassword)
{
	try {
		slLogDebugFunc("");
		if (!m_serv.UserExists(nick)) {
			wxLogWarning("OnUserJoinedBattle(): Lobby server inconsistency: user in battle which doesn't exist. Please report as lobby server bug!");
			return;
		}
		User& user = m_serv.GetUser(nick);
		IBattle& battle = m_serv.GetBattle(battleid);

		battle.OnUserAdded(user);
		user.BattleStatus().scriptPassword = userScriptPassword;
		ui().OnUserJoinedBattle(battle, user);
		try {
			if (&user == &battle.GetFounder()) {
				if (user.Status().in_game) {
					battle.SetInGame(true);
					battle.StartSpring();
				}
			}
		} catch (...) {
		}
	} catch (std::runtime_error& except) {
	}
}
Exemplo n.º 10
0
void MapSelectDialog::OnHorizontalDirectionClicked(wxCommandEvent& /*unused*/)
{
	slLogDebugFunc("");
	m_horizontal_direction = !m_horizontal_direction;
	m_horizontal_direction_button->SetLabel(m_horizontal_direction ? _T(">") : _T("<"));
	UpdateSortAndFilter();
}
Exemplo n.º 11
0
void DownloadDataViewCtrl::AddItem(PrDownloader::DownloadProgress* p)
{
	slLogDebugFunc("");

	BaseDataViewCtrl::AddItem(*p, true);

	itemsIndex[p->name] = p;
}
Exemplo n.º 12
0
void Spring::OnTerminated( wxCommandEvent& event )
{
	slLogDebugFunc("");
	m_running = false;
	m_process = NULL;
	event.SetEventType(GlobalEvent::OnSpringTerminated);
	GlobalEvent::Send(event);
}
Exemplo n.º 13
0
void ServerEvents::OnChannelPart(const std::string& channel, const std::string& who, const std::string& message)
{
	slLogDebugFunc("");
	try {
		m_serv.GetChannel(channel).Left(m_serv.GetUser(who), message);
	} catch (std::runtime_error& except) {
	}
}
Exemplo n.º 14
0
void ServerEvents::OnChannelTopic(const std::string& channel, const std::string& who, const std::string& message, int /*unused*/)
{
	slLogDebugFunc("");
	try {
		m_serv.GetChannel(channel).SetTopic(message, who);
	} catch (std::runtime_error& except) {
	}
}
Exemplo n.º 15
0
void DownloadDataViewCtrl::OnDownloadStarted(wxCommandEvent& /*event*/)
{
	slLogDebugFunc("");

	PrDownloader::DownloadProgress* p = new PrDownloader::DownloadProgress;
	prDownloader().GetProgress(*p);
	AddItem(p);
}
Exemplo n.º 16
0
void MapSelectDialog::OnMapGridLeftDClick(wxMouseEvent& /*unused*/)
{
	slLogDebugFunc("");

	if (m_mapgrid->GetSelectedMap()) {
		EndModal(wxID_OK);
	}
}
Exemplo n.º 17
0
void ServerEvents::OnUserJoinChannel(const std::string& channel, const std::string& who)
{
	slLogDebugFunc("");
	try {
		m_serv.GetChannel(channel).Joined(m_serv.GetUser(who));
	} catch (std::runtime_error& except) {
	}
}
Exemplo n.º 18
0
void Channel::DidAction( User& who, const std::string& action )
{
	slLogDebugFunc("");
	if ( uidata.panel == 0 ) {
		wxLogError( _T("OnChannelDidAction: ud->panel NULL") );
		return;
	}
	uidata.panel->DidAction( TowxString(who.GetNick()), TowxString(action ));
}
Exemplo n.º 19
0
void Channel::Said( User& who, const std::string& message )
{
	slLogDebugFunc("");
	if (uidata.panel == 0 ) {
		wxLogError( _T("OnChannelSaid: ud->panel NULL") );
		return;
	}
	uidata.panel->Said( TowxString(who.GetNick()), TowxString(message));
}
Exemplo n.º 20
0
void BattleMapTab::OnMapBrowse(wxCommandEvent& /*unused*/)
{
	if (!m_battle)
		return;
	slLogDebugFunc("");

	wxString mapname = mapSelectDialog();
	if (!mapname.empty()) {
		slLogDebugFunc("");
		if (!m_battle->IsFounderMe()) {
			m_battle->DoAction("suggests " + STD_STRING(mapname));
			return;
		}
		const int idx = m_map_combo->FindString(mapname, true /*case sensitive*/);
		if (idx != wxNOT_FOUND)
			SetMap(idx);
	}
}
Exemplo n.º 21
0
void ServerEvents::OnPrivateMessageEx(User& chan, User& who, const std::string& action)
{
	slLogDebugFunc("");
	try {
		if (!useractions().DoActionOnUser(UserActions::ActIgnorePM, TowxString(who.GetNick())))
			ui().OnUserSaidEx(chan, who, TowxString(action));
	} catch (std::runtime_error& except) {
	}
}
Exemplo n.º 22
0
void ServerEvents::OnBattleEnableAllUnits(int battleid)
{
	slLogDebugFunc("");
	try {
		IBattle& battle = m_serv.GetBattle(battleid);
		battle.UnrestrictAllUnits();
	} catch (assert_exception) {
	}
}
Exemplo n.º 23
0
void ServerEvents::OnChannelAction(const std::string& channel, const std::string& who, const std::string& action)
{
	slLogDebugFunc("");
	try {
		if ((m_serv.GetMe().GetNick() == who) || !useractions().DoActionOnUser(UserActions::ActIgnoreChat, TowxString(who)))
			m_serv.GetChannel(channel).DidAction(m_serv.GetUser(who), action);
	} catch (std::runtime_error& except) {
	}
}
Exemplo n.º 24
0
void ServerEvents::OnBattleEnableUnit(int battleid, const std::string& unitname)
{
	slLogDebugFunc("");
	try {
		IBattle& battle = m_serv.GetBattle(battleid);
		battle.UnrestrictUnit(unitname);
	} catch (assert_exception) {
	}
}
Exemplo n.º 25
0
/**
 @brief Blends two images based on alpha channel present in foreground image.
 @param foreground Foreground image, must have an alpha channel
 @param background Background image, may have an alpha channel
 @param blend_alpha Whether the returned image will have an alpha channel.
 @return A copy of the background image with the foreground image blended on
 top of it. The returned image will have an alpha channel iff the background
 image has an alpha channel. In that case the alpha channel is blended
 identical to the red/green/blue channels.
*/
wxImage BlendImage(const wxImage& foreground, const wxImage& background, bool blend_alpha)
{
	if ((foreground.GetWidth() != background.GetWidth()) || (background.GetHeight() != foreground.GetHeight())) {
		slLogDebugFunc("size mismatch while blending");
		return background;
	}

	bool zhu = blend_alpha && background.HasAlpha();
	if (foreground.HasAlpha()) {
		wxImage ret(background.GetWidth(), foreground.GetHeight());
		const unsigned char* background_data = background.GetData();
		const unsigned char* foreground_data = foreground.GetData();
		const unsigned char* background_alpha = NULL;
		const unsigned char* foreground_alpha = foreground.GetAlpha();
		unsigned char* result_data = ret.GetData();
		unsigned char* result_alpha = NULL;
		unsigned int pixel_count = background.GetWidth() * background.GetHeight();

		if (zhu) {
			background_alpha = background.GetAlpha();
			ret.InitAlpha();
			result_alpha = ret.GetAlpha();
		}

		for (unsigned int i = 0, i_a = 0; i < pixel_count * 3; i += 3, i_a++) {
			unsigned char fore_alpha = foreground_alpha[i_a];
			float back_blend_fac = (255 - fore_alpha) / 255.0;
			float fore_blend_fac = fore_alpha / 255.0;

			result_data[i] = foreground_data[i] * fore_blend_fac + background_data[i] * back_blend_fac;
			result_data[i + 1] = foreground_data[i + 1] * fore_blend_fac + background_data[i + 1] * back_blend_fac;
			result_data[i + 2] = foreground_data[i + 2] * fore_blend_fac + background_data[i + 2] * back_blend_fac;

			if (zhu) {
				unsigned char back_alpha = background_alpha[i_a];
				result_alpha[i_a] = fore_alpha * fore_blend_fac + back_alpha * back_blend_fac;
			}
		}
		return ret;
	}
	slLogDebugFunc("cannot blend without alpha");
	return background;
}
Exemplo n.º 26
0
void BattleroomListCtrl::OnHandicapSelect(wxCommandEvent& /*unused*/)
{
	slLogDebugFunc("");
	if (!m_sel_user)
		return;
	long handicap = wxGetNumberFromUser(_("Please enter a value between 0 and 100"), _("Set Resource Bonus"), wxEmptyString, m_sel_user->BattleStatus().handicap, 0, 100, (wxWindow*)&ui().mw(), wxDefaultPosition);
	if (handicap != -1) {
		m_battle->SetHandicap(*m_sel_user, handicap);
	}
}
Exemplo n.º 27
0
void BattleListTab::OnSelect( wxListEvent& event )
{
	slLogDebugFunc("");
	if ( event.GetIndex() == -1 ) {
		SelectBattle( 0 );
		return;
	}
	IBattle* b = ( m_battle_list->GetSelectedData());
	SelectBattle( b );
}
Exemplo n.º 28
0
void ChatPanel::Part()
{
	slLogDebugFunc("");
	if (m_type == CPT_Channel) {
		if (m_channel == 0)
			return;
		m_channel->Leave();
		m_channel->panel = 0;
	}
}
Exemplo n.º 29
0
void ServerEvents::OnBattleDisableUnit(int battleid, const std::string& unitname, int count)
{
	slLogDebugFunc("");
	try {
		IBattle& battle = m_serv.GetBattle(battleid);
		battle.RestrictUnit(unitname, count);
		wxLogDebug("OnBattleDisableUnit %d %s %d", battleid, unitname.c_str(), count);
	} catch (assert_exception) {
	}
}
Exemplo n.º 30
0
void ServerEvents::OnBattleInfoUpdated(int battleid)
{
	slLogDebugFunc("");
	try {
		IBattle& battle = m_serv.GetBattle(battleid);
		ui().OnBattleInfoUpdated(battle, wxEmptyString);
	} catch (assert_exception) {
		wxLogWarning("Exception in OnBattleInfoUpdated(%d)", battleid);
	}
}