|
@@ -26,6 +26,7 @@
|
|
|
#include "common/Logger.h"
|
|
#include "common/Logger.h"
|
|
|
#include "engine/ui/UiManager.h"
|
|
#include "engine/ui/UiManager.h"
|
|
|
#include "engine/ui/UiTextArea.h"
|
|
#include "engine/ui/UiTextArea.h"
|
|
|
|
|
+#include "engine/ui/UiTextParser.h"
|
|
|
#include "engine/Timer.h"
|
|
#include "engine/Timer.h"
|
|
|
#include "engine/ui/UiSprite.h"
|
|
#include "engine/ui/UiSprite.h"
|
|
|
#include "common/Utilities.h"
|
|
#include "common/Utilities.h"
|
|
@@ -49,6 +50,7 @@ void UiTextArea::Initialise(){
|
|
|
text_print_speed_ = -1; // -1 instant
|
|
text_print_speed_ = -1; // -1 instant
|
|
|
text_print_speed_mod_ = 1;
|
|
text_print_speed_mod_ = 1;
|
|
|
text_state_ = TS_DONE;
|
|
text_state_ = TS_DONE;
|
|
|
|
|
+ text_scroll_time_ = 0;
|
|
|
text_y_offset_ = 0;
|
|
text_y_offset_ = 0;
|
|
|
text_y_offset_target_ = 0;
|
|
text_y_offset_target_ = 0;
|
|
|
pause_time_ = 0;
|
|
pause_time_ = 0;
|
|
@@ -62,7 +64,7 @@ void UiTextArea::Initialise(){
|
|
|
timer_ = false;
|
|
timer_ = false;
|
|
|
timer_time_ = 0;
|
|
timer_time_ = 0;
|
|
|
TextVariable var;
|
|
TextVariable var;
|
|
|
- var.name = "UITextAreaTimer";
|
|
|
|
|
|
|
+ var.name = UiTextParser::TIMER_VARIABLE;
|
|
|
var.value = "00:00";
|
|
var.value = "00:00";
|
|
|
text_variable_.push_back(var);
|
|
text_variable_.push_back(var);
|
|
|
scene_manager_ = Ogre::Root::getSingleton().getSceneManager("Scene");
|
|
scene_manager_ = Ogre::Root::getSingleton().getSceneManager("Scene");
|
|
@@ -72,84 +74,15 @@ void UiTextArea::Initialise(){
|
|
|
|
|
|
|
|
void UiTextArea::Update(){
|
|
void UiTextArea::Update(){
|
|
|
if (visible_ == true){
|
|
if (visible_ == true){
|
|
|
- if (timer_ == true){
|
|
|
|
|
- int time = Timer::getSingleton().GetGameTimer();
|
|
|
|
|
- if (time > 5999) time = 5999; // 99:59
|
|
|
|
|
-
|
|
|
|
|
- if (time != timer_time_){
|
|
|
|
|
- timer_time_ = time;
|
|
|
|
|
- Ogre::String time_string = "";
|
|
|
|
|
- time_string += Ogre::StringUtil::format("%2d", timer_time_ / 60);
|
|
|
|
|
- time_string += (timer_time_ & 1) ? ":" : ";";
|
|
|
|
|
- time_string += Ogre::StringUtil::format("%2d", timer_time_ % 60);
|
|
|
|
|
- SetVariable("UITextAreaTimer", time_string);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (timer_ == true) UpdateTimer();
|
|
|
switch(text_state_){
|
|
switch(text_state_){
|
|
|
- case TS_SHOW_TEXT:
|
|
|
|
|
- if (text_print_speed_ == -1) text_limit_ = max_letters_;
|
|
|
|
|
- else{
|
|
|
|
|
- float time = Timer::getSingleton().GetGameTimeDelta() * 30;
|
|
|
|
|
- float addition;
|
|
|
|
|
- float limit;
|
|
|
|
|
- if (next_pressed_ == true || next_repeated_ == true)
|
|
|
|
|
- text_print_speed_mod_ += (text_print_speed_mod_ >= 128) ? 0 : 1.0f * time;
|
|
|
|
|
- else text_print_speed_mod_ -= (text_print_speed_mod_ <= 1) ? 0 : 1.0f * time;
|
|
|
|
|
- if (text_print_speed_ < 128){
|
|
|
|
|
- addition = ((128 - text_print_speed_) / 32) + 2;
|
|
|
|
|
- limit = 1;
|
|
|
|
|
- }
|
|
|
|
|
- else{
|
|
|
|
|
- addition = 2;
|
|
|
|
|
- limit = ((text_print_speed_ - 128) / 32) + 1;
|
|
|
|
|
- }
|
|
|
|
|
- float char_to_add = (limit * text_print_speed_mod_ / 16 + addition) / limit;
|
|
|
|
|
- text_limit_ += time * char_to_add;
|
|
|
|
|
- }
|
|
|
|
|
- update_transformation_ = true;
|
|
|
|
|
- break;
|
|
|
|
|
- case TS_SCROLL_TEXT:
|
|
|
|
|
- text_y_offset_
|
|
|
|
|
- -= font_->GetHeight()
|
|
|
|
|
- * Timer::getSingleton().GetGameTimeDelta()
|
|
|
|
|
- / text_scroll_time_;
|
|
|
|
|
- if (text_y_offset_ <= text_y_offset_target_){
|
|
|
|
|
- text_y_offset_ = text_y_offset_target_;
|
|
|
|
|
- text_print_speed_mod_ = 1;
|
|
|
|
|
- text_state_ = TS_SHOW_TEXT;
|
|
|
|
|
- }
|
|
|
|
|
- update_transformation_ = true;
|
|
|
|
|
- break;
|
|
|
|
|
- case TS_PAUSE_OK:
|
|
|
|
|
- if (next_pressed_ == true){
|
|
|
|
|
- text_print_speed_mod_ = 1;
|
|
|
|
|
- text_state_ = TS_SHOW_TEXT;
|
|
|
|
|
- }
|
|
|
|
|
- break;
|
|
|
|
|
- case TS_PAUSE_TIME:
|
|
|
|
|
- pause_time_ -= Timer::getSingleton().GetGameTimeDelta();
|
|
|
|
|
- if (pause_time_ <= 0){
|
|
|
|
|
- text_print_speed_mod_ = 1;
|
|
|
|
|
- text_state_ = TS_SHOW_TEXT;
|
|
|
|
|
- }
|
|
|
|
|
- break;
|
|
|
|
|
- case TS_OVERFLOW:
|
|
|
|
|
- if (next_pressed_ == true){
|
|
|
|
|
- text_y_offset_target_ = text_y_offset_ - font_->GetHeight();
|
|
|
|
|
- text_state_ = TS_SCROLL_TEXT;
|
|
|
|
|
- }
|
|
|
|
|
- break;
|
|
|
|
|
- case TS_NEXT_PAGE:
|
|
|
|
|
- if (next_pressed_ == true){
|
|
|
|
|
- RemoveSpritesFromText(next_page_start_);
|
|
|
|
|
- text_.erase(text_.begin(), text_.begin() + next_page_start_);
|
|
|
|
|
- text_limit_ = 0;
|
|
|
|
|
- text_print_speed_mod_ = 1;
|
|
|
|
|
- text_y_offset_ = 0;
|
|
|
|
|
- text_y_offset_target_ = 0;
|
|
|
|
|
- text_state_ = TS_SHOW_TEXT;
|
|
|
|
|
- }
|
|
|
|
|
- break;
|
|
|
|
|
|
|
+ case TS_SHOW_TEXT: UpdateShowText(); break;
|
|
|
|
|
+ case TS_SCROLL_TEXT: UpdateScrollText(); break;
|
|
|
|
|
+ case TS_PAUSE_OK: if (next_pressed_) ContinueText(); break;
|
|
|
|
|
+ case TS_PAUSE_TIME: UpdatePauseTime(); break;
|
|
|
|
|
+ case TS_OVERFLOW: if (next_pressed_) ScrollOneLine(); break;
|
|
|
|
|
+ case TS_NEXT_PAGE: if (next_pressed_) ShowNextPage(); break;
|
|
|
|
|
+ case TS_DONE: break;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
next_pressed_ = false;
|
|
next_pressed_ = false;
|
|
@@ -157,6 +90,75 @@ void UiTextArea::Update(){
|
|
|
UiWidget::Update();
|
|
UiWidget::Update();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+void UiTextArea::UpdateTimer(){
|
|
|
|
|
+ int time = Timer::getSingleton().GetGameTimer();
|
|
|
|
|
+ if (time > 5999) time = 5999; // 99:59
|
|
|
|
|
+ if (time == timer_time_) return;
|
|
|
|
|
+ timer_time_ = time;
|
|
|
|
|
+ Ogre::String time_string = Ogre::StringUtil::format("%2d", timer_time_ / 60);
|
|
|
|
|
+ time_string += (timer_time_ & 1) ? ":" : ";";
|
|
|
|
|
+ time_string += Ogre::StringUtil::format("%2d", timer_time_ % 60);
|
|
|
|
|
+ SetVariable(UiTextParser::TIMER_VARIABLE, time_string);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void UiTextArea::UpdateShowText(){
|
|
|
|
|
+ if (text_print_speed_ == -1) text_limit_ = max_letters_;
|
|
|
|
|
+ else{
|
|
|
|
|
+ // Holding the button makes the text print faster.
|
|
|
|
|
+ const float time = Timer::getSingleton().GetGameTimeDelta() * 30;
|
|
|
|
|
+ if (next_pressed_ == true || next_repeated_ == true)
|
|
|
|
|
+ text_print_speed_mod_ += (text_print_speed_mod_ >= 128) ? 0 : 1.0f * time;
|
|
|
|
|
+ else text_print_speed_mod_ -= (text_print_speed_mod_ <= 1) ? 0 : 1.0f * time;
|
|
|
|
|
+ float addition;
|
|
|
|
|
+ float limit;
|
|
|
|
|
+ if (text_print_speed_ < 128){
|
|
|
|
|
+ addition = ((128 - text_print_speed_) / 32) + 2;
|
|
|
|
|
+ limit = 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ else{
|
|
|
|
|
+ addition = 2;
|
|
|
|
|
+ limit = ((text_print_speed_ - 128) / 32) + 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ const float characters = (limit * text_print_speed_mod_ / 16 + addition) / limit;
|
|
|
|
|
+ text_limit_ += time * characters;
|
|
|
|
|
+ }
|
|
|
|
|
+ update_transformation_ = true;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void UiTextArea::UpdateScrollText(){
|
|
|
|
|
+ text_y_offset_
|
|
|
|
|
+ -= font_->GetHeight() * Timer::getSingleton().GetGameTimeDelta() / text_scroll_time_;
|
|
|
|
|
+ if (text_y_offset_ <= text_y_offset_target_){
|
|
|
|
|
+ text_y_offset_ = text_y_offset_target_;
|
|
|
|
|
+ ContinueText();
|
|
|
|
|
+ }
|
|
|
|
|
+ update_transformation_ = true;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void UiTextArea::UpdatePauseTime(){
|
|
|
|
|
+ pause_time_ -= Timer::getSingleton().GetGameTimeDelta();
|
|
|
|
|
+ if (pause_time_ <= 0) ContinueText();
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void UiTextArea::ContinueText(){
|
|
|
|
|
+ text_print_speed_mod_ = 1;
|
|
|
|
|
+ text_state_ = TS_SHOW_TEXT;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void UiTextArea::ScrollOneLine(){
|
|
|
|
|
+ text_y_offset_target_ = text_y_offset_ - font_->GetHeight();
|
|
|
|
|
+ text_state_ = TS_SCROLL_TEXT;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void UiTextArea::ShowNextPage(){
|
|
|
|
|
+ RemoveSpritesFromText(next_page_start_);
|
|
|
|
|
+ text_.erase(text_.begin(), text_.begin() + next_page_start_);
|
|
|
|
|
+ text_limit_ = 0;
|
|
|
|
|
+ text_y_offset_ = 0;
|
|
|
|
|
+ text_y_offset_target_ = 0;
|
|
|
|
|
+ ContinueText();
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
void UiTextArea::Render(){
|
|
void UiTextArea::Render(){
|
|
|
// Scripts that run after the widgets update (like the battle) can change the text or the
|
|
// Scripts that run after the widgets update (like the battle) can change the text or the
|
|
|
// position of a widget in the same frame it is drawn, so the geometry is refreshed here.
|
|
// position of a widget in the same frame it is drawn, so the geometry is refreshed here.
|
|
@@ -232,26 +234,19 @@ void UiTextArea::PutNumber(const std::string& number, const int digits){
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void UiTextArea::SetText(const char* text){
|
|
void UiTextArea::SetText(const char* text){
|
|
|
- // Don't call PrepareTextFromNode from here!
|
|
|
|
|
- // Use the non-recursive SetTextFromNode.
|
|
|
|
|
- Ogre::UTFString str_text = Ogre::UTFString(text);
|
|
|
|
|
|
|
+ // Unlike the other ways of setting the text, the one already shown is not cleared: what has
|
|
|
|
|
+ // been printed is not printed again.
|
|
|
text_.clear();
|
|
text_.clear();
|
|
|
TiXmlDocument doc;
|
|
TiXmlDocument doc;
|
|
|
- Ogre::UTFString xml_text = "<container>" + str_text + "</container>";
|
|
|
|
|
|
|
+ const Ogre::UTFString xml_text = "<container>" + Ogre::UTFString(text) + "</container>";
|
|
|
doc.Parse(xml_text.asUTF8_c_str(), 0, TIXML_ENCODING_UTF8);
|
|
doc.Parse(xml_text.asUTF8_c_str(), 0, TIXML_ENCODING_UTF8);
|
|
|
- SetTextFromNode(doc.RootElement(), colour_1_);
|
|
|
|
|
- text_state_ = TS_SHOW_TEXT;
|
|
|
|
|
- update_transformation_ = true;
|
|
|
|
|
- GrowVertexBuffer(text_.size());
|
|
|
|
|
- if (text_.size() > max_letters_){
|
|
|
|
|
- text_.clear();
|
|
|
|
|
|
|
+ if (doc.Error()){
|
|
|
LOG_ERROR(
|
|
LOG_ERROR(
|
|
|
- "Max number of text reached in '" + path_name_ + "'. Can't render text from node. "
|
|
|
|
|
- + "Max number of letters is " + Ogre::StringConverter::toString(max_letters_) + "."
|
|
|
|
|
|
|
+ "Can't parse text '" + Ogre::String(text) + "'. TinyXml Error: " + doc.ErrorDesc()
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
- text_state_ = TS_SHOW_TEXT;
|
|
|
|
|
- update_transformation_ = true;
|
|
|
|
|
|
|
+ // What could be read of an invalid text is shown.
|
|
|
|
|
+ ShowText(doc.RootElement());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void UiTextArea::SetText(const Ogre::UTFString& text){
|
|
void UiTextArea::SetText(const Ogre::UTFString& text){
|
|
@@ -266,19 +261,34 @@ void UiTextArea::SetText(const Ogre::UTFString& text){
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void UiTextArea::SetText(TiXmlNode* text){
|
|
void UiTextArea::SetText(TiXmlNode* text){
|
|
|
- if (text == NULL){
|
|
|
|
|
|
|
+ if (text == nullptr){
|
|
|
LOG_ERROR("Text pointer is NULL.");
|
|
LOG_ERROR("Text pointer is NULL.");
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
// Reload font if language was changed.
|
|
// Reload font if language was changed.
|
|
|
- if (font_ != NULL){
|
|
|
|
|
- Ogre::String language = font_->GetLanguage();
|
|
|
|
|
- if (language != "")
|
|
|
|
|
- if (TextHandler::getSingleton().GetLanguage() != language) SetFont(font_->GetName());
|
|
|
|
|
|
|
+ if (font_ != nullptr){
|
|
|
|
|
+ const Ogre::String language = font_->GetLanguage();
|
|
|
|
|
+ if (language != "" && TextHandler::getSingleton().GetLanguage() != language)
|
|
|
|
|
+ SetFont(font_->GetName());
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
TextClear();
|
|
TextClear();
|
|
|
- PrepareTextFromNode(text, colour_1_);
|
|
|
|
|
|
|
+ ShowText(text);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void UiTextArea::ShowText(TiXmlNode* node){
|
|
|
|
|
+ UiTextParser::Sources sources;
|
|
|
|
|
+ sources.variable = [this](const Ogre::String& name){return GetVariable(name);};
|
|
|
|
|
+ sources.character_name = [](int id){return TextHandler::getSingleton().GetCharacterName(id);};
|
|
|
|
|
+ sources.party_name = [](int position){
|
|
|
|
|
+ return TextHandler::getSingleton().GetPartyCharacterName(position);
|
|
|
|
|
+ };
|
|
|
|
|
+ sources.text = [](const Ogre::String& name){return TextHandler::getSingleton().GetText(name);};
|
|
|
|
|
+ sources.image = [this](const Ogre::String& name, TextChar& character){
|
|
|
|
|
+ return CreateImage(name, character);
|
|
|
|
|
+ };
|
|
|
|
|
+ UiTextParser parser(sources, text_);
|
|
|
|
|
+ parser.Parse(node, colour_1_);
|
|
|
|
|
+ if (parser.UsesTimer()) timer_ = true;
|
|
|
text_state_ = TS_SHOW_TEXT;
|
|
text_state_ = TS_SHOW_TEXT;
|
|
|
update_transformation_ = true;
|
|
update_transformation_ = true;
|
|
|
GrowVertexBuffer(text_.size());
|
|
GrowVertexBuffer(text_.size());
|
|
@@ -291,6 +301,44 @@ void UiTextArea::SetText(TiXmlNode* text){
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+bool UiTextArea::CreateImage(const Ogre::String& name, TextChar& character){
|
|
|
|
|
+ TiXmlNode* prototype = UiManager::getSingleton().GetPrototype("TextAreaSprite");
|
|
|
|
|
+ if (prototype == nullptr) return false;
|
|
|
|
|
+ for (TiXmlNode* node = prototype->FirstChild(); node != nullptr; node = node->NextSibling()){
|
|
|
|
|
+ if (
|
|
|
|
|
+ node->Type() != TiXmlNode::TINYXML_ELEMENT || node->ValueStr() != "sprite"
|
|
|
|
|
+ || GetString(node, "name") != name
|
|
|
|
|
+ ) continue;
|
|
|
|
|
+ UiSprite* sprite = new UiSprite(name, name_ + "." + name, this);
|
|
|
|
|
+ const Ogre::String image = GetString(node, "image");
|
|
|
|
|
+ if (image != "") sprite->SetImage(image);
|
|
|
|
|
+ const Ogre::String y = GetString(node, "y");
|
|
|
|
|
+ if (y != ""){
|
|
|
|
|
+ float percent = 0;
|
|
|
|
|
+ ParsePercent(percent, character.sprite_y, y);
|
|
|
|
|
+ }
|
|
|
|
|
+ const Ogre::String width = GetString(node, "width");
|
|
|
|
|
+ if (width != ""){
|
|
|
|
|
+ float percent = 0;
|
|
|
|
|
+ float pixels = 0;
|
|
|
|
|
+ ParsePercent(percent, pixels, width);
|
|
|
|
|
+ sprite->SetWidth(0, pixels);
|
|
|
|
|
+ }
|
|
|
|
|
+ const Ogre::String height = GetString(node, "height");
|
|
|
|
|
+ if (height != ""){
|
|
|
|
|
+ float percent = 0;
|
|
|
|
|
+ float pixels = 0;
|
|
|
|
|
+ ParsePercent(percent, pixels, height);
|
|
|
|
|
+ sprite->SetHeight(percent, pixels);
|
|
|
|
|
+ }
|
|
|
|
|
+ sprite->SetVisible(false);
|
|
|
|
|
+ AddChild(sprite);
|
|
|
|
|
+ character.sprite = sprite;
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
void UiTextArea::TextClear(){
|
|
void UiTextArea::TextClear(){
|
|
|
RemoveSpritesFromText(text_.size());
|
|
RemoveSpritesFromText(text_.size());
|
|
|
text_.clear();
|
|
text_.clear();
|
|
@@ -407,552 +455,96 @@ unsigned int UiTextArea::GetTextSize() const{return text_.size();}
|
|
|
float UiTextArea::GetPauseTime() const{return pause_time_;}
|
|
float UiTextArea::GetPauseTime() const{return pause_time_;}
|
|
|
|
|
|
|
|
void UiTextArea::UpdateGeometry(){
|
|
void UiTextArea::UpdateGeometry(){
|
|
|
- if (font_ == NULL){
|
|
|
|
|
|
|
+ if (font_ == nullptr){
|
|
|
LOG_ERROR("Font for '" + path_name_ + "' if not set.");
|
|
LOG_ERROR("Font for '" + path_name_ + "' if not set.");
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- float width = 0;
|
|
|
|
|
|
|
+ float align_width = 0;
|
|
|
if (text_align_ != LEFT){
|
|
if (text_align_ != LEFT){
|
|
|
- width = GetTextWidth();
|
|
|
|
|
- if (text_align_ == CENTER) width /= 2;
|
|
|
|
|
|
|
+ align_width = UiTextLayout::TextWidth(
|
|
|
|
|
+ text_, [this](int code){return font_->GetCharData(code);}
|
|
|
|
|
+ );
|
|
|
|
|
+ if (text_align_ == CENTER) align_width /= 2;
|
|
|
}
|
|
}
|
|
|
- float* write_iterator
|
|
|
|
|
- = static_cast<float*>(vertex_buffer_->lock(Ogre::HardwareBuffer::HBL_NORMAL));
|
|
|
|
|
|
|
+ const UiTextLayout::Area area{
|
|
|
|
|
+ final_origin_, final_size_, final_scale_, screen_height_,
|
|
|
|
|
+ padding_top_, padding_right_, padding_bottom_, padding_left_
|
|
|
|
|
+ };
|
|
|
|
|
+ UiTextLayout layout(area, align_width, text_y_offset_, font_->GetHeight());
|
|
|
|
|
+ float* vertices = static_cast<float*>(vertex_buffer_->lock(Ogre::HardwareBuffer::HBL_NORMAL));
|
|
|
render_operation_.vertexData->vertexCount = 0;
|
|
render_operation_.vertexData->vertexCount = 0;
|
|
|
- float local_x_start
|
|
|
|
|
- = -final_origin_.x - (width - padding_left_) * final_scale_.x * screen_height_ / 720.0f;
|
|
|
|
|
- float local_x1 = local_x_start;
|
|
|
|
|
- float local_y1 = -final_origin_.y + ((text_y_offset_ + padding_top_)
|
|
|
|
|
- * final_scale_.y * screen_height_ / 720.0f);
|
|
|
|
|
- float local_x2;
|
|
|
|
|
- float local_y2;
|
|
|
|
|
- float x = final_translate_.x;
|
|
|
|
|
- float y = final_translate_.y;
|
|
|
|
|
unsigned int i = 0;
|
|
unsigned int i = 0;
|
|
|
for (; (i < text_limit_) && (i < text_.size()); ++ i){
|
|
for (; (i < text_limit_) && (i < text_.size()); ++ i){
|
|
|
- if (text_[i].skip == true) continue;
|
|
|
|
|
- else if (text_[i].pause_ok == true){
|
|
|
|
|
- text_[i].skip = true;
|
|
|
|
|
- text_state_ = TS_PAUSE_OK;
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
- else if (text_[i].pause_time != 0){
|
|
|
|
|
- text_[i].skip = true;
|
|
|
|
|
- pause_time_ = text_[i].pause_time;
|
|
|
|
|
- text_state_ = TS_PAUSE_TIME;
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
- else if (text_[i].next_page == true){
|
|
|
|
|
- text_[i].skip = true;
|
|
|
|
|
- next_page_start_ = i + 1;
|
|
|
|
|
- text_state_ = TS_NEXT_PAGE;
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
- else if (text_[i].sprite != NULL){
|
|
|
|
|
- float width_percent = 0;
|
|
|
|
|
- float img_width = 0;
|
|
|
|
|
- text_[i].sprite->GetWidth(width_percent, img_width);
|
|
|
|
|
- text_[i].sprite->SetX(0, local_x1 / (final_scale_.x * screen_height_ / 720.0f));
|
|
|
|
|
- local_x1 += img_width * final_scale_.x * screen_height_ / 720.0f;
|
|
|
|
|
- float height_percent = 0;
|
|
|
|
|
- float img_height = 0;
|
|
|
|
|
- text_[i].sprite->GetHeight(height_percent, img_height);
|
|
|
|
|
- text_[i].sprite->SetY(
|
|
|
|
|
- 0, text_[i].sprite_y + (local_y1 / (final_scale_.y * screen_height_ / 720.0f))
|
|
|
|
|
- );
|
|
|
|
|
- text_[i].sprite->SetVisible(true);
|
|
|
|
|
- text_[i].sprite->UpdateGeometry();
|
|
|
|
|
|
|
+ TextChar& character = text_[i];
|
|
|
|
|
+ if (character.skip) continue;
|
|
|
|
|
+ if (StopAtCommand(i)) break;
|
|
|
|
|
+ if (character.sprite != nullptr){
|
|
|
|
|
+ PlaceSprite(character, layout);
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
- UiCharData char_data = font_->GetCharData(text_[i].char_code);
|
|
|
|
|
- Ogre::ColourValue colour = text_[i].colour;
|
|
|
|
|
- if (char_data.char_code == 10){ // LF (line feed): \n
|
|
|
|
|
- local_x1 = local_x_start;
|
|
|
|
|
- local_y1 += font_->GetHeight() * final_scale_.y * screen_height_ / 720.0f;
|
|
|
|
|
|
|
+ const UiCharData data = font_->GetCharData(character.char_code);
|
|
|
|
|
+ if (data.char_code == 10){ // LF (line feed): \n
|
|
|
|
|
+ layout.NewLine();
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
- local_x1 += char_data.pre * final_scale_.x * screen_height_ / 720.0f;
|
|
|
|
|
- local_x2 = local_x1 + char_data.width * final_scale_.x * screen_height_ / 720.0f;
|
|
|
|
|
- local_y2 = local_y1 + char_data.height * final_scale_.y * screen_height_ / 720.0f;
|
|
|
|
|
- if (
|
|
|
|
|
- local_x2 + char_data.post * final_scale_.x * screen_height_ / 720.0f
|
|
|
|
|
- > final_size_.x - padding_right_ * final_scale_.x * screen_height_ / 720.0f
|
|
|
|
|
- ){
|
|
|
|
|
- local_x1 = local_x_start;
|
|
|
|
|
- local_x2 = local_x1 + char_data.width * final_scale_.x * screen_height_ / 720.0f;
|
|
|
|
|
- local_y1 += font_->GetHeight() * final_scale_.y * screen_height_ / 720.0f;
|
|
|
|
|
- local_y2 = local_y1 + char_data.height * final_scale_.y * screen_height_ / 720.0f;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // If the lower border of the textarea is crossed:
|
|
|
|
|
- // generate event and stop rendering
|
|
|
|
|
- if (local_y2 > final_size_.y - padding_bottom_ * final_scale_.y * screen_height_ / 720.0f){
|
|
|
|
|
|
|
+ UiTextLayout::Box box;
|
|
|
|
|
+ // The text goes below the area: the rest is not drawn.
|
|
|
|
|
+ if (!layout.Place(data, box)){
|
|
|
if (text_state_ != TS_SCROLL_TEXT) text_state_ = TS_OVERFLOW;
|
|
if (text_state_ != TS_SCROLL_TEXT) text_state_ = TS_OVERFLOW;
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
- int x1, y1, x2, y2, x3, y3, x4, y4;
|
|
|
|
|
- if (final_rotation_ != 0){
|
|
|
|
|
- float cos = Ogre::Math::Cos(Ogre::Radian(Ogre::Degree(final_rotation_)));
|
|
|
|
|
- float sin = Ogre::Math::Sin(Ogre::Radian(Ogre::Degree(final_rotation_)));
|
|
|
|
|
- x1 = local_x1 * cos - local_y1 * sin + x;
|
|
|
|
|
- y1 = local_x1 * sin + local_y1 * cos + y;
|
|
|
|
|
- x2 = local_x2 * cos - local_y1 * sin + x;
|
|
|
|
|
- y2 = local_x2 * sin + local_y1 * cos + y;
|
|
|
|
|
- x3 = local_x2 * cos - local_y2 * sin + x;
|
|
|
|
|
- y3 = local_x2 * sin + local_y2 * cos + y;
|
|
|
|
|
- x4 = local_x1 * cos - local_y2 * sin + x;
|
|
|
|
|
- y4 = local_x1 * sin + local_y2 * cos + y;
|
|
|
|
|
- }
|
|
|
|
|
- else{
|
|
|
|
|
- x1 = local_x1 + x;
|
|
|
|
|
- y1 = local_y1 + y;
|
|
|
|
|
- x2 = local_x2 + x;
|
|
|
|
|
- y2 = local_y1 + y;
|
|
|
|
|
- x3 = local_x2 + x;
|
|
|
|
|
- y3 = local_y2 + y;
|
|
|
|
|
- x4 = local_x1 + x;
|
|
|
|
|
- y4 = local_y2 + y;
|
|
|
|
|
- }
|
|
|
|
|
- float new_x1 = (x1 / screen_width_) * 2 - 1;
|
|
|
|
|
- float new_y1 = -((y1 / screen_height_) * 2 - 1);
|
|
|
|
|
- float new_x2 = (x2 / screen_width_) * 2 - 1;
|
|
|
|
|
- float new_y2 = -((y2 / screen_height_) * 2 - 1);
|
|
|
|
|
- float new_x3 = (x3 / screen_width_) * 2 - 1;
|
|
|
|
|
- float new_y3 = -((y3 / screen_height_) * 2 - 1);
|
|
|
|
|
- float new_x4 = (x4 / screen_width_) * 2 - 1;
|
|
|
|
|
- float new_y4 = -((y4 / screen_height_) * 2 - 1);
|
|
|
|
|
- local_x1 += (char_data.width + char_data.post) * final_scale_.x * screen_height_ / 720.0f;
|
|
|
|
|
- float img_width = font_->GetImageWidth();
|
|
|
|
|
- float img_height = font_->GetImageHeight();
|
|
|
|
|
- float left = (float)char_data.x / img_width;
|
|
|
|
|
- float right = (float)(char_data.x + char_data.width) / img_width;
|
|
|
|
|
- float top = (float)char_data.y / img_height;
|
|
|
|
|
- float bottom = (float)(char_data.y + char_data.height) / img_height;
|
|
|
|
|
-
|
|
|
|
|
- *write_iterator ++ = new_x1;
|
|
|
|
|
- *write_iterator ++ = new_y1;
|
|
|
|
|
- *write_iterator ++ = final_z_;
|
|
|
|
|
- *write_iterator ++ = colour.r;
|
|
|
|
|
- *write_iterator ++ = colour.g;
|
|
|
|
|
- *write_iterator ++ = colour.b;
|
|
|
|
|
- *write_iterator ++ = colour.a;
|
|
|
|
|
- *write_iterator ++ = left;
|
|
|
|
|
- *write_iterator ++ = top;
|
|
|
|
|
-
|
|
|
|
|
- *write_iterator ++ = new_x2;
|
|
|
|
|
- *write_iterator ++ = new_y2;
|
|
|
|
|
- *write_iterator ++ = final_z_;
|
|
|
|
|
- *write_iterator ++ = colour.r;
|
|
|
|
|
- *write_iterator ++ = colour.g;
|
|
|
|
|
- *write_iterator ++ = colour.b;
|
|
|
|
|
- *write_iterator ++ = colour.a;
|
|
|
|
|
- *write_iterator ++ = right;
|
|
|
|
|
- *write_iterator ++ = top;
|
|
|
|
|
-
|
|
|
|
|
- *write_iterator ++ = new_x3;
|
|
|
|
|
- *write_iterator ++ = new_y3;
|
|
|
|
|
- *write_iterator ++ = final_z_;
|
|
|
|
|
- *write_iterator ++ = colour.r;
|
|
|
|
|
- *write_iterator ++ = colour.g;
|
|
|
|
|
- *write_iterator ++ = colour.b;
|
|
|
|
|
- *write_iterator ++ = colour.a;
|
|
|
|
|
- *write_iterator ++ = right;
|
|
|
|
|
- *write_iterator ++ = bottom;
|
|
|
|
|
-
|
|
|
|
|
- *write_iterator ++ = new_x1;
|
|
|
|
|
- *write_iterator ++ = new_y1;
|
|
|
|
|
- *write_iterator ++ = final_z_;
|
|
|
|
|
- *write_iterator ++ = colour.r;
|
|
|
|
|
- *write_iterator ++ = colour.g;
|
|
|
|
|
- *write_iterator ++ = colour.b;
|
|
|
|
|
- *write_iterator ++ = colour.a;
|
|
|
|
|
- *write_iterator ++ = left;
|
|
|
|
|
- *write_iterator ++ = top;
|
|
|
|
|
-
|
|
|
|
|
- *write_iterator ++ = new_x3;
|
|
|
|
|
- *write_iterator ++ = new_y3;
|
|
|
|
|
- *write_iterator ++ = final_z_;
|
|
|
|
|
- *write_iterator ++ = colour.r;
|
|
|
|
|
- *write_iterator ++ = colour.g;
|
|
|
|
|
- *write_iterator ++ = colour.b;
|
|
|
|
|
- *write_iterator ++ = colour.a;
|
|
|
|
|
- *write_iterator ++ = right;
|
|
|
|
|
- *write_iterator ++ = bottom;
|
|
|
|
|
-
|
|
|
|
|
- *write_iterator ++ = new_x4;
|
|
|
|
|
- *write_iterator ++ = new_y4;
|
|
|
|
|
- *write_iterator ++ = final_z_;
|
|
|
|
|
- *write_iterator ++ = colour.r;
|
|
|
|
|
- *write_iterator ++ = colour.g;
|
|
|
|
|
- *write_iterator ++ = colour.b;
|
|
|
|
|
- *write_iterator ++ = colour.a;
|
|
|
|
|
- *write_iterator ++ = left;
|
|
|
|
|
- *write_iterator ++ = bottom;
|
|
|
|
|
-
|
|
|
|
|
- render_operation_.vertexData->vertexCount += 6;
|
|
|
|
|
|
|
+ WriteCharacter(vertices, box, data, character.colour);
|
|
|
}
|
|
}
|
|
|
vertex_buffer_->unlock();
|
|
vertex_buffer_->unlock();
|
|
|
if (i == text_.size()) text_state_ = TS_DONE;
|
|
if (i == text_.size()) text_state_ = TS_DONE;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-float UiTextArea::GetTextWidth() const{
|
|
|
|
|
- float width = 0;
|
|
|
|
|
- float width_max = 0;
|
|
|
|
|
- for (unsigned int i = 0; i < text_.size(); ++ i){
|
|
|
|
|
- UiCharData char_data = font_->GetCharData(text_[i].char_code);
|
|
|
|
|
- // If newline, store previous row max width
|
|
|
|
|
- if (char_data.char_code == 10){
|
|
|
|
|
- width_max = (width > width_max) ? width : width_max;
|
|
|
|
|
- width = 0;
|
|
|
|
|
- }
|
|
|
|
|
- else width += char_data.pre + char_data.width + char_data.post;
|
|
|
|
|
|
|
+bool UiTextArea::StopAtCommand(const unsigned int index){
|
|
|
|
|
+ TextChar& character = text_[index];
|
|
|
|
|
+ if (character.pause_ok) text_state_ = TS_PAUSE_OK;
|
|
|
|
|
+ else if (character.pause_time != 0){
|
|
|
|
|
+ pause_time_ = character.pause_time;
|
|
|
|
|
+ text_state_ = TS_PAUSE_TIME;
|
|
|
}
|
|
}
|
|
|
- return (width > width_max) ? width : width_max;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-void UiTextArea::PrepareTextFromNode(TiXmlNode* node, const Ogre::ColourValue& colour){
|
|
|
|
|
-
|
|
|
|
|
- while (node != NULL){
|
|
|
|
|
- switch(node->Type()){
|
|
|
|
|
- case TiXmlNode::TINYXML_TEXT:
|
|
|
|
|
- {
|
|
|
|
|
- TiXmlText* childText = node->ToText();
|
|
|
|
|
- if (childText) PrepareTextFromText(childText->Value(), colour);
|
|
|
|
|
- }
|
|
|
|
|
- break;
|
|
|
|
|
- case TiXmlNode::TINYXML_ELEMENT:
|
|
|
|
|
- {
|
|
|
|
|
- Ogre::ColourValue colour_child = colour;
|
|
|
|
|
- Ogre::String name = node->ValueStr();
|
|
|
|
|
- if (name == "colour"){
|
|
|
|
|
- colour_child = Ogre::StringConverter::parseColourValue(
|
|
|
|
|
- node->ToElement()->Attribute("value")
|
|
|
|
|
- );
|
|
|
|
|
- }
|
|
|
|
|
- else if (name == "pause_ok"){
|
|
|
|
|
- TextChar new_char;
|
|
|
|
|
- new_char.pause_ok = true;
|
|
|
|
|
- text_.push_back(new_char);
|
|
|
|
|
- }
|
|
|
|
|
- else if (name == "pause"){
|
|
|
|
|
- const std::string* string
|
|
|
|
|
- = node->ToElement()->Attribute(Ogre::String("time"));
|
|
|
|
|
- if (string != NULL){
|
|
|
|
|
- TextChar new_char;
|
|
|
|
|
- // The time of the pause is in frames of the game (30 per second), as in the original game.
|
|
|
|
|
- new_char.pause_time = Ogre::StringConverter::parseReal(*string) / 30.0f;
|
|
|
|
|
- text_.push_back(new_char);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- else if (name == "next_page"){
|
|
|
|
|
- TextChar new_char;
|
|
|
|
|
- new_char.next_page = true;
|
|
|
|
|
- text_.push_back(new_char);
|
|
|
|
|
- }
|
|
|
|
|
- else if (name == "timer"){
|
|
|
|
|
- timer_ = true;
|
|
|
|
|
- TextChar new_char;
|
|
|
|
|
- new_char.skip = true;
|
|
|
|
|
- new_char.variable = "UITextAreaTimer";
|
|
|
|
|
- new_char.colour = colour;
|
|
|
|
|
- Ogre::UTFString var = GetVariable("UITextAreaTimer");
|
|
|
|
|
- new_char.variable_len = var.size();
|
|
|
|
|
- text_.push_back(new_char);
|
|
|
|
|
- for (unsigned int i = 0; i < var.size(); ++ i){
|
|
|
|
|
- TextChar text_char;
|
|
|
|
|
- text_char.char_code = var[i];
|
|
|
|
|
- text_char.colour = colour;
|
|
|
|
|
- text_.push_back(text_char);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- else if (name == "variable"){
|
|
|
|
|
- const std::string* string
|
|
|
|
|
- = node->ToElement()->Attribute(Ogre::String("name"));
|
|
|
|
|
- if (string != NULL){
|
|
|
|
|
- TextChar new_char;
|
|
|
|
|
- new_char.skip = true;
|
|
|
|
|
- new_char.variable = *string;
|
|
|
|
|
- new_char.colour = colour;
|
|
|
|
|
- Ogre::UTFString var = GetVariable(*string);
|
|
|
|
|
- new_char.variable_len = var.size();
|
|
|
|
|
- text_.push_back(new_char);
|
|
|
|
|
- for (unsigned int i = 0; i < var.size(); ++ i){
|
|
|
|
|
- TextChar text_char;
|
|
|
|
|
- text_char.char_code = var[i];
|
|
|
|
|
- text_char.colour = colour;
|
|
|
|
|
- text_.push_back(text_char);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- else if (name == "character"){
|
|
|
|
|
- const std::string* id = node->ToElement()->Attribute(Ogre::String("id"));
|
|
|
|
|
- const std::string char_name = TextHandler::getSingleton().GetCharacterName(
|
|
|
|
|
- std::stoi(*id)
|
|
|
|
|
- );
|
|
|
|
|
- for (unsigned int i = 0; i < char_name.length(); ++ i){
|
|
|
|
|
- TextChar text_char;
|
|
|
|
|
- text_char.char_code = char_name.at(i);
|
|
|
|
|
- text_char.colour = colour;
|
|
|
|
|
- text_.push_back(text_char);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- else if (name == "party"){
|
|
|
|
|
- const std::string* pos = node->ToElement()->Attribute(Ogre::String("pos"));
|
|
|
|
|
- const std::string char_name
|
|
|
|
|
- = TextHandler::getSingleton().GetPartyCharacterName(std::stoi(*pos));
|
|
|
|
|
- for (unsigned int i = 0; i < char_name.length(); ++ i){
|
|
|
|
|
- TextChar text_char;
|
|
|
|
|
- text_char.char_code = char_name.at(i);
|
|
|
|
|
- text_char.colour = colour;
|
|
|
|
|
- text_.push_back(text_char);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- else if (name == "include"){
|
|
|
|
|
- const std::string* text_name = node->ToElement()->Attribute(
|
|
|
|
|
- Ogre::String("name")
|
|
|
|
|
- );
|
|
|
|
|
- if (text_name != NULL){
|
|
|
|
|
- TiXmlNode* text = TextHandler::getSingleton().GetText(*text_name);
|
|
|
|
|
- if (text != NULL) PrepareTextFromNode(text, colour_child);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- else if (name == "image"){
|
|
|
|
|
- Ogre::String name1 = GetString(node, "sprite");
|
|
|
|
|
- if (name1 != ""){
|
|
|
|
|
- TiXmlNode* sprites = UiManager::getSingleton().GetPrototype(
|
|
|
|
|
- "TextAreaSprite"
|
|
|
|
|
- );
|
|
|
|
|
- if (sprites != NULL){
|
|
|
|
|
- sprites = sprites->FirstChild();
|
|
|
|
|
- while (sprites != NULL){
|
|
|
|
|
- if (
|
|
|
|
|
- sprites->Type() == TiXmlNode::TINYXML_ELEMENT
|
|
|
|
|
- && sprites->ValueStr() == "sprite"
|
|
|
|
|
- ){
|
|
|
|
|
- Ogre::String name2 = GetString(sprites, "name");
|
|
|
|
|
- if (name1 == name2){
|
|
|
|
|
- TextChar new_char;
|
|
|
|
|
- UiSprite* sprite = new UiSprite(
|
|
|
|
|
- name1, name_ + "." + name1, this
|
|
|
|
|
- );
|
|
|
|
|
- Ogre::String image = GetString(sprites, "image");
|
|
|
|
|
- if (image != "") sprite->SetImage(image);
|
|
|
|
|
- Ogre::String y_str = GetString(sprites, "y");
|
|
|
|
|
- if (y_str != ""){
|
|
|
|
|
- float y_percent = 0;
|
|
|
|
|
- float y = 0;
|
|
|
|
|
- ParsePercent(y_percent, y, y_str);
|
|
|
|
|
- new_char.sprite_y = y;
|
|
|
|
|
- }
|
|
|
|
|
- Ogre::String width_str = GetString(sprites, "width");
|
|
|
|
|
- if (width_str != ""){
|
|
|
|
|
- float width_percent = 0;
|
|
|
|
|
- float width = 0;
|
|
|
|
|
- ParsePercent(width_percent, width, width_str);
|
|
|
|
|
- sprite->SetWidth(0, width);
|
|
|
|
|
- }
|
|
|
|
|
- Ogre::String height_str = GetString(sprites, "height");
|
|
|
|
|
- if (height_str != ""){
|
|
|
|
|
- float height_percent = 0;
|
|
|
|
|
- float height = 0;
|
|
|
|
|
- ParsePercent(height_percent, height, height_str);
|
|
|
|
|
- sprite->SetHeight(height_percent, height);
|
|
|
|
|
- }
|
|
|
|
|
- sprite->SetVisible(false);
|
|
|
|
|
- AddChild(sprite);
|
|
|
|
|
- new_char.sprite = sprite;
|
|
|
|
|
- text_.push_back(new_char);
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- sprites = sprites->NextSibling();
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- TiXmlNode* node_child = node->FirstChild();
|
|
|
|
|
- if (node_child != NULL) PrepareTextFromNode(node_child, colour_child);
|
|
|
|
|
- }
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
- node = node->NextSibling();
|
|
|
|
|
|
|
+ else if (character.next_page){
|
|
|
|
|
+ next_page_start_ = index + 1;
|
|
|
|
|
+ text_state_ = TS_NEXT_PAGE;
|
|
|
}
|
|
}
|
|
|
|
|
+ else return false;
|
|
|
|
|
+ // The command is done only once.
|
|
|
|
|
+ character.skip = true;
|
|
|
|
|
+ return true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-void UiTextArea::SetTextFromNode(TiXmlNode* node, const Ogre::ColourValue& colour){
|
|
|
|
|
- switch(node->Type()){
|
|
|
|
|
- case TiXmlNode::TINYXML_TEXT:
|
|
|
|
|
- {
|
|
|
|
|
- TiXmlText* childText = node->ToText();
|
|
|
|
|
- if (childText) PrepareTextFromText(childText->Value(), colour);
|
|
|
|
|
- }
|
|
|
|
|
- break;
|
|
|
|
|
- case TiXmlNode::TINYXML_ELEMENT:
|
|
|
|
|
- {
|
|
|
|
|
- Ogre::ColourValue colour_child = colour;
|
|
|
|
|
- Ogre::String name = node->ValueStr();
|
|
|
|
|
- if (name == "colour"){
|
|
|
|
|
- colour_child = Ogre::StringConverter::parseColourValue(
|
|
|
|
|
- node->ToElement()->Attribute("value")
|
|
|
|
|
- );
|
|
|
|
|
- }
|
|
|
|
|
- else if (name == "pause_ok"){
|
|
|
|
|
- TextChar new_char;
|
|
|
|
|
- new_char.pause_ok = true;
|
|
|
|
|
- text_.push_back(new_char);
|
|
|
|
|
- }
|
|
|
|
|
- else if (name == "pause"){
|
|
|
|
|
- const std::string* string
|
|
|
|
|
- = node->ToElement()->Attribute(Ogre::String("time"));
|
|
|
|
|
- if (string != NULL){
|
|
|
|
|
- TextChar new_char;
|
|
|
|
|
- // The time of the pause is in frames of the game (30 per second), as in the original game.
|
|
|
|
|
- new_char.pause_time = Ogre::StringConverter::parseReal(*string) / 30.0f;
|
|
|
|
|
- text_.push_back(new_char);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- else if (name == "next_page"){
|
|
|
|
|
- TextChar new_char;
|
|
|
|
|
- new_char.next_page = true;
|
|
|
|
|
- text_.push_back(new_char);
|
|
|
|
|
- }
|
|
|
|
|
- else if (name == "timer"){
|
|
|
|
|
- timer_ = true;
|
|
|
|
|
- TextChar new_char;
|
|
|
|
|
- new_char.skip = true;
|
|
|
|
|
- new_char.variable = "UITextAreaTimer";
|
|
|
|
|
- new_char.colour = colour;
|
|
|
|
|
- Ogre::UTFString var = GetVariable("UITextAreaTimer");
|
|
|
|
|
- new_char.variable_len = var.size();
|
|
|
|
|
- text_.push_back(new_char);
|
|
|
|
|
- for (unsigned int i = 0; i < var.size(); ++ i){
|
|
|
|
|
- TextChar text_char;
|
|
|
|
|
- text_char.char_code = var[i];
|
|
|
|
|
- text_char.colour = colour;
|
|
|
|
|
- text_.push_back(text_char);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- else if (name == "variable"){
|
|
|
|
|
- const std::string* string
|
|
|
|
|
- = node->ToElement()->Attribute(Ogre::String("name"));
|
|
|
|
|
- if (string != NULL){
|
|
|
|
|
- TextChar new_char;
|
|
|
|
|
- new_char.skip = true;
|
|
|
|
|
- new_char.variable = *string;
|
|
|
|
|
- new_char.colour = colour;
|
|
|
|
|
- Ogre::UTFString var = GetVariable(*string);
|
|
|
|
|
- new_char.variable_len = var.size();
|
|
|
|
|
- text_.push_back(new_char);
|
|
|
|
|
- for (unsigned int i = 0; i < var.size(); ++ i){
|
|
|
|
|
- TextChar text_char;
|
|
|
|
|
- text_char.char_code = var[i];
|
|
|
|
|
- text_char.colour = colour;
|
|
|
|
|
- text_.push_back(text_char);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- else if (name == "character"){
|
|
|
|
|
- const std::string* id = node->ToElement()->Attribute(Ogre::String("id"));
|
|
|
|
|
- const std::string char_name = TextHandler::getSingleton().GetCharacterName(
|
|
|
|
|
- std::stoi(*id)
|
|
|
|
|
- );
|
|
|
|
|
- for (unsigned int i = 0; i < char_name.length(); ++ i){
|
|
|
|
|
- TextChar text_char;
|
|
|
|
|
- text_char.char_code = char_name.at(i);
|
|
|
|
|
- text_char.colour = colour;
|
|
|
|
|
- text_.push_back(text_char);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- else if (name == "party"){
|
|
|
|
|
- const std::string* pos = node->ToElement()->Attribute(Ogre::String("pos"));
|
|
|
|
|
- const std::string char_name
|
|
|
|
|
- = TextHandler::getSingleton().GetPartyCharacterName(std::stoi(*pos));
|
|
|
|
|
- for (unsigned int i = 0; i < char_name.length(); ++ i){
|
|
|
|
|
- TextChar text_char;
|
|
|
|
|
- text_char.char_code = char_name.at(i);
|
|
|
|
|
- text_char.colour = colour;
|
|
|
|
|
- text_.push_back(text_char);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- else if (name == "include"){
|
|
|
|
|
- const std::string* text_name = node->ToElement()->Attribute(
|
|
|
|
|
- Ogre::String("name")
|
|
|
|
|
- );
|
|
|
|
|
- if (text_name != NULL){
|
|
|
|
|
- TiXmlNode* text = TextHandler::getSingleton().GetText(*text_name);
|
|
|
|
|
- if (text != NULL) SetTextFromNode(text, colour_child);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- else if (name == "image"){
|
|
|
|
|
- Ogre::String name1 = GetString(node, "sprite");
|
|
|
|
|
- if (name1 != ""){
|
|
|
|
|
- TiXmlNode* sprites = UiManager::getSingleton().GetPrototype(
|
|
|
|
|
- "TextAreaSprite"
|
|
|
|
|
- );
|
|
|
|
|
- if (sprites != NULL){
|
|
|
|
|
- sprites = sprites->FirstChild();
|
|
|
|
|
- while (sprites != NULL){
|
|
|
|
|
- if (
|
|
|
|
|
- sprites->Type() == TiXmlNode::TINYXML_ELEMENT
|
|
|
|
|
- && sprites->ValueStr() == "sprite"
|
|
|
|
|
- ){
|
|
|
|
|
- Ogre::String name2 = GetString(sprites, "name");
|
|
|
|
|
- if (name1 == name2){
|
|
|
|
|
- TextChar new_char;
|
|
|
|
|
- UiSprite* sprite = new UiSprite(
|
|
|
|
|
- name1, name_ + "." + name1, this
|
|
|
|
|
- );
|
|
|
|
|
- Ogre::String image = GetString(sprites, "image");
|
|
|
|
|
- if (image != "") sprite->SetImage(image);
|
|
|
|
|
- Ogre::String y_str = GetString(sprites, "y");
|
|
|
|
|
- if (y_str != ""){
|
|
|
|
|
- float y_percent = 0;
|
|
|
|
|
- float y = 0;
|
|
|
|
|
- ParsePercent(y_percent, y, y_str);
|
|
|
|
|
- new_char.sprite_y = y;
|
|
|
|
|
- }
|
|
|
|
|
- Ogre::String width_str = GetString(sprites, "width");
|
|
|
|
|
- if (width_str != ""){
|
|
|
|
|
- float width_percent = 0;
|
|
|
|
|
- float width = 0;
|
|
|
|
|
- ParsePercent(width_percent, width, width_str);
|
|
|
|
|
- sprite->SetWidth(0, width);
|
|
|
|
|
- }
|
|
|
|
|
- Ogre::String height_str = GetString(sprites, "height");
|
|
|
|
|
- if (height_str != ""){
|
|
|
|
|
- float height_percent = 0;
|
|
|
|
|
- float height = 0;
|
|
|
|
|
- ParsePercent(height_percent, height, height_str);
|
|
|
|
|
- sprite->SetHeight(height_percent, height);
|
|
|
|
|
- }
|
|
|
|
|
- sprite->SetVisible(false);
|
|
|
|
|
- AddChild(sprite);
|
|
|
|
|
- new_char.sprite = sprite;
|
|
|
|
|
- text_.push_back(new_char);
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- sprites = sprites->NextSibling();
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- TiXmlNode* node_child = node->FirstChild();
|
|
|
|
|
- if (node_child != NULL) SetTextFromNode(node_child, colour_child);
|
|
|
|
|
- }
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+void UiTextArea::PlaceSprite(const TextChar& character, UiTextLayout& layout){
|
|
|
|
|
+ float percent = 0;
|
|
|
|
|
+ float width = 0;
|
|
|
|
|
+ character.sprite->GetWidth(percent, width);
|
|
|
|
|
+ float x = 0;
|
|
|
|
|
+ float y = 0;
|
|
|
|
|
+ layout.PlaceImage(width, x, y);
|
|
|
|
|
+ character.sprite->SetX(0, x);
|
|
|
|
|
+ character.sprite->SetY(0, character.sprite_y + y);
|
|
|
|
|
+ character.sprite->SetVisible(true);
|
|
|
|
|
+ character.sprite->UpdateGeometry();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-void UiTextArea::PrepareTextFromText(
|
|
|
|
|
- const Ogre::UTFString& text, const Ogre::ColourValue& colour_child
|
|
|
|
|
|
|
+void UiTextArea::WriteCharacter(
|
|
|
|
|
+ float*& vertices, const UiTextLayout::Box& box, const UiCharData& data,
|
|
|
|
|
+ const Ogre::ColourValue& colour
|
|
|
){
|
|
){
|
|
|
- for (unsigned int i = 0; i < text.size(); ++ i){
|
|
|
|
|
- TextChar new_char;
|
|
|
|
|
- new_char.char_code = text[i];
|
|
|
|
|
- new_char.colour = colour_child;
|
|
|
|
|
- text_.push_back(new_char);
|
|
|
|
|
|
|
+ const float width = font_->GetImageWidth();
|
|
|
|
|
+ const float height = font_->GetImageHeight();
|
|
|
|
|
+ const UiTextLayout::Box texture{
|
|
|
|
|
+ static_cast<float>(data.x) / width, static_cast<float>(data.y) / height,
|
|
|
|
|
+ static_cast<float>(data.x + data.width) / width,
|
|
|
|
|
+ static_cast<float>(data.y + data.height) / height
|
|
|
};
|
|
};
|
|
|
|
|
+ const std::array<Ogre::Vector2, 4> corners = UiTextLayout::ScreenCorners(
|
|
|
|
|
+ box, final_translate_, final_rotation_, Ogre::Vector2(screen_width_, screen_height_)
|
|
|
|
|
+ );
|
|
|
|
|
+ UiTextLayout::WriteQuad(vertices, corners, texture, final_z_, colour);
|
|
|
|
|
+ render_operation_.vertexData->vertexCount += 6;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void UiTextArea::GrowVertexBuffer(const unsigned int letters){
|
|
void UiTextArea::GrowVertexBuffer(const unsigned int letters){
|