Skip to content

Commit

Permalink
Rebased and fix the update scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
adenovan committed Jun 7, 2017
1 parent e25bc9b commit 9187b57
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 19 deletions.
29 changes: 17 additions & 12 deletions UI/ChatScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ void ChatMenu::CreateViews() {
float yres = screenManager()->getUIContext()->GetBounds().h;

switch (g_Config.iChatScreenPosition) {
// the chat screen size is still static 280,250 need a dynamic size based on device resolution
case 0:
box_ = new LinearLayout(ORIENT_VERTICAL, new AnchorLayoutParams(PopupWidth(), FillVertical() ? yres - 30 : WRAP_CONTENT, 280, NONE, NONE, 250, true));
break;
Expand Down Expand Up @@ -87,16 +88,16 @@ void ChatMenu::CreateViews() {

CreatePopupContents(box_);
#if defined(_WIN32) || defined(USING_QT_UI)
//not work yet for tywald requests cant set the focus to chat edit after chat opened
root_->SetDefaultFocusView(box_);
box_->SubviewFocused(chatEdit_);
root_->SetFocus();
#else
root_->SetDefaultFocusView(box_);
#endif
UpdateChat();
chatScreenVisible = true;
newChat = 0;
UI::EnableFocusMovement(true);
UpdateChat();
}

void ChatMenu::dialogFinished(const Screen *dialog, DialogResult result) {
Expand All @@ -115,13 +116,18 @@ UI::EventReturn ChatMenu::OnSubmit(UI::EventParams &e) {
return UI::EVENT_DONE;
}

/*
maximum chat length in one message from server is only 64 character
need to split the chat to fit the static chat screen size
if the chat screen size become dynamic from device resolution
we need to change split function logic also.
*/
std::vector<std::string> Split(const std::string& str)
{
std::vector<std::string> ret;
int counter = 0;
int firstSentenceEnd = 0;
int secondSentenceEnd = 0;
//NOTICE_LOG(HLE, "Splitted %s %i", str.c_str(),str.size());
for (auto i = 0; i<str.length(); i++) {
if (isspace(str[i])) {
if (i < 35) {
Expand Down Expand Up @@ -153,8 +159,8 @@ void ChatMenu::UpdateChat() {
chatVert_->Clear(); //read Access violation is proadhoc.cpp use NULL_->Clear() pointer?
std::vector<std::string> chatLog = getChatLog();
for (auto i : chatLog) {
//split long text
if (i.length() > 30) {
//split long text
std::vector<std::string> splitted = Split(i);
for (auto j : splitted) {
TextView *v = chatVert_->Add(new TextView(j, FLAG_DYNAMIC_ASCII, false));
Expand Down Expand Up @@ -185,17 +191,16 @@ bool ChatMenu::touch(const TouchInput &touch) {
return UIDialogScreen::touch(touch);
}

void ChatMenu::update(InputState &input) {
PopupScreen::update(input);
void ChatMenu::update() {
PopupScreen::update();
if (updateChatScreen) {
UpdateChat();
}
}

void ChatMenu::postRender() {
if (scroll_ && toBottom_) {
scroll_->ScrollToBottom();
toBottom_ = false;
else {
if (scroll_ && toBottom_) {
toBottom_ = false;
scroll_->ScrollToBottom();
}
}
}

Expand Down
5 changes: 2 additions & 3 deletions UI/ChatScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@

class ChatMenu : public PopupScreen {
public:
ChatMenu() : PopupScreen("Chat") {}
ChatMenu() : PopupScreen("Chat") , toBottom_(false) {}
~ChatMenu();
void CreatePopupContents(UI::ViewGroup *parent) override;
void CreateViews() override;
void dialogFinished(const Screen *dialog, DialogResult result) override;
bool touch(const TouchInput &touch) override;
void update(InputState &input) override;
void postRender() override;
void update() override;
void UpdateChat();
private:
UI::EventReturn OnSubmit(UI::EventParams &e);
Expand Down
11 changes: 8 additions & 3 deletions UI/EmuScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,12 +380,16 @@ void EmuScreen::sendMessage(const char *message, const char *value) {
if (g_Config.bBypassOSKWithKeyboard) {
osm.Show("Disable windows native keyboard options to use ctrl + c hotkey", 2.0f);
} else {
if (g_Config.bEnableNetworkChat) {
chatButtons->SetVisibility(UI::V_GONE);
screenManager()->push(new ChatMenu());
}
}
#else
if (g_Config.bEnableNetworkChat) {
chatButtons->SetVisibility(UI::V_GONE);
screenManager()->push(new ChatMenu());
}
#else
chatButtons->SetVisibility(UI::V_GONE);
screenManager()->push(new ChatMenu());
#endif
}
}
Expand Down Expand Up @@ -807,6 +811,7 @@ void EmuScreen::CreateViews() {
break;
case 3:
chatButtons = new ChoiceWithValueDisplay(&newChat, sc->T("Chat"), new AnchorLayoutParams(130, WRAP_CONTENT, 80, 50, NONE, NONE, true));
break;
case 4:
chatButtons = new ChoiceWithValueDisplay(&newChat, sc->T("Chat"), new AnchorLayoutParams(130, WRAP_CONTENT, bounds.centerX(), 50, NONE, NONE, true));
break;
Expand Down
2 changes: 1 addition & 1 deletion Windows/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@
#define ID_FILE_DUMPAUDIO 40167
#define ID_HELP_GITHUB 40168
#define IDC_GEDBG_RECORD 40169
#define ID_EMULATION_CHAT 40168
#define ID_EMULATION_CHAT 40170


// Dummy option to let the buffered rendering hotkey cycle through all the options.
Expand Down

0 comments on commit 9187b57

Please sign in to comment.