Help declaring string and showing a new gui
Moderator: OpenTTD Developers
-
- Traffic Manager
- Posts: 141
- Joined: 30 Apr 2007 10:26
Help declaring string and showing a new gui
Im trying to get into coding for ottd,
starting off with a simple gui 'hello world'
I have been investigating but dont want to make a mess of it.
Any help in the basics would be grand. I understand the use of {} ; etc
starting off with a simple gui 'hello world'
I have been investigating but dont want to make a mess of it.
Any help in the basics would be grand. I understand the use of {} ; etc
- Digitalfox
- Chief Executive
- Posts: 710
- Joined: 28 Oct 2004 04:42
- Location: Catch the Fox if you can...
- belugas
- OpenTTD Developer
- Posts: 1507
- Joined: 05 Apr 2005 01:48
- Location: Deep down the deepest blue
- Contact:
The GUI system of OpenTTD is not exactly the best thing to start with ...
You might try to understand something quite simpler
You might try to understand something quite simpler
If you are not ready to work a bit for your ideas, it means they don't count much for you.
OpenTTD and Realism? Well... Here are a few thoughs on the matter.
He he he he
------------------------------------------------------------
Music from the Bloody Time Zones
OpenTTD and Realism? Well... Here are a few thoughs on the matter.
He he he he
------------------------------------------------------------
Music from the Bloody Time Zones
-
- Traffic Manager
- Posts: 141
- Joined: 30 Apr 2007 10:26
I have made it show my gui, eventually but i cant find how to add another option on to the end of say the options or finances click and hold menu button.
I changed one of the transparency options to show my menu instead but it still shows the text for transparency ("Transparent station names") and i cant add a new line to the menu, where are they defined?
Thanks for your help
I changed one of the transparency options to show my menu instead but it still shows the text for transparency ("Transparent station names") and i cant add a new line to the menu, where are they defined?
Thanks for your help
- belugas
- OpenTTD Developer
- Posts: 1507
- Joined: 05 Apr 2005 01:48
- Location: Deep down the deepest blue
- Contact:
Maybe a diff/patch to see what you've done so far?
That would certainly help...
That would certainly help...
If you are not ready to work a bit for your ideas, it means they don't count much for you.
OpenTTD and Realism? Well... Here are a few thoughs on the matter.
He he he he
------------------------------------------------------------
Music from the Bloody Time Zones
OpenTTD and Realism? Well... Here are a few thoughs on the matter.
He he he he
------------------------------------------------------------
Music from the Bloody Time Zones
they are widgets
is very simple to add them
for example, the transparency gui code (which is my work):
some includes needed by the gui
the widgets enum, instead of use numbers, we can use strings, easy to remembera function which does something, this toggles the value of a bit and plays a sound
the event switch function, which does the right action depends on what event is triggered
the first three widgets of the gui, X, title and pinthe button widgets
{ TYPE, RESIZABLE, COLOR, x_start, x_end, y_start, y_end, sprite (or string, depending on TYPE), tool description text},size and flags
creates the gui (if i'm not wrong) 
is very simple to add them
for example, the transparency gui code (which is my work):
Code: Select all
#include "stdafx.h"
#include "openttd.h"
#include "table/sprites.h"
#include "table/strings.h"
#include "functions.h"
#include "window.h"
#include "gui.h"
#include "viewport.h"
#include "gfx.h"
#include "sound.h"
#include "variables.h"
Code: Select all
enum TransparencyToolbarWidgets{
/* Widgets not toggled when pressing the X key */
TTW_WIDGET_SIGNS = 3, ///< Make signs background transparent
/* Widgets toggled when pressing the X key */
TTW_WIDGET_TREES, ///< Make trees transparent
TTW_WIDGET_HOUSES, ///< Make houses transparent
TTW_WIDGET_INDUSTRIES, ///< Make Industries transparent
TTW_WIDGET_BUILDINGS, ///< Make player buildings and structures transparent
TTW_WIDGET_BRIDGES, ///< Make bridges transparent
TTW_WIDGET_STRUCTURES, ///< Make unmovable structures transparent
};
Code: Select all
/** Toggle the bits of the transparencies variable
* when clicking on a widget, and play a sound
* @param widget been clicked.
*/
static void Transparent_Click(byte widget)
{
TOGGLEBIT(_transparent_opt, widget);
SndPlayFx(SND_15_BEEP);
}
Code: Select all
static void TransparencyToolbWndProc(Window *w, WindowEvent *e)
{
switch (e->event) {
case WE_PAINT:
/* must be sure that the widgets show the transparency variable changes
* also when we use shortcuts */
for (uint i = TTW_WIDGET_SIGNS; i < TTW_WIDGET_STRUCTURES; i++) {
SetWindowWidgetLoweredState(w, i, HASBIT(_transparent_opt, i - TTW_WIDGET_SIGNS));
}
DrawWindowWidgets(w);
break;
case WE_CLICK:
if (e->we.click.widget >= TTW_WIDGET_SIGNS) {
Transparent_Click(e->we.click.widget - TTW_WIDGET_SIGNS);
MarkWholeScreenDirty();
}
break;
}
}
Code: Select all
static const Widget _transparency_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, RESIZE_NONE, 7, 11, 162, 0, 13, STR_TRANSPARENCY_TOOLB, STR_018C_WINDOW_TITLE_DRAG_THIS},
{WWT_STICKYBOX, RESIZE_NONE, 7, 163, 174, 0, 13, STR_NULL, STR_STICKY_BUTTON},
Code: Select all
/* transparency widgets:
* transparent signs, trees, houses, industries, player's buildings, bridges and unmovable structures */
{ WWT_IMGBTN, RESIZE_NONE, 7, 0, 21, 14, 35, SPR_IMG_PLACE_SIGN, STR_TRANSPARENT_SIGNS_DESC},
{ WWT_IMGBTN, RESIZE_NONE, 7, 22, 43, 14, 35, SPR_IMG_PLANTTREES, STR_TRANSPARENT_TREES_DESC},
{ WWT_IMGBTN, RESIZE_NONE, 7, 44, 65, 14, 35, SPR_IMG_TOWN, STR_TRANSPARENT_HOUSES_DESC},
{ WWT_IMGBTN, RESIZE_NONE, 7, 66, 87, 14, 35, SPR_IMG_INDUSTRY, STR_TRANSPARENT_INDUSTRIES_DESC},
{ WWT_IMGBTN, RESIZE_NONE, 7, 88, 109, 14, 35, SPR_IMG_COMPANY_LIST, STR_TRANSPARENT_BUILDINGS_DESC},
{ WWT_IMGBTN, RESIZE_NONE, 7, 110, 152, 14, 35, SPR_IMG_BRIDGE, STR_TRANSPARENT_BRIDGES_DESC},
{ WWT_IMGBTN, RESIZE_NONE, 7, 153, 174, 14, 35, SPR_IMG_TRANSMITTER, STR_TRANSPARENT_STRUCTURES_DESC},
{ WIDGETS_END},
};
{ TYPE, RESIZABLE, COLOR, x_start, x_end, y_start, y_end, sprite (or string, depending on TYPE), tool description text},
Code: Select all
static const WindowDesc _transparency_desc = {
WDP_ALIGN_TBR, 58+36, 175, 36,
WC_TRANSPARENCY_TOOLBAR, WC_NONE,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
_transparency_widgets,
TransparencyToolbWndProc
};
Code: Select all
void ShowTransparencyToolbar(void)
{
AllocateWindowDescFront(&_transparency_desc, 0);
}

