void CubeMapTextureBrowser::ReloadTexturesFromUI(QString& path)
{
	if(path.at(path.size() - 1) != QChar('/') &&
	   path.at(path.size() - 1) != QChar('\\'))
	{
		path += "/";
	}
	
	ui->textRootPath->setText(path);
	
	FilePath projectPath = path.toStdString();
	SettingsManager::SetValue(Settings::Internal_CubemapLastProjDir, VariantType(projectPath));
	
	ReloadTextures(path.toStdString());
}
void CubeMapTextureBrowser::ReloadTexturesFromUI(QString& path)
{
	if(path.at(path.size() - 1) != QChar('/') &&
	   path.at(path.size() - 1) != QChar('\\'))
	{
		path += "/";
	}
	
	ui->textRootPath->setText(path);
	
	FilePath projectPath = path.toStdString();
	EditorSettings::Instance()->GetSettings()->SetString(ResourceEditor::CUBEMAP_LAST_PROJECT_DIR_KEY,
														 projectPath.GetAbsolutePathname());
	EditorSettings::Instance()->Save();
	
	ReloadTextures(path.toStdString());
}
CubeMapTextureBrowser::CubeMapTextureBrowser(SceneEditor2* currentScene, QWidget *parent) :
    QDialog(parent),
    ui(new Ui::CubeMapTextureBrowser),
	cubeListItemDelegate(QSize(FACE_IMAGE_SIZE, FACE_IMAGE_SIZE))
{
	scene = currentScene;
	
    ui->setupUi(this);
	ui->loadingWidget->setVisible(false);
	ui->listTextures->setItemDelegate(&cubeListItemDelegate);
	
	ConnectSignals();
	
	FilePath projectPath = CubemapUtils::GetDialogSavedPath("Internal/CubemapLastProjDir",
															ProjectManager::Instance()->CurProjectDataSourcePath().GetAbsolutePathname());
		
	ui->textRootPath->setText(projectPath.GetAbsolutePathname().c_str());
	ReloadTextures(projectPath.GetAbsolutePathname());
	
	UpdateCheckedState();
}
CubeMapTextureBrowser::CubeMapTextureBrowser(SceneEditor2* currentScene, QWidget *parent) :
    QDialog(parent),
    ui(new Ui::CubeMapTextureBrowser),
	cubeListItemDelegate(QSize(FACE_IMAGE_SIZE, FACE_IMAGE_SIZE))
{
	scene = currentScene;
	
    ui->setupUi(this);
	ui->loadingWidget->setVisible(false);
	ui->listTextures->setItemDelegate(&cubeListItemDelegate);
	
	ConnectSignals();
	
	FilePath projectPath = CubemapUtils::GetDialogSavedPath(ResourceEditor::CUBEMAP_LAST_PROJECT_DIR_KEY,
															EditorSettings::Instance()->GetDataSourcePath().GetAbsolutePathname(),
															EditorSettings::Instance()->GetDataSourcePath().GetAbsolutePathname());
		
	ui->textRootPath->setText(projectPath.GetAbsolutePathname().c_str());
	ReloadTextures(projectPath.GetAbsolutePathname());
	
	UpdateCheckedState();
}
  //
  // Preview::Preview
  //
  Preview::Preview(const Missions::Mission *missionIn) 
  : teams(&TeamInfo::node),
    terrain(NULL),
    ruleSetFixed(FALSE)
  {
    if (missionIn)
    {
      name = missionIn->GetName().str;
      path = missionIn->GetGroup().GetPath().str;
    }
    else
    {
      name = "";
      path = "";
    }

    // Open mission stream
    const char *oldStream = OpenMissionStream();

    // Open the game configuration file
    PTree pTree;

    // Parse the file
    if (pTree.AddFile(FILENAME_MISSION_CONFIG))
    {
      // Get the global scope
      FScope *gScope = pTree.GetGlobalScope();
      FScope *sScope;

      // Process each function
      while ((sScope = gScope->NextFunction()) != NULL)
      {
        switch (sScope->NameCrc())
        {
          case 0xEDF7E07D: // "DefaultRule"
            ruleSet = StdLoad::TypeString(sScope);
            break;

          case 0x7F6A7C11: // "FixedRule"
            ruleSetFixed = StdLoad::TypeU32(sScope);
            break;

          case 0x1D4A8250: // "WorldInfo"
            // Load map size
            size = StdLoad::TypeU32(sScope, "CellMapX");
            break;

          case 0xCA519158: // "DefineTeams"
          {
            ASSERT(!teams.GetCount())

            // Count the number of teams we find
            FScope *fScope;

            // Process each function
            while ((fScope = sScope->NextFunction()) != NULL)
            {
              switch (fScope->NameCrc())
              {
                case 0xB884B9E8: // "CreateTeam"
                {
                  // Is this team available for play
                  if (StdLoad::TypeU32(fScope, "AvailablePlay", 1))
                  {
                    // Create new team info
                    TeamInfo *info = new TeamInfo(fScope);

                    // Add to the tree
                    teams.Add(info->GetName().crc, info);
                  }
                  break;
                }
              }
            }

            break;
          }
        }
      }
    }
    else
    {
      size = 0;
    }

    // Load preview texture
    ReloadTextures();

    // Restore old stuff
    if (oldStream)
    {
      CloseMissionStream(oldStream);
    }
  }