src/signs_gui.cpp
author rubidium
Tue, 20 May 2008 22:05:25 +0000
branch0.6
changeset 10659 2d983c15a049
parent 8760 ce0891c412ce
child 9233 4daa9bb8dbf7
permissions -rw-r--r--
(svn r13203) [0.6] -Prepare: for 0.6.1-RC2.
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6573
diff changeset
     3
/** @file signs_gui.cpp */
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6573
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1575
diff changeset
     6
#include "openttd.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     7
#include "gui.h"
8603
88c5ce6a5215 (svn r11668) -Codechange: more refactoring aimed at reducing compile time and making it more logic where function definitions can be found.
rubidium
parents: 8602
diff changeset
     8
#include "textbuf_gui.h"
88c5ce6a5215 (svn r11668) -Codechange: more refactoring aimed at reducing compile time and making it more logic where function definitions can be found.
rubidium
parents: 8602
diff changeset
     9
#include "window_gui.h"
8750
fdd6054e7bae (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents: 8720
diff changeset
    10
#include "player_gui.h"
1575
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
    11
#include "signs.h"
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
    12
#include "debug.h"
2159
3b634157c3b2 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2135
diff changeset
    13
#include "variables.h"
8612
6414fc21c2f3 (svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents: 8610
diff changeset
    14
#include "command_func.h"
8610
17cc343a23dd (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents: 8603
diff changeset
    15
#include "strings_func.h"
8626
440dfcd14c4a (svn r11691) -Codechange: move+rename helpers.hpp and only include it when it is really needed.
rubidium
parents: 8617
diff changeset
    16
#include "core/alloc_func.hpp"
8627
448ebf3a8291 (svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents: 8626
diff changeset
    17
#include "window_func.h"
8635
3bbb6f87fced (svn r11701) -Codechange: removal unnecessary inclusions of map.h (and split map.h).
rubidium
parents: 8627
diff changeset
    18
#include "map_func.h"
8720
4e60c30e2006 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents: 8635
diff changeset
    19
#include "gfx_func.h"
4e60c30e2006 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents: 8635
diff changeset
    20
#include "viewport_func.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    21
8760
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8754
diff changeset
    22
#include "table/strings.h"
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8754
diff changeset
    23
#include "table/sprites.h"
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8754
diff changeset
    24
4353
2b941f2c325c (svn r6054) Change the sign sorter in a similar way as the other sorters: Remember a list of pointers to signs instead of a list of SignIDs - This removes a layer of indirection
tron
parents: 4349
diff changeset
    25
static const Sign **_sign_sort;
2b941f2c325c (svn r6054) Change the sign sorter in a similar way as the other sorters: Remember a list of pointers to signs instead of a list of SignIDs - This removes a layer of indirection
tron
parents: 4349
diff changeset
    26
static uint _num_sign_sort;
1575
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
    27
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
    28
static char _bufcache[64];
4353
2b941f2c325c (svn r6054) Change the sign sorter in a similar way as the other sorters: Remember a list of pointers to signs instead of a list of SignIDs - This removes a layer of indirection
tron
parents: 4349
diff changeset
    29
static const Sign *_last_sign;
1575
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
    30
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
    31
static int CDECL SignNameSorter(const void *a, const void *b)
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
    32
{
4353
2b941f2c325c (svn r6054) Change the sign sorter in a similar way as the other sorters: Remember a list of pointers to signs instead of a list of SignIDs - This removes a layer of indirection
tron
parents: 4349
diff changeset
    33
	const Sign *sign0 = *(const Sign**)a;
2b941f2c325c (svn r6054) Change the sign sorter in a similar way as the other sorters: Remember a list of pointers to signs instead of a list of SignIDs - This removes a layer of indirection
tron
parents: 4349
diff changeset
    34
	const Sign *sign1 = *(const Sign**)b;
1575
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
    35
	char buf1[64];
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
    36
8754
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
    37
	SetDParam(0, sign0->index);
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
    38
	GetString(buf1, STR_SIGN_NAME, lastof(buf1));
1575
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
    39
4353
2b941f2c325c (svn r6054) Change the sign sorter in a similar way as the other sorters: Remember a list of pointers to signs instead of a list of SignIDs - This removes a layer of indirection
tron
parents: 4349
diff changeset
    40
	if (sign1 != _last_sign) {
2b941f2c325c (svn r6054) Change the sign sorter in a similar way as the other sorters: Remember a list of pointers to signs instead of a list of SignIDs - This removes a layer of indirection
tron
parents: 4349
diff changeset
    41
		_last_sign = sign1;
8754
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
    42
		SetDParam(0, sign1->index);
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
    43
		GetString(_bufcache, STR_SIGN_NAME, lastof(_bufcache));
1575
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
    44
	}
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
    45
3801
866d8cb1d707 (svn r4809) Codechange : Merged two loops in only one.
belugas
parents: 3733
diff changeset
    46
	return strcmp(buf1, _bufcache); // sort by name
1575
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
    47
}
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
    48
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6144
diff changeset
    49
static void GlobalSortSignList()
1575
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
    50
{
4349
2fc39ff2626e (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
    51
	const Sign *si;
4353
2b941f2c325c (svn r6054) Change the sign sorter in a similar way as the other sorters: Remember a list of pointers to signs instead of a list of SignIDs - This removes a layer of indirection
tron
parents: 4349
diff changeset
    52
	uint n = 0;
1575
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
    53
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
    54
	/* Create array for sorting */
5860
7fdc9b423ba1 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5852
diff changeset
    55
	_sign_sort = ReallocT(_sign_sort, GetMaxSignIndex() + 1);
1575
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
    56
4353
2b941f2c325c (svn r6054) Change the sign sorter in a similar way as the other sorters: Remember a list of pointers to signs instead of a list of SignIDs - This removes a layer of indirection
tron
parents: 4349
diff changeset
    57
	FOR_ALL_SIGNS(si) _sign_sort[n++] = si;
2b941f2c325c (svn r6054) Change the sign sorter in a similar way as the other sorters: Remember a list of pointers to signs instead of a list of SignIDs - This removes a layer of indirection
tron
parents: 4349
diff changeset
    58
	_num_sign_sort = n;
2b941f2c325c (svn r6054) Change the sign sorter in a similar way as the other sorters: Remember a list of pointers to signs instead of a list of SignIDs - This removes a layer of indirection
tron
parents: 4349
diff changeset
    59
2b941f2c325c (svn r6054) Change the sign sorter in a similar way as the other sorters: Remember a list of pointers to signs instead of a list of SignIDs - This removes a layer of indirection
tron
parents: 4349
diff changeset
    60
	qsort((void*)_sign_sort, n, sizeof(_sign_sort[0]), SignNameSorter);
1575
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
    61
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
    62
	_sign_sort_dirty = false;
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
    63
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5291
diff changeset
    64
	DEBUG(misc, 3, "Resorting global signs list");
1575
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
    65
}
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
    66
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
    67
static void SignListWndProc(Window *w, WindowEvent *e)
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
    68
{
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
    69
	switch (e->event) {
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
    70
	case WE_PAINT: {
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
    71
		int y = 16; // offset from top of widget
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
    72
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
    73
		if (_sign_sort_dirty)
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
    74
			GlobalSortSignList();
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
    75
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
    76
		SetVScrollCount(w, _num_sign_sort);
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
    77
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
    78
		SetDParam(0, w->vscroll.count);
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
    79
		DrawWindowWidgets(w);
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
    80
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
    81
		/* No signs? */
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
    82
		if (w->vscroll.count == 0) {
8320
6ffad7a5d242 (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7837
diff changeset
    83
			DrawString(2, y, STR_304A_NONE, TC_FROMSTRING);
1575
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
    84
			return;
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
    85
		}
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
    86
4349
2fc39ff2626e (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
    87
		{
2135
48fb9f0322cb (svn r2645) Fix (useless)warning in graph_gui and add brackets around HASBIT in an if statement
Darkvater
parents: 2133
diff changeset
    88
			uint16 i;
1575
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
    89
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
    90
			/* Start drawing the signs */
2133
098c9da8292e (svn r2643) Get rid of some unnecessary casts
tron
parents: 2063
diff changeset
    91
			for (i = w->vscroll.pos; i < w->vscroll.cap + w->vscroll.pos && i < w->vscroll.count; i++) {
4353
2b941f2c325c (svn r6054) Change the sign sorter in a similar way as the other sorters: Remember a list of pointers to signs instead of a list of SignIDs - This removes a layer of indirection
tron
parents: 4349
diff changeset
    92
				const Sign *si = _sign_sort[i];
1575
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
    93
4349
2fc39ff2626e (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
    94
				if (si->owner != OWNER_NONE)
2fc39ff2626e (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
    95
					DrawPlayerIcon(si->owner, 4, y + 1);
1575
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
    96
7552
064d734e9900 (svn r10321) -Codechange: refer to sign text by index
peter1138
parents: 6916
diff changeset
    97
				SetDParam(0, si->index);
8320
6ffad7a5d242 (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7837
diff changeset
    98
				DrawString(22, y, STR_SIGN_NAME, TC_YELLOW);
1575
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
    99
				y += 10;
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
   100
			}
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
   101
		}
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
   102
	} break;
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
   103
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
   104
	case WE_CLICK: {
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4444
diff changeset
   105
		switch (e->we.click.widget) {
1575
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
   106
		case 3: {
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4444
diff changeset
   107
			uint32 id_v = (e->we.click.pt.y - 15) / 10;
4349
2fc39ff2626e (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
   108
			const Sign *si;
1575
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
   109
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
   110
			if (id_v >= w->vscroll.cap)
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
   111
				return;
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
   112
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
   113
			id_v += w->vscroll.pos;
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
   114
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
   115
			if (id_v >= w->vscroll.count)
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
   116
				return;
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
   117
4353
2b941f2c325c (svn r6054) Change the sign sorter in a similar way as the other sorters: Remember a list of pointers to signs instead of a list of SignIDs - This removes a layer of indirection
tron
parents: 4349
diff changeset
   118
			si = _sign_sort[id_v];
4349
2fc39ff2626e (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
   119
			ScrollMainWindowToTile(TileVirtXY(si->x, si->y));
1575
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
   120
		} break;
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
   121
		}
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
   122
	} break;
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
   123
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
   124
	case WE_RESIZE:
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4444
diff changeset
   125
		w->vscroll.cap += e->we.sizing.diff.y / 10;
1575
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
   126
		break;
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
   127
	}
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
   128
}
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
   129
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
   130
static const Widget _sign_list_widget[] = {
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4293
diff changeset
   131
{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,              STR_018B_CLOSE_WINDOW},
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4293
diff changeset
   132
{    WWT_CAPTION,  RESIZE_RIGHT,    14,    11,   345,     0,    13, STR_SIGN_LIST_CAPTION, STR_018C_WINDOW_TITLE_DRAG_THIS},
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4293
diff changeset
   133
{  WWT_STICKYBOX,     RESIZE_LR,    14,   346,   357,     0,    13, 0x0,                   STR_STICKY_BUTTON},
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4293
diff changeset
   134
{      WWT_PANEL,     RESIZE_RB,    14,     0,   345,    14,   137, 0x0,                   STR_NULL},
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4293
diff changeset
   135
{  WWT_SCROLLBAR,    RESIZE_LRB,    14,   346,   357,    14,   125, 0x0,                   STR_0190_SCROLL_BAR_SCROLLS_LIST},
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4293
diff changeset
   136
{  WWT_RESIZEBOX,   RESIZE_LRTB,    14,   346,   357,   126,   137, 0x0,                   STR_RESIZE_BUTTON},
1575
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
   137
{   WIDGETS_END},
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
   138
};
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
   139
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
   140
static const WindowDesc _sign_list_desc = {
7837
65d7362153a6 (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7623
diff changeset
   141
	WDP_AUTO, WDP_AUTO, 358, 138, 358, 138,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 6002
diff changeset
   142
	WC_SIGN_LIST, WC_NONE,
1575
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
   143
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON | WDF_RESIZABLE,
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
   144
	_sign_list_widget,
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
   145
	SignListWndProc
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
   146
};
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
   147
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
   148
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6144
diff changeset
   149
void ShowSignList()
1575
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
   150
{
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
   151
	Window *w;
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
   152
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
   153
	w = AllocateWindowDescFront(&_sign_list_desc, 0);
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
   154
	if (w != NULL) {
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
   155
		w->vscroll.cap = 12;
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
   156
		w->resize.step_height = 10;
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
   157
		w->resize.height = w->height - 10 * 7; // minimum if 5 in the list
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
   158
	}
a566a645401f (svn r2079) -Add: signlist, shows all signs in the map. Clicking on them, and you go
truelight
parents: 1130
diff changeset
   159
}
7623
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   160
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   161
/* Edit sign window stuff */
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   162
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   163
struct editsign_d : querystr_d {
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   164
	SignID cur_sign;
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   165
};
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   166
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   167
static char _edit_str_buf[64];
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   168
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   169
enum QueryEditSignWidgets {
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   170
	QUERY_EDIT_SIGN_WIDGET_TEXT = 3,
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   171
	QUERY_EDIT_SIGN_WIDGET_OK,
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   172
	QUERY_EDIT_SIGN_WIDGET_CANCEL,
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   173
	QUERY_EDIT_SIGN_WIDGET_DELETE,
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   174
	QUERY_EDIT_SIGN_WIDGET_PREVIOUS = QUERY_EDIT_SIGN_WIDGET_DELETE + 2,
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   175
	QUERY_EDIT_SIGN_WIDGET_NEXT,
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   176
};
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   177
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   178
static void UpdateSignEditWindow(Window *w, const Sign *si)
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   179
{
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   180
	/* Display an empty string when the sign hasnt been edited yet */
8754
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   181
	if (si->name != NULL) {
7623
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   182
		SetDParam(0, si->index);
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   183
		GetString(_edit_str_buf, STR_SIGN_NAME, lastof(_edit_str_buf));
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   184
	} else {
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   185
		GetString(_edit_str_buf, STR_EMPTY, lastof(_edit_str_buf));
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   186
	}
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   187
	_edit_str_buf[lengthof(_edit_str_buf) - 1] = '\0';
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   188
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   189
	WP(w, editsign_d).cur_sign = si->index;
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   190
	InitializeTextBuffer(&WP(w, querystr_d).text, _edit_str_buf, 31, 255); // Allow 31 characters (including \0)
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   191
8524
baf4ab1ba18d (svn r11588) -Codechange: use the new member introduced in r11551
glx
parents: 8515
diff changeset
   192
	w->InvalidateWidget(QUERY_EDIT_SIGN_WIDGET_TEXT);
7623
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   193
}
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   194
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   195
static void RenameSign(SignID index, const char *text)
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   196
{
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   197
	_cmd_text = text;
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   198
	DoCommandP(0, index, 0, NULL, CMD_RENAME_SIGN | CMD_MSG(STR_280C_CAN_T_CHANGE_SIGN_NAME));
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   199
}
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   200
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   201
static void QuerySignEditWndProc(Window *w, WindowEvent *e)
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   202
{
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   203
	editsign_d *qs = &WP(w, editsign_d);
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   204
	Sign       *si;
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   205
	uint       sign_index = 0;
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   206
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   207
	switch (e->event) {
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   208
		case WE_CREATE:
8427
143b0be22af1 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 8425
diff changeset
   209
			SetBit(_no_scroll, SCROLL_EDIT);
7623
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   210
			break;
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   211
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   212
		case WE_PAINT:
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   213
			SetDParam(0, qs->caption);
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   214
			DrawWindowWidgets(w);
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   215
			DrawEditBox(w, qs, QUERY_EDIT_SIGN_WIDGET_TEXT);
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   216
			break;
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   217
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   218
		case WE_CLICK:
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   219
			switch (e->we.click.widget) {
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   220
				case QUERY_EDIT_SIGN_WIDGET_PREVIOUS:
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   221
					if (_sign_sort_dirty) GlobalSortSignList();
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   222
					sign_index = _sign_sort[_num_sign_sort - 1]->index;
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   223
					for (uint i = 1; i < _num_sign_sort; i++) {
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   224
						if (qs->cur_sign == _sign_sort[i]->index) {
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   225
							sign_index = _sign_sort[i - 1]->index;
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   226
							break;
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   227
						}
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   228
					}
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   229
					si = GetSign(sign_index);
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   230
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   231
					/* Scroll to sign and reopen window */
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   232
					ScrollMainWindowToTile(TileVirtXY(si->x, si->y));
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   233
					UpdateSignEditWindow(w, si);
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   234
					break;
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   235
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   236
				case QUERY_EDIT_SIGN_WIDGET_NEXT:
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   237
					if (_sign_sort_dirty) GlobalSortSignList();
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   238
					sign_index = _sign_sort[0]->index;
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   239
					for (uint i = 0; i < _num_sign_sort-1; i++) {
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   240
						if (qs->cur_sign == _sign_sort[i]->index) {
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   241
							sign_index = _sign_sort[i + 1]->index;
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   242
							break;
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   243
						}
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   244
					}
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   245
					si = GetSign(sign_index);
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   246
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   247
					/* Scroll to sign and reopen window */
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   248
					ScrollMainWindowToTile(TileVirtXY(si->x, si->y));
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   249
					UpdateSignEditWindow(w, si);
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   250
					break;
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   251
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   252
				case QUERY_EDIT_SIGN_WIDGET_DELETE:
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   253
					/* Only need to set the buffer to null, the rest is handled as the OK button */
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   254
					DeleteTextBufferAll(&qs->text);
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   255
					/* FALL THROUGH */
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   256
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   257
				case QUERY_EDIT_SIGN_WIDGET_OK:
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   258
					RenameSign(qs->cur_sign, qs->text.buf);
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   259
					/* FALL THROUGH */
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   260
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   261
				case QUERY_EDIT_SIGN_WIDGET_CANCEL:
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   262
					DeleteWindow(w);
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   263
					break;
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   264
			}
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   265
			break;
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   266
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   267
		case WE_KEYPRESS:
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   268
			switch (HandleEditBoxKey(w, qs, QUERY_EDIT_SIGN_WIDGET_TEXT, e)) {
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   269
				case 1: // Enter pressed, confirms change
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   270
					RenameSign(qs->cur_sign, qs->text.buf);
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   271
					/* FALL THROUGH */
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   272
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   273
				case 2: // ESC pressed, closes window, abandons changes
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   274
					DeleteWindow(w);
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   275
					break;
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   276
			}
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   277
			break;
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   278
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   279
		case WE_MOUSELOOP:
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   280
			HandleEditBox(w, qs, QUERY_EDIT_SIGN_WIDGET_TEXT);
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   281
			break;
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   282
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   283
		case WE_DESTROY:
8425
72a71d480c5f (svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13
parents: 8320
diff changeset
   284
			ClrBit(_no_scroll, SCROLL_EDIT);
7623
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   285
			break;
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   286
	}
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   287
}
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   288
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   289
static const Widget _query_sign_edit_widgets[] = {
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   290
{ WWT_CLOSEBOX, RESIZE_NONE,  14,   0,  10,   0,  13, STR_00C5,        STR_018B_CLOSE_WINDOW},
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   291
{  WWT_CAPTION, RESIZE_NONE,  14,  11, 259,   0,  13, STR_012D,        STR_NULL },
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   292
{    WWT_PANEL, RESIZE_NONE,  14,   0, 259,  14,  29, STR_NULL,        STR_NULL },
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   293
{    WWT_PANEL, RESIZE_NONE,  14,   2, 257,  16,  27, STR_NULL,        STR_NULL },  // Text field
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   294
{  WWT_TEXTBTN, RESIZE_NONE,  14,   0,  60,  30,  41, STR_012F_OK,     STR_NULL },
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   295
{  WWT_TEXTBTN, RESIZE_NONE,  14,  61, 120,  30,  41, STR_012E_CANCEL, STR_NULL },
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   296
{  WWT_TEXTBTN, RESIZE_NONE,  14, 121, 180,  30,  41, STR_0290_DELETE, STR_NULL },
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   297
{    WWT_PANEL, RESIZE_NONE,  14, 181, 237,  30,  41, STR_NULL,        STR_NULL },
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   298
{  WWT_TEXTBTN, RESIZE_NONE,  14, 238, 248,  30,  41, STR_6819,        STR_PREVIOUS_SIGN_TOOLTIP },
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   299
{  WWT_TEXTBTN, RESIZE_NONE,  14, 249, 259,  30,  41, STR_681A,        STR_NEXT_SIGN_TOOLTIP },
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   300
{ WIDGETS_END },
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   301
};
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   302
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   303
static const WindowDesc _query_sign_edit_desc = {
7837
65d7362153a6 (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7623
diff changeset
   304
	190, 170, 260, 42, 260, 42,
7623
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   305
	WC_QUERY_STRING, WC_NONE,
8515
d0401d967e99 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8514
diff changeset
   306
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
7623
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   307
	_query_sign_edit_widgets,
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   308
	QuerySignEditWndProc
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   309
};
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   310
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   311
void ShowRenameSignWindow(const Sign *si)
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   312
{
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   313
	Window *w;
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   314
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   315
	/* Delete all other edit windows and the save window */
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   316
	DeleteWindowById(WC_QUERY_STRING, 0);
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   317
	DeleteWindowById(WC_SAVELOAD, 0);
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   318
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   319
	w = AllocateWindowDesc(&_query_sign_edit_desc);
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   320
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   321
	WP(w, editsign_d).caption = STR_280B_EDIT_SIGN_TEXT;
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   322
	WP(w, editsign_d).afilter = CS_ALPHANUMERAL;
8493
3ab458f7cff4 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 8427
diff changeset
   323
	w->LowerWidget(QUERY_EDIT_SIGN_WIDGET_TEXT);
7623
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   324
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   325
	UpdateSignEditWindow(w, si);
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   326
}
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   327
74bc263b1f4c (svn r10401) -Feature: new sign editor features including switching to previous/next sign (XeryusTC)
peter1138
parents: 7552
diff changeset
   328
8320
6ffad7a5d242 (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7837
diff changeset
   329