Skip to content

Add Codex popup UI (phase 2) - #1040

Open
Billytifft wants to merge 7 commits into
C7-Game:Developmentfrom
Billytifft:billy/codex-phase-2-ui
Open

Billytifft wants to merge 7 commits into
C7-Game:Developmentfrom
Billytifft:billy/codex-phase-2-ui

Conversation

@Billytifft

Copy link
Copy Markdown
Contributor

Phase 2 of the Codex feature (#997): a working in-game Civilopedia popup backed by the phase-1 data parser. UI/data only — no navigation, search, or content pipeline yet (see "Deferred"). Opening as a draft to get early feedback on the tab-alignment approach (see "Outstanding").

Screenshots

Codex popup screenshot 1

Codex popup screenshot 2

Codex popup screenshot 3

Codex popup screenshot 4

What's included

Popup UI (C7/UIElements/Codex/CodexPopup.cs)

  • Fixed 1060x700 centered popup opened from the top-left Civilopedia toolbar button.
  • Header with disabled Back/Forward + search placeholders, title, and an ui.exit close button; closes on the button and on Esc.
  • Left pane: 11 section buttons plus a scrollable index of the section's entries.
  • Right pane: icon, name, generated stat block, a markdown article, and a Body/Description pager when an entry has both.
  • Article uses the markdownlabel submodule (automatic_links=false) with a plain RichTextLabel fallback; body font size pinned to 13 across all RichTextLabel style keys.

Catalog (C7/UIElements/Codex/CodexCatalog.cs)

  • 11 sections: Units, City Improvements, Great Wonders, Small Wonders, Technologies, Civilizations, Governments, Terrain, Resources, Terrain Improvements, Game Concepts.
  • Generated stat lines from game data; icons via TextureLoader.Load (failures fall back to no icon).
  • Prose pulled from gameData.Codex; alphabetical except Game Concepts (authored order).
  • Terrain has no Civilopedia key, so it renders stats only.

Parser/data fixes (C7Engine/C7GameData/Codex.cs)

  • Case-insensitive Entries lookup (fixes PRTO_NUKE vs PRTO_Nuke).
  • contentStarted guard so entries whose first line lacks a ^ still parse (e.g. Apollo Project).
  • Markdown conversion: [..] -> italics, {..} -> bold, a whole-line {Title} (no tabs) -> ## heading; $LINK -> [label](key:target).

Ruleset + wiring

  • C7/Lua/civ3/ruleset.json: civilopediaEntry added to 124 units, 82 buildings, 32 civilizations (from the BIQ).
  • C7/Game.cs: load Civilopedia text when the Codex is empty (native JSON rulesets don't carry it).
  • C7/UIElements/UpperLeftNav/CivilopediaButton.cs + C7/C7Game.tscn: open the popup via PopupOverlay.
  • GameData.cs: Civilizations read-only accessor (GameData.cs:57).

Testing

  • dotnet build C7/C7.sln — 0 errors.
  • dotnet format C7/C7.sln whitespace --verify-no-changes — clean.
  • dotnet test with CIV3_HOME set — 171 passed / 2 failed (both pre-existing, see below).
  • New tests: BaseRulesetPediaKeysTest (all units/buildings/civs have non-empty PRTO_/BLDG_/RACE_ keys) and CodexTest additions covering italics/bold/heading conversion, case-insensitive lookup, body/desc merge, and caret-less leading lines.

Outstanding / known issues

  1. Tab-column alignment in tabbed tables is still imperfect. Civ3's tables (Food, Difficulty/Content Citizens, terrain, keyboard shortcuts) were tuned to Civ3's own font and tab-stop width. Godot tabs are stop-based, and the first tab after a long name only advances to the next stop, so a single tab can look like ~2 spaces while later tabs are full stops. We set TabSize = 5 (CodexPopup.cs:252) as the best fit across all 49 tab tables for the current font — but it's a heuristic, some rows remain ragged, and the correct value changes with the font.
  2. The article RichTextLabel is unthemed, so it renders in Godot's default font while the rest of the UI uses NotoSans 14. This should be fixed for consistency, but changing the font will shift tab alignment again (best fit changes from 5 to ~6).
  3. ruleset.json has a large generated diff (+238 lines). It may be better generated from the BIQ at build time rather than committed. Needs a maintainer call.
  4. Pre-existing test failures, unrelated to this PR: GameDataTest.SeedInGameData_JSON and UnitPrototypeConquestsTest.UnitAvailability_JSON (a Dropbox-hosted save fails $.buildings[6].flags[1] -> SaveBuilding+Flag conversion).

Deferred (later phases)

  • Back/Forward and search are disabled placeholders; hyperlink navigation is off (automatic_links=false).
  • No content pipeline / dynamic generation; no per-civilization or context-sensitive views.

Add a Civilopedia popup opened from the top-left nav button: section list
with index, icon/stats panel, and a markdown article with Body/Description
paging. Convert Civ3 [..]/{..} markup to italics/bold (whole-line braces
become headings), look up Codex entries case-insensitively, and keep
leading body lines that lack a caret. Add civilopediaEntry keys for units,
buildings, and civilizations to the ruleset, with tests for the parser and
the ruleset keys.
@WildWeazel

Copy link
Copy Markdown
Member

Conceptually this looks great. I may have been too general when I said we could rethink the UI. Compatibility with imported content is important, so we want to conform to the original background texture layouts. (That is unless and until we have a system to swap out scenes based on our operating mode without duplicating the whole UI layer, but that's well beyond the scope of this work.) So for now this should "fit" in the original pedia graphics, even if we draw over some of it. For example, I think your left side column could go into the lower right side below the icon, and the search bar in the top margin:
image

@WildWeazel

Copy link
Copy Markdown
Member

BTW we do want to support importing any graphics we need, but that doesn't mean we have to use all the graphics. If you look in the files you'll see there are several variants of this background with different internal sections in the main content area, corresponding to different types/formats of articles (eg. look at a unit vs government vs civ). I wouldn't say we necessarily need to use all of those in the same cases if as long as we have a background that works for us. Which is just to say, we don't need to go as far as copying the exact section breakdown within the articles, just keep it in that main area.

Align the popup to the measured regions of civilopediaBackground.pcx and
load full-size Civilopedia icons from PediaIcons.txt instead of the small
in-game art:

- PediaIcons now exposes the large civilopedia icon for buildings, resources,
  and techs, threaded through GameData/SaveGame, with a lazy fallback.
- Codex icons use the pedia art where available, falling back to the
  TextureLoader crops; add a default placeholder and a black backdrop for
  circular leader heads.
- Lay the popup out on the art's regions (title cut-out, body column, side
  column, close area) instead of generic margins.
@Billytifft

Copy link
Copy Markdown
Contributor Author

BTW we do want to support importing any graphics we need, but that doesn't mean we have to use all the graphics. If you look in the files you'll see there are several variants of this background with different internal sections in the main content area, corresponding to different types/formats of articles (eg. look at a unit vs government vs civ). I wouldn't say we necessarily need to use all of those in the same cases if as long as we have a background that works for us. Which is just to say, we don't need to go as far as copying the exact section breakdown within the articles, just keep it in that main area.

So there are a bunch of different backgrounds, but I have rigged up a commit to use the Art/Civilopedia/civilopediaBackground.pcx.
Screenshot 2026-10-19 at 7 30 36 PM
Screenshot 2026-10-19 at 7 30 46 PM

Let me know your thoughts.

@WildWeazel

Copy link
Copy Markdown
Member

Yeah, exactly. That background should be fine at least for a first pass.

That UI looks good to me but I'll let others weigh in. I haven't had a chance to look at any code yet.

@Billytifft
Billytifft marked this pull request as ready for review October 22, 2026 01:54
@stavrosfa

Copy link
Copy Markdown
Contributor

I haven't looked at the code, but I want to weigh in on the visuals.

I don't mind having a completely new redesigned UI for the civilopedia (or anything really) for the standalone mode, but I would like us to keep the old look for the one that we use the old graphics for, even if it's super hard to navigate, old fashioned, etc. For me it's part of the appeal/nostalgia. We could add to it, like the search bar for example that I see here, keep it in the original style, but not do it half way like this, and half way like that.

That's my take..

@Billytifft

Copy link
Copy Markdown
Contributor Author

Im good with faithfully reproducing the Civilopedia design for the civ3 graphics, but I think we can expand on it. I can also do the faithful reproduction for when using civ3 graphics, and then a different/better design when using the standalone graphics (similar to the my first try on this PR).

@ajhalme

ajhalme commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

I'm not a huge fan of the original's UI, but I agree that it would be nice if we can support the old shapes, as all kinds of mods may have worked with those texture sets.

I think we want different "modes" for engaging with the pedia (and a switch in the INI/Lua/settings):

  1. Classic mode, the old textures and functionality, as they were,
  2. Classic+, with old textures and something like an extra search bar,
  3. Modern, fully reimagined and making use of Godot to the fullest, etc.

I'd once again split out the efforts a bit. There are generally useful bits in this PR, needed for every mode, and we should try and get those in first. If the new, proposed UI goes into its own branch, we can continue designing the modern version independently of the Classic one (and Classic+).

So, how about pushing all the new UI bits out of this PR into something new? Or, alternatively, a new PR with all the non-UI parts from this one?

- Rebuild the popup from the Civ3 pedia art: title bar, history
  arrows, colored name bar, description toggle, A-Z index, and
  section menu.
- Use PediaIcons large and small icons with the classic section order.
- Add a standalone fallback panel at the Civ3 pedia screen's rect.
- Make icon lookups case-insensitive and tolerate PediaIcons blocks
  without an era row number.
- Enable the Civilopedia toolbar button.
Escape was closed locally by the popup before Game.ProcessAction ran,
so the same key press fell through to the quit handling. Let the
central popup check close it instead.
@Billytifft

Copy link
Copy Markdown
Contributor Author

This should complete Classic mode for codex.
Screenshot 2026-11-16 at 7 15 19 PM
This can definitely be spruced up in standalone mode, but future codex phase will pull in the assets from the wiki.
Screenshot 2026-11-16 at 7 54 01 PM

@ajhalme

ajhalme commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Looks great, works great! Using the general background texture as the overall body works wonderfully.

Ideally, we'd have placeholder texture assets in the Assets repo for all the codex/pedia assets fro standalone, but a flat box texture and just not drawing the embellishments works fine.

One thing I would change is to push all the .pcx references from CodexPopup.cs into textures.lua alongside textures.civilopedia_screen. I'd consider rebranding to textures.codex, and then having background, etc. underneath it.

If you look at the other entries in textures.lua you can see how we can tdo exture slicing at load time, so we don't need to piece together pixel perfect texture clippings inside the Codex popup. For example, instead of:

    var backButton = MakeArrowButton(BackSheet, 37, 69, 101, 1, 15, 24, new Vector2(BackLeft, ArrowTop), "Back", GoBack);

You can have in textures.lua something like (untested):

textures.codex = {
      back_button = {
        normal = {
          path = CODEX .. "fwdBackarrows.pcx",
          crop_region = { 0, 37, 15, 24 },
        },
        hover = {
          path = CODEX .. "fwdBackarrows.pcx",
          crop_region = { 0, 69, 15, 24 },
        },
        pressed = {
          path = CODEX .. "fwdBackarrows.pcx",
          crop_region = { 0, 85, 15, 24 },
        },
      },
}

And then all you need in the .cs code is something like:

    TextureLoader.SetButtonTextures(backButton, "codex.back_button");

This makes life easier for whoever wants to have a go at replacing the Codex textures with custom .png files, among other things.

Use textures.codex for the background, name bars, icons, and
buttons. Define button sprite crops with crop_region so custom texture
sets can replace the Civ3 art without editing C#.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants