1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

[TOT] [TOTPP] Text Library

Discussion in 'Civ2 - Scenario Creation' started by Prof. Garfield, Sep 19, 2019.

  1. Prof. Garfield

    Prof. Garfield Deity Supporter

    Joined:
    Mar 6, 2004
    Messages:
    2,648
    Location:
    Ontario
    The Text Library provides code for displaying text, making menus, and other similar things.

    Very big thanks to @Knighttime for providing a table with the length of the Civ II characters and also his function convertTableToColumnText (also provided by this library), which saved me the trouble of writing similar code.

    Comments, questions, bug reports (I only did minimal testing), bug fixes, and contributions are welcome. Feature requests are also welcome. If there's something that you want/need, let me know. I fully expect to do more work on this at some point anyway.

    Feature Highlights:

    The number of lines of text are counted* and dialog boxes and menus are split into multiple pages automatically if they are too long. Default number of lines is 12, but text.setLinesPerWindow can change this. The character sequence %PAGEBREAK will also split a display text into two windows manually.

    *At the moment, lines of text only counts the number of newline characters, so it is an unfinished job to count the 'size' of characters and figure out how many lines are actually used.

    The character sequences %STRING1 to %STRING9 allow text.substitute to substitute values for %STRING# at the time when the text is used. This will allow the full text of a message to be defined in a text alias, and have the key values substituted at the time the message is displayed.

    A menu can be generated from a table of strings. The menu will show the values of the table, and return the key of the value chosen. If there are a lot of choices, the menu is automatically split into several pages, with options to navigate between the pages instead of making a selection.

    The function text.displayNextOpportunity allows a message to be created and stored in state, but not shown until a particular tribe (or tribes) is the active player (using, for example, an after production (pseudo) event and text.displayAccumulatedMessages).

    There is an archive function, which allows players to "open the archive" and view messages previously displayed. These messages can be 'hidden' (so the player must select "show hidden messages" to see them), or purged (permanently deleted) so that the archive is not cluttered.

    The function text.simpleTabulation converts a "data set" of the form myDataTable[m][n] into a formatted table where the mth row and nth column have the value myDataTable[m][n]. If the table is large, there are options to navigate back and forth between pages. Thanks again to Knighttime for making this possible.

    There is a full list of functions near the top of the module, and some more explanation at each function.

    Notes:

    I separated the table that has the character sizes into its own file, to make it easier to change for anyone who doesn't have the standard font set (this may include @TheNamelessOne, who I believe also runs Civ II on Linux with Wine). I will at some point probably make a relatively easy way to customize font size. Please post if you need it, but remember that even the correct character sizes won't give perfect formatting due to the limitations of Civ II and Lua. Knighttime also provided me with a sample event file for how to use his convertTableToColumnText function. That file is included here (but renamed so as not to accidentally delete someone's events.lua file)

    Most of these functions have arguments that have a default value if left as nil, expressed in the function "contract" as argX=1, for example. Let me know if this is confusing, and I'll change the documentation. Some of these values exist because of the next note.

    For Programmers: I employ tail calls/recursion in many of these functions. https://www.lua.org/pil/6.3.html I talk about recursion only very briefly in my Lua lessons, and I don't think I talk about tail recursion at all. It saves the trouble of of writing complicated loops for things like menus with multiple pages. Tail calls and recursion are not unique to Lua, so you can probably just do a search to find out more.
     

    Attached Files:

  2. Prof. Garfield

    Prof. Garfield Deity Supporter

    Joined:
    Mar 6, 2004
    Messages:
    2,648
    Location:
    Ontario
    This has been updated in Over the Reich. Here's the latest version.

    Tip: When using menu tables, it sometimes helps to "offset" options by a fixed number. For example, suppose you are selecting unit types, you might have a menu like this:

    menuTable[i+2]=civ.getUnitType(i).name

    This way, you can have unit type 0 without breaking anything (menuTable indices start at 1), and just subtract off 2 after the selection is made to get back to the unit type index.
     

    Attached Files:

    Last edited: Dec 28, 2019

Share This Page