Пример #1
0
/**
 * @brief Find node by name two levels deep (first parent, then element)
 * @param aRoot
 * @param aElement
 */
Root* Parser::Find(std::string const &aRoot, std::string const &aElement)
{
  // Find node and search it for an element
  std::vector<HashString> splitString = HashString(aRoot).Split("/");
  Root *node = mDictionary->Find(splitString[0]);

  if(!node)
    return nullptr;

  for(unsigned curLevel = 0; curLevel < splitString.size(); ++curLevel)
  {
    node = node->Find(splitString[curLevel]);
    if(!node)
      return nullptr;
  }

  node = node->Find(aElement);
  return node;
}
Пример #2
0
/**
 * @brief Serialize to file.
 * @param aParser File to write into.
 */
void PCShaderSurface::Serialize(Parser &aParser)
{
    HashString const objectName = HashString("Object_") + Common::IntToString(aParser.GetCurrentObjectIndex());
    HashString const SURFACE = "Surface";
    Root* object = aParser.Find(objectName);
    Surface::Serialize(aParser);
    Root* surface = object->Find(SURFACE);
    surface->Place(SURFACE, "TextureName", GetFileName());
    surface->Place(SURFACE, "VertexShader", mVertexShaderFileName);
    surface->Place(SURFACE, "FragmentShader", mFragmentShaderFileName);
}
Пример #3
0
/**
 * @brief From root, build tree, return lowest level node creating
 * @param aBase Where to start building from.
 * @param aStringHierarchy
 */
Root* Parser::SetUpTree(Root* aBase, std::vector<HashString> const &aStringHierarchy)
{
  Root* current = aBase;
  Root* ret = nullptr;
  
  for(unsigned i = 0; i < aStringHierarchy.size(); ++i)
  {
    Root* next = current->Find(aStringHierarchy[i]);
    if(!next)
    {
      next = new Root();
      current->Insert(next);
      next->SetParent(current);
      next->SetName(aStringHierarchy[i]);
    }
    ret = next;
    current = next;
  }
  
  return ret;
}
Пример #4
0
/**
 * @brief Gathers additional data from deserialized file.
 * @param aParser
 */
void MenuText::ParseAdditionalData(Parser &aParser)
{
  GameApp* app = LUABind::StaticGameApp::GetApp();
  if(aParser.Find("Font"))
  {
    mFont = aParser.Find("Font", "FontName")->GetValue().ToString();
    mSize = Common::StringToInt(aParser.Find("Font", "Size")->GetValue());
  }
  if(aParser.Find("ForegroundColor"))
  {
    mForegroundColor.x = aParser.Find("ForegroundColor", "r")->GetValue().ToInt();
    mForegroundColor.y = aParser.Find("ForegroundColor", "g")->GetValue().ToInt();
    mForegroundColor.z = aParser.Find("ForegroundColor", "b")->GetValue().ToInt();
    mForegroundColor.w = aParser.Find("ForegroundColor", "a")->GetValue().ToInt();
  }
  if(aParser.Find("BackgroundColor"))
  {
    mBackgroundColor.x = aParser.Find("BackgroundColor", "r")->GetValue().ToInt();
    mBackgroundColor.y = aParser.Find("BackgroundColor", "g")->GetValue().ToInt();
    mBackgroundColor.z = aParser.Find("BackgroundColor", "b")->GetValue().ToInt();
    mBackgroundColor.w = aParser.Find("BackgroundColor", "a")->GetValue().ToInt();
  }
  
  // Text can be overwritten in Menu file.
  if(aParser.Find("Text") && mText.Empty())
  {
    mText = aParser.Find("Text", "Value")->GetValue().ToString();
  }
  
  // Set a max width, otherwise default to screen width..
  if(aParser.Find("MaxWidth"))
  {
    mMaxWidth = aParser.Find("MaxWidth", "Value")->GetValue().ToInt();
  }
  else
  {
    mMaxWidth = app->GET<GraphicsManager>()->GetScreen()->GetWidth();
  }

#ifdef SHADER_COMPATIBLE
  PCShaderSurface *surface = (PCShaderSurface*)app->GET<GraphicsManager>()->CreateUISurface();
  Vector3 size = surface->LoadText(mFont, mText, mForegroundColor, mBackgroundColor, mSize, mMaxWidth);
#elif defined(__APPLE__)
  PCSurface *surface = (PCSurface*)app->GET<GraphicsManager>()->CreateUISurface();
  Vector3 size = surface->LoadText(mFont, mText, mForegroundColor, mBackgroundColor, mSize, mMaxWidth);
#else
  Surface *surface = app->GET<GraphicsManager>()->CreateUISurface();
#endif
  surface->SetViewMode(VIEW_RELATIVE_TO_CAMERA);
  surface->Deserialize(aParser);
  
  // Update texture to be the right size.
  Transform *transform = mObject->GET<Transform>();
  mOriginalSize = size;
  transform->SetSize(size);
  
  // Reveal the text slowly rather than all at once.
  if(aParser.Find("Animation"))
  {
    Root* animation = aParser.Find("Animation");
    std::vector<float> animationSpeed = animation->Find("AnimationSpeeds")->GetValue().ToFloatVector();
    std::vector<int> numFrames;
    
    // Manually set the number of frames, or auto jump a character at a time.
    if(animation->Find("NumFrames"))
    {
      numFrames = animation->Find("NumFrames")->GetValue().ToIntVector();
    }
    else
    {
      numFrames.push_back(mText.Length());
    }

    surface->CreateScrollEffect(ScrollType::HORIZONTAL, mOriginalSize);
    surface->SetTextureCoordinateData(1, numFrames, animationSpeed);
    surface->GetTextureData()->SetXGain(0, 0);
    surface->SetAnimation(0, true);
    surface->SetAnimated(true);
    transform->GetSize().x = 0;
  }
  
  mObject->AddComponent(surface);
}