/// <summary> /// Use the page currently set as selected. Requires a SpellCharge to use. /// </summary> /// <param name="_type">Which type of attack to use on the given page.</param> /// <returns>The AbstractAttack reference.</returns> public AbstractAttack UseCurrentPage(Page.Type _type) { if (!m_SelectedPage.OnCooldown()) { if (m_spellCharges.UseCharge(GetRefreshRate())) { return(m_SelectedPage.UsePage(_type)); } } return(null); }
public Page nextPage() { // walk all pages found in .mcf, return null on last if (_pageIterator >= _pages.Count) { return(null); // handle out of bounds } // the current xml page XmlNode xmlPage = _pages[_pageIterator]; // the reconstructed page (still empty) Page page = new Page(); // keep track which page we are currently processing, every Page object actually consists of // two <fotobook/page> nodes, the left and right side in photobook bool isDouble = false; // need to collect double pages here, in case of cover actually 3 pages. while (xmlPage != null) { // the current page type, later used to handle left/right and special page cases page.type = Page.convert(xmlPage.Attributes.GetNamedItem("type").Value); // store page number if (page.type == Page.Type.Normalpage) { if (isDouble) { page.pageNoRight = getAttributeStr(xmlPage, "pagenr"); } else { page.pageNoLeft = getAttributeStr(xmlPage, "pagenr"); } } // iterate all sub nodes this page contains foreach (XmlNode node in xmlPage.ChildNodes) { switch (node.Name) { // bundlesize is the left & right combined size of the page case "bundlesize": page.bundleSize = new Vector2(getAttributeF(node, "width"), getAttributeF(node, "height")); break; // NOTE: currently only handles background id case "designElementIDs": // store background for left and right individually if (!isDouble) { page.backgroundLeft = getAttributeStr(node, "background"); } else { page.backgroundRight = getAttributeStr(node, "background"); } break; // area is the root class of all content objects // NOTE: currently supports <imagearea> & <textarea> case "area": // get the type of current area string type = node.Attributes.GetNamedItem("areatype").Value; // trick area system... if (type == "spinetextarea") { type = "textarea"; page.spineSize = getAttributeF(node.SelectSingleNode("position"), "height"); } Area newArea; switch (type) { case "imagearea": { // imagearea? image subnode exists! XmlNode image = node.SelectSingleNode("image"); // the image file name stored in .mcf file (in format: "safecontainer:/imageName.jpg) string filename = getAttributeStr(image, "filename"); // replace 'safecontainer:/' with actual path, in case filename does not exist, // store "NULL", will render as magenta outline and print error. string filePath = filename != "" ? filename.Replace("safecontainer:/", _safeContainerPath) : "NULL"; // get & store cutout information XmlNode cutout = image.SelectSingleNode("cutout"); Vector2 cutoutLeftTop = new Vector2(getAttributeF(cutout, "left"), getAttributeF(cutout, "top")); float scale = getAttributeF(cutout, "scale", 1.0f); // construct new area newArea = new ImageArea() { path = filePath, cutout = cutoutLeftTop, scale = scale, }; // get & store border settings XmlNode border = node.SelectSingleNode("decoration/border"); if (border != null) { newArea.border = true; newArea.borderWidth = getAttributeF(border, "width"); newArea.borderColor = getAttributeStr(border, "color"); } break; } case "imagebackgroundarea": { // handle backgroundimages literally just like normal images. // TODO: de-duplicate this code as much as possible XmlNode imgbg = node.SelectSingleNode("imagebackground"); // the image file string filename = getAttributeStr(imgbg, "filename"); // replace 'safecontainer:/' with actual path, in case filename does not exist, // store "NULL", will render as magenta outline and print error. string filePath = filename != "" ? filename.Replace("safecontainer:/", _safeContainerPath) : "NULL"; // get & store cutout information XmlNode cutout = imgbg.SelectSingleNode("cutout"); Vector2 cutoutLeftTop = new Vector2(getAttributeF(cutout, "left"), getAttributeF(cutout, "top")); float scale = getAttributeF(cutout, "scale", 1.0f); string bgPosition = getAttributeStr(imgbg, "backgroundPosition"); ImageBackgroundArea.ImageBackgroundType bgtype = ImageBackgroundArea.ImageBackgroundType.Undefined; if (bgPosition == "LEFT_OR_TOP") { bgtype = ImageBackgroundArea.ImageBackgroundType.Left; } else if (bgPosition == "RIGHT_OR_BOTTOM") { bgtype = ImageBackgroundArea.ImageBackgroundType.Right; } else if (bgPosition == "BUNDLE") { bgtype = ImageBackgroundArea.ImageBackgroundType.Bundle; } else { Log.Error("Unhandled background image position: " + bgPosition); } // construct new area newArea = new ImageBackgroundArea() { path = filePath, cutout = cutoutLeftTop, scale = scale, type = bgtype }; break; } case "textarea": { // in <textarea> these exist: XmlNode text = node.SelectSingleNode("text"); XmlNode textFormat = text.SelectSingleNode("textFormat"); // NOTE: <font> stores several comma-separated values: Fontname,Fonstsize,...and more. Currently only handles these two string[] fontInfo = getAttributeStr(textFormat, "font").Split(","); // get the fontsize, take pdf scale into account and adjust to photobook settings int fontSize = (int)(Convert.ToInt32(fontInfo[1]) * SCALE * FONT); // somewhat matches the result in photobook // text color string color = getAttributeStr(textFormat, "foregroundColor"); // text box background color string bgColor = getAttributeStr(textFormat, "backgroundColor"); // by default align left top string alignLabel = "ALIGNLEFT"; string valignLabel = "ALIGNVTOP"; // NOTE: <align> sometimes holds two comma-separated values (Horizontal and Vertical alignment) // for now only handles second (horizontal). string[] align = getAttributeStr(textFormat, "Alignment").Split(","); alignLabel = align.Last(); if (align.Length > 1) { valignLabel = align.First(); } string str = extractTextFromHTML(text.InnerText, ref color); // construct new area newArea = new TextArea() { textElements = extractTextFromHTMLv2(text.InnerText), text = str, fontsize = fontSize, color = color, font = fontInfo[0], align = alignLabel, valign = valignLabel, backgroundcolor = bgColor, }; break; } default: // there are more areatypes, for now just create an empty area that wont draw anything // and inform user. newArea = new Area(); Log.Warning("Unhandled area type in <page/area> '" + type + "'."); break; } // sanity check, cant be null really :P if (newArea == null) { break; } // all areas contain position information XmlNode position = node.SelectSingleNode("position"); // apply position information to current area newArea.rect = new RectangleF() { X = getAttributeF(position, "left"), Y = getAttributeF(position, "top"), Width = getAttributeF(position, "width"), Height = getAttributeF(position, "height") }; newArea.rotation = getAttributeF(position, "rotation") / SCALE; // undo scale for rotation // store new page in list page.areas.Add(newArea); break; default: // inform user about unhandled node Log.Warning("Unhandled Node in <page> '" + node.Name + "'."); break; } } // Handle all these specific page types and cases if (page.type == Page.Type.Fullcover) { // check if next page is spine, otherwise this was the back side of the cover XmlNode nextPage = _pages[_pageIterator + 1]; Page.Type nextType = Page.convert(nextPage.Attributes.GetNamedItem("type").Value); if (nextType == Page.Type.Spine) { xmlPage = nextPage; } else { xmlPage = null; // cover page is done, proceed } } else if (page.type == Page.Type.Spine) { // check if next page is Fullcover (should be anyway) XmlNode nextPage = _pages[_pageIterator + 1]; Page.Type nextType = Page.convert(nextPage.Attributes.GetNamedItem("type").Value); if (nextType == Page.Type.Fullcover) { xmlPage = nextPage; } else { xmlPage = null; } } else if (page.type == Page.Type.Emptypage) { // check if next page exists... otherwise end of book. if (_pageIterator + 1 < _pages.Count) { XmlNode nextPage = _pages[_pageIterator + 1]; xmlPage = nextPage; isDouble = true; } else { xmlPage = null; } } else if (page.type == Page.Type.Normalpage && !isDouble) { XmlNode nextPage = _pages[_pageIterator + 1]; // next is second half of a double page... xmlPage = nextPage; isDouble = true; } else { // this was second half of a double page, continue with new page xmlPage = null; } // increment to handle next <page> object in list _pageIterator++; } // return the newly constructed page return(page); }