OpenTTDDevBlackBook/Window/UseWindows

From OpenTTD
Jump to: navigation, search
HAL (Hardware Abstraction Layer)

Audio
Music
Graphic

Window System

Using the Window System
Colour codes that exist in OpenTTD
Adding a text box
Understanding the widget focus system

Settings

Add a setting
Add a squirrel function
Do a savegame BUMP

The Map / Scenario

Understanding the Dynamic Landscape Array
Understanding the SaveGame Handler
HOWTO - Create good Scenarios
HOWTO - Add New Town Name Generators

The actual simulation

Vehicles
Using Orders
Pathfinding
Ratings
Train Acceleration

Language and Strings

Format of langfiles
Using OpenTTD Strings
List of Special Strings

Multiplayer

The Core Interface

Starting a Server
Connecting to a Server
Using the list of LAN/Internet Games

The OpenTTD TCP Protocol
The OpenTTD UDP Protocol
HOWTO - Debug desyncs

Ingame Console

The Console Window
Using Console Scripting
HOWTO - Add Functions/Commands to the Console
HOWTO - Add Variables to the Console
HOWTO - Direct Variable Access using ICONSOLE_VAR_POINTER
OpenTTD Console Commands
OpenTTD Console Variables
Development History

A window is drawn on the game screen at every WE_PAINT window event.

Contents

Opening a window

Creating a new struct of a window opens a new window. It should be provided with a doxygen comment explaining the function.

Example:
/**
 * Opens a new instance of a MyNew window.
 * @param void Any parameters required by window
 */
void ShowMyNewWindow(void)
{
	DeleteWindowByClass(window class);
	new MyNewWindow(void);
}

Describing a window

Set up a WindowDesc with the name you gave this->CreateNestedTree() and this->FinishInitNested().

Syntax:
/** Window description for my new window. */
static const WindowDesc _mywindow_desc(
	window positioning,
        default width,
        default height,
        window class,
        parent window class,
        window flags
        widget parts,
        lengthof(widget parts)
);

You will also need a struct describing You can find plenty of examples in the source code, look in a *_gui.cpp file.

Window positioning

The window positioning is one of the values of the WindowPosition enum defined in src/window_gui.h.

Window classes

A window class is a unique number that represents a (set of) windows, for example a window that displays a town has class WC_TOWN_VIEW. To differentiate which town is displayed by an actual window, the latter has an additional window number.

The list of available window classes is defined by the WindowClass enum, in src/window_type.h.

Setting up widgets

Syntax:
static const NWidgetPart _nested_mywindow_widgets[] = {
        NWidget(nwid),
                 NWidget(wwt, colour, wid), SetDataTip(STR_NULL, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
        EndContainer(),
};
Example:
static const NWidgetPart _nested_mywindow_widgets[] = {
	NWidget(NWID_HORIZONTAL),
		NWidget(WWT_TEXT, COLOUR_MAUVE), SetDataTip(STR_NEWGRF_SETTINGS_SELECT_PRESET, STR_NULL),
				SetPadding(0, WD_FRAMETEXT_RIGHT, 0, 0),
		NWidget(WWT_DROPDOWN, COLOUR_YELLOW, WID_NS_PRESET_LIST), SetFill(1, 0), SetResize(1, 0),
				SetDataTip(STR_JUST_STRING, STR_NEWGRF_SETTINGS_PRESET_LIST_TOOLTIP),
	EndContainer(),
};

Widget types

WWT_EMPTY
Klipper.png

To Do
-Include an explanation.

WWT_PANEL
A simple depressed panel.
WWT_INSET
A depressed panel, most commonly used as a combo box text area.
WWT_IMGBTN
Image button.
WWT_IMGBTN_2
Image button. Image changes when button is pressed.
WWT_TEXTBTN
Text button.
WWT_TEXTBTN_2
Text button. Text changes when button is pressed.
WWT_LABEL
A centered label.
WWT_MATRIX
Klipper.png

To Do
-Include an explanation.

WWT_SCROLLBAR
Klipper.png

To Do
-Include an explanation.

WWT_FRAME
Klipper.png

To Do
-Include an explanation.

WWT_CAPTION
Klipper.png

To Do
-Include an explanation.

WWT_HSCROLLBAR
Klipper.png

To Do
-Include an explanation.

WWT_STICKYBOX
The button for stickying a window.
WWT_SCROLL2BAR
Klipper.png

To Do
-Include an explanation.

WWT_RESIZEBOX
The button for resizing a window.
WWT_CLOSEBOX
The button for closing a window.
WWT_PUSHBTN
Klipper.png

To Do
-Include an explanation.

WWT_PUSHTXTBTN
Klipper.png

To Do
-Include an explanation.

WWT_PUSHIMGBTN
Klipper.png

To Do
-Include an explanation.

Colours

For a list of available colors, see OpenTTDDevBlackBook/Window/Colours.

Maintaining the window

Define what to do with the window in a struct, with a constructor

Example:
struct MyNewWindow {
        MyNewWindow()
        {
        }
        ....
}
Personal tools