コード例 #1
0
LocalSaveActivity::LocalSaveActivity(SaveFile save) :
	WindowActivity(ui::Point(-1, -1), ui::Point(220, 200)),
	thumbnail(NULL),
	save(save)
{
	ui::Label * titleLabel = new ui::Label(ui::Point(4, 5), ui::Point(Size.X-8, 16), "Save to computer:");
	titleLabel->SetTextColour(style::Colour::InformationTitle);
	titleLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
	titleLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
	AddComponent(titleLabel);

	filenameField = new ui::Textbox(ui::Point(8, 25), ui::Point(Size.X-16, 16), save.GetDisplayName(), "[filename]");
	filenameField->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
	filenameField->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
	AddComponent(filenameField);

	ui::Button * cancelButton = new ui::Button(ui::Point(0, Size.Y-16), ui::Point(Size.X-75, 16), "Cancel");
	cancelButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
	cancelButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
	cancelButton->Appearance.BorderInactive = ui::Colour(200, 200, 200);
	cancelButton->SetActionCallback(new CancelAction(this));
	AddComponent(cancelButton);
	SetCancelButton(cancelButton);

	ui::Button * okayButton = new ui::Button(ui::Point(Size.X-76, Size.Y-16), ui::Point(76, 16), "Save");
	okayButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
	okayButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
	okayButton->Appearance.TextInactive = style::Colour::InformationTitle;
	okayButton->SetActionCallback(new SaveAction(this));
	AddComponent(okayButton);
	SetOkayButton(okayButton);

	if(save.GetGameSave())
		ThumbnailBroker::Ref().RenderThumbnail(save.GetGameSave(), true, false, Size.X-16, -1, this);
}
コード例 #2
0
	virtual bool doWork()
	{
		std::vector<ByteString> files = Client::Ref().DirectorySearch(directory, search, ".cps");
		std::sort(files.rbegin(), files.rend(), [](ByteString a, ByteString b) { return a.ToLower() < b.ToLower(); });

		notifyProgress(-1);
		for(std::vector<ByteString>::iterator iter = files.begin(), end = files.end(); iter != end; ++iter)
		{
			SaveFile * saveFile = new SaveFile(*iter);
			try
			{
				std::vector<unsigned char> data = Client::Ref().ReadFile(*iter);
				GameSave * tempSave = new GameSave(data);
				saveFile->SetGameSave(tempSave);
				saveFiles.push_back(saveFile);

				ByteString filename = (*iter).SplitFromEndBy(PATH_SEP).After();
				filename = filename.SplitBy('.').Before();
				saveFile->SetDisplayName(filename.FromUtf8());
			}
			catch(std::exception & e)
			{
				//:(
			}
		}
		return true;
	}
コード例 #3
0
ファイル: Object.cpp プロジェクト: ACefalu/tzod
void GC_Object::Notify::Serialize(SaveFile &f)
{
	f.Serialize(type);
	f.Serialize(subscriber);

	// we are not allowed to serialize raw pointers so we use a small hack :)
	f.Serialize(reinterpret_cast<DWORD_PTR&>(handler));
}
コード例 #4
0
ファイル: shop.cpp プロジェクト: InfosHack/NewerSMBW
void dWMShop_c::buyItem(int item) {
	static int itemDefs[6][3] = {
		// Cost, Start Index, Count
		{1, 0, 1}, {2, 1, 1}, {2, 2, 1}, {3, 3, 1},
		{5, 4, 3}, {8, 7, 5}
	};

	int cost = itemDefs[item][0], cash = getUnspentStarCoinCount();

	if (cost > cash) {
		OSReport("Started playing Not Enough\n");
		lakituModel->playingNotEnough = true;
		lakituModel->playAnim("notenough", 1.0f, 1);
		MapSoundPlayer(SoundRelatedClass, SE_SYS_INVALID, 1);
		return;
	}

	MapSoundPlayer(SoundRelatedClass, SE_SYS_DECIDE, 1);

	SaveFile *file = GetSaveFile();
	SaveBlock *block = file->GetBlock(file->header.current_file);

	coinsRemaining = cost;

	// Work out what we need to apply
	int appliedItems[ITEM_TYPE_COUNT];
	for (int i = 0; i < ITEM_TYPE_COUNT; i++)
		appliedItems[i] = 0;

	int invStartIndex = itemDefs[item][1], invCount = itemDefs[item][2];
	for (int i = 0; i < invCount; i++)
		appliedItems[(int)Inventory[shopKind][invStartIndex+i]]++;

	for (int i = 0; i < 8; i++) {
		block->powerups_available[i] += appliedItems[i];

		if (block->powerups_available[i] > 99)
			block->powerups_available[i] = 99;

		dScKoopatlas_c::instance->stockItem->newCounts[i] = block->powerups_available[i];
	}

	// Apply lives to everyone
	for (int i = 0; i < 4; i++) {
		if (Player_Active[i]) {
			int id = Player_ID[i];
			Player_Lives[id] += appliedItems[(int)ONE_UP];
			if (Player_Lives[id] > 99)
				Player_Lives[id] = 99;
		}
	}

	if (appliedItems[(int)ONE_UP] > 0)
		MapSoundPlayer(SoundRelatedClass, SE_SYS_100COIN_ONE_UP, 1);

	state.setState(&StateID_CoinCountdown);
	HideSelectCursor(SelectCursorPointer, 0);
}
コード例 #5
0
 virtual void ControllerExit()
 {
     SaveFile *file = cc->localBrowser->GetSave();
     if (file)
     {
         if (file->GetError().length())
             new ErrorMessage("Error loading stamp", file->GetError());
         else if (cc->localBrowser->GetMoveToFront())
             Client::Ref().MoveStampToFront(file->GetName());
         cc->LoadStamp(file->GetGameSave());
     }
 }
