Skip to content

Commit

Permalink
xrGame/ui/UITalkDialogWnd.h|cpp: support ShoC/CS dialog style
Browse files Browse the repository at this point in the history
Replaced boilerplate code with UIHelper functions

// XXX: Support stringized (trade_btn, upgrade_btn, exit_btn) callbacks
// To support it we just should check that it doesn't called twice
  • Loading branch information
Xottab-DUTY committed Jan 31, 2019
1 parent 58960f8 commit 40f7e09
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 87 deletions.
196 changes: 117 additions & 79 deletions src/xrGame/ui/UITalkDialogWnd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,27 @@
#include "Level.h"
#include "Actor.h"
#include "alife_registry_wrappers.h"
#include "UIHelper.h"

constexpr pcstr TALK_XML = "talk.xml";

CUITalkDialogWnd::CUITalkDialogWnd()
: m_uiXml(nullptr),
m_pParent(nullptr),
mechanic_mode(false),
m_ClickedQuestionID(""),
UIDialogFrameTop(nullptr),
UIDialogFrameBottom(nullptr),
m_btn_pos(),
UIToExitButton(nullptr),
UIOurIcon(nullptr),
UIOthersIcon(nullptr),
UIQuestionsList(nullptr),
UIAnswersList(nullptr),
m_pNameTextFont(nullptr),
m_iNameTextColor(0),
m_uOurReplicsColor(0) {}

#define TALK_XML "talk.xml"

