OpenXcom Forum

Contributions => Programming => Topic started by: panther on December 19, 2010, 12:20:08 am

Title: Ufopaedia development
Post by: panther on December 19, 2010, 12:20:08 am
Hi,

I'm going to implement Ufopaedia in the next weeks. This thread is to keep you updated on the progress.
Here is the plan:

Milestone 1 - learning:
* try to put together a simple article to learn about State behaviour and resource management.

Milestone 2 - present all kinds of articles:
* identify all types of articles: Mission, Alien description, Weapons, Crafts, Base tiles, ...
* present various types of articles with navigation

Milestone 3 - complete material:
* put together all material from Access List to Cydonia
* some article data might be configurable (Weapon stats, base item properties, etc.)

Milestone 4 - final version:
* articles must be activated by game mechanics
* current viewable articles must be stored in/loaded from saved games

Please let me know if I missed something. But Ufopaedia doesn't have any bugs that could be reproduced as far as I know ;)
Title: Re: Ufopaedia development
Post by: Daiky on December 19, 2010, 12:41:06 pm
Have you talked to SupSuper yet, preferably over IRC?
As a contributor to openXcom, I can only give you the advice to start with a few babysteps.
Milestone 2 is very general.
I would have done something like this: "Milestone 2 - create a UfopaediaState class: a screen with a background image and an OK button. This state is launched when you press the ufopaedia button. When you press the OK button, you go back to the geoscape."
Done.
But I'm afraid you will bump into a lot of voids still in this very early stage of the game... new interface objects will need to be made, a structure to hold together all ufopaedia data.... RuleItems that read out of OBDATA.DAT, Rules for soldiers armour, Rules for HWPs, the whole Research structure... you'll need all that to build the ufopaedia on top.
I'm afraid SupSuper had a reason to put Ufopaedia on release 0.6 in the roadmap....

But I'm not the guy to discuss this with, just warning you upfront of possible obstacles :)
Title: Re: Ufopaedia development
Post by: michal on December 19, 2010, 04:00:40 pm
I think that for now you just could create some basic prototype of ufopaedia. Concentrate on layout, showing images, description, without stats.
Title: Re: Ufopaedia development
Post by: panther on December 19, 2010, 10:13:25 pm
Thanks for the warning Daiky! I'm currently finding my way into the code and build a general structure for Ufopaedia articles.
I'm aware, that I cannot finish it before the whole structure is done. The milestones don't have a date tag yet ;)

As michal said, I will concentrate on layout and navigation. Getting real values from game stats is in MS 3.
Title: Re: Ufopaedia development
Post by: panther on December 20, 2010, 12:39:51 am
Well, I was warned. :)
I put together a simple Article state and it works...nearly... ;)

I'm sure you saw such images before. Can someone please give me a hint on how the Palettes have to be set correctly?
Title: Re: Ufopaedia development
Post by: michal on December 20, 2010, 08:43:34 am
I guess you should do it same way as in battlescapestate (line 101):

https://openxcom.svn.sourceforge.net/viewvc/openxcom/trunk/src/Battlescape/BattlescapeState.cpp?revision=225&view=markup

But in your case i think PALETTES.DAT_3 should be used, according to:
https://www.ufopaedia.org/index.php?title=PALETTES.DAT#UFO

(4. Research Displays.)
Title: Re: Ufopaedia development
Post by: panther on December 20, 2010, 06:39:00 pm
Thanks, I guess I understand now. The new screen looks much better now :)

I made some screenshots from the original Ufopaedia to match colors etc. accurately.
It's not there yet, but Milestone 1 is within reach...
Title: Re: Ufopaedia development
Post by: panther on December 20, 2010, 11:04:57 pm
Milestone 1 reached!

A small step for sure, but I'm happy it worked out so fast. :)
The first simple Ufopaedia article is here.
As you can see, the border is correct now (I was using Window instead of a Surface),
the colors of the buttons and texts changed and the positions are like in the original game.
Title: Re: Ufopaedia development
Post by: michal on December 21, 2010, 08:34:29 am
Good start :)
Title: Re: Ufopaedia development
Post by: panther on December 27, 2010, 02:55:23 am
Just a small update:
1.) the Alien lifeform screen works now. (see screenshot)
2.) Navigation (left, right) already works.

