00001
00002
00003
00004
00005
00006
00007
00009
00016 #include "utils.h"
00017
00018 #include "audio.h"
00019 #include "video.h"
00020 #include "input.h"
00021 #include "script.h"
00022 #include "global.h"
00023 #include "menu.h"
00024
00025 #include "map_dialogue.h"
00026 #include "map.h"
00027 #include "map_objects.h"
00028 #include "map_sprites.h"
00029
00030 using namespace std;
00031 using namespace hoa_utils;
00032 using namespace hoa_audio;
00033 using namespace hoa_video;
00034 using namespace hoa_input;
00035 using namespace hoa_script;
00036 using namespace hoa_system;
00037 using namespace hoa_global;
00038 using namespace hoa_menu;
00039
00040 namespace hoa_map {
00041
00042 namespace private_map {
00043
00044
00045
00046
00047
00048 DialogueManager::DialogueManager() {
00049 VideoManager->PushState();
00050 VideoManager->SetCoordSys(0, 1024, 768, 0);
00051
00052
00053
00054
00055 _background_image.SetFilename("img/menus/dialogue_box.png");
00056 if (_background_image.Load() == false)
00057 cerr << "MAP ERROR: failed to load image: " << _background_image.GetFilename() << endl;
00058
00059 _nameplate_image.SetFilename("img/menus/dialogue_nameplate.png");
00060 if (_nameplate_image.Load() == false)
00061 cerr << "MAP ERROR: failed to load image: " << _nameplate_image.GetFilename() << endl;
00062
00063 _display_textbox.SetDisplaySpeed(30);
00064 _display_textbox.SetPosition(300.0f, 768.0f - 180.0f);
00065 _display_textbox.SetDimensions(1024.0f - 300.0f - 60.0f, 180.0f - 70.0f);
00066 _display_textbox.SetFont("map");
00067 _display_textbox.SetTextColor(Color::black);
00068 _display_textbox.SetDisplayMode(VIDEO_TEXT_FADECHAR);
00069 _display_textbox.SetAlignment(VIDEO_X_LEFT, VIDEO_Y_TOP);
00070
00071 VideoManager->PopState();
00072 }
00073
00074
00075 DialogueManager::~DialogueManager() {
00076
00077
00078 }
00079
00080
00081 void DialogueManager::Update() {
00082 static int32 time_remaining = 0;
00083 static MapDialogue* last_dialogue = NULL;
00084 bool finish_line = false;
00085
00086 if (_current_dialogue == NULL)
00087 return;
00088
00089 if (_current_dialogue != last_dialogue) {
00090 time_remaining = _current_dialogue->GetCurrentTime();
00091 _display_textbox.SetDisplayText(_current_dialogue->GetCurrentText());
00092 last_dialogue = _current_dialogue;
00093 }
00094
00095 _display_textbox.Update(MapMode::_current_map->_time_elapsed);
00096
00097
00098 if (time_remaining > 0) {
00099 time_remaining -= MapMode::_current_map->_time_elapsed;
00100
00101 if (time_remaining < 0) {
00102 time_remaining = 0;
00103 finish_line = true;
00104 }
00105 }
00106
00107
00108 if (_current_dialogue->IsBlocked() == false) {
00109 if (InputManager->ConfirmPress()) {
00110
00111 if (!_display_textbox.IsFinished()) {
00112 _display_textbox.ForceFinish();
00113 }
00114
00115 else {
00116 finish_line = true;
00117 }
00118 }
00119 }
00120
00121
00122 if (finish_line == true) {
00123 if (_current_dialogue->GetCurrentAction() != NULL) {
00124 try {
00125 ScriptCallFunction<void>(*(_current_dialogue->GetCurrentAction()));
00126 } catch (luabind::error& e) {
00127 ScriptManager->HandleLuaError(e);
00128 }
00129 }
00130
00131
00132 if (_current_dialogue->ReadNextLine() == true) {
00133 time_remaining = _current_dialogue->GetCurrentTime();
00134 _display_textbox.SetDisplayText(_current_dialogue->GetCurrentText());
00135 }
00136
00137
00138 else {
00139
00140 MapMode::_current_map->_map_state = EXPLORE;
00141
00142 if (_current_dialogue->IsSaving()) {
00143 for (uint32 i = 0; i < _current_dialogue->GetNumLines(); i++) {
00144 static_cast<VirtualSprite*>(MapMode::_current_map->_all_objects[_current_dialogue->GetLineSpeaker(i)])->LoadState();
00145 }
00146 }
00147 _current_dialogue = NULL;
00148 last_dialogue = NULL;
00149 }
00150 }
00151 }
00152
00153
00154
00155 void DialogueManager::Draw() {
00156 VideoManager->PushState();
00157 VideoManager->SetCoordSys(0.0f, 1024.0f, 768.0f, 0.0f);
00158 VideoManager->SetDrawFlags(VIDEO_X_LEFT, VIDEO_Y_BOTTOM, 0);
00159 VideoManager->Move(0.0f, 768.0f);
00160 _background_image.Draw();
00161 VideoManager->MoveRelative(47.0f, -42.0f);
00162 _nameplate_image.Draw();
00163
00164 VideoManager->SetDrawFlags(VIDEO_X_CENTER, VIDEO_Y_BOTTOM, 0);
00165 VideoManager->SetFont("map");
00166 VideoManager->SetTextColor(Color(Color::black));
00167 VideoManager->MoveRelative(120.0f, -10.0f);
00168 VirtualSprite* speaker = reinterpret_cast<VirtualSprite*>(MapMode::_current_map->_all_objects[_current_dialogue->GetCurrentSpeaker()]);
00169 VideoManager->DrawText(speaker->name);
00170 if (speaker->face_portrait != NULL) {
00171 VideoManager->MoveRelative(0.0f, -26.0f);
00172 speaker->face_portrait->Draw();
00173 }
00174 _display_textbox.Draw();
00175 VideoManager->PopState();
00176 }
00177
00178
00179
00180
00181
00182 MapDialogue::MapDialogue(bool save_state) :
00183 _seen(0),
00184 _current_line(0),
00185 _blocked(false)
00186 {
00187 _save_state = save_state;
00188 }
00189
00190
00191
00192 MapDialogue::~MapDialogue() {
00193 for (uint32 i = 0; i < _actions.size(); ++i) {
00194 if (_actions[i] != NULL) {
00195 delete _actions[i];
00196 }
00197 }
00198 }
00199
00200
00201
00202 bool MapDialogue::ReadNextLine() {
00203
00204 if (++_current_line >= _text.size()) {
00205 _current_line = 0;
00206 IncrementTimesSeen();
00207 if (_owner != NULL) {
00208 _owner->UpdateSeenDialogue();
00209 }
00210 return false;
00211 }
00212
00213 return true;
00214 }
00215
00216
00217
00218 void MapDialogue::AddText(std::string text, uint32 speaker_id, int32 time, int32 action) {
00219 _text.push_back(MakeUnicodeString(text));
00220 _speakers.push_back(speaker_id);
00221 _time.push_back(time);
00222 if (action >= 0) {
00223 MapMode::_loading_map->_map_script.OpenTable("map_functions");
00224 ScriptObject* new_action = new ScriptObject();
00225 *new_action = MapMode::_loading_map->_map_script.ReadFunctionPointer(action);
00226 MapMode::_loading_map->_map_script.CloseTable();
00227 _actions.push_back(new_action);
00228 }
00229 else {
00230 _actions.push_back(NULL);
00231 }
00232 }
00233
00234 }
00235
00236 }