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
|
/* 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 2
* 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "sherlock/tattoo/widget_talk.h"
#include "sherlock/tattoo/tattoo_people.h"
#include "sherlock/tattoo/tattoo_talk.h"
#include "sherlock/tattoo/tattoo_scene.h"
#include "sherlock/tattoo/tattoo_user_interface.h"
#include "sherlock/tattoo/tattoo.h"
namespace Sherlock {
namespace Tattoo {
WidgetTalk::WidgetTalk(SherlockEngine *vm) : WidgetBase(vm) {
_talkScroll = false;
}
void WidgetTalk::getTalkWindowSize() {
TattooTalk &talk = *(TattooTalk *)_vm->_talk;
Common::StringArray lines;
const char *const NUM_STR = "19.";
int width, height;
// See how many statements are going to be available
int numStatements = 0;
for (uint idx = 0; idx < talk._statements.size(); ++idx) {
if (talk._statements[idx]._talkMap != -1)
++numStatements;
}
// Figure out the width, allowing room for both the text and the statement numbers on the side
width = SHERLOCK_SCREEN_WIDTH * 2 / 3;
int n = (numStatements < 10) ? 1 : 0;
width -= _surface.stringWidth(NUM_STR + n) + _surface.widestChar() / 2 + 9;
// Now that we have a width, split up the text into individual lines
int numLines = 0;
for (uint idx = 0; idx < talk._statements.size(); ++idx) {
if (talk._statements[idx]._talkMap != -1) {
splitLines(talk._statements[idx]._statement, lines, width, 999);
numLines += lines.size();
}
}
// Make sure that the window does not get too big
if (numLines < 7) {
height = (_surface.fontHeight() + 1) * numLines + 9;
_talkScroll = false;
} else {
// Set up the height to a constrained amount, and add extra width for the scrollbar
width += BUTTON_SIZE + 3;
height = (_surface.fontHeight() + 1) * 6 + 9;
_talkScroll = false;
}
_bounds = Common::Rect(width, height);
// Allocate a surface for the window
_surface.create(_bounds.width(), _bounds.height());
_surface.fill(TRANSPARENCY);
// Form the background for the new window
makeInfoArea();
int yp = 5;
for (int lineNum = 0; yp < (_bounds.height() - _surface.fontHeight() / 2); ++lineNum) {
_surface.writeString(lines[lineNum], Common::Point(_surface.widestChar(), yp), INFO_TOP);
yp += _surface.fontHeight() + 1;
}
}
void WidgetTalk::load() {
TattooPeople &people = *(TattooPeople *)_vm->_people;
TattooScene &scene = *(TattooScene *)_vm->_scene;
TattooUserInterface &ui = *(TattooUserInterface *)_vm->_ui;
ImageFile &images = *ui._interfaceImages;
// Figure out the window size
getTalkWindowSize();
// Place the window centered above the player
Common::Point pt;
int scaleVal = scene.getScaleVal(people[HOLMES]._position);
pt.x = people[HOLMES]._position.x / FIXED_INT_MULTIPLIER;
if (scaleVal == SCALE_THRESHOLD) {
pt.x += people[0].frameWidth() / 2;
pt.y = people[HOLMES]._position.y / FIXED_INT_MULTIPLIER - people[HOLMES].frameHeight()
- _bounds.height() - _surface.fontHeight();
} else {
pt.x += people[HOLMES]._imageFrame->sDrawXSize(scaleVal) / 2;
pt.y = people[HOLMES]._position.y / FIXED_INT_MULTIPLIER - people[HOLMES]._imageFrame->sDrawYSize(scaleVal)
- _bounds.height() - _surface.fontHeight();
}
_bounds.moveTo(pt);
// Set up the surface
_surface.create(_bounds.width(), _bounds.height());
_surface.fill(TRANSPARENCY);
// Form the background for the new window
makeInfoArea();
// If a scrollbar is needed, draw it in
if (_talkScroll) {
int xp = _surface.w() - BUTTON_SIZE - 6;
_surface.vLine(xp, 3, _surface.h() - 4, INFO_TOP);
_surface.vLine(xp + 1, 3, _surface.h() - 4, INFO_MIDDLE);
_surface.vLine(xp + 2, 3, _surface.h() - 4, INFO_BOTTOM);
_surface.transBlitFrom(images[6], Common::Point(xp - 1, 1));
_surface.transBlitFrom(images[7], Common::Point(xp - 1, _surface.h() - 4));
}
}
} // End of namespace Tattoo
} // End of namespace Sherlock
|