Ejemplo n.º 1
0
bool CVFSEntryIDirectoryWrapper::GetKeyboardInput2(const char* heading,
                                                   char** input)
{
  CStdString inp;
  bool result;
  if ((result=GetKeyboardInput(CVariant(std::string(heading)), inp)))
    *input = strdup(inp.c_str());

  return result;
}
Ejemplo n.º 2
0
bool CAddonsDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items)
{
  CStdString path1(strPath);
  URIUtils::RemoveSlashAtEnd(path1);
  CURL path(path1);
  items.ClearProperties();

  items.SetContent("addons");

  VECADDONS addons;
  // get info from repository
  bool reposAsFolders = true;
  if (path.GetHostName().Equals("enabled"))
  {
    CAddonMgr::Get().GetAllAddons(addons, true);
    items.SetProperty("reponame",g_localizeStrings.Get(24062));
    items.SetLabel(g_localizeStrings.Get(24062));
  }
  else if (path.GetHostName().Equals("disabled"))
  { // grab all disabled addons, including disabled repositories
    reposAsFolders = false;
    CAddonMgr::Get().GetAllAddons(addons, false, true);
    items.SetProperty("reponame",g_localizeStrings.Get(24039));
    items.SetLabel(g_localizeStrings.Get(24039));
  }
  else if (path.GetHostName().Equals("outdated"))
  {
    reposAsFolders = false;
    CAddonMgr::Get().GetAllOutdatedAddons(addons);
    items.SetProperty("reponame",g_localizeStrings.Get(24043));
    items.SetLabel(g_localizeStrings.Get(24043));
  }
  else if (path.GetHostName().Equals("repos"))
  {
    CAddonMgr::Get().GetAddons(ADDON_REPOSITORY,addons,true);
    items.SetLabel(g_localizeStrings.Get(24033)); // Get Add-ons
  }
  else if (path.GetHostName().Equals("sources"))
  {
    return GetScriptsAndPlugins(path.GetFileName(), items);
  }
  else if (path.GetHostName().Equals("all"))
  {
    CAddonDatabase database;
    database.Open();
    database.GetAddons(addons);
    items.SetProperty("reponame",g_localizeStrings.Get(24032));
    items.SetLabel(g_localizeStrings.Get(24032));
  }
  else if (path.GetHostName().Equals("search"))
  {
    CStdString search(path.GetFileName());
    if (search.IsEmpty() && !GetKeyboardInput(16017, search))
      return false;

    items.SetProperty("reponame",g_localizeStrings.Get(283));
    items.SetLabel(g_localizeStrings.Get(283));

    CAddonDatabase database;
    database.Open();
    database.Search(search, addons);
    GenerateListing(path, addons, items, true);

    path.SetFileName(search);
    items.SetPath(path.Get());
    return true;
  }
  else
  {
    reposAsFolders = false;
    AddonPtr addon;
    CAddonMgr::Get().GetAddon(path.GetHostName(),addon);
    if (!addon)
      return false;

    // ensure our repos are up to date
    CAddonInstaller::Get().UpdateRepos(false, true);
    CAddonDatabase database;
    database.Open();
    database.GetRepository(addon->ID(),addons);
    items.SetProperty("reponame",addon->Name());
    items.SetLabel(addon->Name());
  }

  if (path.GetFileName().IsEmpty())
  {
    if (!path.GetHostName().Equals("repos"))
    {
      for (int i=ADDON_UNKNOWN+1;i<ADDON_VIZ_LIBRARY;++i)
      {
        for (unsigned int j=0;j<addons.size();++j)
        {
          if (addons[j]->IsType((TYPE)i))
          {
            CFileItemPtr item(new CFileItem(TranslateType((TYPE)i,true)));
            item->SetPath(URIUtils::AddFileToFolder(strPath,TranslateType((TYPE)i,false)));
            item->m_bIsFolder = true;
            CStdString thumb = GetIcon((TYPE)i);
            if (!thumb.IsEmpty() && g_TextureManager.HasTexture(thumb))
              item->SetArt("thumb", thumb);
            items.Add(item);
            break;
          }
        }
      }
      items.SetPath(strPath);
      return true;
    }
  }
  else
  {
    TYPE type = TranslateType(path.GetFileName());
    items.SetProperty("addoncategory",TranslateType(type, true));
    items.SetLabel(TranslateType(type, true));
    items.SetPath(strPath);

    // FIXME: Categorisation of addons needs adding here
    for (unsigned int j=0;j<addons.size();++j)
    {
      if (!addons[j]->IsType(type))
        addons.erase(addons.begin()+j--);
    }
  }

  items.SetPath(strPath);
  GenerateListing(path, addons, items, reposAsFolders);
  // check for available updates
  if (path.GetHostName().Equals("enabled"))
  {
    CAddonDatabase database;
    database.Open();
    for (int i=0;i<items.Size();++i)
    {
      AddonPtr addon2;
      database.GetAddon(items[i]->GetProperty("Addon.ID").asString(),addon2);
      if (addon2 && addon2->Version() > AddonVersion(items[i]->GetProperty("Addon.Version").asString())
                 && !database.IsAddonBlacklisted(addon2->ID(),addon2->Version().c_str()))
      {
        items[i]->SetProperty("Addon.Status",g_localizeStrings.Get(24068));
        items[i]->SetProperty("Addon.UpdateAvail", true);
      }
    }
  }
  if (path.GetHostName().Equals("repos") && items.Size() > 1)
  {
    CFileItemPtr item(new CFileItem("addons://all/",true));
    item->SetLabel(g_localizeStrings.Get(24032));
    items.Add(item);
  }

  return true;
}
Ejemplo n.º 3
0
//Main update function for this game state. Returns true if the game is still running
//and false if the user quits the game
bool Table::Update()
{
	bool gameRunning = true;	

	m_keyboard = Keyboard::Keyboard::NONE;
	GetKeyboardInput();
	
	if(m_keyboard == Keyboard::ESCAPE)
	{
		m_prevState = m_state;
		m_state = State::State::EXIT;
	}

	//This is the main switch statement for the FSM for this game state. Based on the state the
	//game is currently in only the code relevant to that state will get used
	switch( m_state )
	{
		if(m_keyboard != Keyboard::NONE)
		{
			//Gets number of players playing at the table. Creates players for the vector
			//of players and then changes to next state
			case State::GET_PLAYERS:
				{					
					switch(m_keyboard)
					{
						case Keyboard::ONE: m_numPlayers = 1;
							break;
						case Keyboard::TWO: m_numPlayers = 2;
							break;
						case Keyboard::THREE: m_numPlayers = 3;
							break;
						case Keyboard::FOUR: m_numPlayers = 4;
							break;
						case Keyboard::ESCAPE: m_state = State::State::EXIT;
							break;
					}

					if( m_numPlayers != 0 )
					{
						m_state = State::State::GET_BETS;
					
						for(int i = 0; i < m_numPlayers; i++)
						{
							m_players.push_back(Player());
						}
					}
				}
				break;

				//Gets bets for each player. Once one player chooses their bet automatically
				//moves on to the next player. Once all players have bets hand is dealer and
				//state is changed to next state
			case State::GET_BETS:
				{
					if(m_players.at(m_activePlayer).Update(m_state, m_keyboard, &m_shoe))
						m_activePlayer++;
					

					if(m_activePlayer >= m_players.size())
					{
						DealNewHand();
						
						//If the dealer has Blackjack the hand automatically ends. If the player has
						//BJ as well this gets picked up in the DISPLAY_RESULTS state and will get their
						//bet returned there
						if(m_dealer.GetHandValue() == 21)
						{
							m_state = State::State::DEALER_PLAYING;
						}	

						//Checks players for BJ - if BJ then hand gets paid and hand status is set to not live
						else
						{
							for(int i = 0; i < m_numPlayers; i++)
							{
								if(m_players.at(i).GetHandValue() == 21)
								{
									m_players.at(i).Blackjack();
								}
							}

							m_state = State::State::PLAYING_HAND;
							m_activePlayer = 0;
						}				
					}		
				}
				break;

				//Gets player input for hand decision. For each choice it performs the necessary action and
				//returns if the player's turn is over. If it is play automatically moves on to the next player.
				//If there are no more players the state is changed and the dealer plays their hand
			case State::PLAYING_HAND:
				{
					if(m_players.at(m_activePlayer).Update(m_state, m_keyboard, &m_shoe))
						m_activePlayer++;

					if(m_activePlayer >= m_numPlayers)
						m_state = State::State::DEALER_PLAYING;
				}
				break;

			case State::DISPLAY_RESULTS:
				{
					if(m_players.at(0).Update(m_state, m_keyboard, &m_shoe))
						m_state = State::State::END_HAND;
				}
				break;
				//If player chooses exit above this prompts to confirm they wish to exit
				//If they do state changes to menu - if not play resumes
			case State::EXIT:
				{
					switch(m_keyboard)
					{
						case Keyboard::Y:
							{
								m_stateManager->ChangeState(new Menu(m_stateManager));
							}
							break;
						case Keyboard::N:
							{
								m_state = m_prevState;
							}
							break;
					}
				}
				break;
				
			}
			//Checks if it's time for the dealer to play. If it is their hand is revealed. If the dealer's hand is under
			//17 they draw a card. If hand is not under 17 then play ends and state is changed to the next one
			case State::DEALER_PLAYING:
				{
					bool playersActive = false;

					//Checks if any players are still active. Only plays their hand if their are players still in the hand
					for(int i = 0; i < m_numPlayers; i++)
					{
						if(m_players.at(i).IsHandLive())
							playersActive = true;
					}

					if(playersActive)
					{				
						if(m_dealer.Update(&m_shoe))
						{
							m_state = State::State::DISPLAY_RESULTS;

							for(unsigned int i = 0; i < m_numPlayers; i++)
							{
								m_players.at(i).CheckForWin(m_dealer.IsBust(), m_dealer.GetHandValue());
							}
						}
					}

					else
					{
						m_state = State::State::DISPLAY_RESULTS;
						m_dealer.SetVisible(true);

						for(unsigned int i = 0; i < m_numPlayers; i++)
						{
							m_players.at(i).CheckForWin(m_dealer.IsBust(), m_dealer.GetHandValue());
						}
					}
				}
				break;
				//Checks if each player has won. Cycles though all player hands and checks if they won. If they did their chips
				//are adjusted, the table is cleared and a new hand starts
			case State::END_HAND:
				{
					ClearTable();
					m_state = State::State::GET_BETS;
				}
				break;		
	}
	
	return gameRunning;
}