CUITalkDialogWnd::CUITalkDialogWnd() : m_pNameTextFont(NULL)
{
m_ClickedQuestionID = "";
mechanic_mode = false;
}
CUITalkDialogWnd::~CUITalkDialogWnd() { xr_delete(m_uiXml); }
void CUITalkDialogWnd::InitTalkDialogWnd()
{
Expand All @@ -29,69 +42,83 @@ void CUITalkDialogWnd::InitTalkDialogWnd()

CUIXmlInit::InitWindow(*m_uiXml, "main", 0, this);

// CUIXmlInit::InitStatic (*m_uiXml, "right_character_icon", 0, &UIOurIcon);

// CUIXmlInit::InitStatic (*m_uiXml, "left_character_icon", 0, &UIOthersIcon);

// UIOurIcon.AttachChild (&UICharacterInfoLeft);
// UICharacterInfoLeft.InitCharacterInfo(Fvector2().set(0,0), UIOurIcon.GetWndSize(), "talk_character.xml");
UIOurIcon = UIHelper::CreateStatic(*m_uiXml, "right_character_icon", this, false);
if (UIOurIcon)
{
UIOurIcon->AttachChild(&UICharacterInfoLeft);
UICharacterInfoLeft.InitCharacterInfo(Fvector2().set(0, 0), UIOurIcon->GetWndSize(), "talk_character.xml");
}

// UIOthersIcon.AttachChild (&UICharacterInfoRight);
// UICharacterInfoRight.InitCharacterInfo(Fvector2().set(0,0), UIOthersIcon.GetWndSize(), "talk_character.xml");
UIOthersIcon = UIHelper::CreateStatic(*m_uiXml, "left_character_icon", this, false);
if (UIOthersIcon)
{
UIOthersIcon->AttachChild(&UICharacterInfoRight);
UICharacterInfoRight.InitCharacterInfo(Fvector2().set(0, 0), UIOthersIcon->GetWndSize(), "talk_character.xml");
}

// AttachChild (&UIOurIcon);
// AttachChild (&UIOthersIcon);
CUIWindow* answersParent = this;
CUIWindow* questionsParent = this;

// Фрейм с нащими фразами
// AttachChild (&UIDialogFrameBottom);
// CUIXmlInit::InitStatic (*m_uiXml, "frame_bottom", 0, &UIDialogFrameBottom);
// Our phrases frame
UIDialogFrameBottom = UIHelper::CreateStatic(*m_uiXml, "frame_bottom", this, false);
if (UIDialogFrameBottom)
questionsParent = UIDialogFrameBottom;

//основной фрейм диалога
// AttachChild (&UIDialogFrameTop);
// CUIXmlInit::InitStatic (*m_uiXml, "frame_top", 0, &UIDialogFrameTop);
// Main dialog frame
UIDialogFrameTop = UIHelper::CreateStatic(*m_uiXml, "frame_top", this, false);
if (UIDialogFrameBottom)
answersParent = UIDialogFrameBottom;

//Ответы
UIAnswersList = new CUIScrollView();
UIAnswersList->SetAutoDelete(true);
// UIDialogFrameTop.AttachChild(UIAnswersList);
AttachChild(UIAnswersList);
CUIXmlInit::InitScrollView(*m_uiXml, "answers_list", 0, UIAnswersList);
// Answers
UIAnswersList = UIHelper::CreateScrollView(*m_uiXml, "answers_list", answersParent);
UIAnswersList->SetWindowName("---UIAnswersList");

//Вопросы
UIQuestionsList = new CUIScrollView();
UIQuestionsList->SetAutoDelete(true);
// UIDialogFrameBottom.AttachChild(UIQuestionsList);
AttachChild(UIQuestionsList);
CUIXmlInit::InitScrollView(*m_uiXml, "questions_list", 0, UIQuestionsList);
// Questions
UIQuestionsList = UIHelper::CreateScrollView(*m_uiXml, "questions_list", questionsParent);
UIQuestionsList->SetWindowName("---UIQuestionsList");

//кнопка перехода в режим торговли
AttachChild(&UIToTradeButton);
CUIXmlInit::Init3tButton(*m_uiXml, "button", 0, &UIToTradeButton);

// AttachChild (&UIToExitButton);
// CUIXmlInit::Init3tButton (*m_uiXml, "button_exit", 0, &UIToExitButton);
m_btn_pos[0] = UIToTradeButton.GetWndPos();

UIToExitButton = UIHelper::Create3tButton(*m_uiXml, "button_exit", this, false);
if (UIToExitButton)
{
m_btn_pos[1] = UIToExitButton->GetWndPos();
m_btn_pos[2].x = (m_btn_pos[0].x + m_btn_pos[1].x) / 2.0f;
m_btn_pos[2].y = m_btn_pos[0].y;
}
else
{
m_btn_pos[1] = m_btn_pos[0];
m_btn_pos[2] = m_btn_pos[0];
}

// m_btn_pos[0] = UIToTradeButton.GetWndPos();
// m_btn_pos[1] = UIToExitButton.GetWndPos();
// m_btn_pos[2].x = (m_btn_pos[0].x+m_btn_pos[1].x)/2.0f;
// m_btn_pos[2].y = m_btn_pos[0].y;
// шрифт для индикации имени персонажа в окне разговора
CUIXmlInit::InitFont(*m_uiXml, "font", 0, m_iNameTextColor, m_pNameTextFont);

CGameFont* pFont = NULL;
CGameFont* pFont = nullptr;
CUIXmlInit::InitFont(*m_uiXml, "font", 1, m_uOurReplicsColor, pFont);

SetWindowName("----CUITalkDialogWnd");

Register(&UIToTradeButton);
AddCallbackStr(
"question_item", LIST_ITEM_CLICKED, CUIWndCallback::void_function(this, &CUITalkDialogWnd::OnQuestionClicked));
AddCallback(
&UIToTradeButton, BUTTON_CLICKED, CUIWndCallback::void_function(this, &CUITalkDialogWnd::OnTradeClicked));
// AddCallback (&UIToExitButton,BUTTON_CLICKED,CUIWndCallback::void_function(this,
//&CUITalkDialogWnd::OnExitClicked));
AddCallbackStr("question_item", LIST_ITEM_CLICKED, CUIWndCallback::void_function(this, &CUITalkDialogWnd::OnQuestionClicked));

// XXX: Support stringized (trade_btn, upgrade_btn, exit_btn) callbacks
// To support it we just should check that it doesn't called twice
//AddCallbackStr("trade_btn", BUTTON_CLICKED, CUIWndCallback::void_function(this, &CUITalkDialogWnd::OnTradeClicked));
AddCallback(&UIToTradeButton, BUTTON_CLICKED, CUIWndCallback::void_function(this, &CUITalkDialogWnd::OnTradeClicked));

//AddCallbackStr("upgrade_btn", BUTTON_CLICKED, CUIWndCallback::void_function(this, &CUITalkDialogWnd::OnUpgradeClicked));

if (UIToExitButton)
{
AddCallback(UIToExitButton, BUTTON_CLICKED, CUIWndCallback::void_function(this, &CUITalkDialogWnd::OnExitClicked));
//AddCallbackStr("exit_btn", BUTTON_CLICKED, CUIWndCallback::void_function(this, &CUITalkDialogWnd::OnExitClicked));
}
}

