File: global_display.cpp

package info (click to toggle)
scummvm 2.9.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 450,580 kB
  • sloc: cpp: 4,299,825; asm: 28,322; python: 12,901; sh: 11,302; java: 9,289; xml: 7,895; perl: 2,639; ansic: 2,465; yacc: 1,670; javascript: 1,020; makefile: 933; lex: 578; awk: 275; objc: 82; sed: 11; php: 1
file content (213 lines) | stat: -rw-r--r-- 6,824 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include "ags/shared/ac/common.h"
#include "ags/engine/ac/character.h"
#include "ags/engine/ac/display.h"
#include "ags/engine/ac/draw.h"
#include "ags/engine/ac/game.h"
#include "ags/shared/ac/game_setup_struct.h"
#include "ags/shared/font/fonts.h"
#include "ags/engine/ac/game_state.h"
#include "ags/engine/ac/global_character.h"
#include "ags/engine/ac/global_display.h"
#include "ags/engine/ac/global_screen.h"
#include "ags/engine/ac/global_translation.h"
#include "ags/engine/ac/runtime_defines.h"
#include "ags/engine/ac/speech.h"
#include "ags/engine/ac/string.h"
#include "ags/engine/ac/top_bar_settings.h"
#include "ags/engine/debugging/debug_log.h"
#include "ags/shared/game/room_struct.h"
#include "ags/engine/main/game_run.h"

