- fixed input text segfault and corrected entry of playername in menus and added a box around the field when editing.
This commit is contained in:
parent
96ade03a27
commit
6662f35347
|
@ -277,6 +277,8 @@ GraphicLabel::GraphicLabel() {
|
|||
wordWrap = false;
|
||||
centeredW = -1;
|
||||
centeredH = 1;
|
||||
editModeEnabled = false;
|
||||
maxEditWidth = -1;
|
||||
}
|
||||
|
||||
void GraphicLabel::init(int x, int y, int w, int h, bool centered, Vec3f textColor, bool wordWrap) {
|
||||
|
|
|
@ -140,6 +140,9 @@ private:
|
|||
int centeredW;
|
||||
int centeredH;
|
||||
|
||||
bool editModeEnabled;
|
||||
int maxEditWidth;
|
||||
|
||||
public:
|
||||
GraphicLabel();
|
||||
void init(int x, int y, int w=defW, int h=defH, bool centered= false, Vec3f textColor=GraphicComponent::customTextColor, bool wordWrap=false);
|
||||
|
@ -159,6 +162,12 @@ public:
|
|||
bool getWordWrap() const { return wordWrap; }
|
||||
void setWordWrap(bool value) { wordWrap = value; }
|
||||
|
||||
void setEditModeEnabled(bool value) { editModeEnabled = value; }
|
||||
bool getEditModeEnabled() const { return editModeEnabled; }
|
||||
|
||||
void setMaxEditWidth(int value) { maxEditWidth = value; }
|
||||
int getMaxEditWidth() const { return maxEditWidth; }
|
||||
|
||||
};
|
||||
|
||||
// ===========================================================
|
||||
|
|
|
@ -46,6 +46,7 @@ bool Renderer::renderText3DEnabled = true;
|
|||
// =====================================================
|
||||
|
||||
bool MeshCallbackTeamColor::noTeamColors = false;
|
||||
const string DEFAULT_CHAR_FOR_WIDTH_CALC = "V";
|
||||
|
||||
void MeshCallbackTeamColor::execute(const Mesh *mesh) {
|
||||
//team color
|
||||
|
@ -2363,7 +2364,31 @@ Vec2i computeCenteredPos(const string &text, Font3D *font, int x, int y) {
|
|||
return textPos;
|
||||
}
|
||||
|
||||
void Renderer::renderTextBoundingBox3D(const string &text, Font3D *font, float alpha, int x, int y, int w, int h, bool centeredW, bool centeredH) {
|
||||
void Renderer::renderTextSurroundingBox(int x, int y, int w, int h,int maxEditWidth) {
|
||||
//glColor4fv(color.ptr());
|
||||
//glBegin(GL_QUADS); // Start drawing a quad primitive
|
||||
|
||||
if(maxEditWidth >= 0 && maxEditWidth > w) {
|
||||
//printf("B w = %d maxEditWidth = %d\n",w,maxEditWidth);
|
||||
w = maxEditWidth;
|
||||
}
|
||||
//printf("HI!!!\n");
|
||||
glPointSize(20.0f);
|
||||
|
||||
int margin = 4;
|
||||
//glBegin(GL_POINTS); // Start drawing a point primitive
|
||||
glBegin(GL_LINE_LOOP); // Start drawing a line primitive
|
||||
|
||||
glVertex3f(x, y+h, 0.0f); // The bottom left corner
|
||||
glVertex3f(x, y-margin, 0.0f); // The top left corner
|
||||
glVertex3f(x+w, y-margin, 0.0f); // The top right corner
|
||||
glVertex3f(x+w, y+h, 0.0f); // The bottom right corner
|
||||
glEnd();
|
||||
}
|
||||
|
||||
void Renderer::renderTextBoundingBox3D(const string &text, Font3D *font,
|
||||
float alpha, int x, int y, int w, int h, bool centeredW, bool centeredH,
|
||||
bool editModeEnabled,int maxEditWidth) {
|
||||
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) {
|
||||
return;
|
||||
}
|
||||
|
@ -2378,6 +2403,19 @@ void Renderer::renderTextBoundingBox3D(const string &text, Font3D *font, float a
|
|||
getCentered3DPos(text, font, pos, w, h, centeredW, centeredH);
|
||||
}
|
||||
|
||||
if(editModeEnabled) {
|
||||
if(maxEditWidth >= 0) {
|
||||
string temp = "";
|
||||
for(int i = 0; i < maxEditWidth; ++i) {
|
||||
temp += DEFAULT_CHAR_FOR_WIDTH_CALC;
|
||||
}
|
||||
float lineWidth = (font->getTextHandler()->Advance(temp.c_str()) * Font::scaleFontValue);
|
||||
maxEditWidth = (int)lineWidth;
|
||||
}
|
||||
|
||||
renderTextSurroundingBox(pos.x, pos.y, w, h,maxEditWidth);
|
||||
}
|
||||
glColor4fv(Vec4f(1.f, 1.f, 1.f, alpha).ptr());
|
||||
TextRendererSafeWrapper safeTextRender(textRenderer3D,font);
|
||||
//textRenderer3D->begin(font);
|
||||
textRenderer3D->render(text, pos.x, pos.y);
|
||||
|
@ -2496,7 +2534,9 @@ Vec2f Renderer::getCentered3DPos(const string &text, Font3D *font, Vec2f &pos, i
|
|||
return pos;
|
||||
}
|
||||
|
||||
void Renderer::renderTextBoundingBox3D(const string &text, Font3D *font, const Vec3f &color, int x, int y, int w, int h, bool centeredW, bool centeredH) {
|
||||
void Renderer::renderTextBoundingBox3D(const string &text, Font3D *font,
|
||||
const Vec3f &color, int x, int y, int w, int h, bool centeredW,
|
||||
bool centeredH, bool editModeEnabled,int maxEditWidth) {
|
||||
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) {
|
||||
return;
|
||||
}
|
||||
|
@ -2511,6 +2551,19 @@ void Renderer::renderTextBoundingBox3D(const string &text, Font3D *font, const V
|
|||
getCentered3DPos(text, font, pos, w, h,centeredW,centeredH);
|
||||
}
|
||||
|
||||
if(editModeEnabled) {
|
||||
if(maxEditWidth >= 0) {
|
||||
string temp = "";
|
||||
for(int i = 0; i < maxEditWidth; ++i) {
|
||||
temp += DEFAULT_CHAR_FOR_WIDTH_CALC;
|
||||
}
|
||||
float lineWidth = (font->getTextHandler()->Advance(temp.c_str()) * Font::scaleFontValue);
|
||||
maxEditWidth = (int)lineWidth;
|
||||
}
|
||||
|
||||
renderTextSurroundingBox(pos.x, pos.y, w, h,maxEditWidth);
|
||||
}
|
||||
glColor3fv(color.ptr());
|
||||
//textRenderer3D->begin(font);
|
||||
TextRendererSafeWrapper safeTextRender(textRenderer3D,font);
|
||||
textRenderer3D->render(text, pos.x, pos.y);
|
||||
|
@ -2559,7 +2612,9 @@ void Renderer::renderText(const string &text, Font2D *font, const Vec3f &color,
|
|||
glPopAttrib();
|
||||
}
|
||||
|
||||
void Renderer::renderTextBoundingBox3D(const string &text, Font3D *font, const Vec4f &color, int x, int y, int w, int h, bool centeredW, bool centeredH) {
|
||||
void Renderer::renderTextBoundingBox3D(const string &text, Font3D *font,
|
||||
const Vec4f &color, int x, int y, int w, int h, bool centeredW,
|
||||
bool centeredH, bool editModeEnabled,int maxEditWidth) {
|
||||
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) {
|
||||
return;
|
||||
}
|
||||
|
@ -2575,6 +2630,19 @@ void Renderer::renderTextBoundingBox3D(const string &text, Font3D *font, const V
|
|||
getCentered3DPos(text, font, pos, w, h,centeredW,centeredH);
|
||||
}
|
||||
|
||||
if(editModeEnabled) {
|
||||
if(maxEditWidth >= 0) {
|
||||
string temp = "";
|
||||
for(int i = 0; i < maxEditWidth; ++i) {
|
||||
temp += DEFAULT_CHAR_FOR_WIDTH_CALC;
|
||||
}
|
||||
float lineWidth = (font->getTextHandler()->Advance(temp.c_str()) * Font::scaleFontValue);
|
||||
maxEditWidth = (int)lineWidth;
|
||||
}
|
||||
|
||||
renderTextSurroundingBox(pos.x, pos.y, w, h,maxEditWidth);
|
||||
}
|
||||
glColor4fv(color.ptr());
|
||||
//textRenderer3D->begin(font);
|
||||
TextRendererSafeWrapper safeTextRender(textRenderer3D,font);
|
||||
textRenderer3D->render(text, pos.x, pos.y);
|
||||
|
@ -2752,7 +2820,9 @@ void Renderer::renderLabel(GraphicLabel *label,const Vec4f *color) {
|
|||
//renderText3D(lines[i], label->getFont3D(), (*color), textPos.x, textPos.y, label->getCentered());
|
||||
//printf("Text Render3D [%s] font3d [%p]\n",lines[i].c_str(),label->getFont3D());
|
||||
//printf("Label render C\n");
|
||||
renderTextBoundingBox3D(lines[i], label->getFont3D(), (*color), x, y, w, h, label->getCenteredW(),label->getCenteredH());
|
||||
renderTextBoundingBox3D(lines[i], label->getFont3D(), (*color),
|
||||
x, y, w, h, label->getCenteredW(),label->getCenteredH(),
|
||||
label->getEditModeEnabled(),label->getMaxEditWidth());
|
||||
}
|
||||
else {
|
||||
//printf("Label render D\n");
|
||||
|
@ -2764,7 +2834,10 @@ void Renderer::renderLabel(GraphicLabel *label,const Vec4f *color) {
|
|||
//renderText3D(lines[i], label->getFont3D(), GraphicComponent::getFade(), textPos.x, textPos.y, label->getCentered());
|
||||
//printf("Text Render3D [%s] font3d [%p]\n",lines[i].c_str(),label->getFont3D());
|
||||
//printf("Label render E\n");
|
||||
renderTextBoundingBox3D(lines[i], label->getFont3D(), GraphicComponent::getFade(), x, y, w, h, label->getCenteredW(),label->getCenteredH());
|
||||
renderTextBoundingBox3D(lines[i], label->getFont3D(),
|
||||
GraphicComponent::getFade(), x, y, w, h,
|
||||
label->getCenteredW(),label->getCenteredH(),
|
||||
label->getEditModeEnabled(),label->getMaxEditWidth());
|
||||
}
|
||||
else {
|
||||
//printf("Label render F\n");
|
||||
|
@ -2890,7 +2963,8 @@ void Renderer::renderButton(GraphicButton *button, const Vec4f *fontColorOverrid
|
|||
if(button->getEditable()) {
|
||||
if(renderText3DEnabled == true) {
|
||||
//renderText3D(button->getText(), button->getFont3D(), color,x + (w / 2), y + (h / 2), true);
|
||||
renderTextBoundingBox3D(button->getText(), button->getFont3D(), color, x, y, w, h, true, true);
|
||||
renderTextBoundingBox3D(button->getText(), button->getFont3D(),
|
||||
color, x, y, w, h, true, true,false,-1);
|
||||
}
|
||||
else {
|
||||
renderText(button->getText(), button->getFont(), color,x + (w / 2), y + (h / 2), true);
|
||||
|
@ -2901,7 +2975,7 @@ void Renderer::renderButton(GraphicButton *button, const Vec4f *fontColorOverrid
|
|||
//renderText3D(button->getText(), button->getFont3D(),disabledTextColor,
|
||||
// x + (w / 2), y + (h / 2), true);
|
||||
renderTextBoundingBox3D(button->getText(), button->getFont3D(),disabledTextColor,
|
||||
x, y, w, h, true, true);
|
||||
x, y, w, h, true, true,false,-1);
|
||||
}
|
||||
else {
|
||||
renderText(button->getText(), button->getFont(),disabledTextColor,
|
||||
|
@ -7711,7 +7785,8 @@ void Renderer::renderProgressBar3D(int size, int x, int y, Font3D *font, int cus
|
|||
//glColor3fv(defColor.ptr());
|
||||
//printf("Render progress bar3d renderText [%s] y = %d, centeredText = %d\n",renderText.c_str(),y, centeredText);
|
||||
|
||||
renderTextBoundingBox3D(renderText, font, defColor, x, y, maxSize, progressbarHeight, true, true);
|
||||
renderTextBoundingBox3D(renderText, font, defColor, x, y, maxSize,
|
||||
progressbarHeight, true, true, false,-1);
|
||||
}
|
||||
|
||||
void Renderer::renderProgressBar(int size, int x, int y, Font2D *font, int customWidth,
|
||||
|
@ -8918,7 +8993,7 @@ void Renderer::renderPopupMenu(PopupMenu *menu) {
|
|||
renderTextBoundingBox3D(
|
||||
menu->getHeader(), menu->getFont3D(),fontColor,
|
||||
menu->getX(), menu->getY()+93*menu->getH()/100,menu->getW(),0,
|
||||
true,false );
|
||||
true,false, false,-1 );
|
||||
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -491,9 +491,11 @@ public:
|
|||
void renderProgressBar3D(int size, int x, int y, Font3D *font, int customWidth=-1, string prefixLabel="", bool centeredText=true);
|
||||
|
||||
Vec2f getCentered3DPos(const string &text, Font3D *font, Vec2f &pos, int w, int h, bool centeredW, bool centeredH);
|
||||
void renderTextBoundingBox3D(const string &text, Font3D *font, const Vec4f &color, int x, int y, int w, int h, bool centeredW, bool centeredH);
|
||||
void renderTextBoundingBox3D(const string &text, Font3D *font, const Vec3f &color, int x, int y, int w, int h, bool centeredW, bool centeredH);
|
||||
void renderTextBoundingBox3D(const string &text, Font3D *font, float alpha, int x, int y, int w, int h, bool centeredW, bool centeredH);
|
||||
void renderTextBoundingBox3D(const string &text, Font3D *font, const Vec4f &color, int x, int y, int w, int h, bool centeredW, bool centeredH, bool editModeEnabled, int maxEditWidth);
|
||||
void renderTextBoundingBox3D(const string &text, Font3D *font, const Vec3f &color, int x, int y, int w, int h, bool centeredW, bool centeredH, bool editModeEnabled,int maxEditWidth);
|
||||
void renderTextBoundingBox3D(const string &text, Font3D *font, float alpha, int x, int y, int w, int h, bool centeredW, bool centeredH, bool editModeEnabled,int maxEditWidth);
|
||||
|
||||
void renderTextSurroundingBox(int x, int y, int w, int h,int maxEditWidth);
|
||||
|
||||
void beginRenderToTexture(Texture2D **renderToTexture);
|
||||
void endRenderToTexture(Texture2D **renderToTexture);
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "socket.h"
|
||||
#include "menu_state_root.h"
|
||||
#include "video_player.h"
|
||||
#include "string_utils.h"
|
||||
|
||||
#include "leak_dumper.h"
|
||||
|
||||
|
@ -334,4 +335,104 @@ void MenuState::reloadUI() {
|
|||
console.resetFonts();
|
||||
}
|
||||
|
||||
void MenuState::setActiveInputLabel(GraphicLabel *newLabel, GraphicLabel **activeInputLabelPtr) {
|
||||
GraphicLabel *activeInputLabelEdit = *activeInputLabelPtr;
|
||||
if(newLabel != NULL) {
|
||||
if(newLabel == activeInputLabelEdit) {
|
||||
return;
|
||||
}
|
||||
string text= newLabel->getText();
|
||||
size_t found = text.find_last_of("_");
|
||||
if (found == string::npos || found != text.length()-1) {
|
||||
text += "_";
|
||||
}
|
||||
newLabel->setText(text);
|
||||
}
|
||||
if(activeInputLabelEdit != NULL && activeInputLabelEdit->getText().empty() == false) {
|
||||
string text= activeInputLabelEdit->getText();
|
||||
size_t found = text.find_last_of("_");
|
||||
if (found != string::npos && found == text.length()-1) {
|
||||
//printf("Removing trailing edit char, found = %d [%d][%s]\n",found,text.length(),text.c_str());
|
||||
text = text.substr(0,found);
|
||||
}
|
||||
activeInputLabelEdit->setText(text);
|
||||
activeInputLabelEdit->setEditModeEnabled(false);
|
||||
}
|
||||
if(newLabel != NULL) {
|
||||
*activeInputLabelPtr = newLabel;
|
||||
newLabel->setEditModeEnabled(true);
|
||||
}
|
||||
else {
|
||||
*activeInputLabelPtr = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
bool MenuState::keyPressEditLabel(SDL_KeyboardEvent c, GraphicLabel **activeInputLabelPtr) {
|
||||
bool eventHandled = false;
|
||||
GraphicLabel *activeInputLabel = *activeInputLabelPtr;
|
||||
if(activeInputLabel != NULL) {
|
||||
int maxTextSize= activeInputLabel->getMaxEditWidth();
|
||||
|
||||
SDLKey key = extractKeyPressed(c);
|
||||
if(isKeyPressed(SDLK_ESCAPE,c,false) == true ||
|
||||
isKeyPressed(SDLK_RETURN,c,false) == true ) {
|
||||
setActiveInputLabel(NULL,activeInputLabelPtr);
|
||||
eventHandled = true;
|
||||
return eventHandled;
|
||||
}
|
||||
//if((c>='0' && c<='9') || (c>='a' && c<='z') || (c>='A' && c<='Z') ||
|
||||
// (c=='-') || (c=='(') || (c==')')) {
|
||||
if(isAllowedInputTextKey(key)) {
|
||||
if(activeInputLabel->getText().size() < maxTextSize) {
|
||||
string text= activeInputLabel->getText();
|
||||
//text.insert(text.end()-1, key);
|
||||
char szCharText[20]="";
|
||||
sprintf(szCharText,"%c",key);
|
||||
char *utfStr = String::ConvertToUTF8(&szCharText[0]);
|
||||
if(text.size() > 0) {
|
||||
size_t found = text.find_last_of("_");
|
||||
if (found == string::npos || found != text.length()-1) {
|
||||
text.insert(text.end(), utfStr[0]);
|
||||
}
|
||||
else {
|
||||
text.insert(text.end() -1, utfStr[0]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
text = utfStr[0];
|
||||
}
|
||||
delete [] utfStr;
|
||||
|
||||
activeInputLabel->setText(text);
|
||||
|
||||
eventHandled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return eventHandled;
|
||||
}
|
||||
|
||||
bool MenuState::keyDownEditLabel(SDL_KeyboardEvent c, GraphicLabel **activeInputLabelPtr) {
|
||||
bool eventHandled = false;
|
||||
GraphicLabel *activeInputLabel = *activeInputLabelPtr;
|
||||
if(activeInputLabel != NULL) {
|
||||
string text = activeInputLabel->getText();
|
||||
if(isKeyPressed(SDLK_BACKSPACE,c) == true && text.length() > 0) {
|
||||
size_t found = text.find_last_of("_");
|
||||
if (found == string::npos || found != text.length()-1) {
|
||||
text.erase(text.end() - 1);
|
||||
}
|
||||
else {
|
||||
if(text.size() > 1) {
|
||||
text.erase(text.end() - 2);
|
||||
}
|
||||
}
|
||||
|
||||
activeInputLabel->setText(text);
|
||||
eventHandled = true;
|
||||
}
|
||||
}
|
||||
return eventHandled;
|
||||
}
|
||||
|
||||
}}//end namespace
|
||||
|
|
|
@ -103,6 +103,12 @@ protected:
|
|||
const char *containerName;
|
||||
Console console;
|
||||
|
||||
protected:
|
||||
|
||||
void setActiveInputLabel(GraphicLabel *newLabel, GraphicLabel **activeInputLabelPtr);
|
||||
bool keyPressEditLabel(SDL_KeyboardEvent c, GraphicLabel **activeInputLabelPtr);
|
||||
bool keyDownEditLabel(SDL_KeyboardEvent c, GraphicLabel **activeInputLabelPtr);
|
||||
|
||||
public:
|
||||
MenuState(Program *program, MainMenu *mainMenu, const string &stateName);
|
||||
virtual ~MenuState();
|
||||
|
|
|
@ -372,6 +372,7 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM
|
|||
|
||||
labelPlayers[i].setText(lang.get("Player")+" "+intToStr(i));
|
||||
labelPlayerNames[i].setText("");
|
||||
labelPlayerNames[i].setMaxEditWidth(16);
|
||||
|
||||
listBoxTeams[i].setItems(teamItems);
|
||||
listBoxTeams[i].setSelectedItemIndex(i);
|
||||
|
@ -2725,6 +2726,8 @@ bool MenuStateConnectedGame::hasNetworkGameSettings()
|
|||
|
||||
void MenuStateConnectedGame::keyDown(SDL_KeyboardEvent key) {
|
||||
if(activeInputLabel != NULL) {
|
||||
|
||||
/*
|
||||
string text = activeInputLabel->getText();
|
||||
|
||||
//if(key == vkBack && text.length() > 0) {
|
||||
|
@ -2743,6 +2746,14 @@ void MenuStateConnectedGame::keyDown(SDL_KeyboardEvent key) {
|
|||
|
||||
switchSetupRequestFlagType |= ssrft_NetworkPlayerName;
|
||||
needToSetChangedGameSettings = true;
|
||||
lastSetChangedGameSettings = time(NULL);
|
||||
}
|
||||
*/
|
||||
|
||||
bool handled = keyDownEditLabel(key, &activeInputLabel);
|
||||
if(handled == true) {
|
||||
switchSetupRequestFlagType |= ssrft_NetworkPlayerName;
|
||||
needToSetChangedGameSettings = true;
|
||||
lastSetChangedGameSettings = time(NULL);
|
||||
}
|
||||
}
|
||||
|
@ -2785,7 +2796,8 @@ void MenuStateConnectedGame::keyDown(SDL_KeyboardEvent key) {
|
|||
|
||||
void MenuStateConnectedGame::keyPress(SDL_KeyboardEvent c) {
|
||||
if(activeInputLabel != NULL) {
|
||||
int maxTextSize= 16;
|
||||
/*
|
||||
int maxTextSize= activeInputLabel->getMaxEditWidth();
|
||||
for(int i = 0; i < GameConstants::maxPlayers; ++i) {
|
||||
if(&labelPlayerNames[i] == activeInputLabel) {
|
||||
SDLKey key = extractKeyPressed(c);
|
||||
|
@ -2805,7 +2817,13 @@ void MenuStateConnectedGame::keyPress(SDL_KeyboardEvent c) {
|
|||
sprintf(szCharText,"%c",key);
|
||||
char *utfStr = String::ConvertToUTF8(&szCharText[0]);
|
||||
if(utfStr != NULL) {
|
||||
text.insert(text.end() -1, utfStr[0]);
|
||||
if(text.size() > 0) {
|
||||
text.insert(text.end() -1, utfStr[0]);
|
||||
}
|
||||
else {
|
||||
text = utfStr[0];
|
||||
}
|
||||
|
||||
delete [] utfStr;
|
||||
|
||||
activeInputLabel->setText(text);
|
||||
|
@ -2818,6 +2836,14 @@ void MenuStateConnectedGame::keyPress(SDL_KeyboardEvent c) {
|
|||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
bool handled = keyPressEditLabel(c, &activeInputLabel);
|
||||
if(handled == true) {
|
||||
switchSetupRequestFlagType |= ssrft_NetworkPlayerName;
|
||||
needToSetChangedGameSettings = true;
|
||||
lastSetChangedGameSettings = time(NULL);
|
||||
}
|
||||
}
|
||||
else {
|
||||
chatManager.keyPress(c);
|
||||
|
@ -2842,6 +2868,7 @@ void MenuStateConnectedGame::keyUp(SDL_KeyboardEvent key) {
|
|||
}
|
||||
|
||||
void MenuStateConnectedGame::setActiveInputLabel(GraphicLabel *newLable) {
|
||||
/*
|
||||
if(newLable != NULL) {
|
||||
if( newLable==activeInputLabel){
|
||||
return;
|
||||
|
@ -2860,9 +2887,14 @@ void MenuStateConnectedGame::setActiveInputLabel(GraphicLabel *newLable) {
|
|||
text = text.substr(0,found);
|
||||
}
|
||||
activeInputLabel->setText(text);
|
||||
activeInputLabel->setEditModeEnabled(false);
|
||||
}
|
||||
activeInputLabel = newLable;
|
||||
|
||||
if(activeInputLabel != NULL) {
|
||||
activeInputLabel->setEditModeEnabled(true);
|
||||
}
|
||||
*/
|
||||
MenuState::setActiveInputLabel(newLable,&activeInputLabel);
|
||||
}
|
||||
|
||||
string MenuStateConnectedGame::getHumanPlayerName() {
|
||||
|
|
|
@ -379,6 +379,7 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu,
|
|||
else {
|
||||
labelGameName.setText("headless ("+defaultPlayerName+")");
|
||||
}
|
||||
labelGameName.setMaxEditWidth(20);
|
||||
// Network Frame Period
|
||||
//labelNetworkFramePeriod.registerGraphicComponent(containerName,"labelNetworkFramePeriod");
|
||||
//labelNetworkFramePeriod.init(xoffset+230, networkHeadPos, 80);
|
||||
|
@ -536,6 +537,7 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu,
|
|||
|
||||
labelPlayers[i].setText(lang.get("Player")+" "+intToStr(i));
|
||||
labelPlayerNames[i].setText("*");
|
||||
labelPlayerNames[i].setMaxEditWidth(16);
|
||||
|
||||
listBoxTeams[i].setItems(teamItems);
|
||||
listBoxTeams[i].setSelectedItemIndex(i);
|
||||
|
@ -3848,21 +3850,8 @@ void MenuStateCustomGame::keyDown(SDL_KeyboardEvent key) {
|
|||
}
|
||||
|
||||
if(activeInputLabel != NULL) {
|
||||
string text = activeInputLabel->getText();
|
||||
//if(key == vkBack && text.length() > 0) {
|
||||
if(isKeyPressed(SDLK_BACKSPACE,key) == true && text.length() > 0) {
|
||||
size_t found = text.find_last_of("_");
|
||||
if (found == string::npos) {
|
||||
text.erase(text.end() - 1);
|
||||
}
|
||||
else {
|
||||
if(text.size() > 1) {
|
||||
text.erase(text.end() - 2);
|
||||
}
|
||||
}
|
||||
|
||||
activeInputLabel->setText(text);
|
||||
|
||||
bool handled = keyDownEditLabel(key, &activeInputLabel);
|
||||
if(handled == true) {
|
||||
MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__));
|
||||
if(hasNetworkGameSettings() == true) {
|
||||
needToSetChangedGameSettings = true;
|
||||
|
@ -3917,37 +3906,12 @@ void MenuStateCustomGame::keyPress(SDL_KeyboardEvent c) {
|
|||
}
|
||||
|
||||
if(activeInputLabel != NULL) {
|
||||
int maxTextSize= 16;
|
||||
if(&labelGameName == activeInputLabel) {
|
||||
maxTextSize= 20;
|
||||
}
|
||||
|
||||
SDLKey key = extractKeyPressed(c);
|
||||
if(isKeyPressed(SDLK_ESCAPE,c,false) == true || isKeyPressed(SDLK_RETURN,c,false) == true )
|
||||
{
|
||||
setActiveInputLabel(NULL);
|
||||
return;
|
||||
}
|
||||
//if((c>='0' && c<='9') || (c>='a' && c<='z') || (c>='A' && c<='Z') ||
|
||||
// (c=='-') || (c=='(') || (c==')')) {
|
||||
if(isAllowedInputTextKey(key)) {
|
||||
if(activeInputLabel->getText().size() < maxTextSize) {
|
||||
string text= activeInputLabel->getText();
|
||||
//text.insert(text.end()-1, key);
|
||||
char szCharText[20]="";
|
||||
sprintf(szCharText,"%c",key);
|
||||
char *utfStr = String::ConvertToUTF8(&szCharText[0]);
|
||||
text.insert(text.end() -1, utfStr[0]);
|
||||
delete [] utfStr;
|
||||
|
||||
activeInputLabel->setText(text);
|
||||
if(&labelGameName != activeInputLabel){
|
||||
MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__));
|
||||
if(hasNetworkGameSettings() == true) {
|
||||
needToSetChangedGameSettings = true;
|
||||
lastSetChangedGameSettings = time(NULL);
|
||||
}
|
||||
}
|
||||
bool handled = keyPressEditLabel(c, &activeInputLabel);
|
||||
if(handled == true && &labelGameName != activeInputLabel) {
|
||||
MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__));
|
||||
if(hasNetworkGameSettings() == true) {
|
||||
needToSetChangedGameSettings = true;
|
||||
lastSetChangedGameSettings = time(NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4020,36 +3984,11 @@ string MenuStateCustomGame::getCurrentMapFile(){
|
|||
}
|
||||
|
||||
void MenuStateCustomGame::setActiveInputLabel(GraphicLabel *newLable) {
|
||||
if(newLable != NULL) {
|
||||
if( newLable==activeInputLabel){
|
||||
return;
|
||||
}
|
||||
string text= newLable->getText();
|
||||
size_t found = text.find_last_of("_");
|
||||
if (found == string::npos) {
|
||||
text += "_";
|
||||
}
|
||||
newLable->setText(text);
|
||||
}
|
||||
if(activeInputLabel != NULL && activeInputLabel->getText().empty() == false) {
|
||||
string text= activeInputLabel->getText();
|
||||
size_t found = text.find_last_of("_");
|
||||
if (found != string::npos) {
|
||||
text = text.substr(0,found);
|
||||
}
|
||||
activeInputLabel->setText(text);
|
||||
}
|
||||
activeInputLabel = newLable;
|
||||
|
||||
MenuState::setActiveInputLabel(newLable,&activeInputLabel);
|
||||
}
|
||||
|
||||
string MenuStateCustomGame::getHumanPlayerName(int index) {
|
||||
string result = defaultPlayerName;
|
||||
|
||||
//printf("\nIn [%s::%s Line: %d] index = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,index);
|
||||
//fflush(stdout);
|
||||
|
||||
|
||||
if(index < 0) {
|
||||
for(int j = 0; j < GameConstants::maxPlayers; ++j) {
|
||||
if(listBoxControls[j].getSelectedItemIndex() >= 0) {
|
||||
|
@ -4062,9 +4001,6 @@ string MenuStateCustomGame::getHumanPlayerName(int index) {
|
|||
}
|
||||
}
|
||||
|
||||
//printf("\nIn [%s::%s Line: %d] index = %d, labelPlayerNames[index].getText() = [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,index,(index >= 0 ? labelPlayerNames[index].getText().c_str() : "?"));
|
||||
//fflush(stdout);
|
||||
|
||||
if(index >= 0 && index < GameConstants::maxPlayers &&
|
||||
labelPlayerNames[index].getText() != "" &&
|
||||
labelPlayerNames[index].getText() != GameConstants::NETWORK_SLOT_UNCONNECTED_SLOTNAME) {
|
||||
|
|
|
@ -586,7 +586,13 @@ void MenuStateJoinGame::keyPress(SDL_KeyboardEvent c) {
|
|||
char szCharText[20]="";
|
||||
sprintf(szCharText,"%c",key);
|
||||
char *utfStr = String::ConvertToUTF8(&szCharText[0]);
|
||||
text.insert(text.end() -1, utfStr[0]);
|
||||
if(text.size() > 0) {
|
||||
text.insert(text.end() -1, utfStr[0]);
|
||||
}
|
||||
else {
|
||||
text = utfStr[0];
|
||||
}
|
||||
|
||||
delete [] utfStr;
|
||||
|
||||
labelServerIp.setText(text);
|
||||
|
@ -596,7 +602,13 @@ void MenuStateJoinGame::keyPress(SDL_KeyboardEvent c) {
|
|||
else if (key == SDLK_PERIOD) {
|
||||
if(labelServerIp.getText().size() < maxTextSize) {
|
||||
string text= labelServerIp.getText();
|
||||
text.insert(text.end()-1, '.');
|
||||
if(text.size() > 0) {
|
||||
text.insert(text.end() -1, '.');
|
||||
}
|
||||
else {
|
||||
text = ".";
|
||||
}
|
||||
|
||||
labelServerIp.setText(text);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -381,6 +381,7 @@ MenuStateOptions::MenuStateOptions(Program *program, MainMenu *mainMenu):
|
|||
labelPlayerName.setText(config.getString("NetPlayerName",Socket::getHostName().c_str()));
|
||||
labelPlayerName.setFont(CoreData::getInstance().getMenuFontBig());
|
||||
labelPlayerName.setFont3D(CoreData::getInstance().getMenuFontBig3D());
|
||||
labelPlayerName.setMaxEditWidth(16);
|
||||
currentLine-=lineOffset;
|
||||
|
||||
//FontSizeAdjustment
|
||||
|
@ -941,6 +942,7 @@ bool MenuStateOptions::isInSpecialKeyCaptureEvent() {
|
|||
|
||||
void MenuStateOptions::keyDown(SDL_KeyboardEvent key) {
|
||||
if(activeInputLabel != NULL) {
|
||||
/*
|
||||
string text= activeInputLabel->getText();
|
||||
if(isKeyPressed(SDLK_BACKSPACE,key) == true && text.length() > 0) {
|
||||
size_t found = text.find_last_of("_");
|
||||
|
@ -955,43 +957,51 @@ void MenuStateOptions::keyDown(SDL_KeyboardEvent key) {
|
|||
|
||||
activeInputLabel->setText(text);
|
||||
}
|
||||
*/
|
||||
keyDownEditLabel(key, &activeInputLabel);
|
||||
}
|
||||
}
|
||||
|
||||
void MenuStateOptions::keyPress(SDL_KeyboardEvent c) {
|
||||
if(activeInputLabel!=NULL) {
|
||||
if(activeInputLabel != NULL) {
|
||||
//printf("[%d]\n",c); fflush(stdout);
|
||||
if(&labelPlayerName==activeInputLabel) {
|
||||
if(&labelPlayerName == activeInputLabel) {
|
||||
/*
|
||||
SDLKey key = extractKeyPressed(c);
|
||||
if((key>='0' && key<='9')||(key>='a' && key<='z')||(key>='A' && key<='Z')||
|
||||
(key>=(192-256) && key<=(255-256))||
|
||||
(key=='-')||(key=='_')||(key=='(')||(key==')')){
|
||||
//if(isAllowedInputTextKey(key)) {
|
||||
const int maxTextSize= 16;
|
||||
const int maxTextSize= activeInputLabel->getMaxEditWidth();
|
||||
if(activeInputLabel->getText().size()<maxTextSize){
|
||||
string text= activeInputLabel->getText();
|
||||
//text.insert(text.end()-1, key);
|
||||
char szCharText[20]="";
|
||||
sprintf(szCharText,"%c",key);
|
||||
char *utfStr = String::ConvertToUTF8(&szCharText[0]);
|
||||
text.insert(text.end() -1, utfStr[0]);
|
||||
if(text.size() > 0) {
|
||||
text.insert(text.end() -1, utfStr[0]);
|
||||
}
|
||||
else {
|
||||
text = utfStr[0];
|
||||
}
|
||||
delete [] utfStr;
|
||||
|
||||
activeInputLabel->setText(text);
|
||||
}
|
||||
}
|
||||
*/
|
||||
keyPressEditLabel(c, &activeInputLabel);
|
||||
}
|
||||
}
|
||||
else {
|
||||
Config &configKeys = Config::getInstance(std::pair<ConfigType,ConfigType>(cfgMainKeys,cfgUserKeys));
|
||||
//if(c == configKeys.getCharKey("SaveGUILayout")) {
|
||||
if(isKeyPressed(configKeys.getSDLKey("SaveGUILayout"),c) == true) {
|
||||
GraphicComponent::saveAllCustomProperties(containerName);
|
||||
//Lang &lang= Lang::getInstance();
|
||||
//console.addLine(lang.get("GUILayoutSaved") + " [" + (saved ? lang.get("Yes") : lang.get("No"))+ "]");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void MenuStateOptions::render(){
|
||||
|
@ -1189,8 +1199,8 @@ void MenuStateOptions::saveConfig(){
|
|||
Renderer::getInstance().loadConfig();
|
||||
}
|
||||
|
||||
void MenuStateOptions::setActiveInputLable(GraphicLabel *newLable)
|
||||
{
|
||||
void MenuStateOptions::setActiveInputLable(GraphicLabel *newLable) {
|
||||
/*
|
||||
if(newLable!=NULL){
|
||||
string text= newLable->getText();
|
||||
size_t found;
|
||||
|
@ -1210,8 +1220,15 @@ void MenuStateOptions::setActiveInputLable(GraphicLabel *newLable)
|
|||
text=text.substr(0,found);
|
||||
}
|
||||
activeInputLabel->setText(text);
|
||||
activeInputLabel->setEditModeEnabled(false);
|
||||
}
|
||||
activeInputLabel=newLable;
|
||||
if(activeInputLabel != NULL) {
|
||||
activeInputLabel->setEditModeEnabled(true);
|
||||
}
|
||||
*/
|
||||
|
||||
MenuState::setActiveInputLabel(newLable,&activeInputLabel);
|
||||
}
|
||||
|
||||
}}//end namespace
|
||||
|
|
Loading…
Reference in New Issue