예제 #1
0
  // Загрузка локализации из файла
  public boolean LoadFromInternalXML(String locale, String internalPath) {
    strings.clear();
    boolean result = false;
    XmlReader reader = new XmlReader();
    try {
      XmlReader.Element root = reader.parse(Gdx.files.internal(internalPath));
      if (root != null) {
        // Проверка на правильность формата файла локализации
        if (root.getName().equalsIgnoreCase("localization")) {
          int load_count = 0;
          // Перебор всех дочерних элементов
          for (int i = 0; i < root.getChildCount(); i++) {
            XmlReader.Element item = root.getChild(i);
            if (item != null) {
              if (item.getName().equalsIgnoreCase("string")) {
                String key = item.getAttribute("key").trim();
                String default_string;
                String value;
                if (key.length() > 0) {
                  Array<XmlReader.Element> find = item.getChildrenByName("default");
                  if (find.size > 0) default_string = find.get(0).getText();
                  else default_string = item.getAttribute("default", "");

                  find = item.getChildrenByName(locale);
                  if (find.size > 0) value = find.get(0).getText();
                  else value = default_string;

                  find.clear();
                  if (value.length() > 0) {
                    strings.put(key, value);

                    if (default_string.length() > 0) translates.put(default_string, value);

                    load_count++;
                  } else {
                    if (default_string.length() > 0) {
                      strings.put(key, default_string);
                      load_count++;
                    }
                  }
                }
              }
            }
          }
          if (load_count > 0) result = true;
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
      strings.clear();
      result = false;
    }
    return result;
  }
예제 #2
0
  // this loads everything into stage.
  public void RenderScene(String startSceneName) {
    Array<XmlReader.Element> scenes;

    if (startSceneName.endsWith(".xml")) {
      try {
        startSceneName = LoadFile(startSceneName);
      } catch (Exception io) {

      }
    }

    scenes = xml_element.getChildrenByName("scene");

    int Count = 0;

    for (XmlReader.Element sceneElement : scenes) {
      String sceneName = sceneElement.getAttribute("name", "Scene_" + Count++);

      if (startSceneName.equalsIgnoreCase(sceneName)) {
        stage.clear();
        // reset controller
        scopeService.setCurrentController(null);
        scopeService.clearScopeVariables(); // clear all temporary variables

        String controllerName = sceneElement.getAttribute("controller", null);
        scopeService.setCurrentController(controllerName);

        int count = sceneElement.getChildCount();
        UIScene currentScene = new UIScene();
        currentScene.setName(sceneName);
        currentScene.setControllerName(controllerName);
        currentScene.setFillParent(true); // fixed: the table is not full-sized based on window size

        for (int i = 0; i < count; i++) {
          XmlReader.Element child = sceneElement.getChild(i);

          // use factory and dictionary
          // todo:
          // Factory factory = Dictionary.get(ElementName);
          // Actor a = Factory.CreateActor();
          // gScene.addActor(a);

          Actor a = CreateActorFromElement(child);

          if (a != null) {
            currentScene.addActor(a);
          }
        }
        Object controller = scopeService.getCurrentController();

        if (lastRenderedScene != null) {
          // ToDO: perform exitScene here
        }

        if (controller instanceof SceneEventListener) {
          ((SceneEventListener) controller).enterScene(currentScene, this);
        }

        stage.addActor(currentScene);
        lastRenderedScene = currentScene;
        break;
      }
    }
  }