00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "Labels.h"
00010
00011 #include "Path.h"
00012 #include "ResDialogPack.h"
00013 #include "Dialog.h"
00014 #include "ScriptState.h"
00015 #include "def-script.h"
00016
00017
00018 inline Labels *
00019 getLabels(lua_State *L)
00020 {
00021 return dynamic_cast<Labels*>(script_getLeader(L));
00022 }
00023
00024
00025
00026
00027 int
00028 script_label_text(lua_State *L) throw()
00029 {
00030 BEGIN_NOEXCEPTION;
00031 const char *labelName = luaL_checkstring(L, 1);
00032 const char *lang = luaL_checkstring(L, 2);
00033 const char *text = luaL_checkstring(L, 3);
00034
00035 getLabels(L)->addLabel(labelName, lang, text);
00036 END_NOEXCEPTION;
00037 return 0;
00038 }
00039
00040
00041 Labels::Labels(const Path &source)
00042 {
00043 m_labels = new ResDialogPack();
00044 m_script->registerFunc("label_text", script_label_text);
00045 scriptInclude(source);
00046 }
00047
00048 Labels::~Labels()
00049 {
00050 m_labels->removeAll();
00051 delete m_labels;
00052 }
00053
00054 void
00055 Labels::addLabel(const std::string &name, const std::string &lang,
00056 const std::string &text)
00057 {
00058 m_labels->addRes(name, new Dialog(lang, "", text));
00059 }
00060
00061 std::string
00062 Labels::getLabel(const std::string &name) const
00063 {
00064 std::string result;
00065 const Dialog *dialog = m_labels->findDialogHard(name);
00066 if (dialog) {
00067 result = dialog->getSubtitle();
00068 }
00069 else {
00070 result = "???";
00071 }
00072 return result;
00073 }
00074
00075 std::string
00076 Labels::getFormatedLabel(const std::string &name,
00077 const StringTool::t_args &args) const
00078 {
00079 std::string result;
00080 const Dialog *dialog = m_labels->findDialogHard(name);
00081 if (dialog) {
00082 result = dialog->getFormatedSubtitle(args);
00083 }
00084 else {
00085 result = "???";
00086 }
00087 return result;
00088 }
00089