-
- Traffic Manager
- Posts: 141
- Joined: 30 Apr 2007 10:26
-
- Traffic Manager
- Posts: 141
- Joined: 30 Apr 2007 10:26
Patch as requested.belugas wrote:Maybe a diff/patch to see what you've done so far?
That would certainly help...
- Attachments
-
- Train_Research.patch
- 'Hello World' Trials of Ottd coding
- (279.7 KiB) Downloaded 126 times
- athanasios
- Tycoon
- Posts: 3138
- Joined: 23 Jun 2005 00:09
- Contact:
And some screenshots please?belugas wrote:Maybe a diff/patch to see what you've done so far?
That would certainly help...
http://members.fortunecity.com/gamesart
"If no one is a fool I am also a fool." -The TTD maniac.
I prefer to be contacted through PMs. Thanks.
"If no one is a fool I am also a fool." -The TTD maniac.
I prefer to be contacted through PMs. Thanks.
-
- Traffic Manager
- Posts: 141
- Joined: 30 Apr 2007 10:26
Ive been playing with this code for a bit and have come up stumped.
This is my entire trainrnd_gui.cpp file. to be honest im not entirely sure i understand what everything does and some of the syntax for C++.
I grew up with VB so its a bit of a learning curve.
I get the following compile errors.
I think i understand the error 'cant convert...' but not sure how to go about fixing it. If im right i need to create a new rrailvehiclefo object and < it to the railvehicleinfo for engine T but im stuck
as for the second error i have no clue but assume its to do with previous error.
the 3rd error i also cant figure out, i put the show gui bit on the end of the options menu after the transparency options. I get identifier not found.
Any help would be grand, i think i need a C++ book/course!
This is my entire trainrnd_gui.cpp file. to be honest im not entirely sure i understand what everything does and some of the syntax for C++.
I grew up with VB so its a bit of a learning curve.
Code: Select all
/* $Id: trainrnd_gui.cpp 9551 2007-04-03 16:12:28Z belugas $ */
/** @file trainrnd_gui.cpp */
#include "stdafx.h"
#include "openttd.h"
#include "table/sprites.h"
#include "table/strings.h"
#include "functions.h"
#include "window.h"
#include "gui.h"
#include "viewport.h"
#include "gfx.h"
#include "sound.h"
#include "variables.h"
//DoghouseDean's Section
static void TrainRnDWindowProc(Window *w, WindowEvent *e)
{
switch (e->event) {
case WE_CREATE: // Set up window counter and start position of scroller
WP(w, scroller_d).counter = 0;
WP(w, scroller_d).height = w->height - 40;
break;
case WE_PAINT: {
DrawWindowWidgets(w);
DrawStringCentered(210, 17, STR_5808_TRAIN_RESEARCH, 0);
DrawStringCentered(210, 45, STR_HELLO_WORLD, 0);
} break;
case WE_MOUSELOOP: // Timer to scroll the text and adjust the new top
if (WP(w, scroller_d).counter++ % 3 == 0) {
WP(w, scroller_d).height--;
SetWindowDirty(w);
}
break;
}
}
static const Widget _Shw_TrainRnD_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 419, 0, 13, STR_5808_TRAIN_RESEARCH, STR_NULL},
{ WWT_PANEL, RESIZE_NONE, 14, 0, 419, 14, 271, 0x0, STR_NULL},
{ WWT_FRAME, RESIZE_NONE, 14, 5, 414, 40, 245, STR_NULL, STR_NULL},
{ WWT_TEXT, RESIZE_NONE, 7, 7, 250, 15, 45, STR_HELLO_WORLD, STR_NULL},
{ WIDGETS_END},
};
static const WindowDesc _Shw_TrainRnD_desc = {
WDP_AUTO, WDP_AUTO, 420, 272,
WC_GAME_OPTIONS, WC_NONE,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
_Shw_TrainRnD_widgets,
TrainRnDWindowProc
};
void ShowTrainRnDWindow()
{
//DeleteWindowById(WC_GAME_OPTIONS, 0);
AllocateWindowDesc(&_Shw_TrainRnD_desc);
};
// End of DoghouseDean's section
void IncreaseHorsePower(uint16 Hp, uint T) //Increase Horse power Hp for engine T
{
RailVehicleInfo(T).pow_wag_power = Hp;
};
Code: Select all
2>c:\users\dean.pndaly\desktop\ottdcode2\src\trainrnd_gui.cpp(71) : error C2440: '<function-style-cast>' : cannot convert from 'uint' to 'RailVehicleInfo'
2> No constructor could take the source type, or constructor overload resolution was ambiguous
2>c:\users\dean.pndaly\desktop\ottdcode2\src\trainrnd_gui.cpp(71) : error C2228: left of '.pow_wag_power' must have class/struct/union
2>main_gui.cpp
2>c:\users\dean.pndaly\desktop\ottdcode2\src\main_gui.cpp(182) : error C3861: 'ShowTrainRnDWindow': identifier not found
as for the second error i have no clue but assume its to do with previous error.
the 3rd error i also cant figure out, i put the show gui bit on the end of the options menu after the transparency options. I get identifier not found.
Code: Select all
...
case 12: TOGGLEBIT(_transparent_opt, TO_SIGNS); break;
case 13: ShowTrainRnDWindow(); break;
...
-
- Traffic Manager
- Posts: 141
- Joined: 30 Apr 2007 10:26
Who is online
Users browsing this forum: No registered users and 20 guests