MenuManager::MenuManager(PowerManager *_powers, StatBlock *_stats, CampaignManager *_camp, ItemManager *_items) {
	powers = _powers;
	stats = _stats;
	powers = _powers;
	camp = _camp;
	items = _items;

	loadIcons();

	hp = new MenuStatBar("hp");
	menus.push_back(hp); // menus[0]
	mp = new MenuStatBar("mp");
	menus.push_back(mp); // menus[1]
	xp = new MenuStatBar("xp");
	menus.push_back(xp); // menus[2]
	effects = new MenuActiveEffects(icons);
	menus.push_back(effects); // menus[3]
	hudlog = new MenuHUDLog();
	menus.push_back(hudlog); // menus[4]
	act = new MenuActionBar(powers, stats, icons);
	menus.push_back(act); // menus[5]
	enemy = new MenuEnemy();
	menus.push_back(enemy); // menus[6]
	vendor = new MenuVendor(items, stats);
	menus.push_back(vendor); // menus[7]
	talker = new MenuTalker(camp);
	menus.push_back(talker); // menus[8]
	exit = new MenuExit();
	menus.push_back(exit); // menus[9]
	mini = new MenuMiniMap();
	menus.push_back(mini); // menus[10]
	chr = new MenuCharacter(stats);
	menus.push_back(chr); // menus[11]
	inv = new MenuInventory(items, stats, powers);
	menus.push_back(inv); // menus[12]
	pow = new MenuPowers(stats, powers, icons);
	menus.push_back(pow); // menus[13]
	log = new MenuLog();
	menus.push_back(log); // menus[14]
	stash = new MenuStash(items, stats);
	menus.push_back(stash); // menus[15]
	tip = new WidgetTooltip();

	// Load the menu positions and alignments from menus/menus.txt
	int x,y,w,h;
	std::string align;
	int menu_index;
	FileParser infile;
	if (infile.open(mods->locate("menus/menus.txt"))) {
		while (infile.next()) {
			infile.val = infile.val + ',';
			x = eatFirstInt(infile.val, ',');
			y = eatFirstInt(infile.val, ',');
			w = eatFirstInt(infile.val, ',');
			h = eatFirstInt(infile.val, ',');
			align = eatFirstString(infile.val, ',');

			menu_index = -1;

			if (infile.key == "hp") menu_index = 0;
			else if (infile.key == "mp") menu_index = 1;
			else if (infile.key == "xp") menu_index = 2;
			else if (infile.key == "effects") menu_index = 3;
			else if (infile.key == "hudlog") menu_index = 4;
			else if (infile.key == "actionbar") menu_index = 5;
			else if (infile.key == "enemy") menu_index = 6;
			else if (infile.key == "vendor") menu_index = 7;
			else if (infile.key == "talker") menu_index = 8;
			else if (infile.key == "exit") menu_index = 9;
			else if (infile.key == "minimap") menu_index = 10;
			else if (infile.key == "character") menu_index = 11;
			else if (infile.key == "inventory") menu_index = 12;
			else if (infile.key == "powers") menu_index = 13;
			else if (infile.key == "log") menu_index = 14;
			else if (infile.key == "stash") menu_index = 15;

			if (menu_index != -1) {
				menus[menu_index]->window_area.x = x;
				menus[menu_index]->window_area.y = y;
				menus[menu_index]->window_area.w = w;
				menus[menu_index]->window_area.h = h;
				menus[menu_index]->alignment = align;
				menus[menu_index]->align();
			}

		}
		infile.close();
	} else fprintf(stderr, "Unable to open menus/menus.txt!\n");

	// Some menus need to be updated to apply their new dimensions
	act->update();
	vendor->update();
	vendor->buyback_stock.init(NPC_VENDOR_MAX_STOCK, items);
	talker->update();
	exit->update();
	chr->update();
	inv->update();
	pow->update();
	log->update();
	stash->update();

	pause = false;
	dragging = false;
	drag_stack.item = 0;
	drag_stack.quantity = 0;
	drag_power = 0;
	drag_src = 0;
	drop_stack.item = 0;
	drop_stack.quantity = 0;


	loadSounds();

	done = false;

	closeAll(false); // make sure all togglable menus start closed
}
Beispiel #2
0
/**
 * load
 */
