예제 #1
0
void CustomVirtListCtrl<T,L>::OnPeriodicSort( wxTimerEvent& /*unused*/  )
{
	SortList();
}
예제 #2
0
파일: dgl.c 프로젝트: traillog/DirGlance
int wmain( int argc, LPTSTR argv[] )
{
    // Declare vars
    TCHAR targetDir[ MAX_PATH ] = { 0 };
    TCHAR workDir[ MAX_PATH ] = { 0 };
    DWORD targetLength = 0;
    DWORD workLength = 0;
    Item resultsItem = { 0 };
    List resultsList = { 0 };
    LARGE_INTEGER freq;
    LARGE_INTEGER startingT, endingT, elapsedTicks;
    BOOL flags[ MAX_OPTIONS ] = { 0 };
    int targetDirInd = 0;
    PVOID oldValueWow64 = NULL;
    BOOL wow64Disabled = FALSE;

    // Fetch frec & initial ticks count
    QueryPerformanceFrequency( &freq );
    QueryPerformanceCounter( &startingT );

    // Get index of first argument after options
    // Also determine which options are active
    targetDirInd = Options( argc, argv,
        TEXT( "sfdmnthb" ),
        &flags[ FL_SIZE ], &flags[ FL_FILES ], &flags[ FL_DIRS ],
        &flags[ FL_MODIF ], &flags[ FL_NAME ], &flags[ FL_TYPE ],
        &flags[ FL_HELP ], &flags[ FL_DBG ], NULL );

    // Get current working dir
    workLength = GetCurrentDirectory( _countof( workDir ), workDir );

    // Validate target dir
    if ( ( argc > targetDirInd + 1 ) || flags[ FL_HELP ] )
    {
        // More than one target or
        // target with gaps (no quotes) specified or
        // asked for help

        // Print usage
        wprintf_s( TEXT( "\n    Usage:    dgl [options] [target dir]\n\n" ) );
        wprintf_s( TEXT( "    Options:\n\n" ) );
        wprintf_s( TEXT( "      -s   :  Sort by size [bytes] (default)\n" ) );
        wprintf_s( TEXT( "      -f   :  Sort by files count (descending)\n" ) );
        wprintf_s( TEXT( "      -d   :  Sort by dirs count (descending)\n" ) );
        wprintf_s( TEXT( "      -m   :  Sort by date modified (latest to earliest)\n" ) );
        wprintf_s( TEXT( "      -n   :  Soft by name (a to Z)\n" ) );
        wprintf_s( TEXT( "      -t   :  Sort by type (<DIR>, <LIN>, file)\n" ) );
        wprintf_s( TEXT( "      -h   :  Print usage\n" ) );
        wprintf_s( TEXT( "      -b   :  Extended output (debug purposes)\n\n" ) );
        wprintf_s( TEXT( "    If no option is specidied, then '-s' will be used\n" ) );
        wprintf_s( TEXT( "    If no target dir is specified, then the current working dir will be used\n" ) );

        return 1;
    }
    else if ( ( argc < targetDirInd + 1 ) && ( workLength <= MAX_PATH - 3 ) )
    {
        // No target specified --> assume current dir
        wcscpy_s( targetDir, MAX_PATH, workDir );
    }
    else if ( argc == targetDirInd + 1 )
    {
        // One target specified

        // Validate target dir starting with '\'
        if ( argv[ targetDirInd ][ 0 ] == '\\' )
        {
            // Fetch drive letter from working dir
            wcsncpy_s( targetDir, MAX_PATH, workDir, 2 );
        }

        // Append passed dir to target dir
        wcscat_s( targetDir, MAX_PATH, argv[ targetDirInd ] );
    }

    // Set up absolute target dir --> resolve '.' and '..' in target dir
    if ( !SetCurrentDirectory( targetDir ) )
    {
        ReportError( TEXT( "\nTarget directory not found.\n" ), 0, TRUE );
        return 1;
    }

    // Display absolute target dir
    GetCurrentDirectory( _countof( targetDir ), targetDir );
    wprintf_s( TEXT( "\n    Target dir: \"%s\"\n\n" ), targetDir );

    // Initialize results list
    InitializeList( &resultsList );
    if ( ListIsFull( &resultsList ) )
    {
        wprintf_s( TEXT( "\nNo memory available!\n" ) );
        return 1;
    }

    // Debug output
    if ( flags[ FL_DBG ] )
        wprintf_s( TEXT( "    %s\n" ), targetDir );

    // Disable file system redirection
    wow64Disabled = Wow64DisableWow64FsRedirection( &oldValueWow64 );

    // Scan target dir
    scanDir( targetDir, &resultsList, &resultsItem, TRUE, flags[ FL_DBG ] );

    // Re-enable redirection
    if ( wow64Disabled )
    {
        if ( !( Wow64RevertWow64FsRedirection( oldValueWow64 ) ) )
            ReportError( TEXT( "Re-enable redirection failed." ), 1, TRUE );
    }

    // Display results
    if ( ListIsEmpty( &resultsList ) )
        wprintf_s( TEXT( "\nNo data.\n\n" ) );
    else
    {
        // Sort results
        // if-else chain determines sorting priority
        // one sorting type high prio excludes low prio types
        if ( flags[ FL_SIZE ] )
            // Sort by size (descending)
            SortList( &resultsList, cmpItemsSizeCount );
        else if ( flags[ FL_FILES ] )
            // Sort by files count (descending)
            SortList( &resultsList, cmpItemsFilesCount );
        else if ( flags[ FL_DIRS ] )
            // Sort by dirs count (descending)
            SortList( &resultsList, cmpItemsDirsCount );
        else if ( flags[ FL_MODIF ] )
            // Sort by modification date (latest to earliest)
            SortList( &resultsList, cmpItemsLastWriteTime );
        else if ( flags[ FL_NAME ] )
            // Sort by name (a to Z)
            SortList( &resultsList, cmpItemsName );
        else
            // Default: sort by size (descending)
            SortList( &resultsList, cmpItemsSizeCount );

        // Debug output
        if ( flags[ FL_DBG ] )
            wprintf_s( TEXT( "\n" ) );

        // Display sorted results
        showResults( &resultsList, &resultsItem );
    }

    // Housekeeping
    EmptyTheList( &resultsList );

    // Fetch final ticks count
    QueryPerformanceCounter( &endingT );

    // Calc elapsed ticks
    elapsedTicks.QuadPart = endingT.QuadPart - startingT.QuadPart;

    // Calc and display elapsed time
    calcDispElapTime( &elapsedTicks.QuadPart, &freq.QuadPart );

    return 0;
}
예제 #3
0
void CMuleListCtrl::LoadSettings()
{
	wxCHECK_RET(!m_name.IsEmpty(), wxT("Cannot load settings for unnamed list"));

	wxConfigBase* cfg = wxConfigBase::Get();

	// Load sort order (including sort-column)
	m_sort_orders.clear();
	wxString sortOrders = cfg->Read(wxT("/eMule/TableOrdering") + m_name, wxEmptyString);
	wxString columnWidths = cfg->Read(wxT("/eMule/TableWidths") + m_name, wxEmptyString);

	// Prevent sorting from occuring when calling SetSorting
	MuleListCtrlCompare sortFunc = m_sort_func;
	m_sort_func = NULL;

	if (columnWidths.Find(wxT(':')) == wxNOT_FOUND) {
		// Old-style config entries...
		ParseOldConfigEntries(sortOrders, columnWidths);
	} else {
		// Sort orders
		wxStringTokenizer tokens(sortOrders, wxT(","));
		// Sort orders are stored in order primary, secondary, ...
		// We want to apply them with SetSorting(), so we have to apply them in reverse order,
		// so that the primary order is applied last and wins.
		// Read them with tokenizer and store them in a list in reverse order.
		CStringList tokenList;
		while (tokens.HasMoreTokens()) {
			tokenList.push_front(tokens.GetNextToken());
		}
		for (CStringList::iterator it = tokenList.begin(); it != tokenList.end(); ++it) {
			wxString token = *it;
			wxString name = token.BeforeFirst(wxT(':'));
			long order = StrToLong(token.AfterFirst(wxT(':')).BeforeLast(wxT(':')));
			long alt = StrToLong(token.AfterLast(wxT(':')));
			int col = GetColumnIndex(name);
			if (col >= 0) {
				SetSorting(col, (order ? SORT_DES : 0) | (alt ? SORT_ALT : 0));
			}
		}

		// Column widths
		wxStringTokenizer tkz(columnWidths, wxT(","));
		while (tkz.HasMoreTokens()) {
			wxString token = tkz.GetNextToken();
			wxString name = token.BeforeFirst(wxT(':'));
			long width = StrToLong(token.AfterFirst(wxT(':')));
			int col = GetColumnIndex(name);
			if (col >= 0) {
				if (col >= (int) m_column_sizes.size()) {
					m_column_sizes.resize(col + 1, 0);
				}
				m_column_sizes[col] = abs(width);
				SetColumnWidth(col, (width > 0) ? width : 0);
			}
		}
	}

	// Must have at least one sort-order specified
	if (m_sort_orders.empty()) {
		m_sort_orders.push_back(CColPair(0, 0));
	}

	// Re-enable sorting and resort the contents (if any).
	m_sort_func = sortFunc;
	SortList();
}
예제 #4
0
void CustomVirtListCtrl<T,L>::OnSortEvent( wxCommandEvent& evt )
{
	bool force  = evt.GetInt() != 0;
	SortList( force );
}
예제 #5
0
void ProcessMaterials()
{
  long mat, ptr, nmat, nbumat, i, TMS, iso, nuc;
  double T;

  /* Check burnup step */

  if ((long)RDB[DATA_BURN_STEP] > 0)
    Die(FUNCTION_NAME, "Should not be here");

  /* Pointer to material list */
  
  if ((mat = (long)RDB[DATA_PTR_M0]) < VALID_PTR)
    Error(0, "No material definitions");

  /***************************************************************************/

  /***** Finalize material compositions **************************************/
  
  fprintf(out, "Normalizing compositions and processing mixtures...\n");

  /* Calculate fractions */

  mat = (long)RDB[DATA_PTR_M0];
  while (mat > VALID_PTR)
    {
      IsotopeFractions(mat);
      mat = NextItem(mat);
    }

  /* Process mixtures */

  mat = (long)RDB[DATA_PTR_M0];
  while (mat > VALID_PTR)
    {
      ProcessMixture(mat, 0);
      mat = NextItem(mat);
    }

  fprintf(out, "OK.\n\n");

  /* Replace isotopic with atomic data in photon transport calculation */
  /* (NOTE: tätä kutsutaan myöhemmin myös tuolla alempana). */
  
  ReplacePhotonData();
  
  /***************************************************************************/
  
  /***** Sort composition for better memory management ***********************/

  /* Check if macroscopic cross sections are pregenerated (if */
  /* number of materials is large, the calculation hangs here) */

  if ((long)RDB[DATA_OPTI_RECONSTRUCT_MACROXS] == YES)
    {
      /* Use MPI task numbers to remember initial order */
  
      i = 0;
      
      mat = (long)RDB[DATA_PTR_M0];
      while (mat > VALID_PTR)
	{
	  /* Check divided and burn flags */
	  
	  if ((long)RDB[mat + MATERIAL_DIV_TYPE] == MAT_DIV_TYPE_PARENT)
	    WDB[mat + MATERIAL_MPI_ID] = 1E+12;
	  else if (!((long)RDB[mat + MATERIAL_OPTIONS] & OPT_BURN_MAT))
	    WDB[mat + MATERIAL_MPI_ID] = 1E+11;
	  else
	    WDB[mat + MATERIAL_MPI_ID] = (double)(i++);
	  
	  /* Next material */
	  
	  mat = NextItem(mat);
	}
      
      /* Use OpenMP thread number for sort */
      
      i = 0;
      
      mat = (long)RDB[DATA_PTR_M0];
      while (mat > VALID_PTR)
	{
	  /* Check divided and burn flags */
	  
	  if ((long)RDB[mat + MATERIAL_DIV_TYPE] == MAT_DIV_TYPE_PARENT)
	    WDB[mat + MATERIAL_OMP_ID] = 1E+12;
	  else if (!((long)RDB[mat + MATERIAL_OPTIONS] & OPT_BURN_MAT))
	    WDB[mat + MATERIAL_OMP_ID] = 1E+11;
	  else
	    {
	      /* Set id */
	  
	      WDB[mat + MATERIAL_OMP_ID] = (double)(i++);
	      
	      /* Check id */
	      
	      if (i == (long)RDB[DATA_OMP_MAX_THREADS])
		i = 0;
	    }
	  
	  /* Next material */
	  
	  mat = NextItem(mat);
	}
      
      /* Sort */
      
      mat = (long)RDB[DATA_PTR_M0];
      SortList(mat, MATERIAL_OMP_ID, SORT_MODE_ASCEND);
    }

  /***************************************************************************/

  /***** Allocate memory and process *****************************************/

  /* Process compositions of burnable materials */

  BurnMatCompositions();
  
  /* Put composition to divided materials */

  PutCompositions();

  /* Override material compositions */
  
  ReadMaterialComp();

  /* Process burnable materials */

  ProcessBurnMat();

  /* Calculate masses (to get the value on output) */

  CalculateMasses();

  /* Close composition lists */
  
  mat = (long)RDB[DATA_PTR_M0];
  while (mat > VALID_PTR)
    { 
      ptr = (long)RDB[mat + MATERIAL_PTR_COMP];
      CloseList(ptr);

      /* Tämä on lista alkuperäiseen nuklidikoostumukseen joka korvataan */
      /* alkuainekohtaisella koostumuksella fotonitransportmoodissa jos  */
      /* inputti on annettu neutronidatana (JLe 3.6.2015 / 2.1.24). */

      if ((ptr = (long)RDB[mat + MATERIAL_PTR_ORIG_NUC_COMP]) > VALID_PTR)
	CloseList(ptr);

      mat = NextItem(mat);
    }

  /* Check temperatures and TMS flags */

  mat = (long)RDB[DATA_PTR_M0];
  while (mat > VALID_PTR)
    {
      /* Get temperature */
	  
      T = RDB[mat + MATERIAL_DOPPLER_TEMP];

      /* Get TMS flag */

      if (RDB[mat + MATERIAL_TMS_MODE] != TMS_MODE_NONE)
	TMS = NUCLIDE_FLAG_TMS;
      else
	TMS = 0;
      
      /* Loop over composition */
      
      iso = (long)RDB[mat + MATERIAL_PTR_COMP];
      while (iso > VALID_PTR)
	{
	  /* Pointer to nuclide */

	  nuc = (long)RDB[iso + COMPOSITION_PTR_NUCLIDE];
	  CheckPointer(FUNCTION_NAME, "(nuc)", DATA_ARRAY, nuc);

	  /* Skip lost */

	  if (nuc == (long)RDB[DATA_PTR_NUCLIDE_LOST])
	    {
	      /* Next */

	      iso = NextItem(iso);

	      /* Cycle loop */

	      continue;
	    }
	  
	  /* Compare temperature */

	  if ((T > 0) && (T != RDB[nuc + NUCLIDE_TEMP]))
	    Die(FUNCTION_NAME, "Error in temperature: %s %s %E %E",
		GetText(mat + MATERIAL_PTR_NAME), 
		GetText(nuc + NUCLIDE_PTR_NAME), T, RDB[nuc + NUCLIDE_TEMP]);
	  
	  /* Check TMS flag */

	  if (TMS != ((long)RDB[nuc + NUCLIDE_TYPE_FLAGS] & NUCLIDE_FLAG_TMS))
	    Die(FUNCTION_NAME, "Error in TMS flag %s %ld %ld", 
		GetText(nuc + NUCLIDE_PTR_NAME), TMS, 
		((long)RDB[nuc + NUCLIDE_TYPE_FLAGS] & NUCLIDE_FLAG_TMS));

	  /* Check TMS limits */

	  if (TMS != NO)
	    {
	      /* Check minimum */

	      if (RDB[nuc + NUCLIDE_TMS_MIN_TEMP] > 
		  RDB[mat + MATERIAL_TMS_TMIN])
		Die(FUNCTION_NAME, "Error in TMS Tmin: %s %s %E %E",
		    GetText(mat + MATERIAL_PTR_NAME), 
		    GetText(nuc + NUCLIDE_PTR_NAME),
		    RDB[nuc + NUCLIDE_TMS_MIN_TEMP], 
		    RDB[mat + MATERIAL_TMS_TMIN]);

	      /* Check maximum */

	      if (RDB[nuc + NUCLIDE_TMS_MAX_TEMP] < 
		  RDB[mat + MATERIAL_TMS_TMAX])
		Die(FUNCTION_NAME, "Error in TMS Tmax: %s %s %E %E",
		    GetText(mat + MATERIAL_PTR_NAME), 
		    GetText(nuc + NUCLIDE_PTR_NAME),
		    RDB[nuc + NUCLIDE_TMS_MAX_TEMP], 
		    RDB[mat + MATERIAL_TMS_TMAX]);
	    }
	  
	  /* Next */

	  iso = NextItem(iso);
	}

      /* Next material */

      mat = NextItem(mat);
    }

  /* Allocate memory for reaction lists and macroscopic cross sections */

  AllocMacroXS();

  /* Sort composition to get initial order */

  if ((long)RDB[DATA_OPTI_RECONSTRUCT_MACROXS] == YES)
    {
      mat = (long)RDB[DATA_PTR_M0];
      SortList(mat, MATERIAL_MPI_ID, SORT_MODE_ASCEND);
    }

  /* Re-read compositions from restart file (JLe: tämä pitää lukea uudestaan  */
  /* siitä syystä että alialuejako tehdään vasta PutCompositions():issa, jota */
  /* kutsutaan tuolla ylempänä). */

  ReadRestartFile(RESTART_OVERRIDE);

  /* Replace isotopic with atomic data in photon transport calculation */
  /* (JLe: Tätä joudutaan kutsumaan uudestaan että myös alialueiden    */
  /* koostumukset menee oikein). */

  ReplacePhotonData();

  /* Check if decay source is used */

  if ((long)RDB[DATA_USE_DECAY_SRC] == YES)
    {
      /* Calculate activities (Aktiivisuudet lasketaan uudestaan */
      /* transportcycle.c:n lopussa.) */

      CalculateActivities();

      /* Process decay source */
      
      ProcessDecaySrc();
      
      /* Print gamma source (spectra for testing) */
      
      PrintGammaSpectra();
    }

  /* Process photon data if photon transport mode */

  if ((long)RDB[DATA_PHOTON_TRANSPORT_MODE] == YES) {

    /* Process photon attenuation data */

    ProcessPhotonAtt();

    /* Process TTB */

    if ((long)RDB[DATA_PHOTON_USE_TTB] == YES)
      ProcessTTB();

    /* Process atomic relaxation */

    ProcessRelaxation();
  }

  /***************************************************************************/
  
  /***** Assign MPI numbers to materials *************************************/

  /* NOTE: tää pitää miettiä uudestaan niin että toi järjestys menee */
  /* jotenkin fiksusti */

  /* Set MPI id's */

  i = 0;

  mat = (long)RDB[DATA_PTR_M0];
  while (mat > VALID_PTR)
    {
      /* Check burn-flag */

      if ((long)RDB[mat + MATERIAL_OPTIONS] & OPT_BURN_MAT)
	{
	  /* Set id (MSR-palamarutiinit pitää suorittaa yhdellä */
	  /* MPI-taskilla) */

	  if ((long)RDB[mat + MATERIAL_FLOW_IDX] == 0)
	    WDB[mat + MATERIAL_MPI_ID] = (double)(i++);
	  else
	    WDB[mat + MATERIAL_MPI_ID] = 0.0;

	  /* Check id */
	  
	  if (i == mpitasks)
	    i = 0;
	}
      else
	WDB[mat + MATERIAL_MPI_ID] = -1.0;
            
      /* Reset OpenMP thread number */

      WDB[mat + MATERIAL_OMP_ID] = -1.0;

      /* Next material */

      mat = NextItem(mat);
    }
  
  /***************************************************************************/
  
  /***** Count materials and set indexes for printout ************************/

  /* Reset counters */

  nmat = 0;
  nbumat = 0;

  /* Loop over materials */

  mat = (long)RDB[DATA_PTR_M0];
  while (mat > VALID_PTR)
    {
      /* Add total counter */

      nmat++;

      /* Put index */

      WDB[mat + MATERIAL_PROC_IDX] = (double)nmat;

      /* Check burn flag */
      
      if (((long)RDB[mat + MATERIAL_OPTIONS] & OPT_BURN_MAT) &&
	  ((long)RDB[mat + MATERIAL_DIV_TYPE] != MAT_DIV_TYPE_PARENT))
	{
	  /* Add burn counter */

	  nbumat++;

	  /* Put index */

	  WDB[mat + MATERIAL_BURN_IDX] = (double)nmat;
	}
      
      /* Next material */
      
      mat = NextItem(mat);
    }

  /* Put counters */

  WDB[DATA_N_MATERIALS] = (double)nmat;
  WDB[DATA_N_BURN_MATERIALS] = (double)nbumat;

  /***************************************************************************/

  /***** Calculate memory size and print summary *****************************/

  /* Calculated divided material total memory */

  mat = (long)RDB[DATA_PTR_M0];
  while (mat > VALID_PTR)
    {
      /* Check pointer to parent */

      if ((ptr = (long)RDB[mat + MATERIAL_DIV_PTR_PARENT]) > VALID_PTR)
	WDB[ptr + MATERIAL_TOT_DIV_MEM_SIZE] =
	  RDB[ptr + MATERIAL_TOT_DIV_MEM_SIZE] + RDB[mat + MATERIAL_MEM_SIZE];

      /* Next material */

      mat = NextItem(mat);
    }

  /* Print material data */
  
  PrintMaterialData();

  /***************************************************************************/
}
예제 #6
0
void CLibraryTileView::Update()
{
	CSingleLock oLock( &Library.m_pSection );
	if ( ! oLock.Lock( 250 ) )
	{
		Invalidate();
		return;
	}

	CLibraryTreeItem* pFolders	= GetFolderSelection();
	CAlbumFolder* pFolder		= NULL;

	if ( pFolders == NULL || pFolders->m_pVirtual == NULL )
	{
		pFolder = Library.GetAlbumRoot();
	}
	else
	{
		if ( pFolders->m_pSelNext != NULL || pFolders->m_pVirtual->GetFileCount() > 0 )
		{
			if ( ! empty() )
			{
				clear();
				Invalidate();
			}

			return;
		}

		pFolder = pFolders->m_pVirtual;
	}

	DWORD nCookie = GetFolderCookie();
	bool bChanged = false;

	for ( iterator pTile = begin(); pTile != end(); )
	{
		CAlbumFolder* pAlbum = (*pTile)->GetAlbum();
		if ( pAlbum && pAlbum->GetParent() == pFolder )
		{
			bChanged = (*pTile)->Update() || bChanged;
			pAlbum->m_nListCookie = nCookie;
			++pTile;
		}
		else
		{
			if ( (*pTile)->m_bSelected ) Select( pTile, TRI_FALSE );
			if ( pTile == m_pFocus ) m_pFocus = end();
			if ( pTile == m_pFirst ) m_pFirst = end();

			pTile = m_oList.erase( pTile );

			bChanged = true;
		}
	}

	if ( bChanged )
	{
		CRect rcClient;
		GetClientRect( &rcClient );
		int nMax	= (int)( ( size() + m_nColumns - 1 ) / m_nColumns ) * m_szBlock.cy;
		m_nScroll	= max( 0, min( m_nScroll, nMax - rcClient.Height() + 1 ) );
	}

	for ( POSITION pos = pFolder ? pFolder->GetFolderIterator() : NULL; pos; )
	{
		CAlbumFolder* pChild = pFolder->GetNextFolder( pos );

		if ( pChild->m_nListCookie != nCookie )
		{
			m_oList.push_back( new CLibraryTileItem( pChild ) );

			pChild->m_nListCookie = nCookie;
			bChanged = true;
		}
	}

	if ( bChanged )
	{
		// ToDo: Review if still necessary for modern libs, and no boost::ptr_list
		// Crude workaround broken std::list::sort (vc++7.1):
		// sort() may invalidate at the end iterator
		// As of Boost 1.33.0, ptr_list does not provide
		// iterator versions of sort, which might solve this problem just as well.
		BOOL bFocusAtEnd = m_pFocus == m_oList.end();
		BOOL bFirstAtEnd = m_pFirst == m_oList.end();

		m_oList.sort( SortList() );

		if ( bFocusAtEnd ) m_pFocus = m_oList.end();
		if ( bFirstAtEnd ) m_pFirst = m_oList.end();

		UpdateScroll();
	}
}
예제 #7
0
파일: deck_con.cpp 프로젝트: jiaoy06/ygopro
bool DeckBuilder::OnEvent(const irr::SEvent& event) {
    switch(event.EventType) {
    case irr::EET_GUI_EVENT: {
        s32 id = event.GUIEvent.Caller->getID();
        if(mainGame->wCategories->isVisible() && id != BUTTON_CATEGORY_OK)
            break;
        if(mainGame->wQuery->isVisible() && id != BUTTON_YES && id != BUTTON_NO)
            break;
        switch(event.GUIEvent.EventType) {
        case irr::gui::EGET_BUTTON_CLICKED: {
            switch(id) {
            case BUTTON_CLEAR_DECK: {
                mainGame->gMutex.Lock();
                mainGame->SetStaticText(mainGame->stQMessage, 310, mainGame->textFont, (wchar_t*)dataManager.GetSysString(1339));
                mainGame->PopupElement(mainGame->wQuery);
                mainGame->gMutex.Unlock();
                is_clearing = true;
                break;
            }
            case BUTTON_SORT_DECK: {
                std::sort(deckManager.current_deck.main.begin(), deckManager.current_deck.main.end(), ClientCard::deck_sort_lv);
                std::sort(deckManager.current_deck.extra.begin(), deckManager.current_deck.extra.end(), ClientCard::deck_sort_lv);
                std::sort(deckManager.current_deck.side.begin(), deckManager.current_deck.side.end(), ClientCard::deck_sort_lv);
                break;
            }
            case BUTTON_SHUFFLE_DECK: {
                std::random_shuffle(deckManager.current_deck.main.begin(), deckManager.current_deck.main.end());
                break;
            }
            case BUTTON_SAVE_DECK: {
                if(deckManager.SaveDeck(deckManager.current_deck, mainGame->cbDBDecks->getItem(mainGame->cbDBDecks->getSelected()))) {
                    mainGame->stACMessage->setText(dataManager.GetSysString(1335));
                    mainGame->PopupElement(mainGame->wACMessage, 20);
                }
                break;
            }
            case BUTTON_SAVE_DECK_AS: {
                const wchar_t* dname = mainGame->ebDeckname->getText();
                if(*dname == 0)
                    break;
                int sel = -1;
                for(size_t i = 0; i < mainGame->cbDBDecks->getItemCount(); ++i) {
                    if(!wcscmp(dname, mainGame->cbDBDecks->getItem(i))) {
                        sel = i;
                        break;
                    }
                }
                if(sel >= 0)
                    mainGame->cbDBDecks->setSelected(sel);
                else {
                    mainGame->cbDBDecks->addItem(dname);
                    mainGame->cbDBDecks->setSelected(mainGame->cbDBDecks->getItemCount() - 1);
                }
                if(deckManager.SaveDeck(deckManager.current_deck, dname)) {
                    mainGame->stACMessage->setText(dataManager.GetSysString(1335));
                    mainGame->PopupElement(mainGame->wACMessage, 20);
                }
                break;
            }
            case BUTTON_DELETE_DECK: {
                int sel = mainGame->cbDBDecks->getSelected();
                if(sel == -1)
                    break;
                mainGame->gMutex.Lock();
                wchar_t textBuffer[256];
                myswprintf(textBuffer, L"%ls\n%ls", mainGame->cbDBDecks->getItem(sel), dataManager.GetSysString(1337));
                mainGame->SetStaticText(mainGame->stQMessage, 310, mainGame->textFont, (wchar_t*)textBuffer);
                mainGame->PopupElement(mainGame->wQuery);
                mainGame->gMutex.Unlock();
                is_deleting = true;
                break;
            }
            case BUTTON_LEAVE_GAME: {
                mainGame->is_building = false;
                mainGame->wDeckEdit->setVisible(false);
                mainGame->wCategories->setVisible(false);
                mainGame->wFilter->setVisible(false);
                mainGame->wSort->setVisible(false);
                mainGame->wCardImg->setVisible(false);
                mainGame->wInfos->setVisible(false);
                mainGame->btnLeaveGame->setVisible(false);
                mainGame->PopupElement(mainGame->wMainMenu);
                mainGame->device->setEventReceiver(&mainGame->menuHandler);
                mainGame->wACMessage->setVisible(false);
                imageManager.ClearTexture();
                mainGame->scrFilter->setVisible(false);
                if(mainGame->cbDBDecks->getSelected() != -1) {
                    BufferIO::CopyWStr(mainGame->cbDBDecks->getItem(mainGame->cbDBDecks->getSelected()), mainGame->gameConf.lastdeck, 64);
                }
                if(exit_on_return)
                    mainGame->device->closeDevice();
                break;
            }
            case BUTTON_EFFECT_FILTER: {
                mainGame->PopupElement(mainGame->wCategories);
                break;
            }
            case BUTTON_START_FILTER: {
                filter_type = mainGame->cbCardType->getSelected();
                filter_type2 = mainGame->cbCardType2->getItemData(mainGame->cbCardType2->getSelected());
                filter_lm = mainGame->cbLimit->getSelected();
                if(filter_type == 1) {
                    filter_attrib = mainGame->cbAttribute->getItemData(mainGame->cbAttribute->getSelected());
                    filter_race = mainGame->cbRace->getItemData(mainGame->cbRace->getSelected());
                    filter_atk = parse_filter(mainGame->ebAttack->getText(), &filter_atktype);
                    filter_def = parse_filter(mainGame->ebDefense->getText(), &filter_deftype);
                    filter_lv = parse_filter(mainGame->ebStar->getText(), &filter_lvtype);
                    filter_scl = parse_filter(mainGame->ebScale->getText(), &filter_scltype);
                }
                FilterCards();
                if(!mainGame->gameConf.separate_clear_button)
                    ClearFilter();
                break;
            }
            case BUTTON_CLEAR_FILTER: {
                ClearSearch();
                break;
            }
            case BUTTON_CATEGORY_OK: {
                filter_effect = 0;
                long long filter = 0x1;
                for(int i = 0; i < 32; ++i, filter <<= 1)
                    if(mainGame->chkCategory[i]->isChecked())
                        filter_effect |= filter;
                mainGame->HideElement(mainGame->wCategories);
                break;
            }
            case BUTTON_SIDE_OK: {
                if(deckManager.current_deck.main.size() != pre_mainc || deckManager.current_deck.extra.size() != pre_extrac
                        || deckManager.current_deck.side.size() != pre_sidec) {
                    mainGame->env->addMessageBox(L"", dataManager.GetSysString(1410));
                    break;
                }
                char deckbuf[1024];
                char* pdeck = deckbuf;
                BufferIO::WriteInt32(pdeck, deckManager.current_deck.main.size() + deckManager.current_deck.extra.size());
                BufferIO::WriteInt32(pdeck, deckManager.current_deck.side.size());
                for(size_t i = 0; i < deckManager.current_deck.main.size(); ++i)
                    BufferIO::WriteInt32(pdeck, deckManager.current_deck.main[i]->first);
                for(size_t i = 0; i < deckManager.current_deck.extra.size(); ++i)
                    BufferIO::WriteInt32(pdeck, deckManager.current_deck.extra[i]->first);
                for(size_t i = 0; i < deckManager.current_deck.side.size(); ++i)
                    BufferIO::WriteInt32(pdeck, deckManager.current_deck.side[i]->first);
                DuelClient::SendBufferToServer(CTOS_UPDATE_DECK, deckbuf, pdeck - deckbuf);
                break;
            }
            case BUTTON_YES: {
                mainGame->HideElement(mainGame->wQuery);
                if(!mainGame->is_building || mainGame->is_siding)
                    break;
                if(is_clearing) {
                    deckManager.current_deck.main.clear();
                    deckManager.current_deck.extra.clear();
                    deckManager.current_deck.side.clear();
                } else if(is_deleting) {
                    int sel = mainGame->cbDBDecks->getSelected();
                    if (deckManager.DeleteDeck(deckManager.current_deck, mainGame->cbDBDecks->getItem(sel))) {
                        mainGame->cbDBDecks->removeItem(sel);
                        int count = mainGame->cbDBDecks->getItemCount();
                        if (sel >= count)
                            sel = count - 1;
                        mainGame->cbDBDecks->setSelected(sel);
                        if (sel != -1)
                            deckManager.LoadDeck(mainGame->cbDBDecks->getItem(sel));
                        mainGame->stACMessage->setText(dataManager.GetSysString(1338));
                        mainGame->PopupElement(mainGame->wACMessage, 20);
                    }
                }
                is_clearing = false;
                is_deleting = false;
                break;
            }
            case BUTTON_NO: {
                mainGame->HideElement(mainGame->wQuery);
                is_deleting = false;
                is_clearing = false;
                break;
            }
            }
            break;
        }
        case irr::gui::EGET_SCROLL_BAR_CHANGED: {
            switch(id) {
            case SCROLL_CARDTEXT: {
                u32 pos = mainGame->scrCardText->getPos();
                mainGame->SetStaticText(mainGame->stText, mainGame->stText->getRelativePosition().getWidth()-25, mainGame->textFont, mainGame->showingtext, pos);
                break;
            }
            break;
            }
        }
        case irr::gui::EGET_EDITBOX_ENTER: {
            switch(id) {
            case EDITBOX_KEYWORD: {
                irr::SEvent me;
                me.EventType = irr::EET_GUI_EVENT;
                me.GUIEvent.EventType = irr::gui::EGET_BUTTON_CLICKED;
                me.GUIEvent.Caller = mainGame->btnStartFilter;
                me.GUIEvent.Element = mainGame->btnStartFilter;
                mainGame->device->postEventFromUser(me);
                break;
            }
            }
            break;
        }
        case irr::gui::EGET_COMBO_BOX_CHANGED: {
            switch(id) {
            case COMBOBOX_DBLFLIST: {
                filterList = deckManager._lfList[mainGame->cbDBLFList->getSelected()].content;
                break;
            }
            case COMBOBOX_DBDECKS: {
                deckManager.LoadDeck(mainGame->cbDBDecks->getItem(mainGame->cbDBDecks->getSelected()));
                break;
            }
            case COMBOBOX_MAINTYPE: {
                mainGame->cbCardType2->setSelected(0);
                mainGame->cbAttribute->setSelected(0);
                mainGame->cbRace->setSelected(0);
                mainGame->ebAttack->setText(L"");
                mainGame->ebDefense->setText(L"");
                mainGame->ebStar->setText(L"");
                mainGame->ebScale->setText(L"");
                switch(mainGame->cbCardType->getSelected()) {
                case 0: {
                    mainGame->cbCardType2->setEnabled(false);
                    mainGame->cbCardType2->setSelected(0);
                    mainGame->cbRace->setEnabled(false);
                    mainGame->cbAttribute->setEnabled(false);
                    mainGame->ebAttack->setEnabled(false);
                    mainGame->ebDefense->setEnabled(false);
                    mainGame->ebStar->setEnabled(false);
                    mainGame->ebScale->setEnabled(false);
                    break;
                }
                case 1: {
                    wchar_t normaltuner[32];
                    wchar_t normalpen[32];
                    wchar_t syntuner[32];
                    mainGame->cbCardType2->setEnabled(true);
                    mainGame->cbRace->setEnabled(true);
                    mainGame->cbAttribute->setEnabled(true);
                    mainGame->ebAttack->setEnabled(true);
                    mainGame->ebDefense->setEnabled(true);
                    mainGame->ebStar->setEnabled(true);
                    mainGame->ebScale->setEnabled(true);
                    mainGame->cbCardType2->clear();
                    mainGame->cbCardType2->addItem(dataManager.GetSysString(1080), 0);
                    mainGame->cbCardType2->addItem(dataManager.GetSysString(1054), TYPE_MONSTER + TYPE_NORMAL);
                    mainGame->cbCardType2->addItem(dataManager.GetSysString(1055), TYPE_MONSTER + TYPE_EFFECT);
                    mainGame->cbCardType2->addItem(dataManager.GetSysString(1056), TYPE_MONSTER + TYPE_FUSION);
                    mainGame->cbCardType2->addItem(dataManager.GetSysString(1057), TYPE_MONSTER + TYPE_RITUAL);
                    mainGame->cbCardType2->addItem(dataManager.GetSysString(1063), TYPE_MONSTER + TYPE_SYNCHRO);
                    mainGame->cbCardType2->addItem(dataManager.GetSysString(1073), TYPE_MONSTER + TYPE_XYZ);
                    mainGame->cbCardType2->addItem(dataManager.GetSysString(1074), TYPE_MONSTER + TYPE_PENDULUM);
                    myswprintf(normaltuner, L"%ls|%ls", dataManager.GetSysString(1054), dataManager.GetSysString(1062));
                    mainGame->cbCardType2->addItem(normaltuner, TYPE_MONSTER + TYPE_NORMAL + TYPE_TUNER);
                    myswprintf(normalpen, L"%ls|%ls", dataManager.GetSysString(1054), dataManager.GetSysString(1074));
                    mainGame->cbCardType2->addItem(normalpen, TYPE_MONSTER + TYPE_NORMAL + TYPE_PENDULUM);
                    myswprintf(syntuner, L"%ls|%ls", dataManager.GetSysString(1063), dataManager.GetSysString(1062));
                    mainGame->cbCardType2->addItem(syntuner, TYPE_MONSTER + TYPE_SYNCHRO + TYPE_TUNER);
                    mainGame->cbCardType2->addItem(dataManager.GetSysString(1062), TYPE_MONSTER + TYPE_TUNER);
                    mainGame->cbCardType2->addItem(dataManager.GetSysString(1061), TYPE_MONSTER + TYPE_DUAL);
                    mainGame->cbCardType2->addItem(dataManager.GetSysString(1060), TYPE_MONSTER + TYPE_UNION);
                    mainGame->cbCardType2->addItem(dataManager.GetSysString(1059), TYPE_MONSTER + TYPE_SPIRIT);
                    mainGame->cbCardType2->addItem(dataManager.GetSysString(1071), TYPE_MONSTER + TYPE_FLIP);
                    mainGame->cbCardType2->addItem(dataManager.GetSysString(1072), TYPE_MONSTER + TYPE_TOON);
                    break;
                }
                case 2: {
                    mainGame->cbCardType2->setEnabled(true);
                    mainGame->cbRace->setEnabled(false);
                    mainGame->cbAttribute->setEnabled(false);
                    mainGame->ebAttack->setEnabled(false);
                    mainGame->ebDefense->setEnabled(false);
                    mainGame->ebStar->setEnabled(false);
                    mainGame->ebScale->setEnabled(false);
                    mainGame->cbCardType2->clear();
                    mainGame->cbCardType2->addItem(dataManager.GetSysString(1080), 0);
                    mainGame->cbCardType2->addItem(dataManager.GetSysString(1054), TYPE_SPELL);
                    mainGame->cbCardType2->addItem(dataManager.GetSysString(1066), TYPE_SPELL + TYPE_QUICKPLAY);
                    mainGame->cbCardType2->addItem(dataManager.GetSysString(1067), TYPE_SPELL + TYPE_CONTINUOUS);
                    mainGame->cbCardType2->addItem(dataManager.GetSysString(1057), TYPE_SPELL + TYPE_RITUAL);
                    mainGame->cbCardType2->addItem(dataManager.GetSysString(1068), TYPE_SPELL + TYPE_EQUIP);
                    mainGame->cbCardType2->addItem(dataManager.GetSysString(1069), TYPE_SPELL + TYPE_FIELD);
                    break;
                }
                case 3: {
                    mainGame->cbCardType2->setEnabled(true);
                    mainGame->cbRace->setEnabled(false);
                    mainGame->cbAttribute->setEnabled(false);
                    mainGame->ebAttack->setEnabled(false);
                    mainGame->ebDefense->setEnabled(false);
                    mainGame->ebStar->setEnabled(false);
                    mainGame->ebScale->setEnabled(false);
                    mainGame->cbCardType2->clear();
                    mainGame->cbCardType2->addItem(dataManager.GetSysString(1080), 0);
                    mainGame->cbCardType2->addItem(dataManager.GetSysString(1054), TYPE_TRAP);
                    mainGame->cbCardType2->addItem(dataManager.GetSysString(1067), TYPE_TRAP + TYPE_CONTINUOUS);
                    mainGame->cbCardType2->addItem(dataManager.GetSysString(1070), TYPE_TRAP + TYPE_COUNTER);
                    break;
                }
                }
                break;
            }
            case COMBOBOX_SORTTYPE: {
                SortList();
                mainGame->env->setFocus(0);
                break;
            }
            }
        }
        default:
            break;
        }
        break;
    }
    case irr::EET_MOUSE_INPUT_EVENT: {
        switch(event.MouseInput.Event) {
        case irr::EMIE_LMOUSE_PRESSED_DOWN: {
            irr::core::position2di mouse_pos(event.MouseInput.X, event.MouseInput.Y);
            irr::gui::IGUIElement* root = mainGame->env->getRootGUIElement();
            if(root->getElementFromPoint(mouse_pos) != root)
                break;
            if(mainGame->wCategories->isVisible() || mainGame->wQuery->isVisible())
                break;
            if(hovered_pos == 0 || hovered_seq == -1)
                break;
            click_pos = hovered_pos;
            dragx = event.MouseInput.X;
            dragy = event.MouseInput.Y;
            draging_pointer = dataManager.GetCodePointer(hovered_code);
            if(draging_pointer == dataManager._datas.end())
                break;
            unsigned int limitcode = draging_pointer->second.alias ? draging_pointer->second.alias : draging_pointer->first;
            if(hovered_pos == 4) {
                int limit = 3;
                if(filterList->count(limitcode))
                    limit = (*filterList)[limitcode];
                for(size_t i = 0; i < deckManager.current_deck.main.size(); ++i)
                    if(deckManager.current_deck.main[i]->first == limitcode
                            || deckManager.current_deck.main[i]->second.alias == limitcode)
                        limit--;
                for(size_t i = 0; i < deckManager.current_deck.extra.size(); ++i)
                    if(deckManager.current_deck.extra[i]->first == limitcode
                            || deckManager.current_deck.extra[i]->second.alias == limitcode)
                        limit--;
                for(size_t i = 0; i < deckManager.current_deck.side.size(); ++i)
                    if(deckManager.current_deck.side[i]->first == limitcode
                            || deckManager.current_deck.side[i]->second.alias == limitcode)
                        limit--;
                if(limit <= 0)
                    break;
            }
            if(hovered_pos == 1)
                deckManager.current_deck.main.erase(deckManager.current_deck.main.begin() + hovered_seq);
            else if(hovered_pos == 2)
                deckManager.current_deck.extra.erase(deckManager.current_deck.extra.begin() + hovered_seq);
            else if(hovered_pos == 3)
                deckManager.current_deck.side.erase(deckManager.current_deck.side.begin() + hovered_seq);
            is_draging = true;
            break;
        }
        case irr::EMIE_LMOUSE_LEFT_UP: {
            if(!is_draging)
                break;
            if(!mainGame->is_siding) {
                if((hovered_pos == 1 && (draging_pointer->second.type & 0x802040)) || (hovered_pos == 2 && !(draging_pointer->second.type & 0x802040)))
                    hovered_pos = 0;
                if((hovered_pos == 1 || (hovered_pos == 0 && click_pos == 1)) && deckManager.current_deck.main.size() < 60) {
                    if(hovered_seq == -1)
                        deckManager.current_deck.main.push_back(draging_pointer);
                    else if(hovered_seq < (int)deckManager.current_deck.main.size() && hovered_pos)
                        deckManager.current_deck.main.insert(deckManager.current_deck.main.begin() + hovered_seq, draging_pointer);
                    else deckManager.current_deck.main.push_back(draging_pointer);
                    is_draging = false;
                } else if((hovered_pos == 2 || (hovered_pos == 0 && click_pos == 2)) && deckManager.current_deck.extra.size() < 15) {
                    if(hovered_seq == -1)
                        deckManager.current_deck.extra.push_back(draging_pointer);
                    else if(hovered_seq < (int)deckManager.current_deck.extra.size() && hovered_pos)
                        deckManager.current_deck.extra.insert(deckManager.current_deck.extra.begin() + hovered_seq, draging_pointer);
                    else deckManager.current_deck.extra.push_back(draging_pointer);
                    is_draging = false;
                } else if((hovered_pos == 3 || (hovered_pos == 0 && click_pos == 3)) && deckManager.current_deck.side.size() < 15) {
                    if(hovered_seq == -1)
                        deckManager.current_deck.side.push_back(draging_pointer);
                    else if(hovered_seq < (int)deckManager.current_deck.side.size() && hovered_pos)
                        deckManager.current_deck.side.insert(deckManager.current_deck.side.begin() + hovered_seq, draging_pointer);
                    else deckManager.current_deck.side.push_back(draging_pointer);
                    is_draging = false;
                } else if (hovered_pos == 4)
                    is_draging = false;
            } else {
                if((hovered_pos == 1 && (draging_pointer->second.type & 0x802040)) || (hovered_pos == 2 && !(draging_pointer->second.type & 0x802040)) || hovered_pos == 4)
                    hovered_pos = 0;
                if((hovered_pos == 1 || (hovered_pos == 0 && click_pos == 1)) && deckManager.current_deck.main.size() < 65) {
                    if(hovered_seq == -1)
                        deckManager.current_deck.main.push_back(draging_pointer);
                    else if(hovered_seq < (int)deckManager.current_deck.main.size() && hovered_pos)
                        deckManager.current_deck.main.insert(deckManager.current_deck.main.begin() + hovered_seq, draging_pointer);
                    else deckManager.current_deck.main.push_back(draging_pointer);
                    is_draging = false;
                } else if((hovered_pos == 2 || (hovered_pos == 0 && click_pos == 2)) && deckManager.current_deck.extra.size() < 20) {
                    if(hovered_seq == -1)
                        deckManager.current_deck.extra.push_back(draging_pointer);
                    else if(hovered_seq < (int)deckManager.current_deck.extra.size() && hovered_pos)
                        deckManager.current_deck.extra.insert(deckManager.current_deck.extra.begin() + hovered_seq, draging_pointer);
                    else deckManager.current_deck.extra.push_back(draging_pointer);
                    is_draging = false;
                } else if((hovered_pos == 3 || (hovered_pos == 0 && click_pos == 3)) && deckManager.current_deck.side.size() < 20) {
                    if(hovered_seq == -1)
                        deckManager.current_deck.side.push_back(draging_pointer);
                    else if(hovered_seq < (int)deckManager.current_deck.side.size() && hovered_pos)
                        deckManager.current_deck.side.insert(deckManager.current_deck.side.begin() + hovered_seq, draging_pointer);
                    else deckManager.current_deck.side.push_back(draging_pointer);
                    is_draging = false;
                }
            }
            if(is_draging) {
                if(click_pos == 1)
                    deckManager.current_deck.main.push_back(draging_pointer);
                else if(click_pos == 2)
                    deckManager.current_deck.extra.push_back(draging_pointer);
                else if(click_pos == 3)
                    deckManager.current_deck.side.push_back(draging_pointer);
            }
            is_draging = false;
            break;
        }
        case irr::EMIE_RMOUSE_LEFT_UP: {
            if(mainGame->is_siding) {
                if(is_draging)
                    break;
                if(hovered_pos == 0 || hovered_seq == -1)
                    break;
                draging_pointer = dataManager.GetCodePointer(hovered_code);
                if(draging_pointer == dataManager._datas.end())
                    break;
                if(hovered_pos == 1) {
                    if(deckManager.current_deck.side.size() < 20) {
                        deckManager.current_deck.main.erase(deckManager.current_deck.main.begin() + hovered_seq);
                        deckManager.current_deck.side.push_back(draging_pointer);
                    }
                } else if(hovered_pos == 2) {
                    if(deckManager.current_deck.side.size() < 20) {
                        deckManager.current_deck.extra.erase(deckManager.current_deck.extra.begin() + hovered_seq);
                        deckManager.current_deck.side.push_back(draging_pointer);
                    }
                } else {
                    if((draging_pointer->second.type & 0x802040) && deckManager.current_deck.extra.size() < 20) {
                        deckManager.current_deck.side.erase(deckManager.current_deck.side.begin() + hovered_seq);
                        deckManager.current_deck.extra.push_back(draging_pointer);
                    }
                    if(!(draging_pointer->second.type & 0x802040) && deckManager.current_deck.main.size() < 64) {
                        deckManager.current_deck.side.erase(deckManager.current_deck.side.begin() + hovered_seq);
                        deckManager.current_deck.main.push_back(draging_pointer);
                    }
                }
                break;
            }
            if(mainGame->wCategories->isVisible() || mainGame->wQuery->isVisible())
                break;
            if(hovered_pos == 0 || hovered_seq == -1)
                break;
            if(!is_draging) {
                draging_pointer = dataManager.GetCodePointer(hovered_code);
                if(draging_pointer == dataManager._datas.end())
                    break;
            }
            if(hovered_pos == 1) {
                if(!is_draging)
                    deckManager.current_deck.main.erase(deckManager.current_deck.main.begin() + hovered_seq);
                else if(deckManager.current_deck.side.size() < 15) {
                    deckManager.current_deck.side.push_back(draging_pointer);
                    is_draging = false;
                }
            } else if(hovered_pos == 2) {
                if(!is_draging)
                    deckManager.current_deck.extra.erase(deckManager.current_deck.extra.begin() + hovered_seq);
                else if(deckManager.current_deck.side.size() < 15) {
                    deckManager.current_deck.side.push_back(draging_pointer);
                    is_draging = false;
                }
            } else if(hovered_pos == 3) {
                if(!is_draging)
                    deckManager.current_deck.side.erase(deckManager.current_deck.side.begin() + hovered_seq);
                else {
                    if((draging_pointer->second.type & 0x802040) && deckManager.current_deck.extra.size() < 15) {
                        deckManager.current_deck.extra.push_back(draging_pointer);
                        is_draging = false;
                    } else if(!(draging_pointer->second.type & 0x802040) && deckManager.current_deck.main.size() < 60) {
                        deckManager.current_deck.main.push_back(draging_pointer);
                        is_draging = false;
                    }
                }
            } else {
                if(is_draging) {
                    if(deckManager.current_deck.side.size() < 15) {
                        deckManager.current_deck.side.push_back(draging_pointer);
                        is_draging = false;
                    }
                } else {
                    unsigned int limitcode = draging_pointer->second.alias ? draging_pointer->second.alias : draging_pointer->first;
                    int limit = 3;
                    if(filterList->count(limitcode))
                        limit = (*filterList)[limitcode];
                    for(size_t i = 0; i < deckManager.current_deck.main.size(); ++i)
                        if(deckManager.current_deck.main[i]->first == limitcode
                                || deckManager.current_deck.main[i]->second.alias == limitcode)
                            limit--;
                    for(size_t i = 0; i < deckManager.current_deck.extra.size(); ++i)
                        if(deckManager.current_deck.extra[i]->first == limitcode
                                || deckManager.current_deck.extra[i]->second.alias == limitcode)
                            limit--;
                    for(size_t i = 0; i < deckManager.current_deck.side.size(); ++i)
                        if(deckManager.current_deck.side[i]->first == limitcode
                                || deckManager.current_deck.side[i]->second.alias == limitcode)
                            limit--;
                    if(limit <= 0)
                        break;
                    if((draging_pointer->second.type & 0x802040) && deckManager.current_deck.extra.size() < 15) {
                        deckManager.current_deck.extra.push_back(draging_pointer);
                    } else if(!(draging_pointer->second.type & 0x802040) && deckManager.current_deck.main.size() < 60) {
                        deckManager.current_deck.main.push_back(draging_pointer);
                    } else if (deckManager.current_deck.side.size() < 15) {
                        deckManager.current_deck.side.push_back(draging_pointer);
                    }
                }
            }
            break;
        }
        case irr::EMIE_MMOUSE_LEFT_UP: {
            if (mainGame->is_siding)
                break;
            if (mainGame->wCategories->isVisible() || mainGame->wQuery->isVisible())
                break;
            if (hovered_pos == 0 || hovered_seq == -1)
                break;
            if (is_draging)
                break;
            draging_pointer = dataManager.GetCodePointer(hovered_code);
            unsigned int limitcode = draging_pointer->second.alias ? draging_pointer->second.alias : draging_pointer->first;
            int limit = 3;
            if (filterList->count(limitcode))
                limit = (*filterList)[limitcode];
            for (size_t i = 0; i < deckManager.current_deck.main.size(); ++i)
                if (deckManager.current_deck.main[i]->first == limitcode
                        || deckManager.current_deck.main[i]->second.alias == limitcode)
                    limit--;
            for (size_t i = 0; i < deckManager.current_deck.extra.size(); ++i)
                if (deckManager.current_deck.extra[i]->first == limitcode
                        || deckManager.current_deck.extra[i]->second.alias == limitcode)
                    limit--;
            for (size_t i = 0; i < deckManager.current_deck.side.size(); ++i)
                if (deckManager.current_deck.side[i]->first == limitcode
                        || deckManager.current_deck.side[i]->second.alias == limitcode)
                    limit--;
            if (limit <= 0)
                break;
            if (hovered_pos == 1) {
                if (deckManager.current_deck.main.size() < 60)
                    deckManager.current_deck.main.push_back(draging_pointer);
                else if (deckManager.current_deck.side.size() < 15)
                    deckManager.current_deck.side.push_back(draging_pointer);
            } else if (hovered_pos == 2) {
                if (deckManager.current_deck.extra.size() < 15)
                    deckManager.current_deck.extra.push_back(draging_pointer);
                else if (deckManager.current_deck.side.size() < 15)
                    deckManager.current_deck.side.push_back(draging_pointer);
            } else if (hovered_pos == 3) {
                if (deckManager.current_deck.side.size() < 15)
                    deckManager.current_deck.side.push_back(draging_pointer);
                else {
                    if ((draging_pointer->second.type & 0x802040) && deckManager.current_deck.extra.size() < 15)
                        deckManager.current_deck.extra.push_back(draging_pointer);
                    else if (!(draging_pointer->second.type & 0x802040) && deckManager.current_deck.main.size() < 60)
                        deckManager.current_deck.main.push_back(draging_pointer);
                }
            } else {
                if ((draging_pointer->second.type & 0x802040) && deckManager.current_deck.extra.size() < 15)
                    deckManager.current_deck.extra.push_back(draging_pointer);
                else if (!(draging_pointer->second.type & 0x802040) && deckManager.current_deck.main.size() < 60)
                    deckManager.current_deck.main.push_back(draging_pointer);
                else if (deckManager.current_deck.side.size() < 15)
                    deckManager.current_deck.side.push_back(draging_pointer);
            }
            break;
        }
        case irr::EMIE_MOUSE_MOVED: {
            int x = event.MouseInput.X;
            int y = event.MouseInput.Y;
            irr::core::position2di mouse_pos(x, y);
            irr::gui::IGUIElement* root = mainGame->env->getRootGUIElement();
            if(root->getElementFromPoint(mouse_pos) != root)
                break;
            int pre_code = hovered_code;
            if(x >= 314 && x <= 794 && y >= 164 && y <= 435) {
                int lx = 10, px, py = (y - 164) / 68;
                hovered_pos = 1;
                if(deckManager.current_deck.main.size() > 40)
                    lx = (deckManager.current_deck.main.size() - 41) / 4 + 11;
                if(x >= 750)
                    px = lx - 1;
                else px = (x - 314) * (lx - 1) / 436;
                if(py*lx + px >= (int)deckManager.current_deck.main.size()) {
                    hovered_seq = -1;
                    hovered_code = 0;
                } else {
                    hovered_seq = py * lx + px;
                    hovered_code = deckManager.current_deck.main[hovered_seq]->first;
                }
            } else if(x >= 314 && x <= 794 && y >= 466 && y <= 530) {
                int lx = deckManager.current_deck.extra.size();
                hovered_pos = 2;
                if(lx < 10)
                    lx = 10;
                if(x >= 750)
                    hovered_seq = lx - 1;
                else hovered_seq = (x - 314) * (lx - 1) / 436;
                if(hovered_seq >= (int)deckManager.current_deck.extra.size()) {
                    hovered_seq = -1;
                    hovered_code = 0;
                } else {
                    hovered_code = deckManager.current_deck.extra[hovered_seq]->first;
                }
            } else if (x >= 314 && x <= 794 && y >= 564 && y <= 628) {
                int lx = deckManager.current_deck.side.size();
                hovered_pos = 3;
                if(lx < 10)
                    lx = 10;
                if(x >= 750)
                    hovered_seq = lx - 1;
                else hovered_seq = (x - 314) * (lx - 1) / 436;
                if(hovered_seq >= (int)deckManager.current_deck.side.size()) {
                    hovered_seq = -1;
                    hovered_code = 0;
                } else {
                    hovered_code = deckManager.current_deck.side[hovered_seq]->first;
                }
            } else if(x >= 810 && x <= 995 && y >= 165 && y <= 626) {
                hovered_pos = 4;
                hovered_seq = (y - 165) / 66;
                if(mainGame->scrFilter->getPos() + hovered_seq >= (int)results.size()) {
                    hovered_seq = -1;
                    hovered_code = 0;
                } else {
                    hovered_code = results[mainGame->scrFilter->getPos() + hovered_seq]->first;
                }
            } else {
                hovered_pos = 0;
                hovered_code = 0;
            }
            if(is_draging) {
                dragx = x;
                dragy = y;
            }
            if(!is_draging && pre_code != hovered_code) {
                if(hovered_code) {
                    mainGame->ShowCardInfo(hovered_code);
                }
                if(pre_code)
                    imageManager.RemoveTexture(pre_code);
            }
            break;
        }
        case irr::EMIE_MOUSE_WHEEL: {
            if(!mainGame->scrFilter->isVisible())
                break;
            if(event.MouseInput.Wheel < 0) {
                if(mainGame->scrFilter->getPos() < mainGame->scrFilter->getMax())
                    mainGame->scrFilter->setPos(mainGame->scrFilter->getPos() + 1);
            } else {
                if(mainGame->scrFilter->getPos() > 0)
                    mainGame->scrFilter->setPos(mainGame->scrFilter->getPos() - 1);
            }
            SEvent e = event;
            e.MouseInput.Event = irr::EMIE_MOUSE_MOVED;
            mainGame->device->postEventFromUser(e);
            break;
        }
        default:
            break;
        }
        break;
    }
    case irr::EET_KEY_INPUT_EVENT: {
        switch(event.KeyInput.Key) {
        case irr::KEY_KEY_R: {
            if(!event.KeyInput.PressedDown && !mainGame->HasFocus(EGUIET_EDIT_BOX))
                mainGame->textFont->setTransparency(true);
            break;
        }
        case irr::KEY_ESCAPE: {
            if(!mainGame->HasFocus(EGUIET_EDIT_BOX))
                mainGame->device->minimizeWindow();
            break;
        }
        default:
            break;
        }
        break;
    }
    default:
        break;
    }
    return false;
}
예제 #8
0
파일: deck_con.cpp 프로젝트: jiaoy06/ygopro
void DeckBuilder::FilterCards() {
    results.clear();
    const wchar_t* pstr = mainGame->ebCardName->getText();
    int trycode = BufferIO::GetVal(pstr);
    if(dataManager.GetData(trycode, 0)) {
        auto ptr = dataManager.GetCodePointer(trycode);	// verified by GetData()
        results.push_back(ptr);
        mainGame->scrFilter->setVisible(false);
        mainGame->scrFilter->setPos(0);
        myswprintf(result_string, L"%d", results.size());
        return;
    }
    unsigned int set_code = 0;
    if(pstr[0] == L'@')
        set_code = dataManager.GetSetCode(&pstr[1]);
    else
        set_code = dataManager.GetSetCode(&pstr[0]);
    if(pstr[0] == 0 || (pstr[0] == L'$' && pstr[1] == 0) || (pstr[0] == L'@' && pstr[1] == 0))
        pstr = 0;
    auto strpointer = dataManager._strings.begin();
    for(code_pointer ptr = dataManager._datas.begin(); ptr != dataManager._datas.end(); ++ptr, ++strpointer) {
        const CardDataC& data = ptr->second;
        const CardString& text = strpointer->second;
        if(data.type & TYPE_TOKEN)
            continue;
        switch(filter_type) {
        case 1: {
            if(!(data.type & TYPE_MONSTER) || (data.type & filter_type2) != filter_type2)
                continue;
            if(filter_race && data.race != filter_race)
                continue;
            if(filter_attrib && data.attribute != filter_attrib)
                continue;
            if(filter_atktype) {
                if((filter_atktype == 1 && data.attack != filter_atk) || (filter_atktype == 2 && data.attack < filter_atk)
                        || (filter_atktype == 3 && data.attack <= filter_atk) || (filter_atktype == 4 && (data.attack > filter_atk || data.attack < 0))
                        || (filter_atktype == 5 && (data.attack >= filter_atk || data.attack < 0)) || (filter_atktype == 6 && data.attack != -2))
                    continue;
            }
            if(filter_deftype) {
                if((filter_deftype == 1 && data.defense != filter_def) || (filter_deftype == 2 && data.defense < filter_def)
                        || (filter_deftype == 3 && data.defense <= filter_def) || (filter_deftype == 4 && (data.defense > filter_def || data.defense < 0))
                        || (filter_deftype == 5 && (data.defense >= filter_def || data.defense < 0)) || (filter_deftype == 6 && data.defense != -2))
                    continue;
            }
            if(filter_lvtype) {
                if((filter_lvtype == 1 && data.level != filter_lv) || (filter_lvtype == 2 && data.level < filter_lv)
                        || (filter_lvtype == 3 && data.level <= filter_lv) || (filter_lvtype == 4 && data.level > filter_lv)
                        || (filter_lvtype == 5 && data.level >= filter_lv) || filter_lvtype == 6)
                    continue;
            }
            if(filter_scltype) {
                if((filter_scltype == 1 && data.lscale != filter_scl) || (filter_scltype == 2 && data.lscale < filter_scl)
                        || (filter_scltype == 3 && data.lscale <= filter_scl) || (filter_scltype == 4 && (data.lscale > filter_scl || data.lscale == 0))
                        || (filter_scltype == 5 && (data.lscale >= filter_scl || data.lscale == 0)) || filter_scltype == 6)
                    continue;
            }
            break;
        }
        case 2: {
            if(!(data.type & TYPE_SPELL))
                continue;
            if(filter_type2 && data.type != filter_type2)
                continue;
            break;
        }
        case 3: {
            if(!(data.type & TYPE_TRAP))
                continue;
            if(filter_type2 && data.type != filter_type2)
                continue;
            break;
        }
        }
        if(filter_effect && !(data.category & filter_effect))
            continue;
        if(filter_lm) {
            if(filter_lm <= 3 && (!filterList->count(ptr->first) || (*filterList)[ptr->first] != filter_lm - 1))
                continue;
            if(filter_lm == 4 && data.ot != 1)
                continue;
            if(filter_lm == 5 && data.ot != 2)
                continue;
            if(filter_lm == 6 && data.ot != 3)
                continue;
            if(filter_lm == 7 && data.ot != 4)
                continue;
        }
        if(pstr) {
            if(pstr[0] == L'$') {
                if(wcsstr(text.name, &pstr[1]) == 0)
                    continue;
            } else if(pstr[0] == L'@' && set_code) {
                if(!check_set_code(data, set_code)) continue;
            } else {
                if(wcsstr(text.name, pstr) == 0 && wcsstr(text.text, pstr) == 0
                        && (!set_code || !check_set_code(data, set_code)))
                    continue;
            }
        }
        results.push_back(ptr);
    }
    myswprintf(result_string, L"%d", results.size());
    if(results.size() > 7) {
        mainGame->scrFilter->setVisible(true);
        mainGame->scrFilter->setMax(results.size() - 7);
        mainGame->scrFilter->setPos(0);
    } else {
        mainGame->scrFilter->setVisible(false);
        mainGame->scrFilter->setPos(0);
    }
    SortList();
}
예제 #9
0
PeepsWindow::PeepsWindow(BMessenger target)
	: BWindow(BRect(50,50,600,470), "Mr. Peeps!", B_DOCUMENT_WINDOW, B_NOT_ZOOMABLE | B_NOT_H_RESIZABLE)
{
	float wmin,wmax,hmin,hmax;
	
	GetSizeLimits(&wmin,&wmax,&hmin,&hmax);
	wmin=500;
	hmin=400;
	
	SetSizeLimits(wmin,wmax,hmin,hmax);
		
	ReadLocaleSettings();
	if(fLocale.CountChars()>0)
	{
		locale_roster->SetLocale(fLocale.String());
		gCurrentLocale=locale_roster->GetLocale();
	}
	
	BRect r(Bounds());
	BMessage *msg;
	
	r.bottom=20;
	BMenuBar *mb=new BMenuBar(r,"menubar");
	AddChild(mb);
	
	fPeopleMenu=new BMenu(TRANSLATE("Person"));
	fPeopleMenu->AddItem(new BMenuItem(TRANSLATE("New"),new BMessage(M_ADD_PERSON),'N'));
	fPeopleMenu->AddSeparatorItem();
	fPeopleMenu->AddItem(new BMenuItem(TRANSLATE("Previous"),new BMessage(M_PREV_ITEM),B_UP_ARROW));
	fPeopleMenu->AddItem(new BMenuItem(TRANSLATE("Next"),new BMessage(M_NEXT_ITEM),B_DOWN_ARROW));
	fPeopleMenu->AddSeparatorItem();
	
	fActionsMenu=new BMenu(TRANSLATE("Actions"));
		
	// Submenu for sending e-mail
	BMenu *emailmenu=new BMenu(TRANSLATE("Send E-Mail to"));
	
	fEmailPersonalItem=new BMenuItem(TRANSLATE("Personal Address"),new BMessage(M_SEND_PERSONAL_EMAIL));
	emailmenu->AddItem(fEmailPersonalItem);
	
	fEmailWorkItem=new BMenuItem(TRANSLATE("Work Address"),new BMessage(M_SEND_WORK_EMAIL));
	emailmenu->AddItem(fEmailWorkItem);
	
	fEmailAltItem=new BMenuItem(TRANSLATE("Alternate Address"),new BMessage(M_SEND_ALT_EMAIL));
	emailmenu->AddItem(fEmailAltItem);
	fActionsMenu->AddItem(emailmenu);
	
	// Submenu for sending e-mail
	BMenu *browsermenu=new BMenu(TRANSLATE("Go to Web Page"));
	
	fBrowseHomeItem=new BMenuItem(TRANSLATE("Personal Web Address"),new BMessage(M_BROWSE_WWW_HOME));
	browsermenu->AddItem(fBrowseHomeItem);
	
	fBrowseWorkItem=new BMenuItem(TRANSLATE("Work Web Address"),new BMessage(M_BROWSE_WWW_WORK));
	browsermenu->AddItem(fBrowseWorkItem);
	
	fBrowseAltItem=new BMenuItem(TRANSLATE("Alternate Web Address"),new BMessage(M_BROWSE_WWW_ALT));
	browsermenu->AddItem(fBrowseAltItem);
	fActionsMenu->AddItem(browsermenu);
	
	fActionsMenu->AddSeparatorItem();
	fPastePhotoItem=new BMenuItem(TRANSLATE("Paste Photo from Clipboard"),new BMessage(M_PASTE_IMAGE));
	fActionsMenu->AddItem(fPastePhotoItem);
	fRemovePhotoItem=new BMenuItem(TRANSLATE("Remove Photo"),new BMessage(M_REMOVE_IMAGE));
	fActionsMenu->AddItem(fRemovePhotoItem);
	fActionsMenu->AddSeparatorItem();
	fActionsMenu->AddItem(new BMenuItem(TRANSLATE("Move To Trash"),new BMessage(M_DELETE_PERSON),'T'));
	fPeopleMenu->AddItem(fActionsMenu);
	fActionsMenu->SetEnabled(false);
	
	
	fPeopleMenu->AddSeparatorItem();
	fPeopleMenu->AddItem(new BMenuItem(TRANSLATE("About..."),new BMessage(B_ABOUT_REQUESTED)));
	mb->AddItem(fPeopleMenu);

	fEditMenu=new BMenu(TRANSLATE("Edit"));
	fEditMenu->AddItem(new BMenuItem(TRANSLATE("Undo"),new BMessage(M_UNDO),'Z'));
	fEditMenu->AddSeparatorItem();
	fEditMenu->AddItem(new BMenuItem(TRANSLATE("Cut"),new BMessage(M_CUT),'X'));
	fEditMenu->AddItem(new BMenuItem(TRANSLATE("Copy"),new BMessage(M_COPY),'C'));
	fEditMenu->AddItem(new BMenuItem(TRANSLATE("Paste"),new BMessage(M_PASTE),'V'));
	mb->AddItem(fEditMenu);
	fEditMenu->SetEnabled(false);
	
	fTabMenu=new BMenu(TRANSLATE("Tab"));
	fTabMenu->AddItem(new BMenuItem(TRANSLATE("Main"),new BMessage(M_TAB_1),'1'));
	fTabMenu->AddItem(new BMenuItem(TRANSLATE("Personal"),new BMessage(M_TAB_2),'2'));
	fTabMenu->AddItem(new BMenuItem(TRANSLATE("Work"),new BMessage(M_TAB_3),'3'));
	fTabMenu->AddItem(new BMenuItem(TRANSLATE("Instant Message"),new BMessage(M_TAB_4),'4'));
	fTabMenu->AddItem(new BMenuItem(TRANSLATE("Notes"),new BMessage(M_TAB_5),'5'));
	mb->AddItem(fTabMenu);
	fTabMenu->SetEnabled(false);
	
	BMessage *menumsg;
	BEntry toolentry;
	
	// Note that I don't just simply have a way to iterate over whatever's in a folder
	// because I want to control what tools are officially supported by Mr. Peeps!
	// It's not that I don't want anyone helping -- I just want quality control with
	// tool usability.
	
	fToolMenu=new BMenu(TRANSLATE("Tools"));
	
	toolentry.SetTo("/boot/home/config/settings/MrPeeps/PeopleMover");
	if(toolentry.Exists())
	{
		menumsg=new BMessage(M_RUN_TOOL);
		menumsg->AddString("signature","application/x-vnd.wgp-PeopleMover");
		fToolPeopleMover=new BMenuItem(TRANSLATE("People Mover"),menumsg);
		fToolMenu->AddItem(fToolPeopleMover);
	}
	else
		fToolPeopleMover=NULL;
	
	toolentry.SetTo("/boot/home/config/settings/MrPeeps/PersonAtAGlance");
	if(toolentry.Exists())
	{
		menumsg=new BMessage(M_RUN_TOOL);
		menumsg->AddString("signature","application/x-vnd.wgp-PersonAtAGlance");
		fToolPeopleAtAGlance=new BMenuItem(TRANSLATE("Person at a Glance"),menumsg);
		fToolPeopleAtAGlance->SetEnabled(false);
		fToolMenu->AddItem(fToolPeopleAtAGlance);
	}
	else
		fToolPeopleAtAGlance=NULL;
	
	toolentry.SetTo("/boot/home/config/settings/MrPeeps/VCardExport");
	if(toolentry.Exists())
	{
		menumsg=new BMessage(M_RUN_TOOL);
		menumsg->AddString("signature","application/x-vnd.wgp-VCardExport");
		fToolVCardExport=new BMenuItem(TRANSLATE("Export Person to VCard"),menumsg);
		fToolVCardExport->SetEnabled(false);
		fToolMenu->AddItem(fToolVCardExport);
	}
	else
		fToolVCardExport=NULL;
	
	if(fToolMenu->CountItems()>0)
	{
		// PeopleMover does not require a selection, so if it is installed, allow the
		// user to select it.
		if(!fToolPeopleMover)
			fToolMenu->SetEnabled(false);
		mb->AddItem(fToolMenu);
	}
	else
	{
		delete fToolMenu;
		fToolMenu=NULL;
	}
	
	if(locale_roster->CountLocales()>1)
	{
		fLanguageMenu=new BMenu(TRANSLATE("Language"));
		fLanguageMenu->SetRadioMode(true);
		for(int32 i=0; i<locale_roster->CountLocales(); i++)
		{
			Locale *locale=locale_roster->LocaleAt(i);
			BMessage *langmsg=new BMessage(M_SET_LANGUAGE);
			langmsg->AddInt32("index",i);
			fLanguageMenu->AddItem(new BMenuItem(locale->Name(),langmsg));
		}
		mb->AddItem(fLanguageMenu);
		
		BMenuItem *markeditem=fLanguageMenu->FindItem(fLocale.String());
		if(markeditem)
			markeditem->SetMarked(true);
	}
	else
		fLanguageMenu=NULL;
	
	// set up left frame
	r.top+=mb->Bounds().bottom+1;
	r.bottom=Bounds().bottom;
	r.right=200;
	left_view=new BView(r, "left_view", B_FOLLOW_TOP_BOTTOM, B_WILL_DRAW);
	AddChild(left_view);
	
	// Check to see that all of the tabs will fit
	float tabwidth=left_view->StringWidth(TRANSLATE("Main"))+
		left_view->StringWidth(TRANSLATE("Personal"))+
		left_view->StringWidth(TRANSLATE("Work"))+
		left_view->StringWidth(TRANSLATE("Instant Message"))+
		left_view->StringWidth(TRANSLATE("Notes"))+120;
	
	r.left=201;

	if(tabwidth+r.left>Bounds().right)
		ResizeTo(tabwidth+r.left, Bounds().Height());
	
	r.right=Bounds().right;
	
	fIntroView=new IntroView(r);
	AddChild(fIntroView);
	
	
	dataview=new DataView(fIntroView->Bounds());
	fIntroView->AddChild(dataview);
	dataview->Hide();
	
	
	// create list for left frame
	BRect tmp_rect=left_view->Bounds();
	tmp_rect.right -= B_V_SCROLL_BAR_WIDTH;
	fPeopleList=new PeopleList(tmp_rect, "fPeopleList",dataview);
	
	// put scrolled list in left_view
	BScrollView *my_scroll=new BScrollView("scroll_people", fPeopleList,
			B_FOLLOW_TOP_BOTTOM, 0, false, true);
	left_view->AddChild(my_scroll);


	// open directory of people
	BDirectory people_dir(PEOPLE_FOLDER);
	
	msg=new BMessage(M_SET_STATUS);
	int32 refcount=people_dir.CountEntries();
	msg->AddInt32("refcount",refcount);
	target.SendMessage(msg);
	
	if(refcount==0)
		fIntroView->SetNoPeopleMsg(true);
	
	// our variables for instantiation and garbage collection later
	entry_ref tmp_ref;
	BFile tmp_file;
	BString filename;
		
	while (people_dir.GetNextRef(&tmp_ref)==B_OK)
	{
		// variables for use here
		tmp_file.SetTo(&tmp_ref, B_READ_WRITE);
		
		if(tmp_file.ReadAttrString(PERSON_NAME,&filename)==B_OK)
			AddPerson(tmp_ref, false);
		
		target.SendMessage(new BMessage(M_UPDATE_STATUS));
	}

	SortList();
	fPeopleList->MakeFocus(true);

	node_ref nref;
	people_dir.GetNodeRef(&nref);
	watch_node(&nref, B_WATCH_NAME | B_WATCH_ATTR | B_WATCH_DIRECTORY,this);
}
예제 #10
0
/*
 * master_create_worker_shards creates empty shards for the given table based
 * on the specified number of initial shards. The function first gets a list of
 * candidate nodes and issues DDL commands on the nodes to create empty shard
 * placements on those nodes. The function then updates metadata on the master
 * node to make this shard (and its placements) visible. Note that the function
 * assumes the table is hash partitioned and calculates the min/max hash token
 * ranges for each shard, giving them an equal split of the hash space.
 */
