game: make the nick a link to the player info dialog

This commit is contained in:
Crypto City 2020-04-10 01:59:43 +00:00
parent 15f5524e58
commit 49f0ad2e11
7 changed files with 55 additions and 15 deletions

View File

@ -1,7 +1,7 @@
WindowInfo
TBLayout: axis: x, distribution-position: "left top"
TBLayout: axis: x, distribution-position: "left top", spacing: 2
TBTextField: id: "prefix"
font: size: 8px
TBTextField: id: "source"
TBButton: id: "source", skin: "TBButton.chat.source"
TBLayout: axis: x, id: "payload"

View File

@ -83,3 +83,6 @@ elements
TBEditField.item-description
TBEditField.public-key
TBButton.chat.source
padding 0

2
external/tb vendored

@ -1 +1 @@
Subproject commit f06e705bd80be284667c60268fb1eb3d2628b8ac
Subproject commit af7b449304159716495dd474155b429bb50e7c45

View File

@ -188,6 +188,7 @@ public:
void HandleRequestItemData(StringHash eventType, VariantMap& eventData);
void HandleRequestBadgeData(StringHash eventType, VariantMap& eventData);
void HandleConsoleCommand(StringHash eventType, VariantMap& eventData);
void HandleConsoleSource(StringHash eventType, VariantMap& eventData);
void HandleGetConsoleFilter(StringHash eventType, VariantMap& eventData);
void HandleSetConsoleFilter(StringHash eventType, VariantMap& eventData);
void HandleChat(StringHash eventType, VariantMap& eventData);
@ -783,6 +784,7 @@ void CryptoCityUrho3D::SetupUI()
SubscribeToEvent(console, E_UI_CONSOLE_COMMAND, URHO3D_HANDLER(CryptoCityUrho3D, HandleConsoleCommand));
SubscribeToEvent(console, E_UI_CONSOLE_GET_FILTER, URHO3D_HANDLER(CryptoCityUrho3D, HandleGetConsoleFilter));
SubscribeToEvent(console, E_UI_CONSOLE_SET_FILTER, URHO3D_HANDLER(CryptoCityUrho3D, HandleSetConsoleFilter));
SubscribeToEvent(console, E_UI_CONSOLE_SOURCE, URHO3D_HANDLER(CryptoCityUrho3D, HandleConsoleSource));
LoadControls();
}
@ -3398,15 +3400,15 @@ void CryptoCityUrho3D::HandleNewChatLine(StringHash eventType, VariantMap& event
const String stimestamp = tools::get_human_readable_timestamp(timestamp).c_str();
const String prefix = "(" + stimestamp + ")";
String source;
std::pair<String, uint32_t> source;
if (me)
{
source = "";
source = std::make_pair("", 0);
line = String(gameState.get_player_name(account_id).c_str()) + " " + line;
}
else
{
source += gameState.get_player_name(account_id).c_str();
source = std::make_pair(gameState.get_player_name(account_id).c_str(), account_id);
}
console->AddLine(prefix, source, line, me ? "ChatEmoteStyle" : "ChatDefaultStyle", color);
@ -3434,7 +3436,7 @@ void CryptoCityUrho3D::HandleWalletSynced(StringHash eventType, VariantMap& even
void CryptoCityUrho3D::HandleGameNotification(StringHash eventType, VariantMap& eventData)
{
String text = eventData[GameNotification::P_TEXT].GetString();
console->AddLine("", "", text, "ChatNotificationStyle", 0);
console->AddLine("", std::make_pair("", 0), text, "ChatNotificationStyle", 0);
}
void CryptoCityUrho3D::SetWindowTitleAndIcon()
@ -3987,6 +3989,12 @@ void CryptoCityUrho3D::HandleConsoleCommand(StringHash eventType, VariantMap& ev
wallet->set_attribute("CC/ChatColor", std::to_string(color));
}
void CryptoCityUrho3D::HandleConsoleSource(StringHash eventType, VariantMap& eventData)
{
const uint32_t id = eventData[UIConsoleSource::P_SOURCE].GetUInt();
ui->ShowPlayerInfo(id);
}
void CryptoCityUrho3D::HandleGetConsoleFilter(StringHash eventType, VariantMap& eventData)
{
std::shared_ptr<tools::wallet2> w = wallet->wallet();

View File

@ -63,6 +63,18 @@ static TBColor color2tb(const Urho3D::Color &c)
return TBColor(c.r_ * 255, c.g_ * 255, c.b_ * 255, c.a_ * 255);
}
class SourceButton: public TBButton
{
public:
SourceButton(): TBButton() {}
virtual void OnHoverChanged(bool hover) {
SetUnderline(hover);
}
private:
};
UIConsole::RowWidget::RowWidget(UIConsole::RowItem *item, RowDataSource *source, TBSelectItemViewer *source_viewer, int index):
m_source(source),
m_source_viewer(source_viewer),
@ -130,12 +142,19 @@ TBWidget *UIConsole::RowDataSource::CreateItemWidget(int index, TBSelectItemView
if (TBLayout *layout = new UIConsole::RowWidget(item, this, viewer, index))
{
TBLayout *row = layout->GetWidgetByIDAndType<TBLayout>("payload");
TBTextField *source_field = layout->GetWidgetByIDAndType<TBTextField>("source");
TBButton *old_source_field = layout->GetWidgetByIDAndType<TBButton>("source");
source_field->SetText(item->row.source.CString());
SourceButton *source_field = new SourceButton();
source_field->SetID(old_source_field->GetID());
source_field->SetSkinBg(old_source_field->GetSkinBg());
old_source_field->GetParent()->AddChildRelative(source_field, WIDGET_Z_REL_BEFORE, old_source_field);
old_source_field->GetParent()->RemoveChild(old_source_field);
source_field->SetText(item->row.source.first.CString());
source_field->data.SetInt(item->row.source.second);
if (colors && item->row.color < colors->size())
source_field->SetTextColor(color2tb((*colors)[item->row.color].second));
if (!item->row.source.Empty())
if (!item->row.source.first.Empty())
{
TBTextField *text = new TBTextField();
text->SetText(": ");
@ -830,7 +849,7 @@ bool UIConsole::HasUnreadPrefix(const char *prefix) const
return false;
}
void UIConsole::AddLine(const String &prefix, const String &source, const String &line, const String &style, unsigned color)
void UIConsole::AddLine(const String &prefix, const std::pair<String, uint32_t> &source, const String &line, const String &style, unsigned color)
{
if (prefix.Empty())
{
@ -892,6 +911,14 @@ void UIConsole::HandleClear(StringHash eventType, VariantMap& eventData)
lineEdit_->SetText("");
}
void UIConsole::HandleSource(StringHash eventType, VariantMap& eventData)
{
TBWidgetEvent *ev = (TBWidgetEvent*)eventData[TBWidgetEventNamespace::P_WIDGET_EVENT].GetVoidPtr();
VariantMap sourceEventData;
sourceEventData[UIConsoleSource::P_SOURCE] = (uint32_t)ev->target->data.GetInt();
SendEvent(E_UI_CONSOLE_SOURCE, sourceEventData);
}
void UIConsole::HandleTBMessage(StringHash eventType, VariantMap& eventData)
{
#define CONNECT(name, function) do { if (ev->target->GetID() == TBIDC(name)) function(eventType, eventData); } while(0)
@ -902,6 +929,7 @@ void UIConsole::HandleTBMessage(StringHash eventType, VariantMap& eventData)
{
CONNECT("send", HandleTextFinished);
CONNECT("clear", HandleClear);
CONNECT("source", HandleSource);
if (!lineEdit_->GetReadOnly())
{

View File

@ -52,6 +52,7 @@ class UITBAnimatedImageWidget;
URHO3D_EVENT(E_UI_CONSOLE_COMMAND, UIConsoleCommand) { URHO3D_PARAM(P_COMMAND, Command); URHO3D_PARAM(P_ID, ID); URHO3D_PARAM(P_COLOR, Color); }
URHO3D_EVENT(E_UI_CONSOLE_GET_FILTER, UIConsoleGetFilter) { URHO3D_PARAM(P_FILTER, Filter); }
URHO3D_EVENT(E_UI_CONSOLE_SET_FILTER, UIConsoleSetFilter) { URHO3D_PARAM(P_FILTER, Filter); }
URHO3D_EVENT(E_UI_CONSOLE_SOURCE, UIConsoleSource) { URHO3D_PARAM(P_SOURCE, Source); }
class ConsoleInputWidget: public Urho3D::Object, public tb::TBEditField
{
@ -70,7 +71,7 @@ class UIConsole: public UITBWindow
struct row_data_t
{
Urho3D::String prefix;
Urho3D::String source;
std::pair<Urho3D::String, uint32_t> source;
Urho3D::String line;
Urho3D::String style;
unsigned color;
@ -204,7 +205,7 @@ public:
void AddInterpreter(const Urho3D::String &name);
void RemoveInterpreter(const Urho3D::String &name);
void AddLine(const Urho3D::String &prefix, const Urho3D::String &source, const Urho3D::String &line, const Urho3D::String &style = "", unsigned color = 0);
void AddLine(const Urho3D::String &prefix, const std::pair<Urho3D::String, uint32_t> &source, const Urho3D::String &line, const Urho3D::String &style = "", unsigned color = 0);
void SetPrefixStyle(const Urho3D::String &s);
void AddImages(const std::vector<std::pair<std::string, std::vector<std::pair<std::shared_ptr<tb::TBBitmap>, unsigned int>>>> &new_images, bool clear = false);
void AddColors(const std::vector<std::pair<std::string, Urho3D::Color>> &new_colors, bool clear = false);
@ -242,6 +243,7 @@ private:
void HandleClose(Urho3D::StringHash eventType, Urho3D::VariantMap& eventData);
void HandleColorSelected(Urho3D::StringHash eventType, Urho3D::VariantMap& eventData);
void HandleFiltersChanged(Urho3D::StringHash eventType, Urho3D::VariantMap& eventData);
void HandleSource(Urho3D::StringHash eventType, Urho3D::VariantMap& eventData);
/// Container for text rows.
tb::TBSelectList* rowContainer_;

View File

@ -128,6 +128,7 @@ public:
void Update(uint32_t mouse_x, uint32_t mouse_y, uint32_t sx0, uint32_t sy0, uint32_t sx1, uint32_t sy1, bool showingFlags, bool building, unsigned num_unread_chat_lines, bool highlight_chat, const std::shared_ptr<GameWallet> &w);
void NewTradeCommand();
void ShowOptions();
void ShowPlayerInfo(uint32_t player_id);
private:
void CreatePlayerWindow();
@ -208,8 +209,6 @@ private:
void ShowWidget(const tb::TBID &id, bool enable);
void ToggleWidget(tb::TBToggleContainer *widget, bool show);
void ShowPlayerInfo(uint32_t player_id);
private:
const GameState *gameState;