Permalink
Browse files

add warning messages when certain words are found in comments

  • Loading branch information...
jacob1 committed Jun 10, 2017
1 parent 4242e38 commit 25b3244d6ca3f2462a99a153f7abbcca8fbb38cc
Showing with 97 additions and 4 deletions.
  1. +88 −4 src/gui/preview/PreviewView.cpp
  2. +9 −0 src/gui/preview/PreviewView.h
@@ -1,6 +1,7 @@
#include <sstream>
#include <vector>
#include <cmath>
#include <algorithm>
#include "PreviewView.h"
#include "gui/dialogues/TextPrompt.h"
#include "simulation/SaveRenderer.h"
@@ -45,6 +46,7 @@ class PreviewView::AutoCommentSizeAction: public ui::TextboxAction
public:
AutoCommentSizeAction(PreviewView * v): v(v) {}
virtual void TextChangedCallback(ui::Textbox * sender) {
v->CheckComment();
v->commentBoxAutoHeight();
}
};
@@ -68,12 +70,15 @@ PreviewView::PreviewView():
savePreview(NULL),
submitCommentButton(NULL),
addCommentBox(NULL),
commentWarningLabel(NULL),
userIsAuthor(false),
doOpen(false),
doError(false),
doErrorMessage(""),
showAvatars(true),
prevPage(false),
commentBoxHeight(20)
commentBoxHeight(20),
commentHelpText(false)
{
class FavAction: public ui::ButtonAction
{
@@ -200,6 +205,15 @@ PreviewView::PreviewView():
commentsPanel = new ui::ScrollPanel(ui::Point((XRES/2)+1, 1), ui::Point((Size.X-(XRES/2))-2, Size.Y-commentBoxHeight));
AddComponent(commentsPanel);
swearWords.insert("fuck");
swearWords.insert("shit ");
swearWords.insert("asshole");
swearWords.insert("dick");
swearWords.insert("cunt");
swearWords.insert(" nigger");
swearWords.insert("faggot");
swearWords.insert("dumbass");
}
void PreviewView::AttachController(PreviewController * controller)
@@ -225,7 +239,7 @@ void PreviewView::commentBoxAutoHeight()
if(!addCommentBox)
return;
int textWidth = Graphics::textwidth(addCommentBox->GetText().c_str());
if(textWidth+15 > Size.X-(XRES/2)-48)
if (commentHelpText || textWidth+15 > Size.X-(XRES/2)-48)
{
addCommentBox->Appearance.VerticalAlign = ui::Appearance::AlignTop;
@@ -239,6 +253,11 @@ void PreviewView::commentBoxAutoHeight()
commentBoxPositionY = Size.Y-(newSize+21);
commentBoxSizeX = Size.X-(XRES/2)-8;
commentBoxSizeY = newSize;
if (commentWarningLabel && commentHelpText && !commentWarningLabel->Visible && addCommentBox->Position.Y+addCommentBox->Size.Y < Size.Y-14)
{
commentWarningLabel->Visible = true;
}
}
else
{
@@ -248,9 +267,63 @@ void PreviewView::commentBoxAutoHeight()
commentBoxPositionX = (XRES/2)+4;
commentBoxPositionY = Size.Y-19;
commentBoxSizeX = Size.X-(XRES/2)-48;
commentBoxSizeY = 16;
commentBoxSizeY = 17;
if (commentWarningLabel && commentWarningLabel->Visible)
{
commentWarningLabel->Visible = false;
}
}
}
bool PreviewView::CheckSwearing(std::string text)
{
for (std::set<std::string>::iterator iter = swearWords.begin(), end = swearWords.end(); iter != end; iter++)
{
if (text.find(*iter) != text.npos)
return true;
}
return false;
}
void PreviewView::CheckComment()
{
if (!commentWarningLabel)
return;
std::string text = addCommentBox->GetText();
std::transform(text.begin(), text.end(), text.begin(), ::tolower);
if (!userIsAuthor && (text.find("stolen") != text.npos || text.find("copied") != text.npos))
{
if (!commentHelpText)
{
if (rand()%2)
commentWarningLabel->SetText("Stolen? Report the save instead");
else
commentWarningLabel->SetText("Please report stolen saves");
commentHelpText = true;
}
}
else if (userIsAuthor && text.find("vote") != text.npos)
{
commentWarningLabel->SetText("Do not ask for votes");
commentHelpText = true;
}
else if (CheckSwearing(text))
{
if (!commentHelpText)
{
if (rand()%2)
commentWarningLabel->SetText("Please do not swear");
else
commentWarningLabel->SetText("Bad language may be deleted");
commentHelpText = true;
}
}
else
{
commentHelpText = false;
commentWarningLabel->Visible = false;
}
commentsPanel->Size.Y = Size.Y-commentBoxHeight;
}
void PreviewView::DoDraw()
@@ -365,6 +438,7 @@ void PreviewView::OnTick(float dt)
addCommentBox->Size.Y += ydiff;
addCommentBox->Invalidate();
}
commentsPanel->Size.Y = addCommentBox->Position.Y-1;
}
c->Update();
@@ -431,6 +505,10 @@ void PreviewView::NotifySaveChanged(PreviewModel * sender)
{
authorDateLabel->SetText("\bgAuthor:\bw " + save->userName + " \bgDate:\bw " + format::UnixtimeToDateMini(save->date));
}
if (Client::Ref().GetAuthUser().ID && save->userName == Client::Ref().GetAuthUser().Username)
userIsAuthor = true;
else
userIsAuthor = false;
viewsLabel->SetText("\bgViews:\bw " + format::NumberToString<int>(save->Views));
saveDescriptionLabel->SetText(save->Description);
if(save->Favourite)
@@ -531,6 +609,12 @@ void PreviewView::NotifyCommentBoxEnabledChanged(PreviewModel * sender)
submitCommentButton->SetActionCallback(new SubmitCommentAction(this));
//submitCommentButton->Enabled = false;
AddComponent(submitCommentButton);
commentWarningLabel = new ui::Label(ui::Point((XRES/2)+4, Size.Y-19), ui::Point(Size.X-(XRES/2)-48, 16), "If you see this it is a bug");
commentWarningLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
commentWarningLabel->SetTextColour(ui::Colour(255, 0, 0));
commentWarningLabel->Visible = false;
AddComponent(commentWarningLabel);
}
else
{
@@ -2,6 +2,8 @@
#define PREVIEWVIEW_H_
#include <vector>
#include <set>
#include <string>
#include "Comment.h"
#include "gui/interface/Window.h"
#include "gui/preview/PreviewController.h"
@@ -33,6 +35,7 @@ class PreviewView: public ui::Window {
ui::Button * reportButton;
ui::Button * submitCommentButton;
ui::Textbox * addCommentBox;
ui::Label * commentWarningLabel;
ui::Label * saveNameLabel;
ui::Label * authorDateLabel;
ui::AvatarButton * avatarButton;
@@ -47,6 +50,7 @@ class PreviewView: public ui::Window {
std::vector<ui::Component*> commentTextComponents;
int votesUp;
int votesDown;
bool userIsAuthor;
bool doOpen;
bool doError;
std::string doErrorMessage;
@@ -58,10 +62,15 @@ class PreviewView: public ui::Window {
float commentBoxPositionY;
float commentBoxSizeX;
float commentBoxSizeY;
bool commentHelpText;
std::set<std::string> swearWords;
void displayComments();
void commentBoxAutoHeight();
void submitComment();
bool CheckSwearing(std::string text);
void CheckComment();
public:
void AttachController(PreviewController * controller);
PreviewView();

0 comments on commit 25b3244

Please sign in to comment.