Datum
master_create_worker_shards(PG_FUNCTION_ARGS)
{
	text *tableNameText = PG_GETARG_TEXT_P(0);
	int32 shardCount = PG_GETARG_INT32(1);
	int32 replicationFactor = PG_GETARG_INT32(2);

	Oid distributedTableId = ResolveRelationId(tableNameText);
	char relationKind = get_rel_relkind(distributedTableId);
	char *tableName = text_to_cstring(tableNameText);
	char *relationOwner = NULL;
	char shardStorageType = '\0';
	List *workerNodeList = NIL;
	List *ddlCommandList = NIL;
	int32 workerNodeCount = 0;
	uint32 placementAttemptCount = 0;
	uint64 hashTokenIncrement = 0;
	List *existingShardList = NIL;
	int64 shardIndex = 0;

	/* make sure table is hash partitioned */
	CheckHashPartitionedTable(distributedTableId);

	/*
	 * In contrast to append/range partitioned tables it makes more sense to
	 * require ownership privileges - shards for hash-partitioned tables are
	 * only created once, not continually during ingest as for the other
	 * partitioning types.
	 */
	EnsureTableOwner(distributedTableId);

	/* we plan to add shards: get an exclusive metadata lock */
	LockRelationDistributionMetadata(distributedTableId, ExclusiveLock);

	relationOwner = TableOwner(distributedTableId);

	/* validate that shards haven't already been created for this table */
	existingShardList = LoadShardList(distributedTableId);
	if (existingShardList != NIL)
	{
		ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
						errmsg("table \"%s\" has already had shards created for it",
							   tableName)));
	}

	/* make sure that at least one shard is specified */
	if (shardCount <= 0)
	{
		ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
						errmsg("shard_count must be positive")));
	}

	/* make sure that at least one replica is specified */
	if (replicationFactor <= 0)
	{
		ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
						errmsg("replication_factor must be positive")));
	}

	/* calculate the split of the hash space */
	hashTokenIncrement = HASH_TOKEN_COUNT / shardCount;

	/* load and sort the worker node list for deterministic placement */
	workerNodeList = WorkerNodeList();
	workerNodeList = SortList(workerNodeList, CompareWorkerNodes);

	/* make sure we don't process cancel signals until all shards are created */
	HOLD_INTERRUPTS();

	/* retrieve the DDL commands for the table */
	ddlCommandList = GetTableDDLEvents(distributedTableId);

	workerNodeCount = list_length(workerNodeList);
	if (replicationFactor > workerNodeCount)
	{
		ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
						errmsg("replication_factor (%d) exceeds number of worker nodes "
							   "(%d)", replicationFactor, workerNodeCount),
						errhint("Add more worker nodes or try again with a lower "
								"replication factor.")));
	}

	/* if we have enough nodes, add an extra placement attempt for backup */
	placementAttemptCount = (uint32) replicationFactor;
	if (workerNodeCount > replicationFactor)
	{
		placementAttemptCount++;
	}

	/* set shard storage type according to relation type */
	if (relationKind == RELKIND_FOREIGN_TABLE)
	{
		bool cstoreTable = CStoreTable(distributedTableId);
		if (cstoreTable)
		{
			shardStorageType = SHARD_STORAGE_COLUMNAR;
		}
		else
		{
			shardStorageType = SHARD_STORAGE_FOREIGN;
		}
	}
	else
	{
		shardStorageType = SHARD_STORAGE_TABLE;
	}

	for (shardIndex = 0; shardIndex < shardCount; shardIndex++)
	{
		uint32 roundRobinNodeIndex = shardIndex % workerNodeCount;

		/* initialize the hash token space for this shard */
		text *minHashTokenText = NULL;
		text *maxHashTokenText = NULL;
		int32 shardMinHashToken = INT32_MIN + (shardIndex * hashTokenIncrement);
		int32 shardMaxHashToken = shardMinHashToken + (hashTokenIncrement - 1);
		Datum shardIdDatum = master_get_new_shardid(NULL);
		int64 shardId = DatumGetInt64(shardIdDatum);

		/* if we are at the last shard, make sure the max token value is INT_MAX */
		if (shardIndex == (shardCount - 1))
		{
			shardMaxHashToken = INT32_MAX;
		}

		/* insert the shard metadata row along with its min/max values */
		minHashTokenText = IntegerToText(shardMinHashToken);
		maxHashTokenText = IntegerToText(shardMaxHashToken);

		/*
		 * Grabbing the shard metadata lock isn't technically necessary since
		 * we already hold an exclusive lock on the partition table, but we'll
		 * acquire it for the sake of completeness. As we're adding new active
		 * placements, the mode must be exclusive.
		 */
		LockShardDistributionMetadata(shardId, ExclusiveLock);

		CreateShardPlacements(shardId, ddlCommandList, relationOwner, workerNodeList,
							  roundRobinNodeIndex, replicationFactor);

		InsertShardRow(distributedTableId, shardId, shardStorageType,
					   minHashTokenText, maxHashTokenText);
	}

	if (QueryCancelPending)
	{
		ereport(WARNING, (errmsg("cancel requests are ignored during shard creation")));
		QueryCancelPending = false;
	}

	RESUME_INTERRUPTS();

	PG_RETURN_VOID();
}
예제 #11
0
void PeepsWindow::MessageReceived(BMessage *msg)
{
	switch(msg->what)
	{
		case B_ABOUT_REQUESTED:
		{
			be_app->PostMessage(msg);
			break;
		}
		case M_RUN_TOOL:
		{
			BString sig;
			if(msg->FindString("signature",&sig)==B_OK)
			{
				if(strcmp(sig.String(),"application/x-vnd.wgp-PeopleMover")==0)
				{
					be_roster->Launch(sig.String());
					break;
				}
				
				// Get the filename for the currently-selected person
				int32 selection=fPeopleList->CurrentSelection();
				if(selection<0)
					break;
				
				PeepsListItem *peepsitem=(PeepsListItem*)fPeopleList->ItemAt(selection);
				if(!peepsitem || peepsitem->IsGroup())
					break;
				
				PersonItem *personitem=(PersonItem*)peepsitem;
				PersonData *persondata=personitem->GetData();
				
				if(!persondata)
					break;
				
				entry_ref ref=persondata->FileRef();
				BPath path(&ref);
				
				char *launchv[1];
				launchv[0]=new char[255];
				
				sprintf(launchv[0],"%s",path.Path());
				
				be_roster->Launch(sig.String(),1,launchv,NULL);
				
				delete [] launchv[0];
			}
			break;
		}
		case M_SHOW_ACTIONS:
		{
			uint32 buttons;
			BPoint pt;
			
			fPeopleList->GetMouse(&pt,&buttons,false);
			pt.x=(pt.x>5)?pt.x-5:0;
			pt.y=(pt.y>5)?pt.y-5:0;
			fPeopleList->ShowContextMenu(fPeopleList->ConvertToScreen(pt));
			
			break;
		}
		case M_BITMAP_REMOVED:
		case M_PHOTO_MODIFIED:
		{
			fPeopleList->SaveImageData();
			break;
		}
		case B_REFS_RECEIVED:
		case B_SIMPLE_DATA:
		{
			entry_ref ref;
			if(msg->FindRef("refs",0,&ref)==B_OK)
			{
				if(!IsPerson(ref))
				{
					// Might be an image dropped on the photo view. find out which child is the
					// target
					BPoint pt;
					if(msg->FindPoint("_drop_offset",&pt)!=B_OK)
						break;
					
					BView *target=FindView(pt);
					if(!target || strcmp(target->Name(),"photoview")!=0)
						break;
					
					// This will set the image, if possible
					target->MessageReceived(msg);
					
					// Save the image data to a real file and attach the Person attributes
					// to it
					fPeopleList->SaveImageData();
				}
				
				// Offer to move/copy file if not in People directory
				BDirectory dir,peopledir("/boot/home/people");
				BEntry entry(&ref);
				entry.GetParent(&dir);
				if(dir!=peopledir)
				{
					BString refname(ref.name);
					BString errstr=TRANSLATE("%s is not currently stored in the People folder. Mr. Peeps! will not"
						" see it on startup unless it is stored there. Would you like to move it"
						" there?");
					char errmsg[errstr.CountChars() - 2 + refname.CountChars() + 1];
					sprintf(errmsg,errstr.String(),refname.String());
					
					BAlert *alert=new BAlert("Mr. Peeps!",errmsg,TRANSLATE("Move"),TRANSLATE("Don't Move"));
					if(alert->Go()==0)
					{
						entry.MoveTo(&peopledir);
						entry.GetRef(&ref);
					}
				}
				if(!SelectPerson(ref))
					AddPerson(ref,true);
			}
			break;
		}
		case M_PREV_ITEM:
		{
			if(fPeopleList->CountItems()==0)
				break;
				
			int32 selection=fPeopleList->CurrentSelection();

			if(!fPeopleList->IsFocus())
			{
				fPeopleList->MakeFocus(true);
				PeepsListItem *pitem=(PeepsListItem*)fPeopleList->ItemAt(selection);
				if(!pitem->IsGroup())
				{
					fPeopleList->SyncData((PersonItem*)pitem);
//					fPeopleList->SaveData();
				}
				fPeopleList->SaveData();
			}

			if(selection>=0)
			{
				if(selection>0)
					fPeopleList->Select(selection-1);
			}
			else
			{
				fPeopleList->Select(0L);
			}
			break;
		}
		case M_NEXT_ITEM:
		{
			if(fPeopleList->CountItems()==0)
				break;
				
			int32 selection=fPeopleList->CurrentSelection();

			if(!fPeopleList->IsFocus())
			{
				fPeopleList->MakeFocus(true);
				PeepsListItem *pitem=(PeepsListItem*)fPeopleList->ItemAt(selection);
				if(!pitem->IsGroup())
				{
					fPeopleList->SyncData((PersonItem*)pitem);
//					fPeopleList->SaveData();
				}
				fPeopleList->SaveData();
			}
			
			if(selection==fPeopleList->CountItems()-1 || selection<0)
				fPeopleList->Select(fPeopleList->CountItems()-1);
			else
				fPeopleList->Select(selection+1);
			
			break;
		}
		case M_MOD_DATA:
		case M_SAVE:
		{
			fPeopleList->SyncData(NULL);
			fPeopleList->SaveData();
			break;
		}
		case M_ADD_PERSON:
		{
			entry_ref ref;
			
			status_t stat=CreatePerson(&ref);
			if(stat==B_FILE_EXISTS)
			{
				for(int32 i=0;i<gPeopleData.CountItems(); i++)
				{
					PersonData *pdata=(PersonData*)gPeopleData.ItemAt(i);
					
					if(BString(TRANSLATE("New Person")).ICompare(pdata->Name())==0)
					{
						int32 selection=fPeopleList->CurrentSelection();
						if(selection>=0)
						{
							PeepsListItem *peepsitem=(PeepsListItem*)fPeopleList->ItemAt(selection);
							if(peepsitem && !peepsitem->IsGroup())
								fPeopleList->Collapse(fPeopleList->Superitem(peepsitem));
						}
						PersonItem *pitem=pdata->InstanceAt(0);
						GroupItem *gitem=(GroupItem*)fPeopleList->Superitem(pitem);
						if(!gitem->IsExpanded())
							fPeopleList->Expand(gitem);
						fPeopleList->Select(fPeopleList->IndexOf(pitem));
						fPeopleList->ScrollToSelection();
						break;
					}
				}
			}
			else
			{
				// Add the current group to the New Person's file so that we end up staying
				// in the current group.
				if(stat==B_OK)
				{
					int32 selection=fPeopleList->CurrentSelection();
					BString groupstr(TRANSLATE("Ungrouped"));

					if(selection>=0)
					{
						PeepsListItem *currentitem=(PeepsListItem*)fPeopleList->ItemAt(selection);
						if(currentitem->IsGroup())
							groupstr=currentitem->Name();
						else
							groupstr=((PersonItem*)currentitem)->Group();
					}
					PersonData *pdata=new PersonData(ref);
					pdata->SetGroup(groupstr.String());
					pdata->SetName(TRANSLATE("New Person"));
					pdata->SaveToFile();
					delete pdata;
					AddPerson(ref,true);
					SortList();
					SelectPerson(TRANSLATE("New Person"));
					dataview->SetFirstFieldFocus();
				}
			}
			break;
		}
		case M_DELETE_PERSON:
		{
			int32 selection=fPeopleList->CurrentSelection();
			if(selection<0)
				break;
			PeepsListItem *item=(PeepsListItem*)fPeopleList->ItemAt(selection);
			if(item->IsGroup())
				DeleteGroup((GroupItem*)item);
			else
			{
				DeletePerson(((PersonItem*)item)->GetData());
			}
			break;
		}
		case M_DISABLE_DELETE:
		{
			BMenuItem *item=fPeopleMenu->FindItem(TRANSLATE("Move To Trash"));
			if(item)
				item->SetEnabled(false);
			break;
		}	
		case M_ENABLE_DELETE:
		{
			BMenuItem *item=fPeopleMenu->FindItem(TRANSLATE("Move To Trash"));
			if(item)
				item->SetEnabled(true);
			break;
		}	
		case M_SET_LANGUAGE:
		{
			// Restart MrPeeps!
			gRestartApp=true;
			
			int32 language;
			if(msg->FindInt32("index",&language)!=B_OK)
				break;
			
			BMenuItem *item = fLanguageMenu->ItemAt(language);
			if(!item)
				break;
			
			fLocale = item->Label();
			WriteLocaleSettings();
			
			be_app->PostMessage(B_QUIT_REQUESTED);
			break;
		}
		case M_HANDLE_NO_SELECTION:
		{
			// This is the initial case. No selection means quite a few different
			// menu items are disabled.
			fTabMenu->SetEnabled(false);
			fEditMenu->SetEnabled(false);
			
			if(fToolPeopleAtAGlance)
				fToolPeopleAtAGlance->SetEnabled(false);
			
			if(fToolVCardExport)
				fToolVCardExport->SetEnabled(false);
			
			UpdateActions(true);
			break;
		}	
		case M_HANDLE_GROUP_SELECTION:
		{
			// This is the initial case. No selection means quite a few different
			// menu items are disabled.
			fTabMenu->SetEnabled(false);
			fEditMenu->SetEnabled(true);
			
			if(fToolPeopleAtAGlance)
				fToolPeopleAtAGlance->SetEnabled(false);
			
			if(fToolVCardExport)
				fToolVCardExport->SetEnabled(false);
			
			UpdateActions(true);
			break;
		}	
		case M_HANDLE_PERSON_SELECTION:
		{
			// This is the initial case. No selection means quite a few different
			// menu items are disabled.
			fTabMenu->SetEnabled(true);
			fEditMenu->SetEnabled(true);
			
			if(fToolPeopleAtAGlance)
				fToolPeopleAtAGlance->SetEnabled(true);
			
			if(fToolVCardExport)
				fToolVCardExport->SetEnabled(true);
			
			UpdateActions(false);
			break;
		}	
		case M_SEND_PERSONAL_EMAIL:
		{
			if(dataview->Email())
			{
				BMessage *emailmsg=new BMessage(M_SEND_EMAIL);
				emailmsg->AddString("address",dataview->Email());
				be_app->PostMessage(emailmsg);
			}
			break;
		}
		case M_SEND_WORK_EMAIL:
		{
			if(dataview->WorkEmail())
			{
				BMessage *emailmsg=new BMessage(M_SEND_EMAIL);
				emailmsg->AddString("address",dataview->WorkEmail());
				be_app->PostMessage(emailmsg);
			}
			break;
		}
		case M_SEND_ALT_EMAIL:
		{
			if(dataview->Email3())
			{
				BMessage *emailmsg=new BMessage(M_SEND_EMAIL);
				emailmsg->AddString("address",dataview->Email3());
				be_app->PostMessage(emailmsg);
			}
			break;
		}
		case M_BROWSE_WWW_HOME:
		{
			if(dataview->URL())
			{
				BMessage *wwwmsg=new BMessage(M_LAUNCH_BROWSER);
				wwwmsg->AddString("address",dataview->URL());
				be_app->PostMessage(wwwmsg);
			}
			break;
		}
		case M_BROWSE_WWW_WORK:
		{
			if(dataview->WorkURL())
			{
				BMessage *wwwmsg=new BMessage(M_LAUNCH_BROWSER);
				wwwmsg->AddString("address",dataview->WorkURL());
				be_app->PostMessage(wwwmsg);
			}
			break;
		}
		case M_BROWSE_WWW_ALT:
		{
			if(dataview->OtherURL())
			{
				BMessage *wwwmsg=new BMessage(M_LAUNCH_BROWSER);
				wwwmsg->AddString("address",dataview->OtherURL());
				be_app->PostMessage(wwwmsg);
			}
			break;
		}
		case M_TAB_1:
		{
			fPeopleList->SyncData();
			fPeopleList->SaveData();
			dataview->ShowTab(0);
			if(!fPeopleList->IsFocus())
				dataview->SetFirstFieldFocus();
			break;
		}
		case M_TAB_2:
		{
			fPeopleList->SyncData();
			fPeopleList->SaveData();
			dataview->ShowTab(1);
			if(!fPeopleList->IsFocus())
				dataview->SetFirstFieldFocus();
			break;
		}
		case M_TAB_3:
		{
			fPeopleList->SyncData();
			fPeopleList->SaveData();
			dataview->ShowTab(2);
			if(!fPeopleList->IsFocus())
				dataview->SetFirstFieldFocus();
			break;
		}
		case M_TAB_4:
		{
			fPeopleList->SyncData();
			fPeopleList->SaveData();
			dataview->ShowTab(3);
			if(!fPeopleList->IsFocus())
				dataview->SetFirstFieldFocus();
			break;
		}
		case M_TAB_5:
		{
			fPeopleList->SyncData();
			fPeopleList->SaveData();
			dataview->ShowTab(4);
			if(!fPeopleList->IsFocus())
				dataview->SetFirstFieldFocus();
			break;
		}
		case M_UNDO:
		{
			dataview->UndoField();
			break;
		}
		case M_CUT:
		{
			dataview->CutField();
			break;
		}
		case M_COPY:
		{
			dataview->CopyField();
			break;
		}
		case M_PASTE:
		{
			dataview->PasteField();
			break;
		}
		case B_NODE_MONITOR:
		{
			HandleNodeMonitoring(msg);
			break;
		}
		default:
		{
			BWindow::MessageReceived(msg);
			break;
		}
	}
}
예제 #12
0
파일: search.c 프로젝트: dank101/net-2
dsEnqError srch_start()
{
  struct ds_search_arg search_arg;
  struct ds_search_result result;
  struct DSError          error;
  dsEnqError return_error;
  extern Filter make_filter();
  DN curr_rdn;

  if (*mvalue == '\0') {
    return list_start();
  }

  if (get_default_service (&search_arg.sra_common) != 0) {
    return nothingfound;
  }

  search_arg.sra_common.ca_servicecontrol.svc_options = SVC_OPT_PREFERCHAIN;

  curr_rdn = search_arg.sra_baseobject = (*base_path != 'T'?
					  str2dn (base_path):
					  NULLDN);

  search_arg.sra_eis.eis_allattributes = FALSE;
  search_arg.sra_eis.eis_infotypes = EIS_ATTRIBUTETYPESONLY;
  search_arg.sra_eis.eis_select = 0;
  search_arg.sra_searchaliases = TRUE;

  search_arg.sra_subset = SRA_ONELEVEL;
  while (curr_rdn != NULLDN) {
    if (!strcmp(curr_rdn->dn_rdn->rdn_at->oa_ot.ot_stroid, 
		"2.5.4.10")) {
      search_arg.sra_subset = SRA_WHOLESUBTREE;
      break;
    }
    curr_rdn = curr_rdn->dn_parent;
  }

  if ((search_arg.sra_filter = make_filter(filt_arr[typeindx])) == NULLFILTER)
    return duaerror;

#ifndef NO_STATS
  LLOG (log_stat, LLOG_NOTICE, ("search +%s, extent %d, val %s",
                                base_path,search_arg.sra_subset, mvalue));
#endif

  if(ds_search (&search_arg, &error, &result) != DS_OK) {
    /* deal with error */
    free_seq(dnseq);
    dnseq = NULLDS;
    dn_number = 0;
    log_ds_error(&error);
    ds_error_free(&error);
    switch (error.dse_type) {
    case DSE_LOCALERROR:
      return_error = duaerror;
      break;
    case DSE_REMOTEERROR:
      return_error = localdsaerror;
      break;
    case DSE_ATTRIBUTEERROR:
      return_error = attributerror;
      break;
    case DSE_REFERRAL:
    case DSE_DSAREFERRAL:
      return_error = remotedsaerror;
      break;
    case DSE_SECURITYERROR:
      return_error = security;
      break;
    case DSE_NAMEERROR:
      return_error = namerror;
      break;
    case DSE_SERVICEERROR:
      return_error = serviceerror;
      break;
    default:
      return_error = localdsaerror;
      break;
    }
  } else {
    correlate_search_results (&result);
    dn_number = 0;

    if (result.CSR_entries != NULLENTRYINFO) {
      register EntryInfo *ptr;

      return_error = Okay;
      free_seq(dnseq);
      dnseq = NULLDS;
      dn_number = 0;

      for (ptr = result.CSR_entries;
           ptr != NULLENTRYINFO; 
	   ptr = ptr->ent_next){
        dn_number++;
        dn2buf((caddr_t) ptr->ent_dn, goto_path);
        add_seq(&dnseq, goto_path);
      }

      if (dn_number) dnseq = SortList(dnseq);
    } else if (result.CSR_limitproblem == LSR_NOLIMITPROBLEM) {
      free_seq(dnseq);
      dnseq = NULLDS;
      dn_number = 0;
      return_error = nothingfound;
    }

    if(result.CSR_limitproblem != LSR_NOLIMITPROBLEM) {
      switch (result.CSR_limitproblem) {
      case LSR_TIMELIMITEXCEEDED:
	if (dn_number > 0) return_error = timelimit_w_partial;
	else {
	  free_seq(dnseq);
	  dnseq = NULLDS;
	  return_error = timelimit;
	}
	break;
      case LSR_SIZELIMITEXCEEDED:
	return_error = listsizelimit;
	break;
      case LSR_ADMINSIZEEXCEEDED:
	if (dn_number > 0) return_error = adminlimit_w_partial;
	else {
	  free_seq(dnseq);
	  dnseq = NULLDS;
	  return_error = adminlimit;
	}
	break;
      }
      entryinfo_free(result.CSR_entries, 0);
    }
  }
  entry_number = dn_number;
  filter_free(search_arg.sra_filter);
  dn_free(search_arg.sra_baseobject);
  ds_error_free(&error);
  return return_error;
}
예제 #13
0
void DeckBuilder::FilterCards() {
	results.clear();
	struct element_t {
		std::wstring keyword;
		int setcode;
		enum class type_t {
			all,
			name,
			setcode
		} type;
		bool exclude;
		element_t(): setcode(0), type(type_t::all), exclude(false) {}
	};
	const wchar_t* pstr = mainGame->ebCardName->getText();
	std::wstring str = std::wstring(pstr);
	std::vector<element_t> query_elements;
	if(mainGame->gameConf.search_multiple_keywords) {
		const wchar_t separator = mainGame->gameConf.search_multiple_keywords == 1 ? L' ' : L'+';
		const wchar_t minussign = L'-';
		const wchar_t quotation = L'\"';
		size_t element_start = 0;
		for(;;) {
			element_start = str.find_first_not_of(separator, element_start);
			if(element_start == std::wstring::npos)
				break;
			element_t element;
			if(str[element_start] == minussign) {
				element.exclude = true;
				element_start++;
			}
			if(element_start >= str.size())
				break;
			if(str[element_start] == L'$') {
				element.type = element_t::type_t::name;
				element_start++;
			} else if(str[element_start] == L'@') {
				element.type = element_t::type_t::setcode;
				element_start++;
			}
			if(element_start >= str.size())
				break;
			wchar_t delimiter = separator;
			if(str[element_start] == quotation) {
				delimiter = quotation;
				element_start++;
			}
			size_t element_end = str.find_first_of(delimiter, element_start);
			if(element_end != std::wstring::npos) {
				size_t length = element_end - element_start;
				element.keyword = str.substr(element_start, length);
			} else
				element.keyword = str.substr(element_start);
			element.setcode = dataManager.GetSetCode(element.keyword.c_str());
			query_elements.push_back(element);
			if(element_end == std::wstring::npos)
				break;
			element_start = element_end + 1;
		}
	} else {
		element_t element;
		size_t element_start = 0;
		if(str[element_start] == L'$') {
			element.type = element_t::type_t::name;
			element_start++;
		} else if(str[element_start] == L'@') {
			element.type = element_t::type_t::setcode;
			element_start++;
		}
		if(element_start < str.size()) {
			element.keyword = str.substr(element_start);
			element.setcode = dataManager.GetSetCode(element.keyword.c_str());
			query_elements.push_back(element);
		}
	}
	auto strpointer = dataManager._strings.begin();
	for(code_pointer ptr = dataManager._datas.begin(); ptr != dataManager._datas.end(); ++ptr, ++strpointer) {
		const CardDataC& data = ptr->second;
		const CardString& text = strpointer->second;
		if(data.type & TYPE_TOKEN)
			continue;
		switch(filter_type) {
		case 1: {
			if(!(data.type & TYPE_MONSTER) || (data.type & filter_type2) != filter_type2)
				continue;
			if(filter_race && data.race != filter_race)
				continue;
			if(filter_attrib && data.attribute != filter_attrib)
				continue;
			if(filter_atktype) {
				if((filter_atktype == 1 && data.attack != filter_atk) || (filter_atktype == 2 && data.attack < filter_atk)
				        || (filter_atktype == 3 && data.attack <= filter_atk) || (filter_atktype == 4 && (data.attack > filter_atk || data.attack < 0))
				        || (filter_atktype == 5 && (data.attack >= filter_atk || data.attack < 0)) || (filter_atktype == 6 && data.attack != -2))
					continue;
			}
			if(filter_deftype) {
				if((filter_deftype == 1 && data.defense != filter_def) || (filter_deftype == 2 && data.defense < filter_def)
				        || (filter_deftype == 3 && data.defense <= filter_def) || (filter_deftype == 4 && (data.defense > filter_def || data.defense < 0))
				        || (filter_deftype == 5 && (data.defense >= filter_def || data.defense < 0)) || (filter_deftype == 6 && data.defense != -2)
				        || (data.type & TYPE_LINK))
					continue;
			}
			if(filter_lvtype) {
				if((filter_lvtype == 1 && data.level != filter_lv) || (filter_lvtype == 2 && data.level < filter_lv)
				        || (filter_lvtype == 3 && data.level <= filter_lv) || (filter_lvtype == 4 && data.level > filter_lv)
				        || (filter_lvtype == 5 && data.level >= filter_lv) || filter_lvtype == 6)
					continue;
			}
			if(filter_scltype) {
				if((filter_scltype == 1 && data.lscale != filter_scl) || (filter_scltype == 2 && data.lscale < filter_scl)
				        || (filter_scltype == 3 && data.lscale <= filter_scl) || (filter_scltype == 4 && (data.lscale > filter_scl || data.lscale == 0))
				        || (filter_scltype == 5 && (data.lscale >= filter_scl || data.lscale == 0)) || filter_scltype == 6
				        || !(data.type & TYPE_PENDULUM))
					continue;
			}
			break;
		}
		case 2: {
			if(!(data.type & TYPE_SPELL))
				continue;
			if(filter_type2 && data.type != filter_type2)
				continue;
			break;
		}
		case 3: {
			if(!(data.type & TYPE_TRAP))
				continue;
			if(filter_type2 && data.type != filter_type2)
				continue;
			break;
		}
		}
		if(filter_effect && !(data.category & filter_effect))
			continue;
		if(filter_marks && (data.link_marker & filter_marks)!= filter_marks)
			continue;
		if(filter_lm) {
			if(filter_lm <= 3 && (!filterList->count(ptr->first) || (*filterList)[ptr->first] != filter_lm - 1))
				continue;
			if(filter_lm == 4 && data.ot != 1)
				continue;
			if(filter_lm == 5 && data.ot != 2)
				continue;
			if(filter_lm == 6 && data.ot != 3)
				continue;
			if(filter_lm == 7 && data.ot != 4)
				continue;
		}
		bool is_target = true;
		for (auto elements_iterator = query_elements.begin(); elements_iterator != query_elements.end(); ++elements_iterator) {
			bool match = false;
			if (elements_iterator->type == element_t::type_t::name) {
				match = CardNameContains(text.name.c_str(), elements_iterator->keyword.c_str());
			} else if (elements_iterator->type == element_t::type_t::setcode) {
				match = elements_iterator->setcode && check_set_code(data, elements_iterator->setcode);
			} else {
				int trycode = BufferIO::GetVal(elements_iterator->keyword.c_str());
				bool tryresult = dataManager.GetData(trycode, 0);
				if(!tryresult) {
					match = CardNameContains(text.name.c_str(), elements_iterator->keyword.c_str())
						|| text.text.find(elements_iterator->keyword) != std::wstring::npos
						|| (elements_iterator->setcode && check_set_code(data, elements_iterator->setcode));
				} else {
					match = data.code == trycode || data.alias == trycode;
				}
			}
			if(elements_iterator->exclude)
				match = !match;
			if(!match) {
				is_target = false;
				break;
			}
		}
		if(is_target)
			results.push_back(ptr);
		else
			continue;
	}
	myswprintf(result_string, L"%d", results.size());
	if(results.size() > 7) {
		mainGame->scrFilter->setVisible(true);
		mainGame->scrFilter->setMax(results.size() - 7);
		mainGame->scrFilter->setPos(0);
	} else {
		mainGame->scrFilter->setVisible(false);
		mainGame->scrFilter->setPos(0);
	}
	SortList();
}
예제 #14
0
bool DeckBuilder::OnEvent(const irr::SEvent& event) {
	if(mainGame->dField.OnCommonEvent(event))
		return false;
	switch(event.EventType) {
	case irr::EET_GUI_EVENT: {
		s32 id = event.GUIEvent.Caller->getID();
		if(mainGame->wCategories->isVisible() && id != BUTTON_CATEGORY_OK)
			break;
		if(mainGame->wQuery->isVisible() && id != BUTTON_YES && id != BUTTON_NO)
			break;
		if(mainGame->wLinkMarks->isVisible() && id != BUTTON_MARKERS_OK)
			break;
		switch(event.GUIEvent.EventType) {
		case irr::gui::EGET_BUTTON_CLICKED: {
			soundManager.PlaySoundEffect(SOUND_BUTTON);
			switch(id) {
			case BUTTON_CLEAR_DECK: {
				mainGame->gMutex.Lock();
				mainGame->SetStaticText(mainGame->stQMessage, 310, mainGame->guiFont, dataManager.GetSysString(1339));
				mainGame->PopupElement(mainGame->wQuery);
				mainGame->gMutex.Unlock();
				prev_operation = id;
				break;
			}
			case BUTTON_SORT_DECK: {
				std::sort(deckManager.current_deck.main.begin(), deckManager.current_deck.main.end(), ClientCard::deck_sort_lv);
				std::sort(deckManager.current_deck.extra.begin(), deckManager.current_deck.extra.end(), ClientCard::deck_sort_lv);
				std::sort(deckManager.current_deck.side.begin(), deckManager.current_deck.side.end(), ClientCard::deck_sort_lv);
				break;
			}
			case BUTTON_SHUFFLE_DECK: {
				std::random_shuffle(deckManager.current_deck.main.begin(), deckManager.current_deck.main.end());
				break;
			}
			case BUTTON_SAVE_DECK: {
				int sel = mainGame->cbDBDecks->getSelected();
				if(sel >= 0 && deckManager.SaveDeck(deckManager.current_deck, mainGame->cbDBDecks->getItem(sel))) {
					mainGame->stACMessage->setText(dataManager.GetSysString(1335));
					mainGame->PopupElement(mainGame->wACMessage, 20);
					is_modified = false;
				}
				break;
			}
			case BUTTON_SAVE_DECK_AS: {
				const wchar_t* dname = mainGame->ebDeckname->getText();
				if(*dname == 0)
					break;
				int sel = -1;
				for(size_t i = 0; i < mainGame->cbDBDecks->getItemCount(); ++i) {
					if(!wcscmp(dname, mainGame->cbDBDecks->getItem(i))) {
						sel = i;
						break;
					}
				}
				if(sel >= 0)
					mainGame->cbDBDecks->setSelected(sel);
				else {
					mainGame->cbDBDecks->addItem(dname);
					mainGame->cbDBDecks->setSelected(mainGame->cbDBDecks->getItemCount() - 1);
				}
				if(deckManager.SaveDeck(deckManager.current_deck, dname)) {
					mainGame->stACMessage->setText(dataManager.GetSysString(1335));
					mainGame->PopupElement(mainGame->wACMessage, 20);
					is_modified = false;
				}
				break;
			}
			case BUTTON_DELETE_DECK: {
				int sel = mainGame->cbDBDecks->getSelected();
				if(sel == -1)
					break;
				mainGame->gMutex.Lock();
				wchar_t textBuffer[256];
				myswprintf(textBuffer, L"%ls\n%ls", mainGame->cbDBDecks->getItem(sel), dataManager.GetSysString(1337));
				mainGame->SetStaticText(mainGame->stQMessage, 310, mainGame->guiFont, textBuffer);
				mainGame->PopupElement(mainGame->wQuery);
				mainGame->gMutex.Unlock();
				prev_operation = id;
				prev_sel = sel;
				break;
			}
			case BUTTON_LEAVE_GAME: {
				if(is_modified && !mainGame->chkIgnoreDeckChanges->isChecked()) {
					mainGame->gMutex.Lock();
					mainGame->SetStaticText(mainGame->stQMessage, 310, mainGame->guiFont, dataManager.GetSysString(1356));
					mainGame->PopupElement(mainGame->wQuery);
					mainGame->gMutex.Unlock();
					prev_operation = id;
					break;
				}
				Terminate();
				break;
			}
			case BUTTON_EFFECT_FILTER: {
				mainGame->PopupElement(mainGame->wCategories);
				break;
			}
			case BUTTON_START_FILTER: {
				StartFilter();
				if(!mainGame->gameConf.separate_clear_button)
					ClearFilter();
				break;
			}
			case BUTTON_CLEAR_FILTER: {
				ClearSearch();
				break;
			}
			case BUTTON_CATEGORY_OK: {
				filter_effect = 0;
				long long filter = 0x1;
				for(int i = 0; i < 32; ++i, filter <<= 1)
					if(mainGame->chkCategory[i]->isChecked())
						filter_effect |= filter;
				mainGame->btnEffectFilter->setPressed(filter_effect > 0);
				mainGame->HideElement(mainGame->wCategories);
				InstantSearch();
				break;
			}
			case BUTTON_SIDE_OK: {
				if(deckManager.current_deck.main.size() != pre_mainc || deckManager.current_deck.extra.size() != pre_extrac
				        || deckManager.current_deck.side.size() != pre_sidec) {
					soundManager.PlaySoundEffect(SOUND_INFO);
					mainGame->env->addMessageBox(L"", dataManager.GetSysString(1410));
					break;
				}
				mainGame->ClearCardInfo();
				char deckbuf[1024];
				char* pdeck = deckbuf;
				BufferIO::WriteInt32(pdeck, deckManager.current_deck.main.size() + deckManager.current_deck.extra.size());
				BufferIO::WriteInt32(pdeck, deckManager.current_deck.side.size());
				for(size_t i = 0; i < deckManager.current_deck.main.size(); ++i)
					BufferIO::WriteInt32(pdeck, deckManager.current_deck.main[i]->first);
				for(size_t i = 0; i < deckManager.current_deck.extra.size(); ++i)
					BufferIO::WriteInt32(pdeck, deckManager.current_deck.extra[i]->first);
				for(size_t i = 0; i < deckManager.current_deck.side.size(); ++i)
					BufferIO::WriteInt32(pdeck, deckManager.current_deck.side[i]->first);
				DuelClient::SendBufferToServer(CTOS_UPDATE_DECK, deckbuf, pdeck - deckbuf);
				break;
			}
			case BUTTON_SIDE_RELOAD: {
				deckManager.LoadDeck(mainGame->cbDeckSelect->getItem(mainGame->cbDeckSelect->getSelected()));
				break;
			}
			case BUTTON_MSG_OK: {
				mainGame->HideElement(mainGame->wMessage);
				mainGame->actionSignal.Set();
				break;
			}
			case BUTTON_YES: {
				mainGame->HideElement(mainGame->wQuery);
				if(!mainGame->is_building || mainGame->is_siding)
					break;
				if(prev_operation == BUTTON_CLEAR_DECK) {
					deckManager.current_deck.main.clear();
					deckManager.current_deck.extra.clear();
					deckManager.current_deck.side.clear();
				} else if(prev_operation == BUTTON_DELETE_DECK) {
					int sel = prev_sel;
					if(deckManager.DeleteDeck(deckManager.current_deck, mainGame->cbDBDecks->getItem(sel))) {
						mainGame->cbDBDecks->removeItem(sel);
						int count = mainGame->cbDBDecks->getItemCount();
						if(sel >= count)
							sel = count - 1;
						mainGame->cbDBDecks->setSelected(sel);
						if(sel != -1)
							deckManager.LoadDeck(mainGame->cbDBDecks->getItem(sel));
						mainGame->stACMessage->setText(dataManager.GetSysString(1338));
						mainGame->PopupElement(mainGame->wACMessage, 20);
						prev_deck = sel;
						is_modified = false;
					}
					prev_sel = -1;
				} else if(prev_operation == BUTTON_LEAVE_GAME) {
					Terminate();
				} else if(prev_operation == COMBOBOX_DBDECKS) {
					int sel = mainGame->cbDBDecks->getSelected();
					deckManager.LoadDeck(mainGame->cbDBDecks->getItem(sel));
					prev_deck = sel;
					is_modified = false;
				}
				prev_operation = 0;
				break;
			}
			case BUTTON_NO: {
				mainGame->HideElement(mainGame->wQuery);
				if (prev_operation == COMBOBOX_DBDECKS) {
					mainGame->cbDBDecks->setSelected(prev_deck);
				}
				prev_operation = 0;
				break;
			}
			case BUTTON_MARKS_FILTER: {
				mainGame->PopupElement(mainGame->wLinkMarks);
				break;
			}
			case BUTTON_MARKERS_OK: {
				filter_marks = 0;
				if (mainGame->btnMark[0]->isPressed())
					filter_marks |= 0100;
				if (mainGame->btnMark[1]->isPressed())
					filter_marks |= 0200;
				if (mainGame->btnMark[2]->isPressed())
					filter_marks |= 0400;
				if (mainGame->btnMark[3]->isPressed())
					filter_marks |= 0010;
				if (mainGame->btnMark[4]->isPressed())
					filter_marks |= 0040;
				if (mainGame->btnMark[5]->isPressed())
					filter_marks |= 0001;
				if (mainGame->btnMark[6]->isPressed())
					filter_marks |= 0002;
				if (mainGame->btnMark[7]->isPressed())
					filter_marks |= 0004;
				mainGame->HideElement(mainGame->wLinkMarks);
				mainGame->btnMarksFilter->setPressed(filter_marks > 0);
				InstantSearch();
				break;
			}
			}
			break;
		}
		case irr::gui::EGET_SCROLL_BAR_CHANGED: {
			switch(id) {
			case SCROLL_FILTER: {
				GetHoveredCard();
				break;
			}
			}
			break;
		}
		case irr::gui::EGET_EDITBOX_ENTER: {
			switch(id) {
			case EDITBOX_KEYWORD: {
				StartFilter();
				break;
			}
			}
			break;
		}
		case irr::gui::EGET_EDITBOX_CHANGED: {
			switch(id) {
			case EDITBOX_KEYWORD: {
				InstantSearch();
				break;
			}
			}
			break;
		}
		case irr::gui::EGET_COMBO_BOX_CHANGED: {
			switch(id) {
			case COMBOBOX_DBLFLIST: {
				filterList = deckManager._lfList[mainGame->cbDBLFList->getSelected()].content;
				break;
			}
			case COMBOBOX_DBDECKS: {
				if(is_modified && !mainGame->chkIgnoreDeckChanges->isChecked()) {
					mainGame->gMutex.Lock();
					mainGame->SetStaticText(mainGame->stQMessage, 310, mainGame->guiFont, dataManager.GetSysString(1356));
					mainGame->PopupElement(mainGame->wQuery);
					mainGame->gMutex.Unlock();
					prev_operation = id;
					break;
				}
				int sel = mainGame->cbDBDecks->getSelected();
				if(sel >= 0)
					deckManager.LoadDeck(mainGame->cbDBDecks->getItem(sel));
				prev_deck = sel;
				is_modified = false;
				break;
			}
			case COMBOBOX_MAINTYPE: {
				mainGame->cbCardType2->setSelected(0);
				mainGame->cbAttribute->setSelected(0);
				mainGame->cbRace->setSelected(0);
				mainGame->ebAttack->setText(L"");
				mainGame->ebDefense->setText(L"");
				mainGame->ebStar->setText(L"");
				mainGame->ebScale->setText(L"");
				switch(mainGame->cbCardType->getSelected()) {
				case 0: {
					mainGame->cbCardType2->setEnabled(false);
					mainGame->cbCardType2->setSelected(0);
					mainGame->cbRace->setEnabled(false);
					mainGame->cbAttribute->setEnabled(false);
					mainGame->ebAttack->setEnabled(false);
					mainGame->ebDefense->setEnabled(false);
					mainGame->ebStar->setEnabled(false);
					mainGame->ebScale->setEnabled(false);
					break;
				}
				case 1: {
					wchar_t normaltuner[32];
					wchar_t normalpen[32];
					wchar_t syntuner[32];
					mainGame->cbCardType2->setEnabled(true);
					mainGame->cbRace->setEnabled(true);
					mainGame->cbAttribute->setEnabled(true);
					mainGame->ebAttack->setEnabled(true);
					mainGame->ebDefense->setEnabled(true);
					mainGame->ebStar->setEnabled(true);
					mainGame->ebScale->setEnabled(true);
					mainGame->cbCardType2->clear();
					mainGame->cbCardType2->addItem(dataManager.GetSysString(1080), 0);
					mainGame->cbCardType2->addItem(dataManager.GetSysString(1054), TYPE_MONSTER + TYPE_NORMAL);
					mainGame->cbCardType2->addItem(dataManager.GetSysString(1055), TYPE_MONSTER + TYPE_EFFECT);
					mainGame->cbCardType2->addItem(dataManager.GetSysString(1056), TYPE_MONSTER + TYPE_FUSION);
					mainGame->cbCardType2->addItem(dataManager.GetSysString(1057), TYPE_MONSTER + TYPE_RITUAL);
					mainGame->cbCardType2->addItem(dataManager.GetSysString(1063), TYPE_MONSTER + TYPE_SYNCHRO);
					mainGame->cbCardType2->addItem(dataManager.GetSysString(1073), TYPE_MONSTER + TYPE_XYZ);
					mainGame->cbCardType2->addItem(dataManager.GetSysString(1074), TYPE_MONSTER + TYPE_PENDULUM);
					mainGame->cbCardType2->addItem(dataManager.GetSysString(1076), TYPE_MONSTER + TYPE_LINK);
					mainGame->cbCardType2->addItem(dataManager.GetSysString(1075), TYPE_MONSTER + TYPE_SPSUMMON);
					myswprintf(normaltuner, L"%ls|%ls", dataManager.GetSysString(1054), dataManager.GetSysString(1062));
					mainGame->cbCardType2->addItem(normaltuner, TYPE_MONSTER + TYPE_NORMAL + TYPE_TUNER);
					myswprintf(normalpen, L"%ls|%ls", dataManager.GetSysString(1054), dataManager.GetSysString(1074));
					mainGame->cbCardType2->addItem(normalpen, TYPE_MONSTER + TYPE_NORMAL + TYPE_PENDULUM);
					myswprintf(syntuner, L"%ls|%ls", dataManager.GetSysString(1063), dataManager.GetSysString(1062));
					mainGame->cbCardType2->addItem(syntuner, TYPE_MONSTER + TYPE_SYNCHRO + TYPE_TUNER);
					mainGame->cbCardType2->addItem(dataManager.GetSysString(1062), TYPE_MONSTER + TYPE_TUNER);
					mainGame->cbCardType2->addItem(dataManager.GetSysString(1061), TYPE_MONSTER + TYPE_DUAL);
					mainGame->cbCardType2->addItem(dataManager.GetSysString(1060), TYPE_MONSTER + TYPE_UNION);
					mainGame->cbCardType2->addItem(dataManager.GetSysString(1059), TYPE_MONSTER + TYPE_SPIRIT);
					mainGame->cbCardType2->addItem(dataManager.GetSysString(1071), TYPE_MONSTER + TYPE_FLIP);
					mainGame->cbCardType2->addItem(dataManager.GetSysString(1072), TYPE_MONSTER + TYPE_TOON);
					break;
				}
				case 2: {
					mainGame->cbCardType2->setEnabled(true);
					mainGame->cbRace->setEnabled(false);
					mainGame->cbAttribute->setEnabled(false);
					mainGame->ebAttack->setEnabled(false);
					mainGame->ebDefense->setEnabled(false);
					mainGame->ebStar->setEnabled(false);
					mainGame->ebScale->setEnabled(false);
					mainGame->cbCardType2->clear();
					mainGame->cbCardType2->addItem(dataManager.GetSysString(1080), 0);
					mainGame->cbCardType2->addItem(dataManager.GetSysString(1054), TYPE_SPELL);
					mainGame->cbCardType2->addItem(dataManager.GetSysString(1066), TYPE_SPELL + TYPE_QUICKPLAY);
					mainGame->cbCardType2->addItem(dataManager.GetSysString(1067), TYPE_SPELL + TYPE_CONTINUOUS);
					mainGame->cbCardType2->addItem(dataManager.GetSysString(1057), TYPE_SPELL + TYPE_RITUAL);
					mainGame->cbCardType2->addItem(dataManager.GetSysString(1068), TYPE_SPELL + TYPE_EQUIP);
					mainGame->cbCardType2->addItem(dataManager.GetSysString(1069), TYPE_SPELL + TYPE_FIELD);
					break;
				}
				case 3: {
					mainGame->cbCardType2->setEnabled(true);
					mainGame->cbRace->setEnabled(false);
					mainGame->cbAttribute->setEnabled(false);
					mainGame->ebAttack->setEnabled(false);
					mainGame->ebDefense->setEnabled(false);
					mainGame->ebStar->setEnabled(false);
					mainGame->ebScale->setEnabled(false);
					mainGame->cbCardType2->clear();
					mainGame->cbCardType2->addItem(dataManager.GetSysString(1080), 0);
					mainGame->cbCardType2->addItem(dataManager.GetSysString(1054), TYPE_TRAP);
					mainGame->cbCardType2->addItem(dataManager.GetSysString(1067), TYPE_TRAP + TYPE_CONTINUOUS);
					mainGame->cbCardType2->addItem(dataManager.GetSysString(1070), TYPE_TRAP + TYPE_COUNTER);
					break;
				}
				}
				InstantSearch();
				break;
			}
			case COMBOBOX_SORTTYPE: {
				SortList();
				mainGame->env->setFocus(0);
				break;
			}
			case COMBOBOX_SECONDTYPE: {
				if (mainGame->cbCardType->getSelected() == 1) {
					if (mainGame->cbCardType2->getSelected() == 8) {
						mainGame->ebDefense->setEnabled(false);
						mainGame->ebDefense->setText(L"");
					} else {
						mainGame->ebDefense->setEnabled(true);
					}
				}
				InstantSearch();
				break;
			}
			case COMBOBOX_ATTRIBUTE:
			case COMBOBOX_RACE:
			case COMBOBOX_LIMIT:
				InstantSearch();
			}
		}
		default: break;
		}
		break;
	}
	case irr::EET_MOUSE_INPUT_EVENT: {
		switch(event.MouseInput.Event) {
		case irr::EMIE_LMOUSE_PRESSED_DOWN: {
			irr::gui::IGUIElement* root = mainGame->env->getRootGUIElement();
			if(root->getElementFromPoint(mouse_pos) != root)
				break;
			if(mainGame->wCategories->isVisible() || mainGame->wQuery->isVisible())
				break;
			if(hovered_pos == 0 || hovered_seq == -1)
				break;
			click_pos = hovered_pos;
			dragx = event.MouseInput.X;
			dragy = event.MouseInput.Y;
			draging_pointer = dataManager.GetCodePointer(hovered_code);
			if(draging_pointer == dataManager._datas.end())
				break;
			if(hovered_pos == 4) {
				if(!check_limit(draging_pointer))
					break;
			}
			is_starting_dragging = true;
			break;
		}
		case irr::EMIE_LMOUSE_LEFT_UP: {
			is_starting_dragging = false;
			if(!is_draging)
				break;
			soundManager.PlaySoundEffect(SOUND_CARD_DROP);
			bool pushed = false;
			if(hovered_pos == 1)
				pushed = push_main(draging_pointer, hovered_seq);
			else if(hovered_pos == 2)
				pushed = push_extra(draging_pointer, hovered_seq + is_lastcard);
			else if(hovered_pos == 3)
				pushed = push_side(draging_pointer, hovered_seq + is_lastcard);
			else if(hovered_pos == 4 && !mainGame->is_siding)
				pushed = true;
			if(!pushed) {
				if(click_pos == 1)
					push_main(draging_pointer);
				else if(click_pos == 2)
					push_extra(draging_pointer);
				else if(click_pos == 3)
					push_side(draging_pointer);
			}
			is_draging = false;
			break;
		}
		case irr::EMIE_RMOUSE_LEFT_UP: {
			if(mainGame->is_siding) {
				if(is_draging)
					break;
				if(hovered_pos == 0 || hovered_seq == -1)
					break;
				auto pointer = dataManager.GetCodePointer(hovered_code);
				if(pointer == dataManager._datas.end())
					break;
				soundManager.PlaySoundEffect(SOUND_CARD_DROP);
				if(hovered_pos == 1) {
					if(push_side(pointer))
						pop_main(hovered_seq);
				} else if(hovered_pos == 2) {
					if(push_side(pointer))
						pop_extra(hovered_seq);
				} else {
					if(push_extra(pointer) || push_main(pointer))
						pop_side(hovered_seq);
				}
				break;
			}
			if(mainGame->wCategories->isVisible() || mainGame->wQuery->isVisible())
				break;
			if(!is_draging) {
				if(hovered_pos == 0 || hovered_seq == -1)
					break;
				soundManager.PlaySoundEffect(SOUND_CARD_DROP);
				if(hovered_pos == 1) {
					pop_main(hovered_seq);
				} else if(hovered_pos == 2) {
					pop_extra(hovered_seq);
				} else if(hovered_pos == 3) {
					pop_side(hovered_seq);
				} else {
					auto pointer = dataManager.GetCodePointer(hovered_code);
					if(pointer == dataManager._datas.end())
						break;
					if(!check_limit(pointer))
						break;
					if(!push_extra(pointer) && !push_main(pointer))
						push_side(pointer);
				}
			} else {
				soundManager.PlaySoundEffect(SOUND_CARD_PICK);
				if(click_pos == 1) {
					push_side(draging_pointer);
				} else if(click_pos == 2) {
					push_side(draging_pointer);
				} else if(click_pos == 3) {
					if(!push_extra(draging_pointer))
						push_main(draging_pointer);
				} else {
					push_side(draging_pointer);
				}
				is_draging = false;
			}
			break;
		}
		case irr::EMIE_MMOUSE_LEFT_UP: {
			if (mainGame->is_siding)
				break;
			if (mainGame->wCategories->isVisible() || mainGame->wQuery->isVisible())
				break;
			if (hovered_pos == 0 || hovered_seq == -1)
				break;
			if (is_draging)
				break;
			auto pointer = dataManager.GetCodePointer(hovered_code);
			if(!check_limit(pointer))
				break;
			soundManager.PlaySoundEffect(SOUND_CARD_PICK);
			if (hovered_pos == 1) {
				if(!push_main(pointer))
					push_side(pointer);
			} else if (hovered_pos == 2) {
				if(!push_extra(pointer))
					push_side(pointer);
			} else if (hovered_pos == 3) {
				if(!push_side(pointer) && !push_extra(pointer))
					push_main(pointer);
			} else {
				if(!push_extra(pointer) && !push_main(pointer))
					push_side(pointer);
			}
			break;
		}
		case irr::EMIE_MOUSE_MOVED: {
			if(is_starting_dragging) {
				is_draging = true;
				soundManager.PlaySoundEffect(SOUND_CARD_PICK);
				if(hovered_pos == 1)
					pop_main(hovered_seq);
				else if(hovered_pos == 2)
					pop_extra(hovered_seq);
				else if(hovered_pos == 3)
					pop_side(hovered_seq);
				is_starting_dragging = false;
			}
			mouse_pos.set(event.MouseInput.X, event.MouseInput.Y);
			GetHoveredCard();
			break;
		}
		case irr::EMIE_MOUSE_WHEEL: {
			if(!mainGame->scrFilter->isVisible())
				break;
			if(mainGame->env->hasFocus(mainGame->scrFilter))
				break;
			irr::gui::IGUIElement* root = mainGame->env->getRootGUIElement();
			if(root->getElementFromPoint(mouse_pos) != root)
				break;
			if(event.MouseInput.Wheel < 0) {
				if(mainGame->scrFilter->getPos() < mainGame->scrFilter->getMax())
					mainGame->scrFilter->setPos(mainGame->scrFilter->getPos() + 1);
			} else {
				if(mainGame->scrFilter->getPos() > 0)
					mainGame->scrFilter->setPos(mainGame->scrFilter->getPos() - 1);
			}
			GetHoveredCard();
			break;
		}
		default: break;
		}
		break;
	}
	case irr::EET_KEY_INPUT_EVENT: {
		break;
	}
	default: break;
	}
	return false;
}
예제 #15
0
int main()
{
  listPtr List, Queue, Stack, Splay;
  char *String1, *String2, *String3, *String4, *Get;
  int Result;

  printf("Testing LINKLIST Library for ANSI C.\n\n");

  String1 = malloc(20);
  String2 = malloc(20);
  String3 = malloc(20);
  String4 = malloc(20);
  strcpy(String1, "Hi");
  strcpy(String2, "Low");
  strcpy(String3, "Up");
  strcpy(String4, "Down");

  printf("Creating List.\n");
  List = NewListAlloc(LIST, DMALLOC, DFREE, (NodeCompareFunc)strcmp);
  printf("Creating Queue.\n");
  Queue = NewListAlloc(QUEUE, DMALLOC, DFREE, NULL);
  printf("Creating Stack.\n");
  Stack = NewListAlloc(STACK, DMALLOC, DFREE, NULL);
  printf("Creating Splay Tree\n");
  Splay = NewListAlloc(STREE, DMALLOC, DFREE, (NodeCompareFunc)StringCompare);

  printf("Adding Elements to List...\n");
  AddNode(List, NewNode("Hi"));
  AddNode(List, NewNode("Low"));
  AddNode(List, NewNode("Up"));
  AddNode(List, NewNode("Down"));

  printf("Adding Elements to Queue...\n");
  AddNode(Queue, NewNode("Hi"));
  AddNode(Queue, NewNode("Low"));
  AddNode(Queue, NewNode("Up"));
  AddNode(Queue, NewNode("Down"));

  printf("Adding Elements to Stack...\n");
  AddNode(Stack, NewNode(String1));
  AddNode(Stack, NewNode(String2));
  AddNode(Stack, NewNode(String3));
  AddNode(Stack, NewNode(String4));

  printf("Adding Elements to Splay Tree...\n");
  AddNode(Splay, NewNode("High"));
  AddNode(Splay, NewNode("Low"));
  AddNode(Splay, NewNode("Up"));
  AddNode(Splay, NewNode("Down"));

  printf("Attempting to add duplicate nodes to Splay Tree...\n");
  Result = AddNode(Splay, NewNode("Down"));
  printf("Result: ");
  if (Result == LLIST_OK)
    printf("OK\n");
  else if (Result == LLIST_BADVALUE)
    printf("Node Already Exists; not added\n");
  else printf("Error\n");

  printf("Calimed Memory: %d bytes\n", DCOUNT(NULL));

  printf("LIST:\n");
  PrintList(List, "%s");
  printf("QUEUE:\n");
  PrintList(Queue, "%s");
  printf("STACK:\n");
  PrintList(Stack, "%s");
  printf("SPLAY:\n");
  PrintList(Splay, "%s");
  
  printf("\n-----------------------\n");

  printf("Reading Element from LIST\n");
  printf("Read Element: %s\n", GetNode(List));
  PrintList(List, "%s");

  printf("\n\nReading Element from QUEUE\n");
  printf("Read Element: %s\n", GetNode(Queue));
  PrintList(Queue, "%s");

  printf("\n\nReading Element from STACK\n");
  printf("Read Element: %s\n", (Get = GetNode(Stack)));
  DFREE(Get);
  PrintList(Stack, "%s");

  printf("\n-----------------------\n");

  printf("Reading Element #2 from LIST\n");
  printf("Read Element: %s\n", IndexNode(List, 2));
  PrintList(List, "%s");

  printf("\nAdding One More Element to LIST\n");
  AddNode(List, NewNode("And"));
  PrintList(List, "%s");

  printf("\n-----------------------\n");

  printf("\nSorting LIST\n");
  SortList(List);
  PrintList(List, "%s");

  printf("\n-----------------------\n");
  
  printf("\nDeleting Element 2 From LIST\n");
  IndexNode(List, 2);
  RemoveList(List);
  PrintList(List, "%s");

  printf("\nDeleting Head From LIST\n");
  DelHeadList(List);
  PrintList(List, "%s");

  printf("\nDeleting Tail From LIST\n");
  DelTailList(List);
  PrintList(List, "%s");

  printf("\n------------------------\n");
  
  printf("Reading Element from Splay Tree\n");
  printf("Read Element: %s\n", GetNode(Splay));

  printf("\nDeleting Element From Splay Tree\n");
  DelNode(Splay);
  PrintList(Splay, "%s");

  printf("\nDeleting Element \"Low\" In Splay Tree\n");
  FindNode(Splay, "Low");
  DelNode(Splay);
  PrintList(Splay, "%s");

  printf("Reading Element from Splay Tree\n");
  printf("Read Element: %s\n", GetNode(Splay));

  printf("\n-----------------------\n");

  printf("Removing List.\n");
  FreeList(List, NULL);
  printf("Removing Queue.\n");
  FreeList(Queue, NULL);
  printf("Removing Stack.\n");
  FreeList(Stack, NULL);
  printf("Removing Splay Tree.\n");
  FreeList(Splay, NULL);

  printf("\n-----------------------\n");
  
  printf("\nUnclaimed Memory: %d bytes\n", DCOUNT(NULL));

  printf("\nLinkList Test/Demo Done.\n");

  return 0;
} /* main */