mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-07-31 05:30:23 +02:00
add warning messages when certain words are found in comments
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <algorithm>
|
||||||
#include "PreviewView.h"
|
#include "PreviewView.h"
|
||||||
#include "gui/dialogues/TextPrompt.h"
|
#include "gui/dialogues/TextPrompt.h"
|
||||||
#include "simulation/SaveRenderer.h"
|
#include "simulation/SaveRenderer.h"
|
||||||
@@ -45,6 +46,7 @@ class PreviewView::AutoCommentSizeAction: public ui::TextboxAction
|
|||||||
public:
|
public:
|
||||||
AutoCommentSizeAction(PreviewView * v): v(v) {}
|
AutoCommentSizeAction(PreviewView * v): v(v) {}
|
||||||
virtual void TextChangedCallback(ui::Textbox * sender) {
|
virtual void TextChangedCallback(ui::Textbox * sender) {
|
||||||
|
v->CheckComment();
|
||||||
v->commentBoxAutoHeight();
|
v->commentBoxAutoHeight();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -68,12 +70,15 @@ PreviewView::PreviewView():
|
|||||||
savePreview(NULL),
|
savePreview(NULL),
|
||||||
submitCommentButton(NULL),
|
submitCommentButton(NULL),
|
||||||
addCommentBox(NULL),
|
addCommentBox(NULL),
|
||||||
|
commentWarningLabel(NULL),
|
||||||
|
userIsAuthor(false),
|
||||||
doOpen(false),
|
doOpen(false),
|
||||||
doError(false),
|
doError(false),
|
||||||
doErrorMessage(""),
|
doErrorMessage(""),
|
||||||
showAvatars(true),
|
showAvatars(true),
|
||||||
prevPage(false),
|
prevPage(false),
|
||||||
commentBoxHeight(20)
|
commentBoxHeight(20),
|
||||||
|
commentHelpText(false)
|
||||||
{
|
{
|
||||||
class FavAction: public ui::ButtonAction
|
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));
|
commentsPanel = new ui::ScrollPanel(ui::Point((XRES/2)+1, 1), ui::Point((Size.X-(XRES/2))-2, Size.Y-commentBoxHeight));
|
||||||
AddComponent(commentsPanel);
|
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)
|
void PreviewView::AttachController(PreviewController * controller)
|
||||||
@@ -225,7 +239,7 @@ void PreviewView::commentBoxAutoHeight()
|
|||||||
if(!addCommentBox)
|
if(!addCommentBox)
|
||||||
return;
|
return;
|
||||||
int textWidth = Graphics::textwidth(addCommentBox->GetText().c_str());
|
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;
|
addCommentBox->Appearance.VerticalAlign = ui::Appearance::AlignTop;
|
||||||
|
|
||||||
@@ -239,6 +253,11 @@ void PreviewView::commentBoxAutoHeight()
|
|||||||
commentBoxPositionY = Size.Y-(newSize+21);
|
commentBoxPositionY = Size.Y-(newSize+21);
|
||||||
commentBoxSizeX = Size.X-(XRES/2)-8;
|
commentBoxSizeX = Size.X-(XRES/2)-8;
|
||||||
commentBoxSizeY = newSize;
|
commentBoxSizeY = newSize;
|
||||||
|
|
||||||
|
if (commentWarningLabel && commentHelpText && !commentWarningLabel->Visible && addCommentBox->Position.Y+addCommentBox->Size.Y < Size.Y-14)
|
||||||
|
{
|
||||||
|
commentWarningLabel->Visible = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -248,9 +267,63 @@ void PreviewView::commentBoxAutoHeight()
|
|||||||
commentBoxPositionX = (XRES/2)+4;
|
commentBoxPositionX = (XRES/2)+4;
|
||||||
commentBoxPositionY = Size.Y-19;
|
commentBoxPositionY = Size.Y-19;
|
||||||
commentBoxSizeX = Size.X-(XRES/2)-48;
|
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()
|
void PreviewView::DoDraw()
|
||||||
@@ -365,6 +438,7 @@ void PreviewView::OnTick(float dt)
|
|||||||
addCommentBox->Size.Y += ydiff;
|
addCommentBox->Size.Y += ydiff;
|
||||||
addCommentBox->Invalidate();
|
addCommentBox->Invalidate();
|
||||||
}
|
}
|
||||||
|
commentsPanel->Size.Y = addCommentBox->Position.Y-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
c->Update();
|
c->Update();
|
||||||
@@ -431,6 +505,10 @@ void PreviewView::NotifySaveChanged(PreviewModel * sender)
|
|||||||
{
|
{
|
||||||
authorDateLabel->SetText("\bgAuthor:\bw " + save->userName + " \bgDate:\bw " + format::UnixtimeToDateMini(save->date));
|
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));
|
viewsLabel->SetText("\bgViews:\bw " + format::NumberToString<int>(save->Views));
|
||||||
saveDescriptionLabel->SetText(save->Description);
|
saveDescriptionLabel->SetText(save->Description);
|
||||||
if(save->Favourite)
|
if(save->Favourite)
|
||||||
@@ -531,6 +609,12 @@ void PreviewView::NotifyCommentBoxEnabledChanged(PreviewModel * sender)
|
|||||||
submitCommentButton->SetActionCallback(new SubmitCommentAction(this));
|
submitCommentButton->SetActionCallback(new SubmitCommentAction(this));
|
||||||
//submitCommentButton->Enabled = false;
|
//submitCommentButton->Enabled = false;
|
||||||
AddComponent(submitCommentButton);
|
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
|
else
|
||||||
{
|
{
|
||||||
|
@@ -2,6 +2,8 @@
|
|||||||
#define PREVIEWVIEW_H_
|
#define PREVIEWVIEW_H_
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <set>
|
||||||
|
#include <string>
|
||||||
#include "Comment.h"
|
#include "Comment.h"
|
||||||
#include "gui/interface/Window.h"
|
#include "gui/interface/Window.h"
|
||||||
#include "gui/preview/PreviewController.h"
|
#include "gui/preview/PreviewController.h"
|
||||||
@@ -33,6 +35,7 @@ class PreviewView: public ui::Window {
|
|||||||
ui::Button * reportButton;
|
ui::Button * reportButton;
|
||||||
ui::Button * submitCommentButton;
|
ui::Button * submitCommentButton;
|
||||||
ui::Textbox * addCommentBox;
|
ui::Textbox * addCommentBox;
|
||||||
|
ui::Label * commentWarningLabel;
|
||||||
ui::Label * saveNameLabel;
|
ui::Label * saveNameLabel;
|
||||||
ui::Label * authorDateLabel;
|
ui::Label * authorDateLabel;
|
||||||
ui::AvatarButton * avatarButton;
|
ui::AvatarButton * avatarButton;
|
||||||
@@ -47,6 +50,7 @@ class PreviewView: public ui::Window {
|
|||||||
std::vector<ui::Component*> commentTextComponents;
|
std::vector<ui::Component*> commentTextComponents;
|
||||||
int votesUp;
|
int votesUp;
|
||||||
int votesDown;
|
int votesDown;
|
||||||
|
bool userIsAuthor;
|
||||||
bool doOpen;
|
bool doOpen;
|
||||||
bool doError;
|
bool doError;
|
||||||
std::string doErrorMessage;
|
std::string doErrorMessage;
|
||||||
@@ -58,10 +62,15 @@ class PreviewView: public ui::Window {
|
|||||||
float commentBoxPositionY;
|
float commentBoxPositionY;
|
||||||
float commentBoxSizeX;
|
float commentBoxSizeX;
|
||||||
float commentBoxSizeY;
|
float commentBoxSizeY;
|
||||||
|
bool commentHelpText;
|
||||||
|
|
||||||
|
std::set<std::string> swearWords;
|
||||||
|
|
||||||
void displayComments();
|
void displayComments();
|
||||||
void commentBoxAutoHeight();
|
void commentBoxAutoHeight();
|
||||||
void submitComment();
|
void submitComment();
|
||||||
|
bool CheckSwearing(std::string text);
|
||||||
|
void CheckComment();
|
||||||
public:
|
public:
|
||||||
void AttachController(PreviewController * controller);
|
void AttachController(PreviewController * controller);
|
||||||
PreviewView();
|
PreviewView();
|
||||||
|
Reference in New Issue
Block a user