namespace AGS3 {

using namespace AGS::Shared;

void DisplayAtYImpl(int ypos, const char *texx, bool as_speech);

void Display(const char *texx, ...) {
	char displbuf[STD_BUFFER_SIZE];
	va_list ap;
	va_start(ap, texx);
	vsnprintf(displbuf, sizeof(displbuf), get_translation(texx), ap);
	va_end(ap);
	DisplayAtY(-1, displbuf);
}

void DisplaySimple(const char *text) {
	DisplayAtY(-1, text);
}

void DisplayMB(const char *text) {
	DisplayAtYImpl(-1, text, false);
}

void DisplayTopBar(int ypos, int ttexcol, int backcol, const char *title, const char *text) {
	// FIXME: refactor source_text_length and get rid of this ugly hack!
	const int real_text_sourcelen = _G(source_text_length);
	snprintf(_GP(topBar).text, sizeof(_GP(topBar).text), "%s", get_translation(title));
	_G(source_text_length) = real_text_sourcelen;

	if (ypos > 0)
		_GP(play).top_bar_ypos = ypos;
	if (ttexcol > 0)
		_GP(play).top_bar_textcolor = ttexcol;
	if (backcol > 0)
		_GP(play).top_bar_backcolor = backcol;

	_GP(topBar).wantIt = 1;
	_GP(topBar).font = FONT_NORMAL;
	_GP(topBar).height = get_font_height_outlined(_GP(topBar).font);
	_GP(topBar).height += data_to_game_coord(_GP(play).top_bar_borderwidth) * 2 + get_fixed_pixel_size(1);

	// they want to customize the font
	if (_GP(play).top_bar_font >= 0)
		_GP(topBar).font = _GP(play).top_bar_font;

	// DisplaySpeech normally sets this up, but since we're not going via it...
	if (_GP(play).speech_skip_style & SKIP_AUTOTIMER)
		_GP(play).messagetime = GetTextDisplayTime(text);

	DisplayAtY(_GP(play).top_bar_ypos, text);
}

// Display a room/global message in the bar
void DisplayMessageBar(int ypos, int ttexcol, int backcol, const char *title, int msgnum) {
	char msgbufr[3001];
	get_message_text(msgnum, msgbufr);
	DisplayTopBar(ypos, ttexcol, backcol, title, msgbufr);
}

void DisplayMessageAtY(int msnum, int ypos) {
	char msgbufr[3001];
	if (msnum >= 500) {
		get_message_text(msnum, msgbufr);
		if (_G(display_message_aschar) > 0)
			DisplaySpeech(msgbufr, _G(display_message_aschar));
		else
			DisplayAtY(ypos, msgbufr);
		_G(display_message_aschar) = 0;
		return;
	}

	if (_G(display_message_aschar) > 0) {
		_G(display_message_aschar) = 0;
		quit("!DisplayMessage: data column specified a character for local\n"
		     "message; use the message editor to select the character for room\n"
		     "messages.\n");
	}

	int repeatloop = 1;
	while (repeatloop) {
		get_message_text(msnum, msgbufr);

		if (_GP(thisroom).MessageInfos[msnum].DisplayAs > 0) {
			DisplaySpeech(msgbufr, _GP(thisroom).MessageInfos[msnum].DisplayAs - 1);
		} else {
			// time out automatically if they have set that
			int oldGameSkipDisp = _GP(play).skip_display;
			if (_GP(thisroom).MessageInfos[msnum].Flags & MSG_TIMELIMIT)
				_GP(play).skip_display = 0;

			DisplayAtY(ypos, msgbufr);

			_GP(play).skip_display = oldGameSkipDisp;
		}
		if (_GP(thisroom).MessageInfos[msnum].Flags & MSG_DISPLAYNEXT) {
			msnum++;
			repeatloop = 1;
		} else
			repeatloop = 0;
	}

}

void DisplayMessage(int msnum) {
	DisplayMessageAtY(msnum, -1);
}

void DisplayAt(int xxp, int yyp, int widd, const char *text) {
	if (_GP(play).screen_is_faded_out > 0)
		debug_script_warn("Warning: blocking Display call during fade-out.");

	data_to_game_coords(&xxp, &yyp);
	widd = data_to_game_coord(widd);

	if (widd < 1) widd = _GP(play).GetUIViewport().GetWidth() / 2;
	if (xxp < 0) xxp = _GP(play).GetUIViewport().GetWidth() / 2 - widd / 2;
	display_at(xxp, yyp, widd, text);
}

void DisplayAtYImpl(int ypos, const char *texx, bool as_speech) {
	const Rect &ui_view = _GP(play).GetUIViewport();
	if ((ypos < -1) || (ypos >= ui_view.GetHeight()))
		quitprintf("!DisplayAtY: invalid Y co-ordinate supplied (used: %d; valid: 0..%d)", ypos, ui_view.GetHeight());
	if (_GP(play).screen_is_faded_out > 0)
		debug_script_warn("Warning: blocking Display call during fade-out.");

	// Display("") ... a bit of a stupid thing to do, so ignore it
	if (texx[0] == 0)
		return;

	if (ypos > 0)
		ypos = data_to_game_coord(ypos);

	if (as_speech)
		DisplaySpeechAt(-1, (ypos > 0) ? game_to_data_coord(ypos) : ypos, -1, _GP(game).playercharacter, texx);
	else {
		// Normal "Display" in text box

		if (is_screen_dirty()) {
			// erase any previous DisplaySpeech
			_GP(play).disabled_user_interface++;
			UpdateGameOnce();
			_GP(play).disabled_user_interface--;
		}

		display_at(-1, ypos, ui_view.GetWidth() / 2 + ui_view.GetWidth() / 4, get_translation(texx));
	}
}

void DisplayAtY(int ypos, const char *texx) {
	DisplayAtYImpl(ypos, texx, _GP(game).options[OPT_ALWAYSSPCH] != 0);
}

void SetSpeechStyle(int newstyle) {
	if ((newstyle < 0) || (newstyle > 3))
		quit("!SetSpeechStyle: must use a SPEECH_* constant as parameter");
	_GP(game).options[OPT_SPEECHTYPE] = newstyle;
}

void SetSkipSpeech(SkipSpeechStyle newval) {
	if ((newval < kSkipSpeechFirst) || (newval > kSkipSpeechLast))
		quit("!SetSkipSpeech: invalid skip mode specified");

	debug_script_log("SkipSpeech style set to %d", newval);
	_GP(play).speech_skip_style = user_to_internal_skip_speech((SkipSpeechStyle)newval);
}

SkipSpeechStyle GetSkipSpeech() {
	return internal_skip_speech_to_user(_GP(play).speech_skip_style);
}

} // namespace AGS3