bool MCDensityMappedImageRep::GetGeometry(uindex_t &r_width, uindex_t &r_height) { uindex_t t_match; if (!GetBestMatch(m_last_density, t_match)) return false; return m_sources[t_match]->GetGeometry(r_width, r_height); }
uindex_t MCDensityMappedImageRep::GetFrameCount() { uindex_t t_match; if (!GetBestMatch(m_last_density, t_match)) return 0; return m_sources[t_match]->GetFrameCount(); }
MCGFloat MCDensityMappedImageRep::GetDensity() { uindex_t t_match; if (!GetBestMatch(m_last_density, t_match)) return 1.0; return m_source_densities[t_match]; }
uint32_t MCDensityMappedImageRep::GetDataCompression() { uindex_t t_match; if (!GetBestMatch(m_last_density, t_match)) return F_RLE; return m_sources[t_match]->GetDataCompression(); }
bool MCDensityMappedImageRep::LockImageFrame(uindex_t p_index, bool p_premultiplied, MCGFloat p_density, MCImageFrame *&r_frame) { uindex_t t_match; if (!GetBestMatch(p_density, t_match)) return false; m_last_density = p_density; m_locked = m_sources[t_match]->LockImageFrame(p_index, p_premultiplied, p_density, r_frame); m_locked_source = t_match; if (m_locked) r_frame->density = m_source_densities[t_match]; return m_locked; }
// //////////////////////////////////////////////////////////////////////////// MLB::Utility::VersionNumber LocateDllPredicate::GetBestMatchVersion() const { return(GetBestMatch().version_number_); }
// //////////////////////////////////////////////////////////////////////////// std::string LocateDllPredicate::GetBestMatchName() const { return(GetBestMatch().file_name_); }
std::string GetBestMatch(const std::vector<std::string>& a, const std::string& s, double* distance ) { auto arr = LSL::Util::vectorToArrayString(a); return STD_STRING(GetBestMatch(arr, TowxString(s), distance)); }
void AutoHost::OnSaidBattle( const wxString& /*unused*/, const wxString& msg ) { // do nothing if autohost functionality is disabled if ( !m_enabled ) return; // protect against command spam time_t currentTime = time( NULL ); if ( ( currentTime - m_lastActionTime ) < 5 ) return; // check for autohost commands wxString command = msg.BeforeFirst( _T( ' ' ) ); wxString params = msg.AfterFirst( _T( ' ' ) ); if ( command == _T( "!start" ) ) { StartBattle(); } else if ( command == _T( "!balance" ) ) { unsigned int num = s2l( params ); m_battle.Autobalance( IBattle::balance_random, false, false, num ); m_battle.DoAction( _T( "is auto-balancing alliances ..." ) ); } else if ( command == _T( "!cbalance" ) ) { unsigned int num = s2l( params ); m_battle.Autobalance( IBattle::balance_random, true, false, num ); m_battle.DoAction( _T( "is auto-balancing alliances ..." ) ); } else if ( command == _T( "!help" ) ) { m_battle.DoAction( _T( "The following commands are available ( <> = mandatory value, {} = optional value ):" ) ); m_battle.DoAction( _T( "!addbox <topx> <topy> <bottomx> <bottomy> {allynumber}: adds a <allynumber> start restriction to the given coordinates, coordinates range from 0 to 200." ) ); m_battle.DoAction( _T( "!balance {number}: tries to put players into allyteams by how many start boxes there are, uses {number} allyteams if present." ) ); m_battle.DoAction( _T( "!cbalance {number}: see !balance but tries to put clanmates together first." ) ); m_battle.DoAction( _T( "!fixcolors: changes players duplicate colours so they are unique." ) ); m_battle.DoAction( _T( "!fixids {number}: tries to put players into control teams by number, if number is omitted it assignes as different controlteam per player." ) ); m_battle.DoAction( _T( "!cfixids {number}: see !fixids but tries to put clanmates together first." ) ); m_battle.DoAction( _T( "!help: this guide." ) ); m_battle.DoAction( _T( "!listprofiles: lists the available battle profiles." ) ); m_battle.DoAction( _T( "!loadprofile profilename: loads an available battle profile." ) ); m_battle.DoAction( _T( "!lock: prevents more people to join." ) ); m_battle.DoAction( _T( "!map <name>: switches to <name>." ) ); m_battle.DoAction( _T( "!removebox <allynumber>: deletes <allynumber> start restriction's box." ) ); m_battle.DoAction( _T( "!ring {name}: rings players that are not ready or {name} if specified." ) ); m_battle.DoAction( _T( "!set <optionname> <value>: sets battle option <optionname> to <value>" ) ); m_battle.DoAction( _T( "!spectunsynced: sets all players with unsynced status to be spectators." ) ); m_battle.DoAction( _T( "!start: starts the battle." ) ); m_battle.DoAction( _T( "!unlock: opens the battle again." ) ); } else if ( command == _T( "!ring" ) ) { if ( !params.IsEmpty() ) { wxString user = GetBestMatch( m_userlist, params ); try { User& u = m_battle.GetUser( user ); m_battle.RingPlayer( u ); m_battle.DoAction( _T( "is ringing " ) + user ); } catch ( ... ) { m_battle.DoAction( _T( "cannot ring " ) + user ); } } else { m_battle.RingNotReadyPlayers(); m_battle.DoAction( _T( "is ringing players not ready ..." ) ); } } else if ( command == _T( "!listprofiles" ) ) { wxArrayString profilelist = m_battle.GetPresetList(); unsigned int count = profilelist.GetCount(); if ( count == 0 ) { m_battle.DoAction( _T( "There are no presets available." ) ); } else { m_battle.DoAction( _T( "The following presets are available:" ) ); for ( unsigned int i = 0; i < count; i++ ) { m_battle.DoAction( profilelist[i] ); } } } else if ( command == _T( "!loadprofile" ) ) { wxString profilename = GetBestMatch( m_battle.GetPresetList(), params ); if ( !m_battle.LoadOptionsPreset( profilename ) ) m_battle.DoAction( _T( "Profile not found, use !listprofiles for a list of available profiles." ) ); else m_battle.DoAction( _T( "has loaded profile: " ) + profilename ); } else if ( command == _T( "!fixcolors" ) ) { m_battle.FixColours(); m_battle.DoAction( _T( "is fixing colors." ) ); } else if ( command == _T( "!lock" ) ) { m_battle.SetIsLocked( true ); m_battle.DoAction( _T( "has locked the battle." ) ); m_battle.SendHostInfo( IBattle::HI_Locked ); } else if ( command == _T( "!unlock" ) ) { m_battle.SetIsLocked( false ); m_battle.DoAction( _T( "has unlocked the battle." ) ); m_battle.SendHostInfo( IBattle::HI_Locked ); } else if ( command == _T( "!fixids" ) ) { unsigned int num = s2l( params ); m_battle.FixTeamIDs( IBattle::balance_divide, false, false, num ); m_battle.DoAction( _T( "is auto-balancing control teams ..." ) ); } else if ( command == _T( "!cfixids" ) ) { unsigned int num = s2l( params ); m_battle.FixTeamIDs( IBattle::balance_divide, true, true, num ); m_battle.DoAction( _T( "is auto-balancing control teams ..." ) ); } else if ( command == _T( "!spectunsynced" ) ) { m_battle.ForceUnsyncedToSpectate(); m_battle.DoAction( _T( "is forcing unsynced players to be spectators." ) ); } else if ( command == _T( "!map" ) ) { if ( params.IsEmpty() ) m_battle.DoAction( _T( "cannot switch to void mapname" ) ); else { wxString mapname = GetBestMatch( usync().GetMapList(), params ); try { UnitSyncMap map = usync().GetMap( mapname ); m_battle.SetLocalMap( map ); m_battle.DoAction( _T( "is switching to map " ) + mapname ); m_battle.SendHostInfo( IBattle::HI_Map ); } catch ( ... ) { m_battle.DoAction( _T( "cannot switch to map " ) + mapname ); } } } else if ( command == _T( "!set" ) ) { wxString key = params.BeforeFirst( _T( ' ' ) ); wxString value = params.AfterFirst( _T( ' ' ) ); bool exists = m_battle.CustomBattleOptions().keyExists( key ); if ( exists ) { bool result = m_battle.CustomBattleOptions().setSingleOption( key, value ); if ( result ) { OptionsWrapper::GameOption section = m_battle.CustomBattleOptions().GetSection( key ); m_battle.SendHostInfo( wxString::Format( _T( "%d_%s" ), section, key.c_str() ) ); m_battle.DoAction( _T( "has set option " ) + key + _T( " to value " ) + value ); } else m_battle.DoAction( _T( "cannot set option " ) + key + _T( " to value " ) + value + _T( ", reason: invalid value." ) ); } else { m_battle.DoAction( _T( "cannot find option entry " ) + key ); } } else if ( command == _T( "!addbox" ) ) { long allynumber; long topleftx; long toplefty; long bottomrightx; long bottomrighty; wxArrayString values = wxStringTokenize( params, _T( " " ) ); int numvalues = values.GetCount(); if ( numvalues > 4 || numvalues < 3 ) m_battle.DoAction( _T( "has recieved an invalid number of params for !addbox" ) ); else { bool valueok = values[0].ToLong( &topleftx ); valueok = valueok && values[1].ToLong( &toplefty ); valueok = valueok && values[2].ToLong( &bottomrightx ); valueok = valueok && values[3].ToLong( &bottomrighty ); if ( numvalues == 5 ) { valueok = valueok && values[4].ToLong( &allynumber ); valueok = valueok && ( allynumber > 0 ); } else { allynumber = m_battle.GetNextFreeRectIdx(); } valueok = valueok && ( topleftx >= 0 ) && ( topleftx <= 200 ); valueok = valueok && ( toplefty >= 0 ) && ( toplefty <= 200 ); valueok = valueok && ( bottomrightx >= 0 ) && ( bottomrightx <= 200 ); valueok = valueok && ( bottomrighty >= 0 ) && ( bottomrighty <= 200 ); if ( valueok ) { allynumber = allynumber - 1; BattleStartRect rect = m_battle.GetStartRect( allynumber ); if ( rect.IsOk() ) { m_battle.DoAction( _T( "cannot add a startbox for allyteam " ) + TowxString( allynumber ) + _T( " because one is already present." ) ); } else { m_battle.AddStartRect( allynumber, topleftx, toplefty, bottomrightx, bottomrighty ); m_battle.SendHostInfo( IBattle::HI_StartRects ); m_battle.DoAction( _T( "has added start box for allyteam " ) + TowxString( allynumber ) ); } } else { m_battle.DoAction( _T( "has recieved an invalid param for !addbox" ) ); } } } else if ( command == _T( "!removebox" ) ) { long boxnumber; bool numberok = params.ToLong( &boxnumber ); if ( numberok ) { boxnumber = boxnumber - 1; BattleStartRect rect = m_battle.GetStartRect( boxnumber ); if ( rect.IsOk() ) { m_battle.RemoveStartRect( boxnumber ); m_battle.SendHostInfo( IBattle::HI_StartRects ); m_battle.DoAction( _T( "has removed the start box for allyteam " ) + TowxString( boxnumber ) ); } else { m_battle.DoAction( _T( "cannot find start box " ) + params ); } } else { m_battle.DoAction( _T( "has recieved an invalid param to !removebox command" ) ); } } else return; m_lastActionTime = currentTime; }
void wxTextCtrlHist::OnChar(wxKeyEvent & event) { const int keyCode = event.GetKeyCode(); const int modifier = event.GetModifiers(); if ( current_pos == int(Historical.GetCount()) ) { m_original = GetValue(); } if(keyCode == WXK_UP) { if(current_pos > 0) { --current_pos; SetValue(Historical[current_pos]); SetInsertionPointEnd(); } } else if(keyCode == WXK_DOWN) { if(current_pos < static_cast<int>(Historical.GetCount())-1) { ++current_pos; SetValue(Historical[current_pos]); } else { current_pos = Historical.GetCount(); SetValue( m_original ); SetInsertionPointEnd(); } } else if(keyCode == WXK_TAB ) { if ( ( modifier & wxMOD_CONTROL ) != 0 ){ ui().mw().GetChatTab().AdvanceSelection( ( modifier & wxMOD_SHIFT ) == 0 ); } else { wxString text = this->GetValue(); long pos_Cursor = this->GetInsertionPoint(); wxString selection_Begin_InsertPos = this->GetRange( 0, pos_Cursor ); wxString selection_InsertPos_End = this->GetRange( pos_Cursor, this->GetLastPosition() ); // Search for the shortest Match, starting from the Insertionpoint to the left, until we find a "\ " // Special Characters according to regular Expression Syntax needs to be escaped: [,] wxRegEx regex_currentWord; #ifdef wxHAS_REGEX_ADVANCED regex_currentWord.Compile( wxT("(_|\\[|\\]|\\w)+$"), wxRE_ADVANCED ); #else regex_currentWord.Compile( wxT("(_|\\[|\\]|\\w)+$"), wxRE_EXTENDED ); #endif if ( regex_currentWord.Matches( selection_Begin_InsertPos ) ) { wxString currentWord = regex_currentWord.GetMatch( selection_Begin_InsertPos ); // std::cout << "#########: Current Word: (" << currentWord.char_str() << ")" << std::endl; wxString selection_Begin_BeforeCurrentWord = this->GetRange( 0, pos_Cursor - currentWord.length() ); // std::cout << "#########: selection_Begin_BeforeCurrentWord: (" << selection_Begin_BeforeCurrentWord.char_str() << ")" << std::endl; HashMap_String_String hm = textcompletiondatabase.GetMapping( currentWord ); // std::cout << "#########: Mapping-Size: (" << hm.size() << ")" << std::endl; wxString completed_Text; int new_Cursor_Pos = 0; if( hm.size() == 1 ) { completed_Text.append( selection_Begin_BeforeCurrentWord ); completed_Text.append( hm.begin()->second ); completed_Text.append( selection_InsertPos_End ); new_Cursor_Pos = selection_Begin_BeforeCurrentWord.length() + hm.begin()->second.length(); } else { //match nearest only makes sense when there's actually more than one match if ( hm.size() > 1 && sett().GetCompletionMethod() == Settings::MatchNearest ) { wxArrayString matches; GetArrayStringFromHashMap( hm , matches ); wxString newWord = GetBestMatch( matches, currentWord ); bool realCompletion = newWord.Len() >= currentWord.Len(); // otherwise we have actually less word than before :P if ( realCompletion ) currentWord = newWord; completed_Text.append( selection_Begin_BeforeCurrentWord ); completed_Text.append( currentWord ); completed_Text.append( selection_InsertPos_End ); new_Cursor_Pos = selection_Begin_BeforeCurrentWord.length() + currentWord.length(); // We ring the System Bell, to signalise the User, that no Completion was applied. if (!realCompletion) wxBell(); } else { completed_Text.append( selection_Begin_BeforeCurrentWord ); completed_Text.append( currentWord ); completed_Text.append( selection_InsertPos_End ); new_Cursor_Pos = selection_Begin_BeforeCurrentWord.length() + currentWord.length(); // We ring the System Bell, to signalise the User, that no Completion was applied. wxBell(); } } // Replace the old Text with our completed Text // or // if nothing was found remove the typed TAB, so that the User stays comfortable not to remove the TAB by himself. this->ChangeValue( completed_Text ); this->SetInsertionPoint( new_Cursor_Pos ); } else { wxString old_Text; old_Text.append( selection_Begin_InsertPos ); old_Text.append( selection_InsertPos_End ); this->ChangeValue( old_Text ); this->SetInsertionPoint( selection_Begin_InsertPos.length() ); wxBell(); } } } else event.Skip(); }