OpenTTDDevBlackBook/Window/TextEdit

From OpenTTD
(Difference between revisions)
Jump to: navigation, search
(I was told by frosch that the one-textbox-per-window bug has been fixed.)
Line 1: Line 1:
 
{{DevDoc}}
 
{{DevDoc}}
 +
{{Outdated}}
  
Only one edit box per window is allowed. The way users interact with edit boxes is influenced by the [[OpenTTDDevBlackBook/Window/WidgetFocus|widget focus system]]. This page describes what modifications that are necessary to add a text box to a window that do not have it yet.  
+
 
 +
The way users interact with edit boxes is influenced by the [[OpenTTDDevBlackBook/Window/WidgetFocus|widget focus system]]. This page describes what modifications that are necessary to add a text box to a window that do not have it yet.  
  
 
== Checklist for adding a text box to a window ==
 
== Checklist for adding a text box to a window ==
 
<!--* Does the window already have a text box? Only one edit box can exist per window. If you need more, you have to either fix that limitation or use the query string window.-->
 
 
  
 
* Add a constant for the widget index eg. OP_WIDGET_NUM_PIZZAS_EDIT (OP = Order Pizza window). Follow the naming pattern of the other widgets in the same window.
 
* Add a constant for the widget index eg. OP_WIDGET_NUM_PIZZAS_EDIT (OP = Order Pizza window). Follow the naming pattern of the other widgets in the same window.

Revision as of 13:43, 5 August 2013

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

Outdated content.png

Out of Date
This article or section is outdated. Some of its content may no longer be accurate due to changes in the latest release. Please update this article.


The way users interact with edit boxes is influenced by the widget focus system. This page describes what modifications that are necessary to add a text box to a window that do not have it yet.

Checklist for adding a text box to a window

  • Add a constant for the widget index eg. OP_WIDGET_NUM_PIZZAS_EDIT (OP = Order Pizza window). Follow the naming pattern of the other widgets in the same window.


  • Add an edit box to the nested widget array:
NWidget(WWT_EDITBOX, COLOUR_WHITE, OP_WIDGET_NUM_PIZZAS_EDIT), 
  SetDataTip(STR_ORDER_PIZZA_NUM_PIZZAS_OSKTITLE, STR_ORDER_PIZZA_NUM_PIZZAS_TOOLTIP),

(should be on one line, but has been broken up on two lines here on the wiki to avoid horizontal scrolling)


  • Make the window class derive from QueryStringBaseWindow instead of just Window.
OrderPizzaWindow(const WindowDesc *desc, WindowNumber number) : 
  QueryStringBaseWindow(MAX_NUM_PIZZA_STRING_LENGTH)

(should be on one line)


  • In your constructor you must do:
InitializeTextBuffer(&this->text, this->edit_str_buf, 
  this->edit_str_size, MAX_NUM_PIZZA_STRING_LENGTH);

(should be on one line)

If you want to focus the edit box by default when the window opens, call the SetFocusedWidget function:

this->SetFocusedWidget(OP_WIDGET_NUM_PIZZAS_EDIT);


  • Make sure that OnMouseLoop is implemented and make it call HandleEditBox. If you don't do this, the carret will not flash when the edit box is focused.
virtual void OnMouseLoop()
{
  this->HandleEditBox(OP_WIDGET_NUM_PIZZAS_EDIT);
}


  • In OnPaint call this->DrawEditBox(OP_WIDGET_NUM_PIZZAS_EDIT) after making sure that the window is not shaded (this->IsShaded()).


  • Make sure that OnKeyPress is implemented and make it call this->HandleEditBoxInput(..). The HandleEditBoxKey function has some interesting return values that are worth to check out. It will tell you if the enter/escape button was pressed or if no input was processed because the edit box was not in global focus.
virtual EventState OnKeyPress(uint16 key, uint16 keycode)
{
  EventState state = ES_NOT_HANDLED;
  this->HandleEditBoxKey(OP_WIDGET_NUM_PIZZAS_EDIT, key, keycode, state);
  return state;
}

Related articles

Understanding the widget focus system

Personal tools