int MapIso::load(string filename) {
	FileParser infile;
	string val;
	string cur_layer;
	string data_format;
  
	clearEvents();
  
	event_count = 0;
	bool collider_set = false;
  
	if (infile.open(PATH_DATA + "maps/" + filename)) {
		while (infile.next()) {
			if (infile.new_section) {
				data_format = "dec"; // default
				
				if (enemy_awaiting_queue) {
					enemies.push(new_enemy);
					enemy_awaiting_queue = false;
				}
				if (npc_awaiting_queue) {
					npcs.push(new_npc);
					npc_awaiting_queue = false;
				}
				if (group_awaiting_queue){
					push_enemy_group(new_group);
					group_awaiting_queue = false;
				}
				
				// for sections that are stored in collections, add a new object here
				if (infile.section == "enemy") {
					clearEnemy(new_enemy);
					enemy_awaiting_queue = true;
				}
				else if (infile.section == "enemygroup") {
					clearGroup(new_group);
					group_awaiting_queue = true;
				}
				else if (infile.section == "npc") {
					clearNPC(new_npc);
					npc_awaiting_queue = true;
				}
				else if (infile.section == "event") {
					event_count++;
				}
				
			}
			if (infile.section == "header") {
				if (infile.key == "title") {
					this->title = infile.val;
				}
				else if (infile.key == "width") {
					this->w = atoi(infile.val.c_str());
				}
				else if (infile.key == "height") {
					this->h = atoi(infile.val.c_str());
				}
				else if (infile.key == "tileset") {
					this->tileset = infile.val;
				}
				else if (infile.key == "music") {
					if (this->music_filename == infile.val) {
						this->new_music = false;
					}
					else {
						this->music_filename = infile.val;
						this->new_music = true;
					}
				}
				else if (infile.key == "spawnpoint") {
					spawn.x = atoi(infile.nextValue().c_str()) * UNITS_PER_TILE + UNITS_PER_TILE/2;
					spawn.y = atoi(infile.nextValue().c_str()) * UNITS_PER_TILE + UNITS_PER_TILE/2;
					spawn_dir = atoi(infile.nextValue().c_str());
				}
			}
			else if (infile.section == "layer") {
				if (infile.key == "id") {
					cur_layer = infile.val;
				}
				else if (infile.key == "format") {
					data_format = infile.val;
				}
				else if (infile.key == "data") {
					// layer map data handled as a special case

					// The next h lines must contain layer data.  TODO: err
					if (data_format == "hex") {
						for (int j=0; j<h; j++) {
							val = infile.getRawLine() + ',';
							for (int i=0; i<w; i++) {
								if (cur_layer == "background") background[i][j] = eatFirstHex(val, ',');
								else if (cur_layer == "object") object[i][j] = eatFirstHex(val, ',');
								else if (cur_layer == "collision") collision[i][j] = eatFirstHex(val, ',');
							}
						}
					}
					else if (data_format == "dec") {
						for (int j=0; j<h; j++) {
							val = infile.getRawLine() + ',';
							for (int i=0; i<w; i++) {
								if (cur_layer == "background") background[i][j] = eatFirstInt(val, ',');
								else if (cur_layer == "object") object[i][j] = eatFirstInt(val, ',');
								else if (cur_layer == "collision") collision[i][j] = eatFirstInt(val, ',');
							}
						}
					}
					if ((cur_layer == "collision") && !collider_set) {
						collider.setmap(collision);
						collider.map_size.x = w;
						collider.map_size.y = h;
					}
				}
			}
			else if (infile.section == "enemy") {
				if (infile.key == "type") {
					new_enemy.type = infile.val;
				}
				else if (infile.key == "spawnpoint") {
					new_enemy.pos.x = atoi(infile.nextValue().c_str()) * UNITS_PER_TILE + UNITS_PER_TILE/2;
					new_enemy.pos.y = atoi(infile.nextValue().c_str()) * UNITS_PER_TILE + UNITS_PER_TILE/2;
					new_enemy.direction = atoi(infile.nextValue().c_str());
				}
			}
			else if (infile.section == "enemygroup") {
				if (infile.key == "category") {
					new_group.category = infile.val;
				}
				else if (infile.key == "level") {
					new_group.levelmin = atoi(infile.nextValue().c_str());
					new_group.levelmax = atoi(infile.nextValue().c_str());
				}
				else if (infile.key == "area") {
					new_group.pos.x = atoi(infile.nextValue().c_str());
					new_group.pos.y = atoi(infile.nextValue().c_str());
					new_group.area.x = atoi(infile.nextValue().c_str());
					new_group.area.y = atoi(infile.nextValue().c_str());
				}
				else if (infile.key == "number") {
					new_group.numbermin = atoi(infile.nextValue().c_str());
					new_group.numbermax = atoi(infile.nextValue().c_str());
				}
			}
			else if (infile.section == "npc") {
				if (infile.key == "id") {
					new_npc.id = infile.val;
				}
				else if (infile.key == "position") {
					new_npc.pos.x = atoi(infile.nextValue().c_str()) * UNITS_PER_TILE + UNITS_PER_TILE/2;
					new_npc.pos.y = atoi(infile.nextValue().c_str()) * UNITS_PER_TILE + UNITS_PER_TILE/2;
				}
			}
			else if (infile.section == "event") {
				if (infile.key == "type") {
					events[event_count-1].type = infile.val;
				}
				else if (infile.key == "location") {
					events[event_count-1].location.x = atoi(infile.nextValue().c_str());
					events[event_count-1].location.y = atoi(infile.nextValue().c_str());
					events[event_count-1].location.w = atoi(infile.nextValue().c_str());
					events[event_count-1].location.h = atoi(infile.nextValue().c_str());
				}
				else if (infile.key == "hotspot") {
					events[event_count-1].hotspot.x = atoi(infile.nextValue().c_str());
					events[event_count-1].hotspot.y = atoi(infile.nextValue().c_str());
					events[event_count-1].hotspot.w = atoi(infile.nextValue().c_str());
					events[event_count-1].hotspot.h = atoi(infile.nextValue().c_str());
				}
				else if (infile.key == "tooltip") {
					events[event_count-1].tooltip = infile.val;
				}
				else if (infile.key == "power_path") {
					events[event_count-1].power_src.x = atoi(infile.nextValue().c_str());
					events[event_count-1].power_src.y = atoi(infile.nextValue().c_str());
					string dest = infile.nextValue();
					if (dest == "hero") {
						events[event_count-1].targetHero = true;
					}
					else {
						events[event_count-1].power_dest.x = atoi(dest.c_str());
						events[event_count-1].power_dest.y = atoi(infile.nextValue().c_str());
					}
				}
				else if (infile.key == "power_damage") {
					events[event_count-1].damagemin = atoi(infile.nextValue().c_str());
					events[event_count-1].damagemax = atoi(infile.nextValue().c_str());
				}
				else if (infile.key == "power_cooldown") {
					events[event_count-1].power_cooldown = atoi(infile.val.c_str());
				}
				else {
					// new event component
					Event_Component *e = &events[event_count-1].components[events[event_count-1].comp_num];
					e->type = infile.key;
					
					if (infile.key == "intermap") {
						e->s = infile.nextValue();
						e->x = atoi(infile.nextValue().c_str());
						e->y = atoi(infile.nextValue().c_str());
					}
					else if (infile.key == "mapmod") {
						e->s = infile.nextValue();
						e->x = atoi(infile.nextValue().c_str());
						e->y = atoi(infile.nextValue().c_str());
						e->z = atoi(infile.nextValue().c_str());
					}
					else if (infile.key == "soundfx") {
						e->s = infile.val;
					}
					else if (infile.key == "loot") {
						e->s = infile.nextValue();
						e->x = atoi(infile.nextValue().c_str()) * UNITS_PER_TILE + UNITS_PER_TILE/2;
						e->y = atoi(infile.nextValue().c_str()) * UNITS_PER_TILE + UNITS_PER_TILE/2;
						e->z = atoi(infile.nextValue().c_str());
					}
					else if (infile.key == "msg") {
						e->s = infile.val;
					}
					else if (infile.key == "shakycam") {
						e->x = atoi(infile.val.c_str());
					}
					else if (infile.key == "requires_status") {
						e->s = infile.val;
					}
					else if (infile.key == "requires_not") {
						e->s = infile.val;
					}
					else if (infile.key == "requires_item") {
						e->x = atoi(infile.val.c_str());
					}
					else if (infile.key == "set_status") {
						e->s = infile.val;
					}
					else if (infile.key == "unset_status") {
						e->s = infile.val;
					}
					else if (infile.key == "remove_item") {
						e->x = atoi(infile.val.c_str());
					}
					else if (infile.key == "reward_xp") {
						e->x = atoi(infile.val.c_str());
					}
					else if (infile.key == "power") {
						e->x = atoi(infile.val.c_str());
					}
					
					events[event_count-1].comp_num++;
				}
			}
		}

		infile.close();
		
		// reached end of file.  Handle any final sections.
		if (enemy_awaiting_queue) {
			enemies.push(new_enemy);
			enemy_awaiting_queue = false;
		}
		if (npc_awaiting_queue) {
			npcs.push(new_npc);
			npc_awaiting_queue = false;
		}
		if (group_awaiting_queue){
			push_enemy_group(new_group);
			group_awaiting_queue = false;
		}
	}


	
	if (this->new_music) {
		loadMusic();
		this->new_music = false;
	}
	tset.load(this->tileset);

	return 0;
}
Beispiel #3
0
/**
 * All powers are defined in powers/powers.txt
 */
