Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revisionBoth sides next revision | ||
op2_sdk:textdialogbox [2016/03/28 02:16] – vagabond | op2_sdk:textdialogbox [2016/12/28 18:57] – vagabond | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== In Game Text Dialog Box ====== | ====== In Game Text Dialog Box ====== | ||
- | A text dialog | + | The Outpost 2 SDK supports adding custom |
- | Creating | + | Creating |
* Write up the briefing/ | * Write up the briefing/ | ||
* Add a resource script (.rc) to the project detailing the design of the dialog box. | * Add a resource script (.rc) to the project detailing the design of the dialog box. | ||
* Add a resource header file (typically resource.h) to the project providing a link between the resource script file and the rest of the source code. | * Add a resource header file (typically resource.h) to the project providing a link between the resource script file and the rest of the source code. | ||
+ | * Include odasl in your project. | ||
* Add code to the scenario that formats and opens the dialog screen through the windows API. | * Add code to the scenario that formats and opens the dialog screen through the windows API. | ||
Line 14: | Line 15: | ||
Rich Text Format documents include metadata such as font and text color which are not available in text (.txt) format. Depending on the program used to open an RTF, the metadata may be hidden. Microsoft Word and Wordpad will default to showing just the text and the effect of the metadata on the text. Notepad or Notepad++ will show all of the metadata. | Rich Text Format documents include metadata such as font and text color which are not available in text (.txt) format. Depending on the program used to open an RTF, the metadata may be hidden. Microsoft Word and Wordpad will default to showing just the text and the effect of the metadata on the text. Notepad or Notepad++ will show all of the metadata. | ||
- | Outpost 2 uses Arial font size 10 for Campaign Mission Briefing Screens. | + | For campaign mission briefing screens, |
- | **Note: | + | Typically, the RTF file is saved as briefing.rtf and added to the root directory of the scenario' |
+ | |||
+ | **Note:** Although Microsoft Word can create and save RTF documents, it is not recommended. Microsoft Word adds large amounts of metadata to the document that is not necessary for Outpost 2, typically increasing a small amount of text from about 3 kb to about 50 kb. This file size increase will carry into the compiled DLL. | ||
**Example RTF file** | **Example RTF file** | ||
Line 43: | Line 46: | ||
===== Adding a Resource Script (.rc) File ===== | ===== Adding a Resource Script (.rc) File ===== | ||
- | Microsoft Visual Studio will autogenerate | + | Resource script files are text documents describing resources associated with an executable or DLL. These include among other things Version Information, |
+ | |||
+ | To add a resource script file and associated resource header: | ||
+ | |||
+ | - Right click on your project in the solution explorer. | ||
+ | |||
+ | By default resource Scripts | ||
+ | |||
+ | Below is a sample resource script file that provides a dialog box before a scenario is initialized. The dialog box will include the contents of briefing.rtf in a rich text box. | ||
+ | |||
+ | For more information on TEXTINCLUDE, | ||
+ | |||
+ | **Common Pre-processor Directives: | ||
+ | |||
+ | * #ifdef // | ||
+ | * #ifndef // | ||
+ | * #undef // | ||
+ | **Resource Script Sample** | ||
<code cpp> | <code cpp> | ||
// Microsoft Visual C++ generated resource script. | // Microsoft Visual C++ generated resource script. | ||
Line 55: | Line 75: | ||
// Generated from the TEXTINCLUDE 2 resource. | // Generated from the TEXTINCLUDE 2 resource. | ||
// | // | ||
- | #include "afxres.h" | + | #include "winres.h" |
///////////////////////////////////////////////////////////////////////////// | ///////////////////////////////////////////////////////////////////////////// | ||
Line 116: | Line 136: | ||
2 TEXTINCLUDE | 2 TEXTINCLUDE | ||
BEGIN | BEGIN | ||
- | "# | + | "# |
" | " | ||
END | END | ||
Line 203: | Line 223: | ||
===== Resource.h | ===== Resource.h | ||
+ | |||
+ | Once the Resource Script is added, the project will not successfully compile until all required items are defined in the resource header. Visual Studio will automatically create a resource header when the resource script is created. Typically, 5 items are defined in resource script as shown in the sample below, IDR_MISSIONTEXT, | ||
Microsoft Resource Naming and Numbering Conventions can be reviewed here: https:// | Microsoft Resource Naming and Numbering Conventions can be reviewed here: https:// | ||
Line 215: | Line 237: | ||
|IDS|String resource|101 through 0x7FFF| | |IDS|String resource|101 through 0x7FFF| | ||
+ | **Note:** //0x prefix on a number indicates it is in hexadecimal form.// | ||
+ | **Resource Header Example** | ||
<code cpp> | <code cpp> | ||
// | // | ||
Line 238: | Line 262: | ||
#endif | #endif | ||
+ | </ | ||
+ | |||
+ | ===== Creating the Dialog Box in Code ===== | ||
+ | |||
+ | Once the resource script and resource header have been included, the briefing screen must be initialized from the code. You will also have to include the Sierra library odasl in your project to ensure the dialog is formatted similar to other Outpost 2 menus. | ||
+ | |||
+ | - Add odasl.h and odasl.lib to your project. Typically, files are placed in a subfolder/ | ||
+ | - Create a reference to the DLL instance from DllMain (HINSTANCE hInst). | ||
+ | - Add code to initialize and open the window. Typically this code is placed in it's own cpp file named briefing.cpp. | ||
+ | - Call code to initialize the window from '' | ||
+ | |||
+ | **Defining a handle to the DLL instance from DllMain:** | ||
+ | |||
+ | **DllMain.cpp** | ||
+ | <code cpp> | ||
+ | #define WIN32_LEAN_AND_MEAN | ||
+ | #include < | ||
+ | |||
+ | // Used by the scenario briefing screen. | ||
+ | HINSTANCE hInst; | ||
+ | |||
+ | BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) | ||
+ | { | ||
+ | if (fdwReason == DLL_PROCESS_ATTACH) | ||
+ | { | ||
+ | DisableThreadLibraryCalls(hinstDLL); | ||
+ | hInst = hinstDLL; | ||
+ | } | ||
+ | |||
+ | return TRUE; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | **Code used to initialize window. This also may be written without a header file.** | ||
+ | |||
+ | **briefing.h** | ||
+ | <code cpp> | ||
+ | #pragma once | ||
+ | |||
+ | #define WIN32_LEAN_AND_MEAN | ||
+ | #include < | ||
+ | |||
+ | #include < | ||
+ | #include " | ||
+ | #include " | ||
+ | |||
+ | void ShowBriefing(); | ||
+ | LRESULT CALLBACK DialogProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); | ||
+ | </ | ||
+ | |||
+ | **briefing.cpp** | ||
+ | <code cpp> | ||
+ | #include " | ||
+ | |||
+ | extern HINSTANCE hInst; | ||
+ | |||
+ | // Briefing source code is pulled from Plymouth Cold War Scenario and was written by BlackBox. | ||
+ | void ShowBriefing() | ||
+ | { | ||
+ | // OP2 turns off the skinning before the game loads. | ||
+ | // We have to re-enable it (otherwise the briefing box will look ugly). | ||
+ | wplEnable(); | ||
+ | // Show the dialog box, using the shell window as the parent | ||
+ | HWND shellWnd = FindWindow(" | ||
+ | DialogBoxParam(hInst, | ||
+ | // Turn off the skinning again (probably not needed but a good idea to do it anyway) | ||
+ | wplDisable(); | ||
+ | } | ||
+ | |||
+ | LRESULT CALLBACK DialogProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) | ||
+ | { | ||
+ | HRSRC txtRes = NULL; | ||
+ | HWND richEdit = NULL; | ||
+ | switch (msg) | ||
+ | { | ||
+ | case WM_INITDIALOG: | ||
+ | // Make the BG black in the rich edit box | ||
+ | richEdit = GetDlgItem(hWnd, | ||
+ | SendMessage(richEdit, | ||
+ | |||
+ | // Find the text resource | ||
+ | txtRes = FindResource(hInst, | ||
+ | if (txtRes) | ||
+ | { | ||
+ | // Load it | ||
+ | HGLOBAL resHdl = LoadResource(hInst, | ||
+ | if (resHdl) | ||
+ | { | ||
+ | // Lock it and set the text | ||
+ | char *briefing = (char*)LockResource(resHdl); | ||
+ | if (briefing) | ||
+ | { | ||
+ | SetDlgItemText(hWnd, | ||
+ | return TRUE; | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | SetDlgItemText(hWnd, | ||
+ | return TRUE; | ||
+ | case WM_COMMAND: | ||
+ | if (wParam == IDOK) | ||
+ | { | ||
+ | EndDialog(hWnd, | ||
+ | return TRUE; | ||
+ | } | ||
+ | return FALSE; | ||
+ | } | ||
+ | return FALSE; | ||
+ | } | ||
</ | </ | ||
Line 244: | Line 377: | ||
- //Go Back to [[op2_sdk: | - //Go Back to [[op2_sdk: | ||
- //Go Back to [[outpost_2: | - //Go Back to [[outpost_2: | ||
- | - //Go Back to [[http:// | + | - //Go Back to [[http:// |