I have already implemented some management code like a factory to get article screens, article class structures, etc.
There is a feature I miss with the text handling. It should be possible to calculate, if a given text fits into the text box, or otherwise, to calculate how large the text will be, when rendered.
The reason is, that some Titles are two liners (like f.i. "Cyberdisk autopsy") where the screen layout must change...

What I missed completely is the main Ufopaedia dialog and the list screens, so these are also on my todo list now. :)
Title: Re: Ufopaedia development
Post by: sir_nacnud on December 27, 2010, 03:22:32 am
I was looking at your screen shot for Sectoid and was wondering how the description text is handled.  Is that just one big string that you are relying on text wrapping to put it in to paragraph form?  If that is the case, looks like there is a bug with text wrapping, as the seventh line includes the space(s) between the period and "They".  I think we would want to remove the staring spaces if the line is wrapped.  This will correctly align the text, as of right now it doesn't look very good with the seventh line indented.
Title: Re: Ufopaedia development
Post by: panther on December 29, 2010, 09:37:19 pm
The text is saved in one chunk. Right now, there is no possibility to check for text wrappings or positioning AFAIK.
But I see this is an annoying issue, so I will definitely try to work on this next. The same problem arises with the two-liner headlines mentioned before...
Title: Re: Ufopaedia development
Post by: pmprog on January 02, 2011, 01:19:50 pm
Word wrapping is pretty easy, here's a pseudo code implementation of how I usually do it:

Code: [Select]
Function DrawWrappedText( String TextToDisplay, Int StartX, Int StartY, Int WrapAtWidth )
{
  Int lineStartIndex, lineEndIndex, lineWidth
  Int drawY
  String TextLine

  lineStartIndex = 0
  drawY = StartY
  While( lineStartIndex < TextToDisplay.Length )
  {
    lineEndIndex = lineStartIndex
    lineWidth = 0

    https:// Find the first character that takes us beyond our limit (or to the end of the text)
    While( lineWidth < WrapAtWidth || lineEndIndex == TextToDisplay.Length - 1 )
    {
      lineWidth += GetCharacterWidth( TextToDisplay[lineEndIndex] )
      lineEndIndex++
    }

    https:// start tracking backwards looking for the first word break character (but only if it causes a wrap)
    While( TextToDisplay[lineEndIndex] Not In ( ' ', '.', ',', '!', '?', ')', '-' ) && lineWidth >= WrapAtWidth )
    {
      lineEndIndex--
    }

    https:// Get and draw the substring
    TextLine = SubString( TextToDisplay[lineStartIndex], lineEndIndex - lineStartIndex )
    DrawText( TextLine, StartX, drawY )

    https:// Move down a line (assuming all characters are same render height)
    drawY += GetCharacterHeight( TextToDisplay[lineStartIndex] )

    https:// Start from the next character after the break
    lineStartIndex = lineEndIndex + 1
  }
}

Hope that helps
Title: Re: Ufopaedia development
Post by: panther on January 02, 2011, 10:51:23 pm
Thanks,
word wrapping is already implemented in the Text class. I extended it now to trim spaces in line beginnings.
I want to finish the Start dialog and the Select-Item screen next, this would be my Milestone 2.

Maybe I can merge my code into trunk then? I will try to make a patch file for the changes.
I have made only two rather minor changes in existing code to make it work.

The next big step for Ufopaedia will be implementing the articles, that depend on game rules like crafts, weapons, HWPs, base elements, ...
But this will depend more on other people's code. So maybe we can discuss about this some time or other via chat or PN?
Title: Re: Ufopaedia development
Post by: panther on January 27, 2011, 12:30:50 am
Just as an update, I'm still working on Ufopaedia.
After a good e-mail discussion with SupSuper, I will scratch what I've coded so far and rebuild the thing in a completely new structure. :)
There are also a lot of changes going on in classes I need to interface, so I'm planning to attach Ufopaedia after to 0.2 release.
Title: Re: Ufopaedia development
Post by: panther on February 11, 2011, 09:05:28 pm
Hi,