void PowerManager::loadPowers() {

	ifstream infile;
	string line;
	string key;
	string val;
	string starts_with;
	int input_id = 0;
	
	infile.open("powers/powers.txt", ios::in);

	if (infile.is_open()) {
		while (!infile.eof()) {
			line = getLine(infile);

			if (line.length() > 0) {
				starts_with = line.at(0);
				
				if (starts_with == "#") {
					// skip comments
				}
				if (starts_with == "[") {
					// not actually necessary.  We know we're at a new power when
					// we see a new id key.
				}
				else { // this is data.  treatment depends on key
					parse_key_pair(line, key, val);          
					key = trim(key, ' ');
					val = trim(val, ' ');
				
					// id needs to be the first component of each power.  That is how we write
					// data to the correct power.
					if (key == "id") {
						input_id = atoi(val.c_str());
					}
					else if (key == "type") {
						if (val == "single") powers[input_id].type = POWTYPE_SINGLE;
						else if (val == "effect") powers[input_id].type = POWTYPE_EFFECT;
						else if (val == "missile") powers[input_id].type = POWTYPE_MISSILE;
						else if (val == "repeater") powers[input_id].type = POWTYPE_REPEATER;
					}
					else if (key == "name") {
						powers[input_id].name = val;
					}
					else if (key == "description") {
						powers[input_id].description = val;
					}
					else if (key == "icon") {
						powers[input_id].icon = atoi(val.c_str());
					}
					else if (key == "new_state") {
						if (val == "swing") powers[input_id].new_state = POWSTATE_SWING;
						else if (val == "shoot") powers[input_id].new_state = POWSTATE_SHOOT;
						else if (val == "cast") powers[input_id].new_state = POWSTATE_CAST;
						else if (val == "block") powers[input_id].new_state = POWSTATE_BLOCK;
					}
					else if (key == "face") {
						if (val == "true") powers[input_id].face = true;
					}
					
					// power requirements
					else if (key == "requires_physical_weapon") {
						if (val == "true") powers[input_id].requires_physical_weapon = true;
					}
					else if (key == "requires_mental_weapon") {
						if (val == "true") powers[input_id].requires_mental_weapon = true;
					}
					else if (key == "requires_offense_weapon") {
						if (val == "true") powers[input_id].requires_offense_weapon = true;
					}
					else if (key == "requires_mp") {
						powers[input_id].requires_mp = atoi(val.c_str());
					}
					else if (key == "requires_los") {
						if (val == "true") powers[input_id].requires_los = true;
					}
					else if (key == "requires_empty_target") {
						if (val == "true") powers[input_id].requires_empty_target = true;
					}
					else if (key == "requires_item") {
						powers[input_id].requires_item = atoi(val.c_str());
					}
					
					// animation info
					else if (key == "gfx") {
						powers[input_id].gfx_index = loadGFX(val);
					}
					else if (key == "sfx") {
						powers[input_id].sfx_index = loadSFX(val);
					}
					else if (key == "rendered") {
						if (val == "true") powers[input_id].rendered = true;				
					}
					else if (key == "directional") {
						if (val == "true") powers[input_id].directional = true;
					}
					else if (key == "visual_random") {
						powers[input_id].visual_random = atoi(val.c_str());
					}
					else if (key == "visual_option") {
						powers[input_id].visual_option = atoi(val.c_str());
					}
					else if (key == "aim_assist") {
						powers[input_id].aim_assist = atoi(val.c_str());
					}
					else if (key == "speed") {
						powers[input_id].speed = atoi(val.c_str());
					}
					else if (key == "lifespan") {
						powers[input_id].lifespan = atoi(val.c_str());
					}
					else if (key == "frame_loop") {
						powers[input_id].frame_loop = atoi(val.c_str());
					}
					else if (key == "frame_duration") {
						powers[input_id].frame_duration = atoi(val.c_str());
					}
					else if (key == "frame_size") {
						val = val + ",";
						powers[input_id].frame_size.x = eatFirstInt(val, ',');										
						powers[input_id].frame_size.y = eatFirstInt(val, ',');				
					}
					else if (key == "frame_offset") {
						val = val + ",";
						powers[input_id].frame_offset.x = eatFirstInt(val, ',');										
						powers[input_id].frame_offset.y = eatFirstInt(val, ',');				
					}
					else if (key == "floor") {
						if (val == "true") powers[input_id].floor = true;
					}
					else if (key == "active_frame") {
						powers[input_id].active_frame = atoi(val.c_str());
					}
					else if (key == "complete_animation") {
						if (val == "true") powers[input_id].complete_animation = true;
					}
					
					// hazard traits
					else if (key == "use_hazard") {
						if (val == "true") powers[input_id].use_hazard = true;
					}
					else if (key == "no_attack") {
						if (val == "true") powers[input_id].no_attack = true;
					}
					else if (key == "radius") {
						powers[input_id].radius = atoi(val.c_str());
					}
					else if (key == "base_damage") {
						if (val == "none")
							powers[input_id].base_damage = BASE_DAMAGE_NONE;
						else if (val == "melee")
							powers[input_id].base_damage = BASE_DAMAGE_MELEE;
						else if (val == "ranged")
							powers[input_id].base_damage = BASE_DAMAGE_RANGED;
						else if (val == "ment")
							powers[input_id].base_damage = BASE_DAMAGE_MENT;
					}
					else if (key == "damage_multiplier") {
						powers[input_id].damage_multiplier = atoi(val.c_str());
					}
					else if (key == "starting_pos") {
						if (val == "source")
							powers[input_id].starting_pos = STARTING_POS_SOURCE;
						else if (val == "target")
							powers[input_id].starting_pos = STARTING_POS_TARGET;
						else if (val == "melee")
							powers[input_id].starting_pos = STARTING_POS_MELEE;
					}
					else if (key == "multitarget") {
						if (val == "true") powers[input_id].multitarget = true;
					}
					else if (key == "trait_armor_penetration") {
						if (val == "true") powers[input_id].trait_armor_penetration = true;
					}
					else if (key == "trait_crits_impaired") {
						powers[input_id].trait_crits_impaired = atoi(val.c_str());
					}
					else if (key == "trait_elemental") {
						if (val == "wood") powers[input_id].trait_elemental = ELEMENT_WOOD;
						else if (val == "metal") powers[input_id].trait_elemental = ELEMENT_METAL;
						else if (val == "wind") powers[input_id].trait_elemental = ELEMENT_WIND;
						else if (val == "water") powers[input_id].trait_elemental = ELEMENT_WATER;
						else if (val == "earth") powers[input_id].trait_elemental = ELEMENT_EARTH;
						else if (val == "fire") powers[input_id].trait_elemental = ELEMENT_FIRE;
						else if (val == "shadow") powers[input_id].trait_elemental = ELEMENT_SHADOW;
						else if (val == "light") powers[input_id].trait_elemental = ELEMENT_LIGHT;
					}
					//steal effects
					else if (key == "hp_steal") {
						powers[input_id].hp_steal = atoi(val.c_str());
					}
					else if (key == "mp_steal") {
						powers[input_id].mp_steal = atoi(val.c_str());
					}
					//missile modifiers
					else if (key == "missile_num") {
						powers[input_id].missile_num = atoi(val.c_str());
					}
					else if (key == "missile_angle") {
						powers[input_id].missile_angle = atoi(val.c_str());
					}
					else if (key == "angle_variance") {
						powers[input_id].angle_variance = atoi(val.c_str());
					}
					else if (key == "speed_variance") {
						powers[input_id].speed_variance = atoi(val.c_str());
					}
					//repeater modifiers
					else if (key == "delay") {
						powers[input_id].delay = atoi(val.c_str());
					}
					else if (key == "start_frame") {
						powers[input_id].start_frame = atoi(val.c_str());
					}
					else if (key == "repeater_num") {
						powers[input_id].repeater_num = atoi(val.c_str());
					}
					// buff/debuff durations
					else if (key == "bleed_duration") {
						powers[input_id].bleed_duration = atoi(val.c_str());
					}
					else if (key == "stun_duration") {
						powers[input_id].stun_duration = atoi(val.c_str());
					}
					else if (key == "slow_duration") {
						powers[input_id].slow_duration = atoi(val.c_str());
					}
					else if (key == "immobilize_duration") {
						powers[input_id].immobilize_duration = atoi(val.c_str());
					}
					else if (key == "immunity_duration") {
						powers[input_id].immunity_duration = atoi(val.c_str());
					}
					else if (key == "haste_duration") {
						powers[input_id].haste_duration = atoi(val.c_str());
					}
					else if (key == "hot_duration") {
						powers[input_id].hot_duration = atoi(val.c_str());
					}
					else if (key == "hot_value") {
						powers[input_id].hot_value = atoi(val.c_str());
					}
					
					// buffs
					else if (key == "buff_heal") {
						if (val == "true") powers[input_id].buff_heal = true;
					}
					else if (key == "buff_shield") {
						if (val == "true") powers[input_id].buff_shield = true;
					}
					else if (key == "buff_teleport") {
						if (val == "true") powers[input_id].buff_teleport = true;
					}
					else if (key == "buff_immunity") {
						if (val == "true") powers[input_id].buff_immunity = true;
					}
					else if (key == "buff_restore_hp") {
						powers[input_id].buff_restore_hp = atoi(val.c_str());
					}
					else if (key == "buff_restore_mp") {
						powers[input_id].buff_restore_mp = atoi(val.c_str());
					}
					
					// pre and post power effects
					else if (key == "post_power") {
						powers[input_id].post_power = atoi(val.c_str());
					}
					else if (key == "wall_power") {
						powers[input_id].wall_power = atoi(val.c_str());
					}
					else if (key == "allow_power_mod") {
						if (val == "true") powers[input_id].allow_power_mod = true;
					}
				}
			}
		}
	}
	infile.close();
}