// Загрузка локализации из файла 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; }
public String LoadFile(String filename) { FileHandle xmlFile = Gdx.files.internal("scenes/" + filename); String script = xmlFile.readString(); XmlReader xml = new XmlReader(); xml_element = xml.parse(script); String startSceneName = xml_element.getAttribute("startScene", null); if (startSceneName == null) { Array<XmlReader.Element> scenes = xml_element.getChildrenByName("scene"); startSceneName = scenes.get(0).get("name"); } return startSceneName; }
public void LoadStage() { FileHandle xmlFile = Gdx.files.internal("scenes/index.xml"); String script = xmlFile.readString(); XmlReader xml = new XmlReader(); xml_element = xml.parse(script); String startSceneName = xml_element.getAttribute("startScene", null); String skinPath = xml_element.getAttribute("skin", null); assetService.setCurrentSkinPath(skinPath); assetService.loadAssets(); if (startSceneName == null) { Array<XmlReader.Element> scenes = xml_element.getChildrenByName("scene"); startSceneName = scenes.get(0).get("name"); } RenderScene(startSceneName); }
public Actor CreateActorFromElement(XmlReader.Element e) { String name = e.getName(); Actor a = null; for (String namespaceName : importedNamespaceNames) { Namespace importedNamespace = rootNamespace.namespace(namespaceName); if (!importedNamespace.isElementListEmpty()) { ArrayList<ElementDirective> DirectiveElements = importedNamespace.getElements(); for (ElementDirective d : DirectiveElements) { if (name.equalsIgnoreCase(d.getName())) { a = d.processDirective(null, e); if (a != null) { if (d.isApplyCommonAttribute()) { if (!importedNamespace.isAttributeListEmpty()) { ArrayList<AttributeDirective> CommonAttributes = importedNamespace.getAttributes(); for (AttributeDirective ad : CommonAttributes) { a = ad.processDirective(a, e); } } } } return a; } } } } return a; }
@Override public void parse(XmlReader.Element xml) { entityName = xml.getText(); numToSpawn = xml.getIntAttribute("Num", 1); delay = xml.getFloatAttribute("Delay", 0); }
@Override public void parse(XmlReader.Element xml) { num = Integer.parseInt(xml.getText()); }
// 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; } } }