mirror of
https://github.com/glest/glest-source.git
synced 2025-02-26 04:32:22 +01:00
GraphicMessageBox can handle multiple buttons now
This commit is contained in:
parent
9dd8dd4098
commit
9870c13a6b
@ -462,38 +462,30 @@ bool GraphicListBox::mouseClick(int x, int y){
|
||||
const int GraphicMessageBox::defH= 240;
|
||||
const int GraphicMessageBox::defW= 350;
|
||||
|
||||
GraphicMessageBox::GraphicMessageBox(std::string containerName, std::string objName)
|
||||
: GraphicComponent(containerName, objName) {
|
||||
buttonCount = 0;
|
||||
header = "";
|
||||
GraphicMessageBox::GraphicMessageBox(std::string containerName, std::string objName) :
|
||||
GraphicComponent(containerName, objName){
|
||||
header= "";
|
||||
}
|
||||
|
||||
|
||||
void GraphicMessageBox::init(const string &button1Str, const string &button2Str, int newWidth,int newHeight) {
|
||||
init(button1Str,newWidth,newHeight);
|
||||
|
||||
button1.init(x+(w-GraphicButton::defW)/4, y+25);
|
||||
button1.setText(button1Str);
|
||||
button2.init(x+3*(w-GraphicButton::defW)/4, y+25);
|
||||
button2.setText(button2Str);
|
||||
buttonCount= 2;
|
||||
GraphicMessageBox::~GraphicMessageBox(){
|
||||
//remove buttons
|
||||
while(!buttons.empty()){
|
||||
delete buttons.back();
|
||||
buttons.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
void GraphicMessageBox::setX(int x) {
|
||||
this->x= x;
|
||||
|
||||
button1.init(x+(w-GraphicButton::defW)/4, y+25);
|
||||
button2.init(x+3*(w-GraphicButton::defW)/4, y+25);
|
||||
void GraphicMessageBox::init(const string &button1Str, const string &button2Str, int newWidth, int newHeight){
|
||||
init(button1Str, newWidth, newHeight);
|
||||
if(getButtonCount()>1){
|
||||
getButton(1)->setText(button2Str);
|
||||
}
|
||||
else{
|
||||
addButton(button2Str);
|
||||
}
|
||||
}
|
||||
|
||||
void GraphicMessageBox::setY(int y) {
|
||||
this->y= y;
|
||||
|
||||
button1.init(x+(w-GraphicButton::defW)/4, y+25);
|
||||
button2.init(x+3*(w-GraphicButton::defW)/4, y+25);
|
||||
}
|
||||
|
||||
void GraphicMessageBox::init(const string &button1Str, int newWidth,int newHeight) {
|
||||
void GraphicMessageBox::init(const string &button1Str, int newWidth, int newHeight){
|
||||
font= CoreData::getInstance().getMenuFontNormal();
|
||||
font3D= CoreData::getInstance().getMenuFontNormal3D();
|
||||
|
||||
@ -502,56 +494,92 @@ void GraphicMessageBox::init(const string &button1Str, int newWidth,int newHeigh
|
||||
|
||||
const Metrics &metrics= Metrics::getInstance();
|
||||
|
||||
x= (metrics.getVirtualW()-w)/2;
|
||||
y= (metrics.getVirtualH()-h)/2;
|
||||
x= (metrics.getVirtualW() - w) / 2;
|
||||
y= (metrics.getVirtualH() - h) / 2;
|
||||
|
||||
button1.init(x+(w-GraphicButton::defW)/2, y+25);
|
||||
button1.setText(button1Str);
|
||||
buttonCount= 1;
|
||||
if(getButtonCount()>0){
|
||||
getButton(0)->setText(button1Str);
|
||||
}
|
||||
else{
|
||||
addButton(button1Str);
|
||||
}
|
||||
}
|
||||
|
||||
void GraphicMessageBox::addButton(const string &buttonStr, int width, int height){
|
||||
GraphicButton *newButton= new GraphicButton();
|
||||
newButton->init(0, 0);
|
||||
newButton->setText(buttonStr);
|
||||
if(width != -1){
|
||||
newButton->setW(width);
|
||||
}
|
||||
if(height != -1){
|
||||
newButton->setH(height);
|
||||
}
|
||||
buttons.push_back(newButton);
|
||||
alignButtons();
|
||||
}
|
||||
|
||||
void GraphicMessageBox::alignButtons(){
|
||||
int currXPos= 0;
|
||||
int totalbuttonListLength=0;
|
||||
int buttonOffset=5;
|
||||
for(int i= 0; i < getButtonCount(); i++){
|
||||
GraphicButton *button= getButton(i);
|
||||
totalbuttonListLength+=button->getW();
|
||||
}
|
||||
totalbuttonListLength+=(getButtonCount()-1)*buttonOffset;
|
||||
currXPos=x+w/2-totalbuttonListLength/2;
|
||||
for(int i= 0; i < getButtonCount(); i++){
|
||||
GraphicButton *button= getButton(i);
|
||||
button->setY(y + 25);
|
||||
button->setX(currXPos);
|
||||
currXPos+=button->getW()+buttonOffset;
|
||||
}
|
||||
}
|
||||
|
||||
void GraphicMessageBox::setX(int x){
|
||||
this->x= x;
|
||||
alignButtons();
|
||||
}
|
||||
|
||||
void GraphicMessageBox::setY(int y){
|
||||
this->y= y;
|
||||
alignButtons();
|
||||
}
|
||||
|
||||
bool GraphicMessageBox::mouseMove(int x, int y){
|
||||
if(this->getVisible() == false) {
|
||||
if(this->getVisible() == false){
|
||||
return false;
|
||||
}
|
||||
|
||||
return button1.mouseMove(x, y) || button2.mouseMove(x, y);
|
||||
for(int i= 0; i < getButtonCount(); i++){
|
||||
if(getButton(i)->mouseMove(x, y)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool GraphicMessageBox::mouseClick(int x, int y){
|
||||
if(this->getVisible() == false) {
|
||||
if(this->getVisible() == false){
|
||||
return false;
|
||||
}
|
||||
|
||||
bool b1= button1.mouseClick(x, y);
|
||||
bool b2= button2.mouseClick(x, y);
|
||||
if(buttonCount==1){
|
||||
return b1;
|
||||
}
|
||||
else{
|
||||
return b1 ||b2;
|
||||
for(int i= 0; i < getButtonCount(); i++){
|
||||
if(getButton(i)->mouseClick(x, y)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool GraphicMessageBox::mouseClick(int x, int y, int &clickedButton){
|
||||
if(this->getVisible() == false) {
|
||||
if(this->getVisible() == false){
|
||||
return false;
|
||||
}
|
||||
|
||||
bool b1= button1.mouseClick(x, y);
|
||||
bool b2= button2.mouseClick(x, y);
|
||||
|
||||
if(buttonCount==1){
|
||||
clickedButton= 1;
|
||||
return b1;
|
||||
}
|
||||
else{
|
||||
if(b1){
|
||||
clickedButton= 1;
|
||||
return true;
|
||||
}
|
||||
else if(b2){
|
||||
clickedButton= 2;
|
||||
for(int i= 0; i < getButtonCount(); i++){
|
||||
if(getButton(i)->mouseClick(x, y)){
|
||||
clickedButton=i;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -231,26 +231,27 @@ public:
|
||||
// ===========================================================
|
||||
// class GraphicMessageBox
|
||||
// ===========================================================
|
||||
|
||||
typedef vector<GraphicButton*> GraphicButtons;
|
||||
class GraphicMessageBox: public GraphicComponent {
|
||||
public:
|
||||
static const int defH;
|
||||
static const int defW;
|
||||
|
||||
private:
|
||||
GraphicButton button1;
|
||||
GraphicButton button2;
|
||||
int buttonCount;
|
||||
GraphicButtons buttons;
|
||||
string header;
|
||||
|
||||
private:
|
||||
void alignButtons();
|
||||
public:
|
||||
GraphicMessageBox(std::string containerName="", std::string objName="");
|
||||
virtual ~GraphicMessageBox();
|
||||
void init(const string &button1Str, const string &button2Str, int newWidth=-1,int newHeight=-1);
|
||||
void init(const string &button1Str, int newWidth=-1,int newHeight=-1);
|
||||
void addButton(const string &buttonStr, int width=-1,int height=-1);
|
||||
|
||||
int getButtonCount() const {return buttonCount;}
|
||||
GraphicButton *getButton1() {return &button1;}
|
||||
GraphicButton *getButton2() {return &button2;}
|
||||
int getButtonCount() const {return buttons.size();}
|
||||
GraphicButton *getButton(int index) {return buttons[index];}
|
||||
string getHeader() const {return header;}
|
||||
|
||||
virtual void setX(int x);
|
||||
|
@ -1785,7 +1785,7 @@ void Game::mouseDownLeft(int x, int y) {
|
||||
|
||||
SwitchTeamVote *vote = world.getThisFactionPtr()->getSwitchTeamVote(world.getThisFaction()->getCurrentSwitchTeamVoteFactionIndex());
|
||||
vote->voted = true;
|
||||
vote->allowSwitchTeam = (button == 1);
|
||||
vote->allowSwitchTeam = (button == 0);
|
||||
|
||||
const Faction *faction = world.getThisFaction();
|
||||
commander.trySwitchTeamVote(faction,vote);
|
||||
@ -1796,7 +1796,7 @@ void Game::mouseDownLeft(int x, int y) {
|
||||
if( mainMessageBox.getEnabled() == false &&
|
||||
errorMessageBox.getEnabled() == false &&
|
||||
scriptManager.getMessageBox()->getEnabled()) {
|
||||
int button= 1;
|
||||
int button= 0;
|
||||
if(scriptManager.getMessageBox()->mouseClick(x, y, button)){
|
||||
scriptManager.onMessageBoxOk();
|
||||
messageBoxClick= true;
|
||||
@ -1847,9 +1847,9 @@ void Game::mouseDownLeft(int x, int y) {
|
||||
}
|
||||
}
|
||||
if(mainMessageBox.getEnabled()){
|
||||
int button= 1;
|
||||
int button= 0;
|
||||
if(mainMessageBox.mouseClick(x, y, button)) {
|
||||
if(button==1) {
|
||||
if(button==0) {
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
|
||||
if(networkManager.getGameNetworkInterface() != NULL) {
|
||||
networkManager.getGameNetworkInterface()->quitGame(true);
|
||||
|
@ -3212,9 +3212,8 @@ void Renderer::renderMessageBox(GraphicMessageBox *messageBox) {
|
||||
|
||||
|
||||
//buttons
|
||||
renderButton(messageBox->getButton1());
|
||||
if(messageBox->getButtonCount()==2){
|
||||
renderButton(messageBox->getButton2());
|
||||
for(int i=0; i<messageBox->getButtonCount();i++){
|
||||
renderButton(messageBox->getButton(i));
|
||||
}
|
||||
|
||||
Vec4f fontColor;
|
||||
|
@ -466,9 +466,9 @@ void BattleEnd::mouseDownLeft(int x, int y){
|
||||
program->setState(new MainMenu(program));
|
||||
}
|
||||
else if(mainMessageBox.getEnabled()) {
|
||||
int button= 1;
|
||||
int button= 0;
|
||||
if(mainMessageBox.mouseClick(x, y, button)) {
|
||||
if(button==1) {
|
||||
if(button==0) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
program->setState(new MainMenu(program));
|
||||
}
|
||||
|
@ -140,7 +140,7 @@ void Program::ShowMessageProgramState::render() {
|
||||
}
|
||||
|
||||
void Program::ShowMessageProgramState::mouseDownLeft(int x, int y) {
|
||||
int button= 1;
|
||||
int button= 0;
|
||||
if(msgBox.mouseClick(x,y,button)) {
|
||||
program->exit();
|
||||
userWantsExit = true;
|
||||
@ -295,7 +295,7 @@ void Program::keyPress(SDL_KeyboardEvent c) {
|
||||
|
||||
void Program::mouseDownLeft(int x, int y) {
|
||||
if(msgBox.getEnabled()) {
|
||||
int button= 1;
|
||||
int button= 0;
|
||||
if(msgBox.mouseClick(x, y, button)) {
|
||||
//if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
//close message box
|
||||
|
@ -724,20 +724,20 @@ void MenuStateConnectedGame::mouseClick(int x, int y, MouseButton mouseButton){
|
||||
Lang &lang= Lang::getInstance();
|
||||
|
||||
if(mainMessageBox.getEnabled()) {
|
||||
int button= 1;
|
||||
int button= 0;
|
||||
if(mainMessageBox.mouseClick(x, y, button)) {
|
||||
soundRenderer.playFx(coreData.getClickSoundA());
|
||||
if(button == 1) {
|
||||
if(button == 0) {
|
||||
mainMessageBox.setEnabled(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(ftpMessageBox.getEnabled()) {
|
||||
int button= 1;
|
||||
int button= 0;
|
||||
if(ftpMessageBox.mouseClick(x, y, button)) {
|
||||
soundRenderer.playFx(coreData.getClickSoundA());
|
||||
ftpMessageBox.setEnabled(false);
|
||||
if(button == 1) {
|
||||
if(button == 0) {
|
||||
if(ftpMissingDataType == ftpmsg_MissingMap) {
|
||||
getMissingMapFromFTPServerInProgress = true;
|
||||
|
||||
|
@ -936,11 +936,11 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton) {
|
||||
int oldListBoxMapfilterIndex=listBoxMapFilter.getSelectedItemIndex();
|
||||
|
||||
if(mainMessageBox.getEnabled()){
|
||||
int button= 1;
|
||||
int button= 0;
|
||||
if(mainMessageBox.mouseClick(x, y, button))
|
||||
{
|
||||
soundRenderer.playFx(coreData.getClickSoundA());
|
||||
if(button==1)
|
||||
if(button==0)
|
||||
{
|
||||
mainMessageBox.setEnabled(false);
|
||||
}
|
||||
|
@ -217,11 +217,11 @@ void MenuStateKeysetup::mouseClick(int x, int y, MouseButton mouseButton){
|
||||
SoundRenderer &soundRenderer= SoundRenderer::getInstance();
|
||||
|
||||
if(mainMessageBox.getEnabled()){
|
||||
int button= 1;
|
||||
int button= 0;
|
||||
if(mainMessageBox.mouseClick(x, y, button))
|
||||
{
|
||||
soundRenderer.playFx(coreData.getClickSoundA());
|
||||
if(button==1)
|
||||
if(button==0)
|
||||
{
|
||||
mainMessageBox.setEnabled(false);
|
||||
}
|
||||
|
@ -469,11 +469,11 @@ void MenuStateMasterserver::mouseClick(int x, int y, MouseButton mouseButton){
|
||||
SoundRenderer &soundRenderer= SoundRenderer::getInstance();
|
||||
|
||||
if(mainMessageBox.getEnabled()){
|
||||
int button= 1;
|
||||
int button= 0;
|
||||
if(mainMessageBox.mouseClick(x, y, button))
|
||||
{
|
||||
soundRenderer.playFx(coreData.getClickSoundA());
|
||||
if(button==1)
|
||||
if(button==0)
|
||||
{
|
||||
mainMessageBox.setEnabled(false);
|
||||
}
|
||||
|
@ -1200,12 +1200,12 @@ void MenuStateMods::mouseClick(int x, int y, MouseButton mouseButton) {
|
||||
}
|
||||
}
|
||||
else if(mainMessageBox.getEnabled()) {
|
||||
int button= 1;
|
||||
int button= 0;
|
||||
if(mainMessageBox.mouseClick(x, y, button)) {
|
||||
soundRenderer.playFx(coreData.getClickSoundA());
|
||||
mainMessageBox.setEnabled(false);
|
||||
mainMessageBox.init(lang.get("Yes"),lang.get("No"),450);
|
||||
if(button == 1) {
|
||||
if(button == 0) {
|
||||
if(mainMessageBoxState == ftpmsg_Quit) {
|
||||
mainMessageBoxState = ftpmsg_None;
|
||||
mainMenu->setState(new MenuStateRoot(program, mainMenu));
|
||||
|
@ -687,11 +687,11 @@ void MenuStateOptions::mouseClick(int x, int y, MouseButton mouseButton){
|
||||
SoundRenderer &soundRenderer= SoundRenderer::getInstance();
|
||||
|
||||
if(mainMessageBox.getEnabled()){
|
||||
int button= 1;
|
||||
int button= 0;
|
||||
if(mainMessageBox.mouseClick(x, y, button))
|
||||
{
|
||||
soundRenderer.playFx(coreData.getClickSoundA());
|
||||
if(button==1)
|
||||
if(button==0)
|
||||
{
|
||||
if(mainMessageBoxState==1)
|
||||
{
|
||||
|
@ -133,9 +133,9 @@ void MenuStateRoot::mouseClick(int x, int y, MouseButton mouseButton){
|
||||
}
|
||||
//exit message box, has to be the last thing to do in this function
|
||||
else if(mainMessageBox.getEnabled()){
|
||||
int button= 1;
|
||||
int button= 0;
|
||||
if(mainMessageBox.mouseClick(x, y, button)) {
|
||||
if(button==1) {
|
||||
if(button==0) {
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
soundRenderer.playFx(coreData.getClickSoundA());
|
||||
program->exit();
|
||||
@ -149,7 +149,7 @@ void MenuStateRoot::mouseClick(int x, int y, MouseButton mouseButton){
|
||||
}
|
||||
//exit message box, has to be the last thing to do in this function
|
||||
else if(errorMessageBox.getEnabled()){
|
||||
int button= 1;
|
||||
int button= 0;
|
||||
if(mainMessageBox.mouseClick(x, y, button)) {
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
//close message box
|
||||
|
@ -144,11 +144,11 @@ void MenuStateScenario::mouseClick(int x, int y, MouseButton mouseButton) {
|
||||
SoundRenderer &soundRenderer= SoundRenderer::getInstance();
|
||||
|
||||
if(mainMessageBox.getEnabled()){
|
||||
int button= 1;
|
||||
int button= 0;
|
||||
if(mainMessageBox.mouseClick(x, y, button))
|
||||
{
|
||||
soundRenderer.playFx(coreData.getClickSoundA());
|
||||
if(button==1) {
|
||||
if(button==0) {
|
||||
mainMessageBox.setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user