E:/Eigene Dateien/Eigene Projekte/c0re/Interface.cpp

Go to the documentation of this file.
00001 /*
00002         This file is part of c0re.
00003 
00004         c0re is a multiplayer RTS on a hexagonal map with an evolving unit concept.
00005     Copyright (C) 2007 Stephan Hofmann
00006 
00007     c0re is free software: you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation, either version 3 of the License, or
00010     (at your option) any later version.
00011 
00012     This program is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015     GNU General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00019 */
00020 
00021 #include "Interface.h"
00022 
00023 #include "system.h"
00024 #include <GL/gl.h>
00025 #include <GL/glu.h>
00026 #include <fstream>
00027 
00028 #include "Level.h"
00029 #include "Field.h"
00030 #include "Player.h"
00031 #include "myTools.h"
00032 #include "Button.h"
00033 
00034 Interface::Interface(Level *p_level)
00035 {
00036         level = p_level;
00037         id += 200;
00038 }
00039 
00040 Interface::~Interface()
00041 {
00042 }
00043 
00044 int Interface::render()
00045 {
00046         int ret = 0;
00047 
00048         glMatrixMode(GL_MODELVIEW);
00049         glLoadIdentity();
00050         glDisable(GL_DEPTH_TEST);
00051 
00052         Texture::render();
00053 
00054         std::vector<Button*>::iterator it;
00055         for (it = buttons.begin(); it != buttons.end(); it++)
00056         {
00057                 (*it)->render();
00058         }
00059 
00060         
00061         //now the selected field with unit on it
00062         if (Unit::s_selectedID != -1)
00063         {
00064                 //get the origin field
00065                 Texture *texture = Texture::get(Field::s_selectedFieldID);
00066                 //clean cast
00067                 Field* field = texture->getField();
00068                 if (field != 0)
00069                 {
00070                         glPushMatrix();
00071                         field->render(unitWindowPos, unitWindow->size);
00072                         //I don't know why i have to add this offset, in normal render it is not needed :(
00073                         field->renderChild(unitWindowPos - Vector3d(0.0, 0.055, 0.0), level, unitWindow->size);
00074                         glPopMatrix();
00075 
00076                 }
00077         }
00078         else // the empty window
00079         {
00080                 unitWindow->render(unitWindowPos);
00081         }
00082 
00083         //now the energy counter and text
00084         glPushMatrix();
00085 
00086         energyCounter->render(energyCounterPos);
00087         glTranslated(energyCounterFontPos.x, energyCounterFontPos.y, energyCounterFontPos.z);
00088         glColor4d(0.5, 0.5, 0.5, 1.0);
00089         level->glPrint2d(0.0, 0.0, "%i", level->players[playerName]->energy);
00090         glPopMatrix();
00091 
00092         glEnable(GL_DEPTH_TEST);
00093 
00094 
00095         return ret;
00096 }
00097 
00098 int Interface::load(std::string p_style, std::string p_playerName)
00099 {
00100         int ret = 0;
00101         playerName = p_playerName;
00102         std::string filename = "textures//interface//" + p_style + "//interface.ini";
00103         std::ifstream fin(filename.c_str());
00104         std::string buffer;
00105         std::vector<std::string> values, more_values;
00106         Button* btn;
00107         while (fin.good()) {
00108                 std::getline(fin,buffer,'\n');
00109                 splitLine(values, buffer, "=");
00110                 if (true)
00111                 {
00112                         if (values[0].find("background") != std::string::npos)
00113                         {
00114                                 loadAndBind("textures//interface//" + p_style + "//" + values[1]);
00115                         } 
00116                         else if (values[0].find("button") != std::string::npos)
00117                         {
00118                                 splitLine(more_values, values[1], ",");
00119                                 btn = new Button(this);
00120                                 btn->loadAndBind("textures//interface//" + p_style + "//" + more_values[0]);
00121                                 btn->size = atof(more_values[1].c_str());
00122                                 btn->pos = Vector3d(atof(more_values[2].c_str()), atof(more_values[3].c_str()), 0.0);
00123                                 btn->label = more_values[4];
00124                                 if (more_values.size() > 5)
00125                                         btn->val = atoi(more_values[5].c_str());
00126                                 buttons.push_back(btn);
00127                         }
00128                         else if (values[0].find("energy_display") != std::string::npos)
00129                         {
00130                                 splitLine(more_values, values[1], ",");
00131                                 energyCounter = new Object();
00132                                 energyCounter->loadAndBind("textures//interface//" + p_style + "//" + more_values[0]);
00133                                 energyCounter->size = atof(more_values[1].c_str());
00134                                 energyCounterPos = Vector3d(atof(more_values[2].c_str()), atof(more_values[3].c_str()), 0.0);
00135                                 energyCounterFontPos = Vector3d(atof(more_values[4].c_str()), atof(more_values[5].c_str()), 0.0);
00136                                 //as the font-pos is regarded aas offset to energycounter, we simply add it
00137                                 energyCounterFontPos += energyCounterPos;
00138                         }
00139                         else if (values[0].find("unit_placeholder") != std::string::npos)
00140                         {
00141                                 splitLine(more_values, values[1], ",");
00142                                 unitWindow = new Object();
00143                                 unitWindow->loadAndBind("textures//interface//" + p_style + "//" + more_values[0]);
00144                                 unitWindow->size = atof(more_values[1].c_str());
00145                                 unitWindowPos = Vector3d(atof(more_values[2].c_str()), atof(more_values[3].c_str()), 0.0);
00146                         }
00147                 }
00148         }
00149         fin.close();
00150         return ret;
00151 }

Generated on Tue Jul 17 22:02:22 2007 for C0re by  doxygen 1.5.2