forked from townforge/townforge
game: include number of unread messages in the main ui panel
This commit is contained in:
parent
16527555e2
commit
eceb994eef
@ -24,17 +24,19 @@ struct cc_message_t
|
||||
uint32_t address;
|
||||
bool sma;
|
||||
bool reply;
|
||||
bool read;
|
||||
|
||||
bool operator==(const cc_message_t &other) const {
|
||||
return id == other.id
|
||||
&& sender == other.sender && recipient == other.recipient
|
||||
&& height == other.height && timestamp == other.timestamp
|
||||
&& subject == other.subject && message == other.message
|
||||
&& address == other.address && sma == other.sma && reply == other.reply;
|
||||
&& address == other.address && sma == other.sma && reply == other.reply
|
||||
&& read == other.read;
|
||||
}
|
||||
|
||||
BEGIN_SERIALIZE_OBJECT()
|
||||
VERSION_FIELD(0)
|
||||
VERSION_FIELD(1)
|
||||
FIELD(id)
|
||||
VARINT_FIELD(sender)
|
||||
VARINT_FIELD(recipient)
|
||||
@ -45,6 +47,12 @@ struct cc_message_t
|
||||
FIELD(address)
|
||||
FIELD(sma)
|
||||
FIELD(reply)
|
||||
if (version < 1)
|
||||
{
|
||||
read = false;
|
||||
return true;
|
||||
}
|
||||
FIELD(read)
|
||||
END_SERIALIZE()
|
||||
};
|
||||
|
||||
|
@ -391,7 +391,9 @@ public:
|
||||
bool get_cc_crop_yield(uint32_t flag, uint32_t &yield);
|
||||
bool get_cc_item_ownership(uint32_t item, std::vector<std::pair<uint32_t, uint32_t>> &ownership);
|
||||
const std::vector<cc::cc_message_t> get_cc_messages();
|
||||
size_t get_num_unread_cc_messages();
|
||||
void delete_cc_message(const crypto::hash &txid);
|
||||
void set_cc_message_read(const crypto::hash &txid);
|
||||
bool send_cc_message(uint32_t recipient, bool reply, const std::string &subject, const std::string &message);
|
||||
void set_cc_pm_key(uint32_t account, const crypto::public_key &pmspk, const crypto::public_key &pmvpk);
|
||||
bool get_cc_pm_key(uint32_t account, crypto::public_key &pmspk, crypto::public_key &pmvpk);
|
||||
@ -1983,6 +1985,13 @@ const std::vector<cc::cc_message_t> GameWalletInternal::get_cc_messages()
|
||||
return w->get_cc_messages();
|
||||
}
|
||||
|
||||
size_t GameWalletInternal::get_num_unread_cc_messages()
|
||||
{
|
||||
std::shared_ptr<tools::wallet2> w = wallet();
|
||||
boost::unique_lock<boost::mutex> lock(mutex);
|
||||
return w->get_num_unread_cc_messages();
|
||||
}
|
||||
|
||||
void GameWalletInternal::delete_cc_message(const crypto::hash &txid)
|
||||
{
|
||||
std::shared_ptr<tools::wallet2> w = wallet();
|
||||
@ -1990,6 +1999,13 @@ void GameWalletInternal::delete_cc_message(const crypto::hash &txid)
|
||||
w->delete_cc_message(txid);
|
||||
}
|
||||
|
||||
void GameWalletInternal::set_cc_message_read(const crypto::hash &txid)
|
||||
{
|
||||
std::shared_ptr<tools::wallet2> w = wallet();
|
||||
boost::unique_lock<boost::mutex> lock(mutex);
|
||||
w->set_cc_message_read(txid);
|
||||
}
|
||||
|
||||
void GameWalletInternal::set_cc_pm_key(uint32_t account, const crypto::public_key &pmspk, const crypto::public_key &pmvpk)
|
||||
{
|
||||
std::shared_ptr<tools::wallet2> w = wallet();
|
||||
@ -3244,11 +3260,21 @@ const std::vector<cc::cc_message_t> GameWallet::get_cc_messages()
|
||||
return internal->get_cc_messages();
|
||||
}
|
||||
|
||||
size_t GameWallet::get_num_unread_cc_messages()
|
||||
{
|
||||
return internal->get_num_unread_cc_messages();
|
||||
}
|
||||
|
||||
void GameWallet::delete_cc_message(const crypto::hash &txid)
|
||||
{
|
||||
internal->delete_cc_message(txid);
|
||||
}
|
||||
|
||||
void GameWallet::set_cc_message_read(const crypto::hash &txid)
|
||||
{
|
||||
internal->set_cc_message_read(txid);
|
||||
}
|
||||
|
||||
void GameWallet::set_cc_pm_key(uint32_t account, const crypto::public_key &pmspk, const crypto::public_key &pmvpk)
|
||||
{
|
||||
internal->set_cc_pm_key(account, pmspk, pmvpk);
|
||||
|
@ -144,7 +144,9 @@ public:
|
||||
const std::vector<std::tuple<std::string, std::string, std::string>> &get_cc_vistas();
|
||||
|
||||
const std::vector<cc::cc_message_t> get_cc_messages();
|
||||
size_t get_num_unread_cc_messages();
|
||||
void delete_cc_message(const crypto::hash &txid);
|
||||
void set_cc_message_read(const crypto::hash &txid);
|
||||
bool send_cc_message(uint32_t recipient, bool reply, const std::string &subject, const std::string &message);
|
||||
void set_cc_pm_key(uint32_t account, const crypto::public_key &pmspk, const crypto::public_key &pmvpk);
|
||||
bool get_cc_pm_key(uint32_t account, crypto::public_key &pmspk, crypto::public_key &pmvpk);
|
||||
|
@ -534,6 +534,7 @@ public:
|
||||
void HandleSendMessage(StringHash eventType, VariantMap& eventData);
|
||||
void HandleDeleteMessage(StringHash eventType, VariantMap& eventData);
|
||||
void HandleSweepMessageFees(StringHash eventType, VariantMap& eventData);
|
||||
void HandleMessagesRead(StringHash eventType, VariantMap& eventData);
|
||||
|
||||
void HandleLoadingWallet(StringHash eventType, VariantMap& eventData);
|
||||
void HandleNewWallet(StringHash eventType, VariantMap& eventData);
|
||||
@ -1718,6 +1719,7 @@ void CryptoCityUrho3D::SetupUI()
|
||||
SubscribeToEvent(ui, E_CRYPTOCITY_SEND_MESSAGE, URHO3D_HANDLER(CryptoCityUrho3D, HandleSendMessage));
|
||||
SubscribeToEvent(ui, E_CRYPTOCITY_DELETE_MESSAGE, URHO3D_HANDLER(CryptoCityUrho3D, HandleDeleteMessage));
|
||||
SubscribeToEvent(ui, E_CRYPTOCITY_SWEEP_MESSAGE_FEES, URHO3D_HANDLER(CryptoCityUrho3D, HandleSweepMessageFees));
|
||||
SubscribeToEvent(ui, E_CRYPTOCITY_MESSAGES_READ, URHO3D_HANDLER(CryptoCityUrho3D, HandleMessagesRead));
|
||||
SubscribeToEvent(&gameState, E_CRYPTOCITY_REQUEST_PLAYER_DATA, URHO3D_HANDLER(CryptoCityUrho3D, HandleRequestPlayerData));
|
||||
SubscribeToEvent(&gameState, E_CRYPTOCITY_REQUEST_ITEM_DATA, URHO3D_HANDLER(CryptoCityUrho3D, HandleRequestItemData));
|
||||
SubscribeToEvent(&gameState, E_CRYPTOCITY_REQUEST_SCRIPT_DATA, URHO3D_HANDLER(CryptoCityUrho3D, HandleRequestScriptData));
|
||||
@ -3565,13 +3567,14 @@ void CryptoCityUrho3D::HandleUpdate(StringHash eventType, VariantMap& eventData)
|
||||
const unsigned num_unread_lines = console->GetNumUnreadLines();
|
||||
if (num_unread_lines == 0)
|
||||
mentioned_in_chat = false;
|
||||
const unsigned num_unread_messages = wallet->get_num_unread_cc_messages();
|
||||
|
||||
if (!IsActionActive(Controls::ACTION_SELECT_MATERIAL))
|
||||
ui->CloseSelectMaterial(true);
|
||||
|
||||
{
|
||||
TIMING_SCOPE("Updating UI");
|
||||
ui->UpdateUI(timeStep, mouse_x, mouse_y, selection.x0, selection.y0, selection.x1, selection.y1, cityMesh->getDisplayMode() == DisplayModeShowFlags, flagUnderConstruction != boost::none, num_unread_lines, mentioned_in_chat, wallet, camera_->position_of_interest(), cameraNode_->GetWorldDirection(), flagUnderConstruction);
|
||||
ui->UpdateUI(timeStep, mouse_x, mouse_y, selection.x0, selection.y0, selection.x1, selection.y1, cityMesh->getDisplayMode() == DisplayModeShowFlags, flagUnderConstruction != boost::none, num_unread_lines, mentioned_in_chat, num_unread_messages, wallet, camera_->position_of_interest(), cameraNode_->GetWorldDirection(), flagUnderConstruction);
|
||||
}
|
||||
mark_new_block = false;
|
||||
|
||||
@ -4474,6 +4477,20 @@ void CryptoCityUrho3D::HandleSweepMessageFees(StringHash eventType, VariantMap&
|
||||
wallet->sweep_cc_message_fees();
|
||||
}
|
||||
|
||||
void CryptoCityUrho3D::HandleMessagesRead(StringHash eventType, VariantMap& eventData)
|
||||
{
|
||||
UnsetFocus();
|
||||
if (!wallet || !wallet->wallet())
|
||||
{
|
||||
new MessageBox(context_, "No wallet loaded - load a wallet to be able to mark messages as read");
|
||||
return;
|
||||
}
|
||||
|
||||
const std::vector<cc::cc_message_t> messages = wallet->get_cc_messages();
|
||||
for (const auto &e: messages)
|
||||
wallet->set_cc_message_read(e.id);
|
||||
}
|
||||
|
||||
void CryptoCityUrho3D::HandleResizeFlag(StringHash eventType, VariantMap& eventData)
|
||||
{
|
||||
UnsetFocus();
|
||||
|
@ -1030,7 +1030,7 @@ void UIUrho3D::UpdateMining(const std::shared_ptr<GameWallet> &w)
|
||||
update_mining = false;
|
||||
}
|
||||
|
||||
void UIUrho3D::UpdateUI(float timeStep, 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, const Vector3 &position, const Vector3 &view_direction, const boost::optional<std::tuple<uint32_t, std::vector<uint16_t>, std::shared_ptr<TileData>, std::shared_ptr<Flag::unpacker>>> &flagUnderConstruction)
|
||||
void UIUrho3D::UpdateUI(float timeStep, 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, unsigned num_unread_messages, const std::shared_ptr<GameWallet> &w, const Vector3 &position, const Vector3 &view_direction, const boost::optional<std::tuple<uint32_t, std::vector<uint16_t>, std::shared_ptr<TileData>, std::shared_ptr<Flag::unpacker>>> &flagUnderConstruction)
|
||||
{
|
||||
this->position = position;
|
||||
sel_x0 = sx0;
|
||||
@ -1166,6 +1166,16 @@ void UIUrho3D::UpdateUI(float timeStep, uint32_t mouse_x, uint32_t mouse_y, uint
|
||||
chatText->SetText(chat_text.CString());
|
||||
chatText->SetSkinBg(highlight_chat ? "TBButton.flat.highlighted" : "TBButton.flat");
|
||||
}
|
||||
TBButton *messagesText = command_window->GetWidgetByIDAndType<TBButton>(TBID("actions-pm"));
|
||||
if (messagesText)
|
||||
{
|
||||
String messages_text = "Messages";
|
||||
if (num_unread_messages > 0)
|
||||
messages_text += " (" + String(num_unread_messages) + ")";
|
||||
if (strcmp(messagesText->GetText().CStr(), messages_text.CString()))
|
||||
messagesText->SetText(messages_text.CString());
|
||||
messagesText->SetSkinBg(num_unread_messages > 0 ? "TBButton.flat.highlighted" : "TBButton.flat");
|
||||
}
|
||||
|
||||
if (buildingSettingsDialog)
|
||||
buildingSettingsDialog->Update(map, gameState, w);
|
||||
@ -2943,6 +2953,8 @@ void UIUrho3D::HandleMessages(Urho3D::StringHash eventType, Urho3D::VariantMap&
|
||||
SubscribeToEvent(messagesDialog, E_MESSAGES_CLOSED, [this](StringHash eventType, VariantMap& eventData) {
|
||||
messagesDialog = NULL;
|
||||
});
|
||||
VariantMap messagesReadData;
|
||||
SendEvent(E_CRYPTOCITY_MESSAGES_READ, messagesReadData);
|
||||
SendTutorialTrigger("screen-messages");
|
||||
}
|
||||
|
||||
|
@ -292,6 +292,7 @@ URHO3D_EVENT(E_CRYPTOCITY_SEND_MESSAGE, SendMessageTo) { URHO3D_PARAM(P_RECIPIEN
|
||||
URHO3D_EVENT(E_CRYPTOCITY_DELETE_MESSAGE, DeleteMessage) { URHO3D_PARAM(P_ID, ID); }
|
||||
URHO3D_EVENT(E_CRYPTOCITY_SWEEP_MESSAGE_FEES, SweepMessageFees) { }
|
||||
URHO3D_EVENT(E_CRYPTOCITY_RTAS, RTAS) { URHO3D_PARAM(P_ENABLE, Enable); URHO3D_PARAM(P_ADDRESS, Address); URHO3D_PARAM(P_SUB_PORT, SubPort); URHO3D_PARAM(P_PUB_PORT, PubPort); }
|
||||
URHO3D_EVENT(E_CRYPTOCITY_MESSAGES_READ, MessagesRead) { }
|
||||
|
||||
class UIUrho3D: public Urho3D::UIElement
|
||||
{
|
||||
@ -306,7 +307,7 @@ public:
|
||||
UITooltip *AddToastNotification(const Urho3D::String &s, const Urho3D::String &icon = "");
|
||||
void SetNotificationLifetime(unsigned seconds);
|
||||
void RefreshNotifications();
|
||||
void UpdateUI(float timeStep, 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, const Urho3D::Vector3 &position, const Urho3D::Vector3 &view_direction, const boost::optional<std::tuple<uint32_t, std::vector<uint16_t>, std::shared_ptr<TileData>, std::shared_ptr<Flag::unpacker>>> &flagUnderConstruction);
|
||||
void UpdateUI(float timeStep, 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, unsigned num_unread_messages, const std::shared_ptr<GameWallet> &w, const Urho3D::Vector3 &position, const Urho3D::Vector3 &view_direction, const boost::optional<std::tuple<uint32_t, std::vector<uint16_t>, std::shared_ptr<TileData>, std::shared_ptr<Flag::unpacker>>> &flagUnderConstruction);
|
||||
void NewTradeCommand();
|
||||
void ShowOptions();
|
||||
void ShowPlayerInfo(uint32_t player_id);
|
||||
|
@ -12360,6 +12360,7 @@ bool simple_wallet::cc_messages_show(const std::vector<std::string> &args)
|
||||
message_writer() << "From: " << sender;
|
||||
message_writer() << "Subject: " << (message.reply ? "Re: " : "") << message.subject;
|
||||
message_writer() << message.message;
|
||||
m_wallet->set_cc_message_read(message.id);
|
||||
return true;
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
|
@ -2449,7 +2449,7 @@ void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote
|
||||
|
||||
if (sender != 0)
|
||||
{
|
||||
cc::cc_message_t m{txid, sender, get_cc_account(), height, ts, subject, message, tx_scan_info[o].received->index.minor, !!sma, reply};
|
||||
cc::cc_message_t m{txid, sender, get_cc_account(), height, ts, subject, message, tx_scan_info[o].received->index.minor, !!sma, reply, false};
|
||||
add_cc_message(m);
|
||||
if (0 != m_callback)
|
||||
m_callback->on_cc_message_received(m);
|
||||
|
@ -1248,8 +1248,10 @@ private:
|
||||
|
||||
const std::vector<cc::cc_message_t> &get_cc_messages() const;
|
||||
size_t get_num_cc_messages() const;
|
||||
size_t get_num_unread_cc_messages() const;
|
||||
void add_cc_message(const cc::cc_message_t &message);
|
||||
bool delete_cc_message(const crypto::hash &txid);
|
||||
bool set_cc_message_read(const crypto::hash &txid);
|
||||
void set_cc_pm_key(uint32_t account, const crypto::public_key &pmspk, const crypto::public_key &pmvpk);
|
||||
bool get_cc_pm_key(uint32_t account, crypto::public_key &pmspk, crypto::public_key &pmvpk) const;
|
||||
void set_cc_pm_keys_sent(uint32_t account, const crypto::hash &txid, uint64_t height);
|
||||
|
@ -1672,6 +1672,15 @@ size_t wallet2::get_num_cc_messages() const
|
||||
return m_cc_messages.size();
|
||||
}
|
||||
|
||||
size_t wallet2::get_num_unread_cc_messages() const
|
||||
{
|
||||
size_t unread = 0;
|
||||
for (const auto &e: m_cc_messages)
|
||||
if (!e.read)
|
||||
++unread;
|
||||
return unread;
|
||||
}
|
||||
|
||||
void wallet2::add_cc_message(const cc::cc_message_t &message)
|
||||
{
|
||||
m_cc_messages.push_back(message);
|
||||
@ -1693,6 +1702,20 @@ bool wallet2::delete_cc_message(const crypto::hash &txid)
|
||||
return found;
|
||||
}
|
||||
|
||||
bool wallet2::set_cc_message_read(const crypto::hash &txid)
|
||||
{
|
||||
bool found = false;
|
||||
for (auto it = m_cc_messages.begin(); it != m_cc_messages.end(); ++it)
|
||||
{
|
||||
if (it->id == txid)
|
||||
{
|
||||
it->read = true;
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
void wallet2::set_cc_pm_key(uint32_t account, const crypto::public_key &pmspk, const crypto::public_key &pmvpk)
|
||||
{
|
||||
m_cc_pm_keys[account] = std::make_pair(pmspk, pmvpk);
|
||||
|
Loading…
Reference in New Issue
Block a user