I have now refactored my code quite a bit so it fits better into the current schema. The attached patch lets you open the Ufopaedia featuring three buttons, list selection and (hold your breath) two articles ;)

It is for the 267 SVN version, which should work. It would be great to apply the changes so I can work on without touching SavedGame, Ruleset etc. again.

Documentation is nearly complete and passes doxygen without warnings. Let me know what you think.
Title: Re: Ufopaedia development
Post by: SupSuper on February 16, 2011, 02:46:17 am
Thanks, I'll have a look sometime this week and post feedback, just figured I'd let you know I didn't miss your post. :)
Title: Re: Ufopaedia development
Post by: panther on February 17, 2011, 12:52:03 am
Great, thanks! It would be so nice if my basic Ufopaedia "attachments" could go into the master branch. So it would be easier for me to stay updated and develop further.
Title: Re: Ufopaedia development
Post by: SupSuper on February 24, 2011, 12:57:54 am
Ok I finally had a look, and it looks very impressive, very professional. :) It still seems overly elaborate, but it seems to integrate much better with the OpenXcom structure, and you'll probably improve it over-time. I'll revise it and put it in the codebase soon, though we've just moved to Git so it'll take a while.

As for staying updated easily, you can look into GitHub forks (https://help.github.com/forking).
Title: Re: Ufopaedia development
Post by: panther on February 28, 2011, 11:32:35 pm
Good to hear, thanks. I haven't been doing much lately, but soon I will have some more time to spend on programming again.
I can fork and send you a pull request for the changes, if you like, now that github is the tool of choice.
But if you put it in the codebase anytime soon, I will fork from there...
Title: Re: Ufopaedia development
Post by: SupSuper on March 09, 2011, 12:21:13 am
Committed. I revised and moved things around a bit, but I figure you know your code better than me. Seems to work well. :)

One thing I noticed is you seem to put all the Ufopaedia articles in the Ruleset, but then... copy them to the SavedGame for some reason? You also worry about things like using a "insertion sort", which I don't think is a concern at all.
Title: Re: Ufopaedia development
Post by: michal on March 09, 2011, 07:54:45 am
There is new git build with ufopaedia :D

https://openxcom.ninex.info/git_builds/

Unfortunately, there were problems building it, there is small error:

Code: [Select]
diff --git a/src/Ufopaedia/UfopaediaSelectState.cpp b/src/Ufopaedia/UfopaediaSelectState.cpp
index 6de0c03..673ac67 100644
--- a/src/Ufopaedia/UfopaediaSelectState.cpp
+++ b/src/Ufopaedia/UfopaediaSelectState.cpp
@@ -31,7 +31,7 @@
 #include "../Interface/TextButton.h"
 #include "../Interface/TextList.h"
 #include "../Resource/ResourcePack.h"
-#include "../SaveGame/SavedGame.h"
+#include "../Savegame/SavedGame.h"
 
 namespace OpenXcom
 {

Remember that linux is case sensitive.
Title: Re: Ufopaedia development
Post by: SupSuper on March 09, 2011, 10:51:51 am
Fixed.
Title: Re: Ufopaedia development
Post by: panther on March 09, 2011, 10:26:56 pm
Committed. I revised and moved things around a bit, but I figure you know your code better than me. Seems to work well. :)

One thing I noticed is you seem to put all the Ufopaedia articles in the Ruleset, but then... copy them to the SavedGame for some reason? You also worry about things like using a "insertion sort", which I don't think is a concern at all.

Thank you! I'm currently rather busy at work but will soon continue OpenXCom development. The articles are necessary in both Ruleset and SavedGame. In Ruleset, I define how to display them, SavedGame stores what is available. This isn't obvious now, since there are only two articles implemented... :)

More to come soon.
Title: Re: Ufopaedia development
Post by: SupSuper on March 10, 2011, 12:20:16 pm
Committed. I revised and moved things around a bit, but I figure you know your code better than me. Seems to work well. :)