void CUITalkDialogWnd::Show()
Expand Down Expand Up @@ -157,12 +184,13 @@ void CUITalkDialogWnd::AddQuestion(LPCSTR str, LPCSTR value, int number, bool b_
{
string16 buff;
xr_sprintf(buff, "%d.", (number == 10) ? 0 : number);
itm->m_num_text->SetText(buff);
if (itm->m_num_text)
itm->m_num_text->SetText(buff);
itm->m_text->SetAccelerator(SDL_SCANCODE_1 - 1 + number, 0);
}
if (b_finalizer)
{
itm->m_text->SetAccelerator(kQUIT, 2);
itm->m_text->SetAccelerator(kQUIT, 2); // XXX: DON'T USE 2, instead use SDL_SCANCODE_*
itm->m_text->SetAccelerator(kUSE, 3);
}

Expand Down Expand Up @@ -215,11 +243,16 @@ void CUITalkDialogWnd::AddIconedAnswer(LPCSTR caption, LPCSTR text, LPCSTR textu

void CUITalkDialogWnd::SetOsoznanieMode(bool b)
{
// UIOurIcon.Show (!b);
// UIOthersIcon.Show (!b);
if (UIOurIcon)
UIOurIcon->Show(!b);

if (UIOthersIcon)
UIOthersIcon->Show(!b);

UIAnswersList->Show(!b);
// UIDialogFrameTop.Show (!b);

if (UIDialogFrameTop)
UIDialogFrameTop->Show(!b);

UIToTradeButton.Show(!b);
if (mechanic_mode)
Expand All @@ -237,33 +270,44 @@ void CUITalkDialogWnd::SetOsoznanieMode(bool b)
void CUITalkDialogWnd::UpdateButtonsLayout(bool b_disable_break, bool trade_enabled)
{
UIToTradeButton.Show(trade_enabled);

if (UIToExitButton)
{
UIToExitButton->Show(!b_disable_break);

if (UIToExitButton->IsShown() && UIToTradeButton.IsShown())
{
UIToTradeButton.SetWndPos(m_btn_pos[0]);
UIToExitButton->SetWndPos(m_btn_pos[1]);
}
else if (UIToExitButton->IsShown())
{
UIToExitButton->SetWndPos(m_btn_pos[2]);
}
else if (UIToTradeButton.IsShown())
{
UIToTradeButton.SetWndPos(m_btn_pos[2]);
}
}
}

void CUIQuestionItem::SendMessage(CUIWindow* pWnd, s16 msg, void* pData) { CUIWndCallback::OnEvent(pWnd, msg, pData); }
CUIQuestionItem::CUIQuestionItem(CUIXml* xml_doc, LPCSTR path)
{
m_text = new CUI3tButton();
m_text->SetAutoDelete(true);
CUIWindow::AttachChild(m_text);

string512 str;
xr_strcpy(str, path);

CUIXmlInit::InitWindow(*xml_doc, str, 0, this);
CUIXmlInit::InitWindow(*xml_doc, path, 0, this);

m_min_height = xml_doc->ReadAttribFlt(path, 0, "min_height", 15.0f);

string512 str;

strconcat(sizeof(str), str, path, ":content_text");
CUIXmlInit::Init3tButton(*xml_doc, str, 0, m_text);
m_text = UIHelper::Create3tButton(*xml_doc, str, this);

Register(m_text);
AddCallback(m_text, BUTTON_CLICKED, CUIWndCallback::void_function(this, &CUIQuestionItem::OnTextClicked));

m_num_text = new CUITextWnd();
m_num_text->SetAutoDelete(true);
CUIWindow::AttachChild(m_num_text);
strconcat(sizeof(str), str, path, ":num_text");
CUIXmlInit::InitTextWnd(*xml_doc, str, 0, m_num_text);
m_num_text = UIHelper::CreateTextWnd(*xml_doc, str, this, false);
}

void CUIQuestionItem::Init(LPCSTR val, LPCSTR text)
Expand All @@ -282,25 +326,19 @@ void CUIQuestionItem::OnTextClicked(CUIWindow* w, void*)

CUIAnswerItem::CUIAnswerItem(CUIXml* xml_doc, LPCSTR path)
{
m_text = new CUITextWnd();
m_text->SetAutoDelete(true);
m_name = new CUITextWnd();
m_name->SetAutoDelete(true);
CUIWindow::AttachChild(m_text);
CUIWindow::AttachChild(m_name);

string512 str;
xr_strcpy(str, path);

CUIXmlInit::InitWindow(*xml_doc, str, 0, this);
CUIXmlInit::InitWindow(*xml_doc, path, 0, this);

m_min_height = xml_doc->ReadAttribFlt(path, 0, "min_height", 15.0f);
m_bottom_footer = xml_doc->ReadAttribFlt(path, 0, "bottom_footer", 0.0f);

string512 str;

strconcat(sizeof(str), str, path, ":content_text");
CUIXmlInit::InitTextWnd(*xml_doc, str, 0, m_text);
m_text = UIHelper::CreateTextWnd(*xml_doc, str, this);

strconcat(sizeof(str), str, path, ":name_caption");
CUIXmlInit::InitTextWnd(*xml_doc, str, 0, m_name);
m_name = UIHelper::CreateTextWnd(*xml_doc, str, this);

SetAutoDelete(true);
}

Expand Down
22 changes: 14 additions & 8 deletions src/xrGame/ui/UITalkDialogWnd.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ class CUITalkWnd;

class CUITalkDialogWnd : public CUIWindow, public CUIWndCallback
{
private:
typedef CUIWindow inherited;
using inherited = CUIWindow;
CUIXml* m_uiXml;

public:
Expand All @@ -33,15 +32,20 @@ class CUITalkDialogWnd : public CUIWindow, public CUIWndCallback
u32 GetOurReplicsColor() { return m_uOurReplicsColor; }
bool mechanic_mode; // for inventory upgrades

//номер выбранного вопроса
// Selected question number
shared_str m_ClickedQuestionID;

//список вопросов, которые мы можем задавать персонажу
// Dialog interface elements
CUIStatic* UIDialogFrameTop;
CUIStatic* UIDialogFrameBottom;

// Fvector2 m_btn_pos[3];
Fvector2 m_btn_pos[3];
CUI3tButton UIToTradeButton;
// CUI3tButton UIToExitButton;
CUI3tButton* UIToExitButton;

// Characters info
CUIStatic* UIOurIcon;
CUIStatic* UIOthersIcon;
CUICharacterInfo UICharacterInfoLeft;
CUICharacterInfo UICharacterInfoRight;

Expand All @@ -56,13 +60,15 @@ class CUITalkDialogWnd : public CUIWindow, public CUIWndCallback
void UpdateButtonsLayout(bool b_disable_break, bool trade_enabled);

private:
// List of questions we can ask the character
CUIScrollView* UIQuestionsList;
CUIScrollView* UIAnswersList;

// Шрифт и цвет текста с именем персонажа
// Font and colour of text with character name
CGameFont* m_pNameTextFont;
u32 m_iNameTextColor;
// Цвет тeкста и шрифт наших реплик

// Text colour of our replics
u32 m_uOurReplicsColor;

void __stdcall OnTradeClicked(CUIWindow* w, void*);
Expand Down

1 comment on commit 40f7e09

@Xottab-DUTY
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to #382 and #392

Please sign in to comment.