00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifdef HAVE_CONFIG_H
00020 # include <config.h>
00021 #endif
00022
00023 #include "Sign_gump.h"
00024 #include "gamewin.h"
00025 #include "game.h"
00026 #include "actors.h"
00027
00028
00029
00030
00031
00032
00033 Sign_gump::Sign_gump
00034 (
00035 int shapenum,
00036 int nlines
00037 ) : Gump(0, shapenum), num_lines(nlines), serpentine(false)
00038 {
00039
00040 if (Game::get_game_type() == SERPENT_ISLE && shapenum==49)
00041 {
00042
00043 Main_actor *avatar = gwin->get_main_actor();
00044 if (!avatar->get_flag(Obj_flags::read))
00045 serpentine = true;
00046
00047 shapenum = game->get_shape("gumps/goldsign");
00048 set_shape(shapenum);
00049 set_pos();
00050 }
00051
00052 if(shapenum==game->get_shape("gumps/woodsign"))
00053 {
00054 set_object_area(Rectangle(0, 4, 196, 92));
00055 }
00056 else if(shapenum==game->get_shape("gumps/tombstone"))
00057 {
00058 set_object_area(Rectangle(0, 8, 200, 112));
00059 }
00060 else if(shapenum==game->get_shape("gumps/goldsign"))
00061 {
00062 if (Game::get_game_type() == BLACK_GATE)
00063 set_object_area(Rectangle(0, 4, 232, 96));
00064 else
00065 set_object_area(Rectangle(4, 4, 312, 96));
00066 }
00067 else if (shapenum==game->get_shape("gumps/scroll"))
00068 set_object_area(Rectangle(48, 30, 146, 118));
00069 lines = new std::string[num_lines];
00070 }
00071
00072
00073
00074
00075
00076 Sign_gump::~Sign_gump
00077 (
00078 )
00079 {
00080 delete [] lines;
00081 }
00082
00083
00084
00085
00086
00087 void Sign_gump::add_text
00088 (
00089 int line,
00090 const std::string &txt
00091 )
00092 {
00093 if (line < 0 || line >= num_lines)
00094 return;
00095
00096
00097 Main_actor *avatar = gwin->get_main_actor();
00098
00099 if (!serpentine && avatar->get_flag(Obj_flags::read))
00100 {
00101 for (int i = 0; i < txt.size(); i++)
00102 {
00103 if (txt[i] == 40)
00104 {
00105 lines[line] += 'T';
00106 lines[line] += 'H';
00107 }
00108 else if (txt[i] == 41)
00109 {
00110 lines[line] += 'E';
00111 lines[line] += 'E';
00112 }
00113 else if (txt[i] == 42)
00114 {
00115 lines[line] += 'N';
00116 lines[line] += 'G';
00117 }
00118 else if (txt[i] == 43)
00119 {
00120 lines[line] += 'E';
00121 lines[line] += 'A';
00122 }
00123 else if (txt[i] == 44)
00124 {
00125 lines[line] += 'S';
00126 lines[line] += 'T';
00127 }
00128 else if (txt[i] == '|')
00129 {
00130 lines[line] += ' ';
00131 }
00132 else if (txt[i] >= 'a')
00133 lines[line] += txt[i] - 32;
00134 else
00135 lines[line] += txt[i];
00136 }
00137 }
00138 else
00139 {
00140 lines[line] = txt;
00141
00142 }
00143 }
00144
00145
00146
00147
00148
00149 void Sign_gump::paint
00150 (
00151 )
00152 {
00153 int font = 1;
00154 if (get_shapenum() == game->get_shape("gumps/goldsign"))
00155 {
00156 if (serpentine)
00157 font = 10;
00158 else
00159 font = 6;
00160 }
00161 else if (serpentine)
00162 font = 8;
00163
00164 int lheight = sman->get_text_height(font);
00165
00166 int lspace = (object_area.h - num_lines*lheight)/(num_lines + 1);
00167
00168 paint_shape(x, y);
00169 int ypos = y + object_area.y;
00170 for (int i = 0; i < num_lines; i++)
00171 {
00172 ypos += lspace;
00173 if (lines[i].empty())
00174 continue;
00175 sman->paint_text(font, lines[i].c_str(),
00176 x + object_area.x +
00177 (object_area.w -
00178 sman->get_text_width(font, lines[i].c_str()))/2,
00179 ypos);
00180 ypos += lheight;
00181 }
00182 gwin->set_painted();
00183 }