One thing I noticed is you seem to put all the Ufopaedia articles in the Ruleset, but then... copy them to the SavedGame for some reason? You also worry about things like using a "insertion sort", which I don't think is a concern at all.

Thank you! I'm currently rather busy at work but will soon continue OpenXCom development. The articles are necessary in both Ruleset and SavedGame. In Ruleset, I define how to display them, SavedGame stores what is available. This isn't obvious now, since there are only two articles implemented... :)

More to come soon.
Ah ok. You were only creating the articles in the Ruleset when newSave was called, which is why I was confusesd... I moved them to the Ruleset constructor, makes more sense now (UfopediaSaved are still created in newSave). :)
Title: Re: Ufopaedia development
Post by: panther on March 18, 2011, 12:20:41 am
If anyone is interested, this is my fork of OpenXCom:
https://github.com/gpin/OpenXcom

Thanks again to marabus for providing the XCode project. I only had to modify some files to reflect the new directory structure (no trunk anymore).

Well, the craft articles are already in there now!
As you can see in the screenshot, I use a TextList to display the craft stats. This is not like the original, I know. It was just more convenient this way :)
I thought I could modify TextList with an option to "pull the columns together" instead of the tabular layout.

And then I noticed a subtle difference in the TextButton rendering, that I corrected. I'm attaching a little patch here.

Title: Re: Ufopaedia development
Post by: michal on March 18, 2011, 10:01:26 am
Nice :)

Now fill a pull request ;)
Title: Re: Ufopaedia development
Post by: Volutar on March 18, 2011, 10:37:34 am
Craft parameters, I hope, are extracted online from actual craft data?
I mean, if anything about craft will be changed - will ufopaedia reflect these changes?
Because in original XCOM ufopaedia extracts craft data from actual craft data tables...
Title: Re: Ufopaedia development
Post by: michal on March 18, 2011, 11:04:01 am
Craft parameters, I hope, are extracted online from actual craft data?

Of course, hardcoding data in ufopaedia would be silly ;)

OpenXcom contains ruleset, which is currently defined here:
https://github.com/gpin/OpenXcom/blob/master/src/Ruleset/XcomRuleset.cpp#L708
Title: Re: Ufopaedia development
Post by: panther on March 18, 2011, 12:29:59 pm
And I'm far too lazy to copy all these values into Ufopaedia myself ;)

@michal: I thought i'd wait with the pull request until there is more substantial things done, to save SupSuper some time.

I'm currently working on Craft weapons, but there I must make some changes to the TextList class.
Title: Re: Ufopaedia development
Post by: michal on March 18, 2011, 12:44:41 pm
I'm currently working on Craft weapons, but there I must make some changes to the TextList class.

Maybe changes to widgets / engine etc should be made in seperate commits - that way you could create pull requests for them immediatelly, so they would be merged sooner?
Title: Re: Ufopaedia development
Post by: panther on March 18, 2011, 04:07:57 pm
Craft weapons are done already, and I filed a pull request. This is easy for me, but merging it into the master takes work...
I will try to make separate commits for widgets/engine changes in the future.

I also discovered, that there are weapon descriptions available in the text resources, but they were not shown in the original Ufopaedia!  Forgotten obviously :)
What do you think, should we put them into OpenXCom? I would move the stats a little to the bottom and insert the description text above it.
Title: Re: Ufopaedia development
Post by: michal on May 14, 2011, 10:16:35 am
Any progress with ufopaedia development?
Title: Re: Ufopaedia development
Post by: panther on June 17, 2011, 01:18:14 am
Hi,

in an attempt to unify my online existences - and because SupSuper didn't approve my MacOsX additions into the master branch :) - I now did a new fork with better OsX separation.

So far I'm up and running again, so I will tackle the next article types soon.
There only seems to be a problem with the YAML dependency, "YAML::BeginDoc is undefined" and I didn't find a current framework for XCode.

I can ignore this for now to continue, but marabus, can you please help me out here?
Title: Re: Ufopaedia development
Post by: panther on June 17, 2011, 03:45:51 am
Ah well, I couldn't resist and wanted to show some progress... :)

