Sign_gump.cc

Go to the documentation of this file.
00001 /*
00002 Copyright (C) 2000 The Exult Team
00003 
00004 This program is free software; you can redistribute it and/or
00005 modify it under the terms of the GNU General Public License
00006 as published by the Free Software Foundation; either version 2
00007 of the License, or (at your option) any later version.
00008 
00009 This program is distributed in the hope that it will be useful,
00010 but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 GNU General Public License for more details.
00013 
00014 You should have received a copy of the GNU General Public License
00015 along with this program; if not, write to the Free Software
00016 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
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  *  Create a sign gump.
00031  */
00032 
00033 Sign_gump::Sign_gump
00034   (
00035   int shapenum,
00036   int nlines      // # of text lines.
00037   ) : Gump(0, shapenum), num_lines(nlines), serpentine(false)
00038 {
00039   // THIS IS A HACK, but don't ask me why this is like this,
00040   if (Game::get_game_type() == SERPENT_ISLE && shapenum==49)
00041   {
00042     // check for avatar read here
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();  // Recenter
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      // SI
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  *  Delete sign.
00074  */
00075 
00076 Sign_gump::~Sign_gump
00077   (
00078   )
00079 {
00080   delete [] lines;
00081 }
00082 
00083 /*
00084  *  Add a line of text.
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   // check for avatar read here
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  *  Paint sign.
00147  */
00148 
00149 void Sign_gump::paint
00150   (
00151   )
00152 {
00153   int font = 1;     // Normal runes.
00154   if (get_shapenum() == game->get_shape("gumps/goldsign"))
00155   {
00156     if (serpentine)
00157       font = 10;
00158     else
00159       font = 6;   // Embossed.
00160   }
00161   else if (serpentine)
00162     font = 8;
00163           // Get height of 1 line.
00164   int lheight = sman->get_text_height(font);
00165           // Get space between lines.
00166   int lspace = (object_area.h - num_lines*lheight)/(num_lines + 1);
00167           // Paint the gump itself.
00168   paint_shape(x, y);
00169   int ypos = y + object_area.y; // Where to paint next line.
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 }

Generated on Mon Jul 9 14:42:47 2007 for ExultEngine by  doxygen 1.5.1