コード例 #6
0
ファイル: object.cpp プロジェクト: emlai/zenith
void Object::save(SaveFile& file) const
{
    file.write(getId());

    for (auto& component : getComponents())
        component->save(file);
}
コード例 #7
0
ファイル: object.cpp プロジェクト: emlai/zenith
Object::Object(const SaveFile& file)
:   Entity(file.readString(), *Game::objectConfig),
    sprite(::getSprite(*Game::objectSpriteSheet, *Game::objectConfig, getId()))
{
    for (auto& component : getComponents())
        component->load(file);
}
コード例 #8
0
	virtual bool doWork()
	{
		std::vector<std::string> files = Client::Ref().DirectorySearch(directory, search, ".cps");
		std::sort(files.rbegin(), files.rend(), [](std::string a, std::string b) {
			std::transform(a.begin(), a.end(), a.begin(), ::tolower);
			std::transform(b.begin(), b.end(), b.begin(), ::tolower);
			return a < b;
		});

		notifyProgress(-1);
		for(std::vector<std::string>::iterator iter = files.begin(), end = files.end(); iter != end; ++iter)
		{
			SaveFile * saveFile = new SaveFile(*iter);
			try
			{
				std::vector<unsigned char> data = Client::Ref().ReadFile(*iter);
				GameSave * tempSave = new GameSave(data);
				saveFile->SetGameSave(tempSave);
				saveFiles.push_back(saveFile);

				std::string filename = *iter;
				size_t folderPos = filename.rfind(PATH_SEP);
				if(folderPos!=std::string::npos && folderPos+1 < filename.size())
				{
					filename = filename.substr(folderPos+1);
				}
				size_t extPos = filename.rfind(".");
				if(extPos!=std::string::npos)
				{
					filename = filename.substr(0, extPos);
				}
				saveFile->SetDisplayName(filename);
			}
			catch(std::exception & e)
			{
				//:(
			}
		}
		return true;
	}