Here I give you the first UFO article. Of course, since it uses the RuleUfo class and all images are the same size, it is only a matter of defining the other articles to put them to work. Hence, another Ufopaedia section is available.  ;D
Title: Re: Ufopaedia development
Post by: hsbckb on June 17, 2011, 12:19:15 pm
Thanks for your update. This photo seems near perfect!
Title: Re: Ufopaedia development
Post by: panther on June 17, 2011, 06:30:09 pm
Thanks, hsbckb!

Today I worked on the BaseFacilities article and already got the text parts. Putting the preview image together is another story here (hangars being larger, backgrounds separate from foreground sprites, etc.) :)
But it's already been done in BaseView, so it should be possible soon.

I did a quick overview on what's to do next to reach Milestone 2:
1.) improve text formatting (numbers, paragraphs, ...)
2.) HWP (Tanks) article -> there is currently no Ruleset defined
3.) Weapons (Guns, Blasters, etc.) article -> this is going to be heavy with all kinds of ammo stats and stuff :-\
Title: Re: Ufopaedia development
Post by: michal on June 18, 2011, 03:06:05 pm
Good work :) I hope SupSuper will soon be active again and will merge your changes.
Title: Re: Ufopaedia development
Post by: SupSuper on June 19, 2011, 06:54:55 pm
Looking good! You will probably run into a bunch of "holes" since the Ruleset is not finished and you're kinda outpacing the project, this is why I left UFOpaedia for last. :P

Hi,

in an attempt to unify my online existences - and because SupSuper didn't approve my MacOsX additions into the master branch :) - I now did a new fork with better OsX separation.

So far I'm up and running again, so I will tackle the next article types soon.
There only seems to be a problem with the YAML dependency, "YAML::BeginDoc is undefined" and I didn't find a current framework for XCode.

I can ignore this for now to continue, but marabus, can you please help me out here?

You need yaml-cpp 0.2.6, though if you're not using the load/save functionality you can probably just comment out those lines with little issue.

Good work :) I hope SupSuper will soon be active again and will merge your changes.

I haven't received any merge requests yet. :P
Title: Re: Ufopaedia development
Post by: panther on June 19, 2011, 10:46:06 pm
Hey SupSuper! Good to hear from you again.

I already issued a pull request, that is the easiest part. :)

Quote
You need yaml-cpp 0.2.6, though if you're not using the load/save functionality you can probably just comment out those lines with little issue.
That's exactly what i did, and this change is simply not staged in git. Works like a charm for now. If the need arises, I will have to update YAML.

Don't worry about me outpacing someone. You did a fabulous job defining the rules! I'm already looking in the item definitions and it's all there already!! HWPs Rule is the only thing missing. And if it is of help, I can create that myself...
Title: Re: Ufopaedia development
Post by: panther on June 24, 2011, 12:47:50 am
Hey,

weapon articles are now available, see screenshots.  ;D
Thanks to Daiky, I could rip off the code for loading the correct image.

As you can see, the article is already changed in layout for different kinds of items (firearms with shot stats, grenades with damage only).
Notice, that Auto-Shot is not yet defined in the Rulesets for Pistol and HC, so it is not displayed.
And maybe you notice, that there is no incendiary ammo for HC. This is due to the fact, that in my setup, I haven't yet researched this ammo type. :) So this is also functional, since later you have to research Plasma weapons and clips seperately.

The display of the ammo image of the HC is not right yet, but otherwise, I'm quite happy with it. So, only two more article types to go - armor (which i nearly forgot :o) and HWP tanks.
Title: Re: Ufopaedia development
Post by: Yankes on June 25, 2011, 10:52:04 pm
You need yaml-cpp 0.2.6, though if you're not using the load/save functionality you can probably just comment out those lines with little issue.

