const QVector<djvStyle::Palette> & djvStyle::palettesDefault() { static const QVector<djvStyle::Palette> data = QVector<djvStyle::Palette>() << Palette( qApp->translate("djvStyle", "Dark"), djvColor(0.9f), djvColor(0.25f), djvColor(0.15f), djvColor(0.25f), djvColor(0.7f, 0.6f, 0.3f)) << Palette( qApp->translate("djvStyle", "Light"), djvColor(0.1f), djvColor(0.8f), djvColor(0.7f), djvColor(0.7f), djvColor(0.7f, 0.6f, 0.3f)) << Palette( qApp->translate("djvStyle", "Default"), djvColorUtil::fromQt(qApp->palette().color(QPalette::Foreground)), djvColorUtil::fromQt(qApp->palette().color(QPalette::Background)), djvColorUtil::fromQt(qApp->palette().color(QPalette::Base)), djvColorUtil::fromQt(qApp->palette().color(QPalette::Button)), djvColorUtil::fromQt(qApp->palette().color(QPalette::Highlight))) << Palette( qApp->translate("djvStyle", "Custom"), djvColor(0.9f), djvColor(0.0f, 0.3f, 0.0f), djvColor(0.3f, 0.4f, 0.3f), djvColor(0.0f, 0.4f, 0.0f), djvColor(0.7f, 0.9f, 0.7f)); return data; }
void main(int argc,char *argv[]) { if (initmouse()==FALSE) { errorbox("GameMaker requires a Microsoft","compatible mouse! (Q)uit",30); exit(quit); } #ifndef DEBUG Palette(5,10,10,10); Palette(7,16,16,16); #endif mouclearbut(); randomize(); #ifdef CHKREG if ((argc >= 2)&&(strcmpi(argv[1],"REGISTER") == 0)) regi(); firststart(); #else gmmain(); #endif Palette(5,42,0,42); Palette(7,42,42,42); clrbox(0,0,79,24,7); exit(quit); }
/** * Load a palette from a GIMP palette file. * * The file format is: * * GIMP Palette * *HEADER FIELDS* * # one or more comment * r g b name * ... * * @param filename palette file name */ Palette Palette::fromFile(const QFileInfo& file) { QFile palfile(file.absoluteFilePath()); if (!palfile.open(QIODevice::ReadOnly | QIODevice::Text)) return Palette(); QTextStream in(&palfile); if(in.readLine() != "GIMP Palette") return Palette(); Palette pal(file.baseName(), file.fileName()); const QRegularExpression colorRe("^(\\d+)\\s+(\\d+)\\s+(\\d+)\\s*(.+)?$"); do { QString line = in.readLine().trimmed(); if(line.isEmpty() || line.at(0) == '#') { // ignore comments and empty lines } else if(line.startsWith("Name:")) { pal._name = line.mid(5).trimmed(); } else if(line.startsWith("Columns:")) { bool ok; int cols = line.mid(9).trimmed().toInt(&ok); if(ok && cols>0) pal._columns = cols; } else { QRegularExpressionMatch m = colorRe.match(line); if(m.hasMatch()) { pal.appendColor( QColor( m.captured(1).toInt(), m.captured(2).toInt(), m.captured(3).toInt() ), m.captured(4) ); } else { qWarning() << "unhandled line" << line << "in" << file.fileName(); } } } while(!in.atEnd()); return pal; }
vogleditor_QTimelineView::vogleditor_QTimelineView(QWidget *parent) : QWidget(parent), m_roundoff(cVOGL_TIMELINEOFFSET), m_curFrameTime(-1), m_curApiCallTime(-1), m_zoom(1), m_scroll(0), m_pModel(NULL), m_pPixmap(NULL) { QLinearGradient gradient(QPointF(0, 1), QPointF(0, 0)); gradient.setCoordinateMode(QGradient::ObjectBoundingMode); gradient.setColorAt(0.0, Qt::white); gradient.setColorAt(1.0, QColor(0xa6, 0xce, 0x39)); m_triangleBrushWhite = QBrush(gradient); gradient.setColorAt(0.0, Qt::black); gradient.setColorAt(1.0, QColor(0xa6, 0xce, 0x39)); m_triangleBrushBlack = QBrush(gradient); QPalette Palette(palette()); Palette.setColor(QPalette::Background, QColor(200, 200, 200)); setAutoFillBackground(true); setPalette(Palette); m_trianglePen = QPen(Qt::black); m_trianglePen.setWidth(1); m_trianglePen.setJoinStyle(Qt::MiterJoin); m_trianglePen.setMiterLimit(3); m_textPen = QPen(Qt::white); m_textFont.setPixelSize(50); m_horizontalScale = 1; m_lineLength = 1; }
//--------------------------------------------------------------------------- void MainWindow::createDragDrop() { clearDragDrop(); QFont Font; Font.setPointSize(Font.pointSize()*4); DragDrop_Image=new QLabel(this); DragDrop_Image->setAlignment(Qt::AlignCenter); DragDrop_Image->setPixmap(QPixmap(":/icon/dropfiles.png").scaled(256, 256)); if (Files_CurrentPos!=(size_t)-1) DragDrop_Image->hide(); ui->verticalLayout->addWidget(DragDrop_Image); DragDrop_Text=new QLabel(this); DragDrop_Text->setAlignment(Qt::AlignCenter); DragDrop_Text->setFont(Font); QPalette Palette(DragDrop_Text->palette()); Palette.setColor(QPalette::WindowText, Qt::darkGray); DragDrop_Text->setPalette(Palette); DragDrop_Text->setText("Drop video file(s) here"); if (Files_CurrentPos!=(size_t)-1) DragDrop_Text->hide(); ui->verticalLayout->addWidget(DragDrop_Text); }
void ShutdownUI::turnOffScreen() { bool success = false; // No way dimming or turning off the screen inside scratchbox #if defined(HAVE_QMSYSTEM) MeeGo::QmDisplayState display; // Try to dim success = display.set(MeeGo::QmDisplayState::Dimmed); // Try to turn off success &= display.set(MeeGo::QmDisplayState::Off); #endif if (!success) { QPalette Palette(palette()); Palette.setColor(QPalette::Background, QColor("black")); setPalette(Palette); setBackgroundRole(QPalette::Background); logo->hide(); } }
// SLOTS // ====================================================================== void EditColorMap::CurrentIndexChangedType (int i) { Palette palette = m_colorMap.GetPalette (); Palette newPalette = Palette (PaletteType::Enum (i), palette.m_sequential, palette.m_diverging); setCombos (newPalette); setPalette (newPalette); }
void InterpolatedColorMap::reset() { if(c) { for(int row=0;row<rows;row++) delete[] c[row]; delete[] c; } p = Palette(); cols=rows=0; c=0; }
void Image::changeToColorOnly(MatrixPtr in_matrix, double lowerZ, double upperZ, bool autoThreshold, const QString &paletteName) { _inputMatrices[THEMATRIX] = in_matrix; _zLower = lowerZ; _zUpper = upperZ; _autoThreshold = autoThreshold; if (_pal.paletteName() != paletteName) { _pal = Palette(paletteName); } _hasColorMap = true; _hasContourMap = false; }
void SetTextColors(void) { #ifndef DEBUG Palette(5,10,10,10); Palette(7,16,16,16); Palette(6,40,40,40); Palette(1,0,0,30); Palette(2,0,0,50); Palette(3,10,10,63); #endif }
void Image::changeToColorAndContour(MatrixPtr in_matrix, double lowerZ, double upperZ, bool autoThreshold, const QString &paletteName, int numContours, const QColor& contourColor, int contourWeight) { _inputMatrices[THEMATRIX] = in_matrix; _zLower = lowerZ; _zUpper = upperZ; _autoThreshold = autoThreshold; if (_pal.paletteName() != paletteName) { _pal = Palette(paletteName); } _numContourLines = numContours; _contourWeight = contourWeight; _contourColor = contourColor; _hasColorMap = true; _hasContourMap = true; }
Palette() { Palette(DEFAULT_NUM_COLORS); }
bool OSRenderer::initialize() { _activePal = Palette(kHighPalFormat, kHighPalNumColors); return true; }
int main(int argc, char *argv[]) { // init fnkdat if(fnkdat(NULL, NULL, 0, FNKDAT_INIT) < 0) { perror("Could not initialize fnkdat"); exit(EXIT_FAILURE); } bool bShowDebug = false; for(int i=1; i < argc; i++) { //check for overiding params std::string parameter(argv[i]); if(parameter == "--showlog") { // special parameter which does not overwrite settings bShowDebug = true; } else if((parameter == "-f") || (parameter == "--fullscreen") || (parameter == "-w") || (parameter == "--window") || (parameter.find("--PlayerName=") == 0) || (parameter.find("--ServerPort=") == 0)) { // normal parameter for overwriting settings // handle later } else { printUsage(); exit(EXIT_FAILURE); } } if(bShowDebug == false) { // get utf8-encoded log file path std::string logfilePath = getLogFilepath(); const char* pLogfilePath = logfilePath.c_str(); #if defined (_WIN32) // on win32 we need an ansi-encoded filepath WCHAR szwLogPath[MAX_PATH]; char szLogPath[MAX_PATH]; if(MultiByteToWideChar(CP_UTF8, 0, pLogfilePath, -1, szwLogPath, MAX_PATH) == 0) { fprintf(stderr, "Conversion of logfile path from utf-8 to utf-16 failed\n"); exit(EXIT_FAILURE); } if(WideCharToMultiByte(CP_ACP, 0, szwLogPath, -1, szLogPath, MAX_PATH, NULL, NULL) == 0) { fprintf(stderr, "Conversion of logfile path from utf-16 to ansi failed\n"); exit(EXIT_FAILURE); } pLogfilePath = szLogPath; #endif int d = open(pLogfilePath, O_WRONLY | O_CREAT | O_TRUNC, 0644); if(d < 0) { fprintf(stderr, "Opening logfile '%s' failed\n", pLogfilePath); exit(EXIT_FAILURE); } // Hint: fileno(stdout) != STDOUT_FILENO on Win32 (see SDL_win32_main.c) if(dup2(d, fileno(stdout)) < 0) { fprintf(stderr, "Redirecting stdout failed\n"); exit(EXIT_FAILURE); } // Hint: fileno(stderr) != STDERR_FILENO on Win32 (see SDL_win32_main.c) if(dup2(d, fileno(stderr)) < 0) { fprintf(stderr, "Redirecting stderr failed\n"); exit(EXIT_FAILURE); } } fprintf(stdout, "Starting Dune Legacy " VERSION " ...\n"); fflush(stdout); if(checkForExcessPrecision() == true) { fprintf(stdout, "WARNING: Floating point operations are internally calculated with higher precision. Network game might get async. Are you using x87-FPU? Check your compile settings!\n"); fflush(stdout); } // First check for missing files std::vector<std::string> missingFiles = FileManager::getMissingFiles(); if(missingFiles.empty() == false) { // create data directory inside config directory char tmp[FILENAME_MAX]; fnkdat("data/", tmp, FILENAME_MAX, FNKDAT_USER | FNKDAT_CREAT); bool cannotShowMissingScreen = false; fprintf(stderr,"The following files are missing:\n"); std::vector<std::string>::const_iterator iter; for(iter = missingFiles.begin() ; iter != missingFiles.end(); ++iter) { fprintf(stderr," %s\n",iter->c_str()); if(iter->find("LEGACY.PAK") != std::string::npos) { cannotShowMissingScreen = true; } } fprintf(stderr,"Put them in one of the following directories:\n"); std::vector<std::string> searchPath = FileManager::getSearchPath(); std::vector<std::string>::const_iterator searchPathIter; for(searchPathIter = searchPath.begin(); searchPathIter != searchPath.end(); ++searchPathIter) { fprintf(stderr," %s\n",searchPathIter->c_str()); } if(cannotShowMissingScreen == true) { return EXIT_FAILURE; } } bool bExitGame = false; bool bFirstInit = true; bool bFirstGamestart = false; debug = false; cursorFrame = UI_CursorNormal; do { int seed = time(NULL); srand(seed); // check if configfile exists std::string configfilepath = getConfigFilepath(); if(existsFile(configfilepath) == false) { std::string userLanguage = getUserLanguage(); if(userLanguage.empty()) { userLanguage = "en"; } if(missingFiles.empty() == true) { // if all pak files were found we can create the ini file bFirstGamestart = true; createDefaultConfigFile(configfilepath, userLanguage); } } INIFile myINIFile(configfilepath); settings.general.playIntro = myINIFile.getBoolValue("General","Play Intro",false); settings.general.playerName = myINIFile.getStringValue("General","Player Name","Player"); settings.video.width = myINIFile.getIntValue("Video","Width",640); settings.video.height = myINIFile.getIntValue("Video","Height",480); settings.video.fullscreen = myINIFile.getBoolValue("Video","Fullscreen",true); settings.video.doubleBuffering = myINIFile.getBoolValue("Video","Double Buffering",true); settings.video.frameLimit = myINIFile.getBoolValue("Video","FrameLimit",true); settings.video.preferredZoomLevel = myINIFile.getIntValue("Video","Preferred Zoom Level", 0); settings.video.scaler = myINIFile.getStringValue("Video","Scaler", "scale2x"); settings.audio.musicType = myINIFile.getStringValue("Audio","Music Type","adl"); settings.audio.playMusic = myINIFile.getBoolValue("Audio","Play Music", true); settings.audio.playSFX = myINIFile.getBoolValue("Audio","Play SFX", true); settings.audio.frequency = myINIFile.getIntValue("Audio","Audio Frequency", 22050); settings.general.language = myINIFile.getStringValue("General","Language","en"); settings.network.serverPort = myINIFile.getIntValue("Network","ServerPort",DEFAULT_PORT); settings.network.metaServer = myINIFile.getStringValue("Network","MetaServer",DEFAULT_METASERVER); settings.network.debugNetwork = myINIFile.getBoolValue("Network","Debug Network",false); settings.ai.campaignAI = myINIFile.getStringValue("AI","Campaign AI",DEFAULTAIPLAYERCLASS); settings.gameOptions.gameSpeed = myINIFile.getIntValue("Game Options","Game Speed",GAMESPEED_DEFAULT); settings.gameOptions.concreteRequired = myINIFile.getBoolValue("Game Options","Concrete Required",true); settings.gameOptions.structuresDegradeOnConcrete = myINIFile.getBoolValue("Game Options","Structures Degrade On Concrete",true); settings.gameOptions.fogOfWar = myINIFile.getBoolValue("Game Options","Fog of War",false); settings.gameOptions.startWithExploredMap = myINIFile.getBoolValue("Game Options","Start with Explored Map",false); settings.gameOptions.instantBuild = myINIFile.getBoolValue("Game Options","Instant Build",false); settings.gameOptions.onlyOnePalace = myINIFile.getBoolValue("Game Options","Only One Palace",false); settings.gameOptions.rocketTurretsNeedPower = myINIFile.getBoolValue("Game Options","Rocket-Turrets Need Power",false); settings.gameOptions.sandwormsRespawn = myINIFile.getBoolValue("Game Options","Sandworms Respawn",false); settings.gameOptions.killedSandwormsDropSpice = myINIFile.getBoolValue("Game Options","Killed Sandworms Drop Spice",false); fprintf(stdout, "loading texts....."); fflush(stdout); pTextManager = new TextManager(); fprintf(stdout, "\t\tfinished\n"); fflush(stdout); if(FileManager::getMissingFiles().size() > 0) { // set back to english std::vector<std::string> missingFiles = FileManager::getMissingFiles(); fprintf(stderr,"The following files are missing for language \"%s\":\n",_("LanguageFileExtension").c_str()); std::vector<std::string>::const_iterator iter; for(iter = missingFiles.begin(); iter != missingFiles.end(); ++iter) { fprintf(stderr," %s\n",iter->c_str()); } fprintf(stderr,"Language is changed to English!\n"); settings.general.language = "en"; } for(int i=1; i < argc; i++) { //check for overiding params std::string parameter(argv[i]); if((parameter == "-f") || (parameter == "--fullscreen")) { settings.video.fullscreen = true; } else if((parameter == "-w") || (parameter == "--window")) { settings.video.fullscreen = false; } else if(parameter.find("--PlayerName=") == 0) { settings.general.playerName = parameter.substr(strlen("--PlayerName=")); } else if(parameter.find("--ServerPort=") == 0) { settings.network.serverPort = atol(argv[i] + strlen("--ServerPort=")); } } if(bFirstInit == true) { fprintf(stdout, "initializing SDL..... \t\t"); fflush(stdout); if(SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO) < 0) { fprintf(stderr, "ERROR: Couldn't initialise SDL: %s\n", SDL_GetError()); exit(EXIT_FAILURE); } fprintf(stdout, "finished\n"); fflush(stdout); } if(bFirstGamestart == true && bFirstInit == true) { // detect 800x600 screen resolution if(SDL_VideoModeOK(800, 600, 8, SDL_HWSURFACE | SDL_FULLSCREEN) > 0) { settings.video.width = 800; settings.video.height = 600; settings.video.preferredZoomLevel = 1; myINIFile.setIntValue("Video","Width",settings.video.width); myINIFile.setIntValue("Video","Height",settings.video.height); myINIFile.setIntValue("Video","Preferred Zoom Level",1); myINIFile.saveChangesTo(getConfigFilepath()); } } Scaler::setDefaultScaler(Scaler::getScalerByName(settings.video.scaler)); SDL_EnableUNICODE(1); SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); char strenv[] = "SDL_VIDEO_CENTERED=center"; SDL_putenv(strenv); SDL_WM_SetCaption("Dune Legacy", "Dune Legacy"); if(bFirstInit == true) { fprintf(stdout, "initializing sound..... \t");fflush(stdout); if( Mix_OpenAudio(settings.audio.frequency, AUDIO_S16SYS, 2, 1024) < 0 ) { SDL_Quit(); fprintf(stderr,"Warning: Couldn't set %d Hz 16-bit audio\n- Reason: %s\n",settings.audio.frequency,SDL_GetError()); exit(EXIT_FAILURE); } else { fprintf(stdout, "allocated %d channels.\n", Mix_AllocateChannels(6)); fflush(stdout); } } pFileManager = new FileManager( !missingFiles.empty() ); // now we can finish loading texts if(missingFiles.empty()) { pTextManager->loadData(); } if(pFileManager->exists("IBM.PAL") == true) { palette = LoadPalette_RW(pFileManager->openFile("IBM.PAL"), true); } else { // create dummy palette for showing missing files info palette = Palette(256); palette[115].r = 202; palette[115].g = 141; palette[115].b = 16; palette[255].r = 255; palette[255].g = 255; palette[255].b = 255; } screen = NULL; setVideoMode(); fprintf(stdout, "loading fonts...");fflush(stdout); pFontManager = new FontManager(); fprintf(stdout, "\t\tfinished\n"); fflush(stdout); if(!missingFiles.empty()) { // some files are missing bExitGame = true; printMissingFilesToScreen(); fprintf(stdout, "Deinitialize....."); fflush(stdout); } else { // everything is just fine and we can start the game fprintf(stdout, "loading graphics..."); fflush(stdout); pGFXManager = new GFXManager(); fprintf(stdout, "\t\tfinished\n"); fflush(stdout); fprintf(stdout, "loading sounds..."); fflush(stdout); pSFXManager = new SFXManager(); fprintf(stdout, "\t\tfinished\n"); fflush(stdout); GUIStyle::setGUIStyle(new DuneStyle); if(bFirstInit == true) { fprintf(stdout, "starting sound player..."); fflush(stdout); soundPlayer = new SoundPlayer(); fprintf(stdout, "\tfinished\n"); fprintf(stdout, "starting music player...\t"); fflush(stdout); if(settings.audio.musicType == "directory") { fprintf(stdout, "playing from music directory\n"); fflush(stdout); musicPlayer = new DirectoryPlayer(); } else if(settings.audio.musicType == "adl") { fprintf(stdout, "playing ADL files\n"); fflush(stdout); musicPlayer = new ADLPlayer(); } else if(settings.audio.musicType == "xmi") { fprintf(stdout, "playing XMI files\n"); fflush(stdout); musicPlayer = new XMIPlayer(); } else { fprintf(stdout, "failed\n"); fflush(stdout); exit(EXIT_FAILURE); } //musicPlayer->changeMusic(MUSIC_INTRO); } // Playing intro if(((bFirstGamestart == true) || (settings.general.playIntro == true)) && (bFirstInit==true)) { fprintf(stdout, "playing intro.....");fflush(stdout); Intro* pIntro = new Intro(); pIntro->run(); delete pIntro; fprintf(stdout, "\t\tfinished\n"); fflush(stdout); } bFirstInit = false; fprintf(stdout, "starting main menu...");fflush(stdout); MainMenu * myMenu = new MainMenu(); fprintf(stdout, "\t\tfinished\n"); fflush(stdout); if(myMenu->showMenu() == MENU_QUIT_DEFAULT) { bExitGame = true; } delete myMenu; fprintf(stdout, "Deinitialize....."); fflush(stdout); GUIStyle::destroyGUIStyle(); // clear everything if(bExitGame == true) { delete musicPlayer; delete soundPlayer; Mix_HaltMusic(); Mix_CloseAudio(); } delete pTextManager; delete pSFXManager; delete pGFXManager; } delete pFontManager; delete pFileManager; if(bExitGame == true) { SDL_Quit(); } fprintf(stdout, "\t\tfinished\n"); fflush(stdout); } while(bExitGame == false); // deinit fnkdat if(fnkdat(NULL, NULL, 0, FNKDAT_UNINIT) < 0) { perror("Could not uninitialize fnkdat"); exit(EXIT_FAILURE); } return EXIT_SUCCESS; }
void EditColorMap::HighlightedPalette (int index) { setPalette (Palette (m_colorMap.GetPalette ().m_type, index)); }
void PaletteWidget2::reset() { setPalette(Palette()); }
bool SpriteSheet::ImportBitmap(const std::string& filename, const std::string& name, int tileWidth, int tileHeight, int widthFrames, int heightFrames, int maxFrames) { //Clear frames m_frames.clear(); //Read BMP BMPReader reader; if(reader.Read(filename)) { if(reader.GetWidth() % tileWidth != 0 || reader.GetHeight() % tileHeight != 0) { //TODO: wx message handler in ion::debug //if(wxMessageBox("Bitmap width/height is not multiple of target platform tile width/height", "Warning", wxOK | wxCANCEL | wxICON_WARNING) == wxCANCEL) { return false; } } //Clear palette m_palette = Palette(); //Import palette for(int i = 0; i < reader.GetPaletteSize(); i++) { BMPReader::Colour bmpColour = reader.GetPaletteEntry(i); m_palette.AddColour(Colour(bmpColour.r, bmpColour.g, bmpColour.b)); } //Get total spriteSheet sheet width/height in tiles int spriteSheetWidthTiles = reader.GetWidth() / tileWidth; int spriteSheetHeightTiles = reader.GetHeight() / tileHeight; //Get frame width/height in tiles m_widthTiles = spriteSheetWidthTiles / widthFrames; m_heightTiles = spriteSheetHeightTiles / heightFrames; //For each frame u32 frameCount = 0; for(int frameY = 0; frameY < heightFrames && frameCount < maxFrames; frameY++) { for(int frameX = 0; frameX < widthFrames && frameCount < maxFrames; frameX++) { //Create new frame SpriteSheetFrame frame; //For each tile in frame (Mega Drive order = column major) for(int tileX = 0; tileX < m_widthTiles; tileX++) { for(int tileY = 0; tileY < m_heightTiles; tileY++) { //Read tile Tile tile(tileWidth, tileHeight); //Read pixel colours from bitmap for(int pixelX = 0; pixelX < tileWidth; pixelX++) { for(int pixelY = 0; pixelY < tileHeight; pixelY++) { //Read pixel int sourcePixelX = (frameX * m_widthTiles * tileWidth) + (tileX * tileWidth) + pixelX; int sourcePixelY = (frameY * m_heightTiles * tileHeight) + (tileY * tileHeight) + pixelY; u8 colourIndex = reader.GetColourIndex(sourcePixelX, sourcePixelY); tile.SetPixelColour(pixelX, pixelY, colourIndex); } } //Add tile frame.push_back(tile); } } //Add frame m_frames.push_back(frame); frameCount++; } } //Set name m_name = name; } CropAllFrames(tileWidth, tileHeight); return true; }
CharacterEquipmentPanel::CharacterEquipmentPanel(GameState *gameState) : Panel(gameState), headOffsets() { this->playerNameTextBox = [gameState]() { int x = 10; int y = 8; Color color(199, 199, 199); std::string text = gameState->getGameData()->getPlayer().getDisplayName(); auto &font = gameState->getFontManager().getFont(FontName::Arena); auto alignment = TextAlignment::Left; return std::unique_ptr<TextBox>(new TextBox( x, y, color, text, font, alignment, gameState->getRenderer())); }(); this->playerRaceTextBox = [gameState]() { int x = 10; int y = 17; Color color(199, 199, 199); std::string text = CharacterRace(gameState->getGameData()->getPlayer() .getRaceName()).toString(); auto &font = gameState->getFontManager().getFont(FontName::Arena); auto alignment = TextAlignment::Left; return std::unique_ptr<TextBox>(new TextBox( x, y, color, text, font, alignment, gameState->getRenderer())); }(); this->playerClassTextBox = [gameState]() { int x = 10; int y = 26; Color color(199, 199, 199); std::string text = gameState->getGameData()->getPlayer().getCharacterClass() .getDisplayName(); auto &font = gameState->getFontManager().getFont(FontName::Arena); auto alignment = TextAlignment::Left; return std::unique_ptr<TextBox>(new TextBox( x, y, color, text, font, alignment, gameState->getRenderer())); }(); this->backToStatsButton = []() { int x = 0; int y = 188; int width = 47; int height = 12; auto function = [](GameState *gameState) { std::unique_ptr<Panel> characterPanel(new CharacterPanel(gameState)); gameState->setPanel(std::move(characterPanel)); }; return std::unique_ptr<Button>(new Button(x, y, width, height, function)); }(); this->spellbookButton = []() { int x = 47; int y = 188; int width = 76; int height = 12; auto function = [](GameState *gameState) { // Nothing yet. }; return std::unique_ptr<Button>(new Button(x, y, width, height, function)); }(); this->dropButton = []() { int x = 123; int y = 188; int width = 48; int height = 12; auto function = [](GameState *gameState) { // Nothing yet. }; return std::unique_ptr<Button>(new Button(x, y, width, height, function)); }(); this->scrollDownButton = []() { Int2 center(16, 131); int width = 9; int height = 9; auto function = [](GameState *gameState) { // Nothing yet. }; return std::unique_ptr<Button>(new Button(center, width, height, function)); }(); this->scrollUpButton = []() { Int2 center(152, 131); int width = 9; int height = 9; auto function = [](GameState *gameState) { // Nothing yet. }; return std::unique_ptr<Button>(new Button(center, width, height, function)); }(); // Get pixel offsets for each head. const auto &player = this->getGameState()->getGameData()->getPlayer(); const std::string &headsFilename = PortraitFile::getHeads( player.getGenderName(), player.getRaceName(), false); CIFFile cifFile(headsFilename, Palette()); for (int i = 0; i < cifFile.getImageCount(); ++i) { this->headOffsets.push_back(Int2(cifFile.getXOffset(i), cifFile.getYOffset(i))); } }
int main(int argc, char *argv[]) { // init fnkdat if(fnkdat(NULL, NULL, 0, FNKDAT_INIT) < 0) { perror("Could not initialize fnkdat"); exit(EXIT_FAILURE); } bool bShowDebug = false; for(int i=1; i < argc; i++) { //check for overiding params if (strcmp(argv[i], "--showlog") == 0) bShowDebug = true; } if(bShowDebug == false) { int d = open(GetLogFilepath().c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0644); if(d < 0) { perror("Opening logfile failed"); exit(EXIT_FAILURE); } if(dup2(d, STDOUT_FILENO) < 0) { perror("Redirecting stdout failed"); exit(EXIT_FAILURE); } if(dup2(d, STDERR_FILENO) < 0) { perror("Redirecting stderr failed"); exit(EXIT_FAILURE); } } // First check for missing files std::vector<std::string> MissingFiles = FileManager::getMissingFiles(LNG_ENG); if(MissingFiles.size() > 0) { // create data directory inside config directory char tmp[FILENAME_MAX]; fnkdat("data/", tmp, FILENAME_MAX, FNKDAT_USER | FNKDAT_CREAT); bool cannotShowMissingScreen = false; fprintf(stderr,"The following files are missing:\n"); std::vector<std::string>::const_iterator iter; for(iter = MissingFiles.begin() ; iter != MissingFiles.end(); ++iter) { fprintf(stderr," %s\n",iter->c_str()); if(iter->find("LEGACY.PAK") != std::string::npos) { cannotShowMissingScreen = true; } } fprintf(stderr,"Put them in one of the following directories:\n"); std::vector<std::string> searchPath = FileManager::getSearchPath(); std::vector<std::string>::const_iterator searchPathIter; for(searchPathIter = searchPath.begin(); searchPathIter != searchPath.end(); ++searchPathIter) { fprintf(stderr," %s\n",searchPathIter->c_str()); } if(cannotShowMissingScreen == true) { return EXIT_FAILURE; } } bool ExitGame = false; bool FirstInit = true; bool FirstGamestart = false; debug = false; cursorFrame = UI_CursorNormal; do { int seed = time(NULL); srand(seed); // check if configfile exists std::string configfilepath = GetConfigFilepath(); if(ExistsFile(configfilepath) == false) { int UserLanguage = GetUserLanguage(); if(UserLanguage == LNG_UNKNOWN) { UserLanguage = LNG_ENG; } if(MissingFiles.empty() == true) { // if all pak files were found we can create the ini file FirstGamestart = true; CreateDefaultConfigFile(configfilepath, UserLanguage); } } INIFile myINIFile(configfilepath); settings.General.PlayIntro = myINIFile.getBoolValue("General","Play Intro",false); settings.General.ConcreteRequired = myINIFile.getBoolValue("General","Concrete Required",true); settings.General.FogOfWar = myINIFile.getBoolValue("General","Fog of War",false); settings.General.PlayerName = myINIFile.getStringValue("General","Player Name","Player"); settings.Video.Width = myINIFile.getIntValue("Video","Width",640); settings.Video.Height = myINIFile.getIntValue("Video","Height",480); settings.Video.Fullscreen = myINIFile.getBoolValue("Video","Fullscreen",true); settings.Video.DoubleBuffering = myINIFile.getBoolValue("Video","Double Buffering",true); settings.Video.FrameLimit = myINIFile.getBoolValue("Video","FrameLimit",true); settings.Audio.MusicType = myINIFile.getStringValue("Audio","Music Type","adl"); std::string Lng = myINIFile.getStringValue("General","Language","en"); if(Lng == "en") { settings.General.setLanguage(LNG_ENG); } else if (Lng == "fr") { settings.General.setLanguage(LNG_FRE); } else if (Lng == "de") { settings.General.setLanguage(LNG_GER); } else { fprintf(stderr,"INI-File: Invalid Language \"%s\"! Default Language (en) is used.\n",Lng.c_str()); settings.General.setLanguage(LNG_ENG); } if(FileManager::getMissingFiles(settings.General.Language).size() > 0) { // set back to english std::vector<std::string> MissingFiles = FileManager::getMissingFiles(settings.General.Language); fprintf(stderr,"The following files are missing for language \"%s\":\n",settings.General.LanguageExt.c_str()); std::vector<std::string>::const_iterator iter; for(iter = MissingFiles.begin() ; iter != MissingFiles.end(); ++iter) { fprintf(stderr," %s\n",iter->c_str()); } fprintf(stderr,"Language is changed to English!\n"); settings.General.setLanguage(LNG_ENG); } lookDist[0] = 10;lookDist[1] = 10;lookDist[2] = 9;lookDist[3] = 9;lookDist[4] = 9;lookDist[5] = 8;lookDist[6] = 8;lookDist[7] = 7;lookDist[8] = 6;lookDist[9] = 4;lookDist[10] = 1; for(int i=1; i < argc; i++) { //check for overiding params if((strcmp(argv[i], "-f") == 0) || (strcmp(argv[i], "--fullscreen") == 0)) settings.Video.Fullscreen = true; else if((strcmp(argv[i], "-w") == 0) || (strcmp(argv[i], "--window") == 0)) settings.Video.Fullscreen = false; } if(SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO) < 0) { fprintf(stderr, "ERROR: Couldn't initialise SDL: %s\n", SDL_GetError()); exit(EXIT_FAILURE); } if(FirstGamestart == true && FirstInit == true) { // detect 800x600 screen resolution if(SDL_VideoModeOK(800, 600, 8, SDL_HWSURFACE | SDL_FULLSCREEN) > 0) { settings.Video.Width = 800; settings.Video.Height = 600; myINIFile.setIntValue("Video","Width",settings.Video.Width); myINIFile.setIntValue("Video","Height",settings.Video.Height); myINIFile.SaveChangesTo(GetConfigFilepath()); } } SDL_EnableUNICODE(1); SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); char strenv[] = "SDL_VIDEO_CENTERED=center"; SDL_putenv(strenv); SDL_WM_SetCaption("Dune Legacy", "Dune Legacy"); if(FirstInit == true) { fprintf(stdout, "initialising sound..... \t");fflush(stdout); if( Mix_OpenAudio(22050, AUDIO_S16SYS, 2, 1024) < 0 ) { SDL_Quit(); fprintf(stderr,"Warning: Couldn't set 22050 Hz 16-bit audio\n- Reason: %s\n",SDL_GetError()); exit(EXIT_FAILURE); } else { fprintf(stdout, "allocated %d channels.\n", Mix_AllocateChannels(4)); fflush(stdout); } } pFileManager = new FileManager( (MissingFiles.size() > 0) ); if(pFileManager->exists("IBM.PAL") == true) { palette = LoadPalette_RW(pFileManager->OpenFile("IBM.PAL"), true); } else { // create dummy palette for showing missing files info palette = Palette(256); palette[255].r = 255; palette[255].g = 255; palette[255].b = 255; } screen = NULL; setVideoMode(); fprintf(stdout, "loading fonts.....");fflush(stdout); pFontManager = new FontManager(); fprintf(stdout, "\t\tfinished\n"); fflush(stdout); if(MissingFiles.size() > 0) { // some files are missing ExitGame = true; PrintMissingFilesToScreen(); fprintf(stdout, "Deinitialize....."); fflush(stdout); } else { // everything is just fine and we can start the game //get the house palettes houseColor[HOUSE_ATREIDES] = COLOR_ATREIDES; houseColor[HOUSE_ORDOS] = COLOR_ORDOS; houseColor[HOUSE_HARKONNEN] = COLOR_HARKONNEN; houseColor[HOUSE_SARDAUKAR] = COLOR_SARDAUKAR; houseColor[HOUSE_FREMEN] = COLOR_FREMEN; houseColor[HOUSE_MERCENARY] = COLOR_MERCENARY; fprintf(stdout, "loading graphics....."); fflush(stdout); if((pGFXManager = new GFXManager()) == NULL) { fprintf(stderr,"main: Cannot create GFXManager!\n"); exit(EXIT_FAILURE); } fprintf(stdout, "\t\tfinished\n"); fflush(stdout); fprintf(stdout, "loading sounds....."); fflush(stdout); if((pSFXManager = new SFXManager()) == NULL) { fprintf(stderr,"main: Cannot create SFXManager!\n"); exit(EXIT_FAILURE); } fprintf(stdout, "\t\tfinished\n"); fflush(stdout); fprintf(stdout, "loading texts....."); fflush(stdout); if((pTextManager = new TextManager()) == NULL) { fprintf(stderr,"main: Cannot create TextManager!\n"); exit(EXIT_FAILURE); } fprintf(stdout, "\t\tfinished\n"); fflush(stdout); GUIStyle::SetGUIStyle(new DuneStyle); if(FirstInit == true) { fprintf(stdout, "starting sound player..."); fflush(stdout); soundPlayer = new SoundPlayer(); fprintf(stdout, "\tfinished\n"); fprintf(stdout, "starting music player...\t"); fflush(stdout); if(settings.Audio.MusicType == "directory") { fprintf(stdout, "playing from music directory\n"); fflush(stdout); musicPlayer = new DirectoryPlayer(); } else if(settings.Audio.MusicType == "adl") { fprintf(stdout, "playing ADL files\n"); fflush(stdout); musicPlayer = new ADLPlayer(); } else if(settings.Audio.MusicType == "xmi") { fprintf(stdout, "playing XMI files\n"); fflush(stdout); musicPlayer = new XMIPlayer(); } else { fprintf(stdout, "failed\n"); fflush(stdout); exit(EXIT_FAILURE); } //musicPlayer->changeMusic(MUSIC_INTRO); } // Playing intro if(((FirstGamestart == true) || (settings.General.PlayIntro == true)) && (FirstInit==true)) { fprintf(stdout, "playing intro.....");fflush(stdout); Intro* pIntro = new Intro(); pIntro->run(); delete pIntro; fprintf(stdout, "\t\tfinished\n"); fflush(stdout); } FirstInit = false; fprintf(stdout, "starting main menu.......");fflush(stdout); MainMenu * myMenu = new MainMenu(); fprintf(stdout, "\tfinished\n"); fflush(stdout); if(myMenu->showMenu() == -1) { ExitGame = true; } delete myMenu; fprintf(stdout, "Deinitialize....."); fflush(stdout); GUIStyle::DestroyGUIStyle(); // clear everything if(ExitGame == true) { delete musicPlayer; delete soundPlayer; Mix_HaltMusic(); Mix_CloseAudio(); } delete pTextManager; delete pSFXManager; delete pGFXManager; } delete pFontManager; delete pFileManager; if(ExitGame == true) { SDL_Quit(); } fprintf(stdout, "\t\tfinished\n"); fflush(stdout); } while(ExitGame == false); // deinit fnkdat if(fnkdat(NULL, NULL, 0, FNKDAT_UNINIT) < 0) { perror("Could not uninitialize fnkdat"); exit(EXIT_FAILURE); } return EXIT_SUCCESS; }