1 /* 2 * Copyright 2010-2014 OpenXcom Developers. 3 * 4 * This file is part of OpenXcom. 5 * 6 * OpenXcom is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * OpenXcom is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with OpenXcom. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #include <sstream> 21 22 #include "Ufopaedia.h" 23 #include "ArticleStateBaseFacility.h" 24 #include "../Ruleset/ArticleDefinition.h" 25 #include "../Ruleset/Ruleset.h" 26 #include "../Ruleset/RuleBaseFacility.h" 27 #include "../Engine/Game.h" 28 #include "../Engine/Palette.h" 29 #include "../Engine/Surface.h" 30 #include "../Engine/SurfaceSet.h" 31 #include "../Engine/Language.h" 32 #include "../Resource/ResourcePack.h" 33 #include "../Interface/Text.h" 34 #include "../Interface/TextButton.h" 35 #include "../Interface/TextList.h" 36 37 namespace OpenXcom 38 { 39 ArticleStateBaseFacility(Game * game,ArticleDefinitionBaseFacility * defs)40 ArticleStateBaseFacility::ArticleStateBaseFacility(Game *game, ArticleDefinitionBaseFacility *defs) : ArticleState(game, defs->id) 41 { 42 RuleBaseFacility *facility = _game->getRuleset()->getBaseFacility(defs->id); 43 44 // add screen elements 45 _txtTitle = new Text(200, 17, 10, 24); 46 47 // Set palette 48 setPalette("PAL_BASESCAPE"); 49 50 ArticleState::initLayout(); 51 52 // add other elements 53 add(_txtTitle); 54 55 // Set up objects 56 _game->getResourcePack()->getSurface("BACK09.SCR")->blit(_bg); 57 _btnOk->setColor(Palette::blockOffset(4)); 58 _btnPrev->setColor(Palette::blockOffset(4)); 59 _btnNext->setColor(Palette::blockOffset(4)); 60 61 _txtTitle->setColor(Palette::blockOffset(13)+10); 62 _txtTitle->setBig(); 63 _txtTitle->setText(tr(defs->title)); 64 65 // build preview image 66 int tile_size = 32; 67 _image = new Surface(tile_size*2, tile_size*2, 232, 16); 68 add(_image); 69 70 SurfaceSet *graphic = _game->getResourcePack()->getSurfaceSet("BASEBITS.PCK"); 71 Surface *frame; 72 int x_offset, y_offset; 73 int x_pos, y_pos; 74 int num; 75 76 if (facility->getSize()==1) 77 { 78 x_offset = y_offset = tile_size/2; 79 } 80 else 81 { 82 x_offset = y_offset = 0; 83 } 84 85 num = 0; 86 y_pos = y_offset; 87 for (int y = 0; y < facility->getSize(); ++y) 88 { 89 x_pos = x_offset; 90 for (int x = 0; x < facility->getSize(); ++x) 91 { 92 frame = graphic->getFrame(facility->getSpriteShape() + num); 93 frame->setX(x_pos); 94 frame->setY(y_pos); 95 frame->blit(_image); 96 97 if (facility->getSize()==1) 98 { 99 frame = graphic->getFrame(facility->getSpriteFacility() + num); 100 frame->setX(x_pos); 101 frame->setY(y_pos); 102 frame->blit(_image); 103 } 104 105 x_pos += tile_size; 106 num++; 107 } 108 y_pos += tile_size; 109 } 110 111 _txtInfo = new Text(300, 90, 10, 104); 112 add(_txtInfo); 113 114 _txtInfo->setColor(Palette::blockOffset(13)+10); 115 _txtInfo->setWordWrap(true); 116 _txtInfo->setText(tr(defs->text)); 117 118 _lstInfo = new TextList(200, 42, 10, 42); 119 add(_lstInfo); 120 121 _lstInfo->setColor(Palette::blockOffset(13)+10); 122 _lstInfo->setColumns(2, 140, 60); 123 _lstInfo->setDot(true); 124 125 _lstInfo->addRow(2, tr("STR_CONSTRUCTION_TIME").c_str(), tr("STR_DAY", facility->getBuildTime()).c_str()); 126 _lstInfo->setCellColor(0, 1, Palette::blockOffset(13)+0); 127 128 std::wostringstream ss; 129 ss << Text::formatFunding(facility->getBuildCost()); 130 _lstInfo->addRow(2, tr("STR_CONSTRUCTION_COST").c_str(), ss.str().c_str()); 131 _lstInfo->setCellColor(1, 1, Palette::blockOffset(13)+0); 132 133 ss.str(L"");ss.clear(); 134 ss << Text::formatFunding(facility->getMonthlyCost()); 135 _lstInfo->addRow(2, tr("STR_MAINTENANCE_COST").c_str(), ss.str().c_str()); 136 _lstInfo->setCellColor(2, 1, Palette::blockOffset(13)+0); 137 138 if (facility->getDefenseValue() > 0) 139 { 140 ss.str(L"");ss.clear(); 141 ss << facility->getDefenseValue(); 142 _lstInfo->addRow(2, tr("STR_DEFENSE_VALUE").c_str(), ss.str().c_str()); 143 _lstInfo->setCellColor(3, 1, Palette::blockOffset(13)+0); 144 145 ss.str(L"");ss.clear(); 146 ss << Text::formatPercentage(facility->getHitRatio()); 147 _lstInfo->addRow(2, tr("STR_HIT_RATIO").c_str(), ss.str().c_str()); 148 _lstInfo->setCellColor(4, 1, Palette::blockOffset(13)+0); 149 } 150 centerAllSurfaces(); 151 } 152 ~ArticleStateBaseFacility()153 ArticleStateBaseFacility::~ArticleStateBaseFacility() 154 {} 155 156 } 157