コード例 #9
0
ファイル: ActionSeries.cpp プロジェクト: mrDIMAS/src
void ActionSeries::Serialize(SaveFile & s) {
	s & mEnabled;
	s & mCounter;
	s & mLastActionTime;
	for(auto & timePointPair : mActions) {
		s & timePointPair.second->mDone;
		if(s.IsLoading()) {
			if(timePointPair.second->mDone) {
				timePointPair.second->Do();
			}
		}
	}
}
コード例 #10
0
ファイル: Rotator.cpp プロジェクト: Asqwel/TZOD-Modified
void Rotator::Serialize(SaveFile &f)
{
	f.Serialize(_accel_current);
	f.Serialize(_accel_stop);
	f.Serialize(_angle_target);
	f.Serialize(_state);
	f.Serialize(_velocity_current);
	f.Serialize(_velocity_limit);
}
コード例 #11
0
ファイル: Object.cpp プロジェクト: ACefalu/tzod
void GC_Object::Serialize(SaveFile &f)
{
	assert(0 == _notifyProtectCount);

	f.Serialize(_flags);


	//
	// name
	//

	if( CheckFlags(GC_FLAG_OBJECT_NAMED) )
	{
		if( f.loading() )
		{
			string_t name;
			f.Serialize(name);

			assert( 0 == g_level->_objectToStringMaps[FastLog2(GC_FLAG_OBJECT_NAMED)].count(this) );
			assert( 0 == g_level->_nameToObjectMap.count(name) );
			g_level->_objectToStringMaps[FastLog2(GC_FLAG_OBJECT_NAMED)][this] = name;
			g_level->_nameToObjectMap[name] = this;
		}
		else
		{
			string_t name = GetName();
			f.Serialize(name);
		}
	}


	//
	// events
	//

	if( f.loading() )
	{
		DWORD tmp = _flags & GC_FLAG_OBJECT_EVENTS_TS_FIXED;
		SetFlags(GC_FLAG_OBJECT_EVENTS_TS_FIXED, false);
		SetEvents(tmp);
	}


	//
	// notifications
	//

	size_t count = 0;
	if( const Notify *n = _firstNotify )
		do { count += !n->IsRemoved(); } while( n = n->next );
	f.Serialize(count);
	if( f.loading() )
	{
		assert(NULL == _firstNotify);
		for( size_t i = 0; i < count; i++ )
		{
			_firstNotify = new Notify(_firstNotify);
			_firstNotify->Serialize(f);
		}
	}
	else
	{
		for( Notify *n = _firstNotify; n; n = n->next )
		{
			if( !n->IsRemoved() )
				n->Serialize(f);
		}
	}
}
コード例 #12
0
ファイル: GameModel.cpp プロジェクト: me4502/PowderToypp
GameModel::GameModel():
	sim(NULL),
	ren(NULL),
	currentBrush(0),
	currentUser(0, ""),
	currentSave(NULL),
	colourSelector(false),
	clipboard(NULL),
	stamp(NULL),
	placeSave(NULL),
	colour(255, 0, 0, 255),
	toolStrength(1.0f)
{
	sim = new Simulation();
	ren = new Renderer(ui::Engine::Ref().g, sim);

    memset(activeTools, 0, sizeof(activeTools));
    
	//Load config into renderer
	try
	{
		ren->SetColourMode(Client::Ref().GetPrefUInteger("Renderer.ColourMode", 0));

		vector<unsigned int> tempArray = Client::Ref().GetPrefUIntegerArray("Renderer.DisplayModes");
		if(tempArray.size())
		{
			std::vector<unsigned int> displayModes(tempArray.begin(), tempArray.end());
			ren->SetDisplayMode(displayModes);
		}

		tempArray = Client::Ref().GetPrefUIntegerArray("Renderer.RenderModes");
		if(tempArray.size())
		{
			std::vector<unsigned int> renderModes(tempArray.begin(), tempArray.end());
			ren->SetRenderMode(renderModes);
		}
	}
	catch(json::Exception & e)
	{

	}

	//Load config into simulation
	sim->SetEdgeMode(Client::Ref().GetPrefInteger("Simulation.EdgeMode", 0));

	//Load last user
	if(Client::Ref().GetAuthUser().ID)
	{
		currentUser = Client::Ref().GetAuthUser();
	}

	//Set stamp to first stamp in list
	vector<string> stamps = Client::Ref().GetStamps(0, 1);
	if(stamps.size()>0)
	{
		SaveFile * stampFile = Client::Ref().GetStamp(stamps[0]);
		if(stampFile && stampFile->GetGameSave())
			stamp = stampFile->GetGameSave();
	}

	BuildMenus();
	BuildQuickOptionMenu();

	//Set default decoration colour
	unsigned char colourR = min(Client::Ref().GetPrefInteger("Decoration.Red", 200), 255);
	unsigned char colourG = min(Client::Ref().GetPrefInteger("Decoration.Green", 100), 255);
	unsigned char colourB = min(Client::Ref().GetPrefInteger("Decoration.Blue", 50), 255);
	unsigned char colourA = min(Client::Ref().GetPrefInteger("Decoration.Alpha", 255), 255);

	SetColourSelectorColour(ui::Colour(colourR, colourG, colourB, colourA));
}
コード例 #13
0
ファイル: GameModel.cpp プロジェクト: Elfang24/The-Powder-Toy
GameModel::GameModel():
	sim(NULL),
	ren(NULL),
	currentBrush(0),
	currentUser(0, ""),
	currentSave(NULL),
	currentFile(NULL),
	colourSelector(false),
	clipboard(NULL),
	stamp(NULL),
	placeSave(NULL),
	colour(255, 0, 0, 255),
	toolStrength(1.0f),
	activeColourPreset(-1),
	activeMenu(-1),
	edgeMode(0)
{
	sim = new Simulation();
	ren = new Renderer(ui::Engine::Ref().g, sim);

	activeTools = regularToolset;

	std::fill(decoToolset, decoToolset+4, (Tool*)NULL);
	std::fill(regularToolset, regularToolset+4, (Tool*)NULL);

	//Default render prefs
	std::vector<unsigned int> tempArray;
	tempArray.push_back(RENDER_FIRE);
	tempArray.push_back(RENDER_EFFE);
	tempArray.push_back(RENDER_BASC);
	ren->SetRenderMode(tempArray);
	tempArray.clear();

	ren->SetDisplayMode(tempArray);

	ren->SetColourMode(0);

	//Load config into renderer
	try
	{
		ren->SetColourMode(Client::Ref().GetPrefUInteger("Renderer.ColourMode", 0));

		vector<unsigned int> tempArray = Client::Ref().GetPrefUIntegerArray("Renderer.DisplayModes");
		if(tempArray.size())
		{
			std::vector<unsigned int> displayModes(tempArray.begin(), tempArray.end());
			ren->SetDisplayMode(displayModes);
		}

		tempArray = Client::Ref().GetPrefUIntegerArray("Renderer.RenderModes");
		if(tempArray.size())
		{
			std::vector<unsigned int> renderModes(tempArray.begin(), tempArray.end());
			ren->SetRenderMode(renderModes);
		}

		ren->gravityFieldEnabled = Client::Ref().GetPrefBool("Renderer.GravityField", false);
		ren->decorations_enable = Client::Ref().GetPrefBool("Renderer.Decorations", true);
	}
	catch(json::Exception & e)
	{
	}

	//Load config into simulation
	edgeMode = Client::Ref().GetPrefInteger("Simulation.EdgeMode", 0);
	sim->SetEdgeMode(edgeMode);
	int ngrav_enable = Client::Ref().GetPrefInteger("Simulation.NewtonianGravity", 0);
	if (ngrav_enable)
		sim->grav->start_grav_async();
	sim->aheat_enable =  Client::Ref().GetPrefInteger("Simulation.AmbientHeat", 0);
	sim->pretty_powder =  Client::Ref().GetPrefInteger("Simulation.PrettyPowder", 0);

	//Load last user
	if(Client::Ref().GetAuthUser().ID)
	{
		currentUser = Client::Ref().GetAuthUser();
	}

	//Set stamp to first stamp in list
	vector<string> stamps = Client::Ref().GetStamps(0, 1);
	if(stamps.size()>0)
	{
		SaveFile * stampFile = Client::Ref().GetStamp(stamps[0]);
		if(stampFile && stampFile->GetGameSave())
			stamp = stampFile->GetGameSave();
	}

	BuildMenus();

	//Set default brush palette
	brushList.push_back(new EllipseBrush(ui::Point(4, 4)));
	brushList.push_back(new Brush(ui::Point(4, 4)));
	brushList.push_back(new TriangleBrush(ui::Point(4, 4)));

	//Load more from brushes folder
	std::vector<string> brushFiles = Client::Ref().DirectorySearch(BRUSH_DIR, "", ".ptb");
	for(int i = 0; i < brushFiles.size(); i++)
	{
		std::vector<unsigned char> brushData = Client::Ref().ReadFile(brushFiles[i]);
		if(!brushData.size())
		{
			std::cout << "Brushes: Skipping " << brushFiles[i] << ". Could not open" << std::endl;
			continue;
		}
		int dimension = std::sqrt((float)brushData.size());
		if(dimension * dimension != brushData.size())
		{
			std::cout << "Brushes: Skipping " << brushFiles[i] << ". Invalid bitmap size" << std::endl;
			continue;
		}
		brushList.push_back(new BitmapBrush(brushData, ui::Point(dimension, dimension)));
	}

	//Set default decoration colour
	unsigned char colourR = min(Client::Ref().GetPrefInteger("Decoration.Red", 200), 255);
	unsigned char colourG = min(Client::Ref().GetPrefInteger("Decoration.Green", 100), 255);
	unsigned char colourB = min(Client::Ref().GetPrefInteger("Decoration.Blue", 50), 255);
	unsigned char colourA = min(Client::Ref().GetPrefInteger("Decoration.Alpha", 255), 255);

	SetColourSelectorColour(ui::Colour(colourR, colourG, colourB, colourA));

	colourPresets.push_back(ui::Colour(255, 255, 255));
	colourPresets.push_back(ui::Colour(0, 255, 255));
	colourPresets.push_back(ui::Colour(255, 0, 255));
	colourPresets.push_back(ui::Colour(255, 255, 0));
	colourPresets.push_back(ui::Colour(255, 0, 0));
	colourPresets.push_back(ui::Colour(0, 255, 0));
	colourPresets.push_back(ui::Colour(0, 0, 255));
	colourPresets.push_back(ui::Colour(0, 0, 0));
}
コード例 #14
0
GameModel::GameModel():
	sim(NULL),
	ren(NULL),
	currentBrush(0),
	currentUser(0, ""),
	currentSave(NULL),
	currentFile(NULL),
	colourSelector(false),
	clipboard(NULL),
	stamp(NULL),
	placeSave(NULL),
	colour(255, 0, 0, 255),
	toolStrength(1.0f),
	activeColourPreset(-1),
	activeMenu(NULL),
	edgeMode(0)
{
	sim = new Simulation();
	ren = new Renderer(ui::Engine::Ref().g, sim);

	activeTools = regularToolset;

	std::fill(decoToolset, decoToolset+3, (Tool*)NULL);
	std::fill(regularToolset, regularToolset+3, (Tool*)NULL);

    	//Default render prefs
	std::vector<unsigned int> tempArray;
	tempArray.push_back(RENDER_FIRE);
	tempArray.push_back(RENDER_EFFE);
	tempArray.push_back(RENDER_BASC);
	ren->SetRenderMode(tempArray);
	tempArray.clear();

	ren->SetDisplayMode(tempArray);

	ren->SetColourMode(0);

	//Load config into renderer
	try
	{
		ren->SetColourMode(Client::Ref().GetPrefUInteger("Renderer.ColourMode", 0));

		vector<unsigned int> tempArray = Client::Ref().GetPrefUIntegerArray("Renderer.DisplayModes");
		if(tempArray.size())
		{
			std::vector<unsigned int> displayModes(tempArray.begin(), tempArray.end());
			ren->SetDisplayMode(displayModes);
		}

		tempArray = Client::Ref().GetPrefUIntegerArray("Renderer.RenderModes");
		if(tempArray.size())
		{
			std::vector<unsigned int> renderModes(tempArray.begin(), tempArray.end());
			ren->SetRenderMode(renderModes);
		}

		ren->gravityFieldEnabled = Client::Ref().GetPrefBool("Renderer.GravityField", false);
		ren->decorations_enable = Client::Ref().GetPrefBool("Renderer.Decorations", true);
	}
	catch(json::Exception & e)
	{
	}

	//Load config into simulation
	edgeMode = Client::Ref().GetPrefInteger("Simulation.EdgeMode", 0);
	sim->SetEdgeMode(edgeMode);

	//Load last user
	if(Client::Ref().GetAuthUser().ID)
	{
		currentUser = Client::Ref().GetAuthUser();
	}

	//Set stamp to first stamp in list
	vector<string> stamps = Client::Ref().GetStamps(0, 1);
	if(stamps.size()>0)
	{
		SaveFile * stampFile = Client::Ref().GetStamp(stamps[0]);
		if(stampFile && stampFile->GetGameSave())
			stamp = stampFile->GetGameSave();
	}

	BuildMenus();

	//Set default decoration colour
	unsigned char colourR = min(Client::Ref().GetPrefInteger("Decoration.Red", 200), 255);
	unsigned char colourG = min(Client::Ref().GetPrefInteger("Decoration.Green", 100), 255);
	unsigned char colourB = min(Client::Ref().GetPrefInteger("Decoration.Blue", 50), 255);
	unsigned char colourA = min(Client::Ref().GetPrefInteger("Decoration.Alpha", 255), 255);

	SetColourSelectorColour(ui::Colour(colourR, colourG, colourB, colourA));

	colourPresets.push_back(ui::Colour(255, 255, 255));
	colourPresets.push_back(ui::Colour(0, 255, 255));
	colourPresets.push_back(ui::Colour(255, 0, 255));
	colourPresets.push_back(ui::Colour(255, 255, 0));
	colourPresets.push_back(ui::Colour(255, 0, 0));
	colourPresets.push_back(ui::Colour(0, 255, 0));
	colourPresets.push_back(ui::Colour(0, 0, 255));
}
コード例 #15
0
ファイル: msgsystem.cpp プロジェクト: emlai/zenith
void Message::save(SaveFile& file) const
{
    file.write(text);
    file.writeInt32(turn);
}
コード例 #16
0
ファイル: msgsystem.cpp プロジェクト: emlai/zenith
Message Message::load(const SaveFile& file)
{
    auto text = file.readString();
    auto turn = file.readInt32();
    return Message(std::move(text), turn);
}