[SOLVED] Problem loading .skin.xml from Resource or XNA Content

Sep 6, 2012 at 11:28 AM
Edited Sep 6, 2012 at 1:26 PM

Hi,

I'm having some trouble loading a a skin definition file from a resource.

I have UserInterfaceBeeb.resx containing BeebSkin which points to Resources\UserInterface\Beeb.skin.xml

The contents of that file are taken from the nuclex source package and modified to point to BeebSheet.png instead of SuaveSheet.png

I've added skin.xsd to the solution.

I've added an XNA Content Project called NuclexContent and to that I've added BeebSheet.png, DefaultFont.spritefont, TitleFont.spritefont

I have not yet added BeebSheet.xnb, DefaultFont.xnb, TitleFont.xnb to UserInterfaceBeeb.resx yet, mainly because I haven't figured out the paths yet.

In my game  constructor I have: 

 

Nuclex.UserInterface.Visuals.Flat.FlatGuiVisualizer Viz;
Viz = Nuclex.UserInterface.Visuals.Flat.FlatGuiVisualizer.FromResource(Services, Resources.UserInterfaceBeeb.ResourceManager, "BeebSkin");


When I run it, FromResource throws the error:

 

InvalidCastException
Unable to cast object of type 'System.String' to type 'System.Byte[]'.

 

I've never worked with resources or xna content so I'm at a loss about what to do.

Is this just because I haven't got around to adding the .xnb files to the xna content project? Or something else?

I'd appreciate any help anyone can give. Thanks.

 

---Edit---

I tried this line:  Viz = Nuclex.UserInterface.Visuals.Flat.FlatGuiVisualizer.FromFile(Services, "Resources\\UserInterface\\Beeb\\Beeb.skin.xml");

and specified that Beeb.skin.xml be copied to the output directory. It finds the file ok but throws the exception:
ArgumentNullException
The GraphicsDevice must not be null when creating new resources.
Parameter name: graphicsDevice

---Edit again---
I see now I was calling the FromFile too early. I called it in Initialize and it no longer throws the ArgumentNullException and just throws an exception about missing fonts (which I expected).

I'm still curious to know what I'm doing wrong with the resources method, but I can proceed using FromFile now.

---Edit again---

I got the spritefont files to compile to Nuclex Framework sprite fonts through the nuclex font importer but now when debugging I get the following exception:

ContentLoadException
Error loading "TitleFont". File not found.


The InnerException to that is:
System.IO.FileNotFoundException
Error loading "Resources\UserInterface\Beeb\TitleFont.xnb". File not found.

I verified that the xnb files were built and exist in:

GameSolution\bin\x86\Debug\Content\Resources\UserInterface\Beeb\TitleFont.xnb

What am I doing wrong?

Coordinator
Sep 6, 2012 at 1:36 PM

It's been some time since I did that, but I think if you select a resource and open the properties window, you can select whether it will be stored as a System.String or as an array of bytes.

Regarding your file not found issue, maybe you didn't assign the base directory to the content manager? For some absurd reason, Visual Studio by default launches projects with the directory that contains the .csproj file as the current working directory instead of bin\x86\${Configuration}, so your path could very well be interpreted as GameSolution\Resources\UserInterface\Beeb\TitleFont.xnb if the content manager has no base directory assigned.

Sep 6, 2012 at 1:58 PM
Edited Sep 6, 2012 at 3:25 PM

I have the line:

  Content.RootDirectory = "Content";

Is this base directory you are talking about? Or do you mean the working directory in the solution properties Debug tab?

This works to load a vanilla xna spritefont using the following code:

 

this._Font = Content.Load<SpriteFont>("Fonts\\OldFont");

 

The Resources folder containing the new Nuclex xnb files is sitting parallel to this old Fonts folder.

(Thanks for the quick reply BTW)

--Edit---

Just to be clear, after building my directory structure looks like:

E:\...\GameSolution\Resources\skin.xsd
E:\...\GameSolution\Resources\UserInterface\Beeb\Beeb.skin.xml
E:\...\GameSolution\bin\x86\Debug\Resources\UserInterface\Beeb\Beeb.skin.xml
E:\...\GameSolution\bin\x86\Debug\Content\Resources\UserInterface\Beeb\TitleFont.xnb

 

FromFile seems to be looking for the fonts in the same dir as the skin.xml exactly as the path is specified in the path parameter. I don't see how they can ever match up seeing as the TitleFont is part of the the Content Project and the skin.xml is just added to the main game project and copied to the output directory at build time. I'm definitely misunderstanding how this is supposed to work.

Sep 6, 2012 at 4:19 PM
Edited Sep 6, 2012 at 4:50 PM

After I do Content.RootDirectory = "Content"
Do I need to do anything with that to let the Nuclex know about it?

Sep 6, 2012 at 4:49 PM
Edited Sep 6, 2012 at 5:31 PM

I got it!

I added a new folder to the main solution which I name "Content" to match the Content Project output folder name and then moved the Resources folder containing Beeb.skin.xml into that. The output folder structures then matched and it all worked.

 

Thanks for the help!    :-)

---Edit---

Except that it's drawing all text on controls a few pixels too low vertically.
I tried it again with clean copies of the nuclex source spritefonts and SuaveSheet.png and it also draws that text too low (or the sheet graphics too high, I can't tell).
If I comment out:

 Viz = Nuclex.UserInterface.Visuals.Flat.FlatGuiVisualizer.FromFile(Services,  "Content\\Resources\\UserInterface\\Beeb\\Beeb.skin.xml");
gui.Visualizer = Viz;

 

then the default skin displays properly.

If I edit the Beeb.skin.xml and modify all the <text yoffset="15"> attributes to <text yoffset="0"> It looks correct. But I'm using the default files apart from changing Beeb.skin.xml to read:   <bitmap name="controls" contentPath="BeebSheet" />
There are no other changes, so I don't understand why it's occuring.

Any ideas?

 

---Edit---

I see my new problem is a duplicate of this one: http://nuclexframework.codeplex.com/discussions/285557
I've used the supplied source spritefonts and built them with the Nuclex SpriteFont processor though. I'm just going to modify the yoffset attributes for now.