btw i tried to compile openxcom under MinGW using
https://openxcom.ninex.info/download/misc/openxcom-deps-win32-mingw.zip
but i got this error too in yaml, this mean this "deps" are outdated.
Title: Re: Ufopaedia development
Post by: panther on June 28, 2011, 12:43:32 am
I started a bit on the Armor article, but I hope to be able to snatch the image display part from the soldier equip screen, when it's available...
Title: Re: Ufopaedia development
Post by: michal on July 16, 2011, 04:07:53 pm
Daiky has merged ufopaedia changes. There's new git build for anyone who would like to see them in action.
Title: Re: Ufopaedia development
Post by: panther on July 16, 2011, 10:59:00 pm
Cool, thanks Daiky!  8)
I'll do the HWP screen next so I can reach my milestone II...
Title: Re: Ufopaedia development
Post by: SupSuper on September 26, 2011, 11:45:46 pm
How's this progressing? Now that Research is actually implemented, it would be nice to get the Ufopaedia going as well. A bunch of stuff still seems to be incomplete or TODO, like Ufopaedia::open you mentioned before...

Btw now that there's a Discovered Research list in the SavedGame, I would suggest making Ufopaedia items unlock from those, as there is no point in keeping separate lists of everything unlocked when it all depends on Research.
Title: Re: Ufopaedia development
Post by: panther on September 29, 2011, 08:52:23 pm
Well, I didn't have much time lately, but the current progress surely motivates me!  8)

The hardest part now is to build Ufopaedia related content on top of YAML. I have made a concept of how to do this and will update my repository today.

I don't know if it is the best solution to unlock UP articles directly from Research, because these are not always 1-to-1 as far as I remember. And maybe it's more flexible this way if modders want to add new articles in the future. We'll see...
Title: Re: Ufopaedia development
Post by: panther on September 30, 2011, 12:03:41 am
Small progress, the Personal Armor article has been added (see pull request).
I will look into the research connection next.
Title: Re: Ufopaedia development
Post by: SupSuper on October 05, 2011, 04:00:51 am
I don't know if it is the best solution to unlock UP articles directly from Research, because these are not always 1-to-1 as far as I remember. And maybe it's more flexible this way if modders want to add new articles in the future. We'll see...

Well you always need to research something to open up an article, even if it's not 1-to-1. My reasoning is that keeping all the "unlocking" in one place helps keep everything consistent and less error-prone.

For example, say we go your way with unlock lists for everything: ufopaedia, items, crafts, weapons, research, manufacture, etc. So when we finish researching an item, we have to explicitly unlock the next research, item, ufopaedia, manufacture, etc. This increases the chances someone will slip up and cause a bug, and you might end up with an unlocked manufacture without the unlocked item, or unlocked research without the unlocked ufopaedia, etc. And even if you fix this bug, any affected savegames will still have the broken unlocks because it's not retroactive (this is similar to the UFO research bugs) since they only check if they themselves have been unlocked.

But if we just tie everything to researches instead, then you'll be sure that if research X is complete, everything associated with it will unlock. There are no inconsistencies. Even if you later fix a research bug, or decide to change what a research unlocks or something, it automatically takes effect because everything just checks if research X is unlocked. This also makes it much easier for modders to keep updating and trying changes without breaking everything.
Title: Re: Ufopaedia development
Post by: panther on October 09, 2011, 12:26:38 am
Point taken. The fact, that ids have to be matched in Research, Ufopaedia, etc. would be an invitation to errors.:)
So I will tie the unlocking part to the research.
Title: Re: Ufopaedia development
Post by: panther on May 02, 2012, 01:26:48 am
Phew, I've been away for a while...  :o
Just installed XCode 4 and managed to build the current OX version  :), so now I can resume my development efforts.

These are my next milestones:
1.) load current data from YAML rulesets instead of hardcoded definitions.
2.) add further main menu buttons to be able to define whole Ufopaedia
3.) attach Ufopaedia unlocking to the research infrastructure
4.) make articles more configurable for modding

I hope to file my next pull request real soon...
Title: Re: Ufopaedia development
Post by: michal on May 07, 2012, 08:33:21 am
Great :)
Title: Re: Ufopaedia development
Post by: Zharik1999 on May 09, 2012, 09:52:11 am
Really great, waiting for your improves in UFOpaedia :D