コード例 #1
0
ファイル: resource_f.py プロジェクト: Teifion/Rob3
def print_form_element(resource_id, current_value):
	"""Prints the relevant form element for a given type of resource"""
	this_type = resource_list.data_dict[resource_id].type
	
	# We don't want a 10.0, we want 10
	if current_value == int(current_value):
		current_value = int(current_value)
	
	output = ''
	
	if this_type == 'discrete':
		return common.text_box("res_%s" % resource_list.data_dict[resource_id].name, current_value, size=6)
	
	elif this_type == 'boolean':
		return common.check_box("res_%s" % resource_list.data_dict[resource_id].name, current_value)
	
	return output

# def all_supplies():
# 	"""docstring for all_supplies"""
# 	res_dict = resource.get_resources_dict_c()
# 	d = Res_dict()
# 	
# 	for k, v in res_dict.items():
# 		if v.type == "boolean":
# 			d.value[k] = 1
# 	
# 	return d

# def resource_grep_list(tradable_only=False):
# 	"""Returns order-grep lists"""
# 	if tradable_only:
# 		query = """SELECT id, resource_name FROM resource_list WHERE tradable = True ORDER BY id DESC"""
# 	else:
# 		query = """SELECT id, resource_name FROM resource_list ORDER BY id DESC"""
# 	
# 	resource_id_list = []
# 	resource_name_list = []
# 	try:
# 		database.cursor.execute(query)#TODO Use new method
# 	except Exception as e:
# 		print("Query: %s\n" % query)
# 		raise e
# 	while (1):
# 		row = database.cursor.fetchone()
# 		if row == None: break
# 		resource_id_list.append(row['id'])
# 		resource_name_list.append(row['resource_name'])
# 	
# 	return resource_id_list, resource_name_list
コード例 #2
0
ファイル: edit_squad.py プロジェクト: Teifion/Rob3
def main(cursor):
	squad_id = int(common.get_val('squad'))
	
	the_squad = squad_q.get_one_squad(cursor, squad_id)
	armies_dict = army_q.get_armies_from_team(cursor, the_squad.team, include_garrisons=True)
	the_unit = unit_q.get_one_unit(cursor, the_squad.unit)
	
	names = {}
	for a, the_army in armies_dict.items():
		names[a] = the_army.name
	
	output = []
	
	output.append("<div style='padding: 5px;'>")
	
	output.append("""
	<form action="exec.py" id="the_squad_form" method="post" accept-charset="utf-8">
		<input type="hidden" name="mode" id="mode" value="edit_squad_commit" />
		<input type="hidden" name="id" id="id" value="%(squad_id)s" />
		
		<label for="name">Editing:</label> %(name_text)s
		<br /><br />
		
		<table border="0" cellspacing="5" cellpadding="5">
			<tr>
				<td><label for="army">Army:</label></td>
				<td style="padding: 1px;">%(army_select)s</td>
			
				<td width="5">&nbsp;</td>
			
				<td>Type: </td>
				<td>%(unit_type)s</td>
			</tr>
			<tr>
				<td><label for="amount">Amount:</label></td>
				<td>%(amount)s</td>
			
				<td>&nbsp;</td>
			
				<td><label for="experience">Experince:</label></td>
				<td>%(experience)s</td>
			</tr>
			<tr>
				<td colspan="5">
					<strong>%(unit_name)s</strong>: %(unit_description)s
				</td>
			</tr>
			<tr>
				<td colspan="5">
					<input type="submit" value="Apply" />
				</td>
			</tr>
		</table>
	</form>
	<form id="delete_form" action="exec.py" method="post" accept-charset="utf-8">
		<input type="hidden" name="squad" id="squad" value="%(squad_id)s" />
		<input type="hidden" name="mode" id="mode" value="remove_squad" />
		<input style="float:right; margin-right:100px;" type="button" value="Delete squad" onclick="var answer = confirm('Delete %(name)s?')
		if (answer) $('#delete_form').submit();" />
	</form>
	<br /><br />""" % {
		"squad_id":			squad_id,
		"name":				the_squad.name,
		"name_text":		common.text_box("name", the_squad.name),
		"unit_type":		the_unit.name,
		"army_select":		common.option_box(
			name='army',
			elements=names,
			element_order=armies_dict.keys(),
			custom_id="army",
			selected=the_squad.army,
		),
		
		"unit_name":		the_unit.name,
		"unit_description":	the_unit.equipment_string,
		
		"amount":			common.text_box("amount", the_squad.amount),
		"experience":		common.text_box("experience", the_squad.experience),
	})
	
	output.append("</div>")
	
	page_data['Title'] = "Editing squad (%s)" % the_squad.name
	return "".join(output)
コード例 #3
0
ファイル: edit_team.py プロジェクト: Teifion/Rob3
def main(cursor):
	# Get team Id
	team_id = int(common.get_val('team', 0))
	if team_id < 1: return "No team selected"
	
	# Build team item
	the_team = team_q.get_one_team(cursor, team_id)
	
	# Get some properties
	the_team.get_population(cursor)
	
	# Lists
	trait_dict = trait_q.get_all_traits(cursor)
	deity_dict = deity_q.get_all_deities(cursor)
	evolution_dict = evolution_q.get_all_evolutions(cursor)
	
	# Is the join turn set?
	if the_team.join_turn == 0:
		the_team.join_turn = common.current_turn()
	
	# First row of check_boxes
	output = ["<div style='padding: 5px;'>"]

	output.append("""
	<span class="stitle">%(name)s</span>
	&nbsp;&nbsp;&nbsp;
	Population: %(team_population)s

	<br /><br />
	<form action="exec.py" method="post" accept-charset="utf-8">
		<input type="hidden" name="mode" id="mode" value="edit_team_commit" />
		<input type="hidden" name="id" id="id" value="%(team_id)d" />
	
		<input type="hidden" name="requestTime" id="requestTime" value="' . $the_team->requestTime . '" />
	
		<label for="active">Active:</label>&nbsp;&nbsp;
		%(active_check_box)s
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

		<label for="ir">IR:</label>&nbsp;&nbsp;
		%(ir_check_box)s
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

		<label for="hidden">Hidden:</label>&nbsp;&nbsp;
		%(hidden_check_box)s
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	
		<label for="not_a_team">Not a team:</label>&nbsp;&nbsp;
		%(not_a_team_check_box)s
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

		<label for="dead">Dead:</label>&nbsp;&nbsp;
		%(dead_check_box)s
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

		<label for="not_in_queue">Not in queue:</label>&nbsp;&nbsp;
		%(not_in_queue_check_box)s
		<br />
		""" % {	'team_id':					team_id,
				'name':				the_team.name,
				'team_population':			common.number_format(the_team.population),
				'active_check_box':			common.check_box('active', the_team.active),
				'ir_check_box':				common.check_box('ir', the_team.ir),
				'hidden_check_box':			common.check_box('hidden', the_team.hidden),
				'not_a_team_check_box':		common.check_box('not_a_team', the_team.not_a_team),
				'dead_check_box':			common.check_box('dead', the_team.dead),
				'not_in_queue_check_box':	common.check_box('not_in_queue', the_team.not_in_queue),
				})

	# Row 1
	output.append("""
		<table border="0" cellspacing="5" cellpadding="5" style="width:100%%;">
			<tr>
				<td><label for="forum_url_id">Forum URL id:</label></td>
				<td>%(forum_text_box)s</td>
		
				<td width="5">&nbsp;</td>
		
				<td><label for="orders_topic">Orders topic:</label></td>
				<td>%(orders_text_box)s</td>
		
				<td width="5">&nbsp;</td>
		
				<td><label for="intorders_topic">Int Orders topic:</label></td>
				<td>%(intorders_text_box)s</td>
			</tr>""" % {'forum_text_box':		common.text_box('forum_url_id', the_team.forum_url_id, warn_on = lambda x:(True if x < 0 else False)),
						'orders_text_box':		common.text_box('orders_topic', the_team.orders_topic, warn_on = lambda x:(True if x < 0 else False)),
						'intorders_text_box':	common.text_box('intorders_topic', the_team.intorders_topic, warn_on = lambda x:(True if x < 0 else False)),
						})


	# Row 2
	output.append("""
			<tr>
				<td><label for="results_topic">Results topic:</label></td>
				<td>{results_topic}</td>
			
				<td width="5">&nbsp;</td>
			
				<td><label for="teaminfo_topic">Team info topic:</label></td>
				<td>{teaminfo_topic}</td>
			
				<td width="5">&nbsp;</td>
			
				<td><label for="team_info_first_post">Team info first post:</label></td>
				<td>{team_info_first_post}</td>
			</tr>""".format(
			results_topic			= common.text_box('results_topic', the_team.results_topic, warn_on = lambda x:(True if x < 0 else False)),
			teaminfo_topic			= common.text_box('teaminfo_topic', the_team.teaminfo_topic, warn_on = lambda x:(True if x < 0 else False)),
			team_info_first_post	= common.text_box('team_info_first_post', the_team.team_info_first_post, warn_on = lambda x:(True if x < 0 else False)),
			))

	# Row 3
	output.append("""
			<tr>
				<td><label for="request_topic">Request topic:</label></td>
				<td>%(request_topic)s</td>
			
				<td width="5">&nbsp;</td>
			
				<td><label for="leader_id">Leader:</label></td>
				<td>%(leader_id)s</td>
			
				<td width="5">&nbsp;</td>
		
				<td>Culture topic:</td>
				<td>%(culture_topic)s</td>
			</tr>""" % {'leader_id':		common.text_box('leader_id', the_team.leader_id, warn_on = lambda x:(True if x < 1 else False)),
						'request_topic':	common.text_box('request_topic', the_team.request_topic, warn_on = lambda x:(True if x < 1 else False)),
						'culture_topic':	common.text_box('culture_topic', the_team.culture_topic, warn_on = lambda x:(True if x < 1 else False)),
					})
	
	output.append("""
	<tr>
		<td><label for="default_borders">Default borders:</label></td>
		<td>%(default_borders)s</td>
		
		<td width="5">&nbsp;</td>
		
		<td><label for="default_taxes">Default taxes:</label></td>
		<td>%(default_taxes)s</td>
		
		<td width="5">&nbsp;</td>
		
		<td><label for="evo_points">Evo points:</label></td>
		<td>%(evo_points)s</td>
	</tr>
	<tr>
		<td colspan="8" style="padding:0px;border-bottom:3px #EEE double;"></td>
	</tr>
	""" % {
		"default_borders":		common.option_box("default_borders", elements=team.border_states, selected=team.border_states[the_team.default_borders]),
		"default_taxes":		common.text_box('default_taxes', the_team.default_taxes, warn_on = lambda x:(True if int(x) < 0 else False), size=4),
		"evo_points":			common.text_box('evo_points', the_team.evo_points, warn_on = lambda x:(True if int(x) < 0 else False)),
	})
	
	output.append("""
			<!--
			<tr>
				<td>Previous resources:</td>
				<td>%(previous_resources)s</td>
			</tr>
			-->
	""" % {
		"previous_resources":	the_team.previous_resources,
		})
	
	# End row
	output.append("""
			<tr>
				<td>Join turn:</td>
				<td>%(join_turn)s</td>

				<td width="5">&nbsp;</td>

				<td>Primary:</td>
				<td>%(primary_colour)s</td>
			
				<td width="5">&nbsp;</td>

				<td>Secondary:</td>
				<td>%(secondary_colour)s</td>
			</tr>
		</table>
		<br />
	
		<input type="submit" value="Perform edit" />
		<input style="float:right; margin-right:100px;" type="button" value="Purge team" onclick="setTimeout('document.location=\\'web.py?mode=purge_team&team=%(team_id)s\\'', 0);"/>
	<a class="block_link" href="web.py?mode=ti&amp;post_output=1&amp;team=%(team_id)s">Update my TI</a>

	<br />""" % {
		"team_id":				team_id,
		'join_turn':			common.text_box('join_turn', the_team.join_turn),
		'previous_resources':	common.text_box('previous_resources', the_team.previous_resources, size=56),
	
		"primary_colour":		common.text_box('primary_colour', the_team.primary_colour),
		"secondary_colour":		common.text_box('secondary_colour', the_team.secondary_colour),
		})
		
	#	Resources
	#------------------------
	the_team.get_resources(cursor)
	
	output.append("""
	<table style="float:left; margin-right: 25px;" border="0" cellspacing="0" cellpadding="5">
	<tr class="row2">
		<th>Resource</th>
		<th>Amount</th>
	</tr>
	""")
	
	counter = -1
	for res_id, the_res in resource_list.data_dict.items():
		if the_res.category == resource_list.category['Map terrain feature']:
			continue
		
		# If it's not set then we need to give it a default
		if not res_id in the_team.resources.value:
			the_team.resources.value[res_id] = 0
		
		counter += 1
		
		output.append("""
		<tr class="row%(row)d">
			<td><label for="res_%(res_name)s">%(res_name)s</label></td>
			<td style="padding:1px;">%(res_amount)s</td>
		</tr>""" % {'row':			(counter % 2),
					'res_name':		the_res.name,
					'res_amount':	resource_f.print_form_element(res_id, the_team.resources[res_id])
					})
	
	output.append("</table></form>")# Subsequent forms are for other stuff
	
	#	Deities
	#----------------------
	the_team.get_deities(cursor)
	
	output.append("""
	<table style="float:left; margin-right: 25px;" border="0" cellspacing="0" cellpadding="5">
	<tr class="row2">
		<th>Deity</th>
		<th>&nbsp;</th>
	</tr>
	""")
	
	counter = -1
	for deity_id, team_favour in the_team.deities.items():
		counter += 1
		
		output.append("""
		<tr class="row%(row)d">
			<td><label for="%(name)s">%(name)s</label></td>
			<td style="padding: 0px;">
				<a class="block_link" href="exec.py?mode=remove_deity&amp;deity=%(deity_id)d&amp;team=%(team_id)d">Remove</a>
			</td>
		</tr>""" % {'row':			(counter % 2),
					'name':	deity_dict[deity_id].name,
					'deity_id':		deity_id,
					'team_id':		team_id
					})
	
	output.append("""
		<tr class="row%(row)d">
		<form id="team_add_deity_form" action="exec.py?mode=add_deity" method="post" accept-charset="utf-8">
			<input type="hidden" name="mode" value="add_deity" />
			<input type="hidden" name="team" value="%(team_id)s" />
			<td style="padding:1px;">
				<select name="deity">
					%(deity_option_box)s
				</select>
			</td>
			<td style="padding: 2px;">
				<input type="submit" value="Add" />
				<!--<a href="#" onclick="$('#team_add_deity_form').submit(); return false;" class="block_link">Add</a>-->
			</td>
		</tr>
		</form>
	</table>
	""" % {	'row':				((counter+1) % 2),
			'team_id':			the_team.id,
			'deity_option_box': deity_f.deity_option_list(cursor, the_team.deities)})
	
	
	#	Evolutions
	#-------------------
	the_team.get_evolutions(cursor)
	
	output.append("""
	<table style="float:left; margin-right: 25px;" border="0" cellspacing="0" cellpadding="5">
	<tr class="row2">
		<th>Evolution</th>
		<th>&nbsp;</th>
		<th>&nbsp;</th>
	</tr>
	""")
	
	counter = -1
	for evo_id, evo_level in the_team.evolutions.items():
		counter += 1
		
		output.append("""
		<tr class="row%(row)d">
			<form id="edit_evo_%(evolution_id)s" action="exec.py" method="post" accept-charset="utf-8">
			<input type="hidden" name="mode" value="set_evolution" />
			<input type="hidden" name="team" value="%(team_id)s" />
			<input type="hidden" name="evolution" value="%(evolution_id)s" />
			<td><label for="%(name)s">%(name)s</label></td>
			<td style="padding:1px;">
				%(text_box)s
			</td>
			</form>
			<td style="padding: 0px;">
				<a class="block_link" href="exec.py?mode=set_evolution&amp;evolution=%(evolution_id)d&amp;team=%(team_id)d">Remove</a>
			</td>
		</tr>""" % {'row':				(counter % 2),
					'name':				evolution_dict[evo_id].name,
					'evolution_level':	evo_level,
					'evolution_id':		evo_id,
					'team_id':			team_id,
					
					"text_box": common.text_box("evolution_level", evo_level, custom_id="", size=3,
						warn_on = lambda e: (True if evolution_dict[evo_id].min_level > e or e > evolution_dict[evo_id].max_level else False)),
					})
	
	output.append("""
		<tr class="row%(row)d">
		<form id="team_add_evolution_form" action="exec.py" method="post" accept-charset="utf-8">
			<input type="hidden" name="mode" value="set_evolution" />
			<input type="hidden" name="team" value="%(team_id)d" />
			<td style="padding:1px;">
				<select name="evolution">
					%(evolution_option_box)s
				</select>
			</td>
			<td style="padding:1px;">
				%(evolution_level)s
			</td>
			<td style="padding: 0px;">
				<a href="#" onclick="$('#team_add_evolution_form').submit();" class="block_link">Add</a>
			</td>
		</tr>
		</form>
	</table>
	""" % {	'row':				((counter+1) % 2),
			'team_id':			the_team.id,
			'evolution_level':	common.text_box('evolution_level', 0, 4),
			'evolution_option_box': evolution_f.evolution_option_list(cursor, the_team.evolutions)})
	
	
	#	Traits
	#----------------------
	the_team.get_traits(cursor)
	
	output.append("""
	<table style="float:left; margin-right: 25px;" border="0" cellspacing="0" cellpadding="5">
	<tr class="row2">
		<th>Trait</th>
		<th>&nbsp;</th>
	</tr>
	""")
	
	counter = -1
	for trait_id in the_team.traits:
		counter += 1
		
		output.append("""
		<tr class="row%(row)d">
			<td><label for="%(name)s">%(name)s</label></td>
			<td style="padding: 0px;">
				<a class="block_link" href="exec.py?mode=remove_trait&amp;trait=%(trait_id)d&amp;team=%(team_id)d">Remove</a>
			</td>
		</tr>""" % {'row':			(counter % 2),
					'name':			trait_dict[trait_id].name,
					'trait_id':		trait_id,
					'team_id':		team_id
					})
	
	output.append("""
		<tr class="row%(row)d">
		<form id="team_add_trait_form" action="exec.py?mode=add_trait" method="post" accept-charset="utf-8">
			<input type="hidden" name="mode" value="add_trait" />
			<input type="hidden" name="team" value="%(team_id)s" />
			<td style="padding:1px;">
				<select name="trait">
					%(trait_option_box)s
				</select>
			</td>
			<td style="padding: 2px;">
				<input type="submit" value="Add" />
				<!--<a href="#" onclick="$('#team_add_trait_form').submit(); return false;" class="block_link">Add</a>-->
			</td>
		</tr>
		</form>
	</table>
	""" % {	'row':				((counter+1) % 2),
			'team_id':			the_team.id,
			'trait_option_box': trait_f.trait_option_list(cursor, the_team.traits)})
	
	
	# Hashes
	output.append("""
	<table style="float:left; margin-right: 25px;" border="0" cellspacing="0" cellpadding="5">
	<tr class="row2">
		<th>Turn</th>
		<th>Hash</th>
	</tr>
	""")

	for i, t in enumerate(range(common.current_turn(), common.current_turn()-5, -1)):
		output.append("""
		<tr class="row{i}">
			<td>{t}</td>
			<td>{hash}</td>
		</tr>""".format(
			i = i % 2,
			t = t,
			hash = team_f.team_hash(the_team.name, turn=t),
	))
	
	output.append("</table>")
	
	
	

	
	output.append("</div>")
	page_data['Title'] = "Edit team (%s)" % the_team.name
	return "".join(output)
コード例 #4
0
ファイル: edit_battle.py プロジェクト: Teifion/Rob3
	</table>
	<br />
	<input type="submit" value="Perform edit" />
</form>
<form id="delete_form" action="exec.py" method="post" accept-charset="utf-8">
	<input type="hidden" name="battle" id="battle" value="%(battle_id)s" />
	<input type="hidden" name="mode" id="mode" value="remove_battle" />
	<input style="float:right; margin-right:100px;" type="button" value="Delete battle" onclick="var answer = confirm('Delete %(esc_name)s?')
	if (answer) $('#delete_form').submit();" />
</form>
<br /><br />""" % {
	"battle_id":					battle_id,
	"name":					the_battle.name,
	"esc_name":				common.js_name(the_battle.name,),
	"battle_turn":					the_battle.turn,
	"name_text":				common.text_box("name", the_battle.name, size=20),
	"battle_turn_text":				common.text_box("turn", the_battle.turn, size=5),
	"battle_city_select":			common.option_box(
		name='city',
		elements=names,
		element_order=city_list,
		custom_id="",
		selected=the_battle.city,
	),
	"battle_location_text":			common.text_box("location", new_location, 10),
})

#	Now for the participants of the battle
#------------------------
teams_dict		= team.get_teams_dict()
army_dict		= army.get_army_dict()
コード例 #5
0
ファイル: setup_battle.py プロジェクト: Teifion/Rob3
def main(cursor, battle_id = -1):
	battle_id = int(common.get_val('battle', battle_id))
	
	if battle_id < 1:
		return "No battle selected"
	
	the_battle = battle_q.get_one_battle(cursor, battle_id)
	
	# If we're being sent the info from the view_map page then this is the new location we need
	new_location = common.get_val('location', "")
	
	if new_location == "":
		new_location = "%s,%s" % (the_battle.x, the_battle.y)# default value
	
	# Get some other stuff
	cities_dict		= city_q.get_live_cities(cursor)
	team_dict		= team_q.get_all_teams(cursor)
	the_campaign	= campaign_q.get_one_campaign(cursor, the_battle.campaign)
	
	names = {0:"No city"}
	for c, the_city in cities_dict.items():
		names[c] = the_city.name
	
	city_keys = [0]
	city_keys.extend(list(cities_dict.keys()))
	
	output = ["<div style='padding: 5px;'>"]
	
	# output.append('<a href="web.py?mode=perform_battle&amp;battle={0}" class="block_link">Perform</a>'.format(battle_id))
	output.append("""
	<a href="web.py?mode=list_campaigns&amp;turn={turn}" class="block_link" style="display:inline; text-align:left;">Campaigns of this turn</a>
	<a href="web.py?mode=setup_campaign&amp;campaign={campaign_id}" class="block_link" style="display:inline;">Setup campaign</a>
	<a href="web.py?mode=list_battles&amp;campaign={campaign_id}" class="block_link" style="display:inline;">List battles</a>
	<a href="web.py?mode=perform_battle&amp;battle={battle_id}" class="block_link" style="display:inline;">Perform</a>
	<br /><br />
	<!-- PY -->
	<form action="exec.py" method="post" accept-charset="utf-8">
	<!-- PYEND -->
		<input type="hidden" name="mode" value="edit_battle_commit" />
		<input type="hidden" name="id" value="{battle_id}" />
		<input type="hidden" name="campaign" value="{campaign_id}" />
		
		Editing: {name_text}
		<br /><br />
		
		<table border="0" cellspacing="5" cellpadding="5">
			<tr>
				<td><label for="start">Start:</label></td>
				<td style="padding: 1px;">{battle_start_text}</td>
				
				<td width="5">&nbsp;</td>
				
				<td><label for="duration">Duration:</label></td>
				<td style="padding: 1px;">{battle_duration_text}</td>
			</tr>
			<tr>
				<td style="padding: 0px;">
					<a class="block_link" href="web.py?mode=view_map&amp;new_mode=setup_battle&amp;battle={battle_id}"">Location:</a>
				</td>
				<td style="padding: 1px;">{battle_location_text}</td>
				
				<td>&nbsp;</td>
				<td><label for="city">City:</label></td>
				<td style="padding: 1px;">{city_menu}</td>
			</tr>
			<tr>
				<td><label for="type">Type:</label></td>
				<td style="padding: 1px;">{type}</td>
				
				<td>&nbsp;</td>
				
				<td><label for="result">Result:</label></td>
				<td style="padding: 1px;">{result}</td>
			</tr>
		</table>
		<!-- PY -->
		<br />
		<input type="submit" value="Perform edit" />
	</form>
	<!-- PYEND -->
	<form id="delete_form" action="exec.py" method="post" accept-charset="utf-8">
		<input type="hidden" name="battle" id="battle" value="{battle_id}" />
		<input type="hidden" name="mode" id="mode" value="remove_battle" />
		<input style="float:right; margin-right:100px;" type="button" value="Delete battle" onclick="var answer = confirm('Delete {esc_name}?')
		if (answer) $('#delete_form').submit();" />
	</form>
	<br /><br />""".format(
		turn					= common.current_turn(),
		battle_id =				battle_id,
		campaign_id = 			the_battle.campaign,
		name =					the_battle.name,
		esc_name =				common.js_name(the_battle.name),
		name_text =				common.text_box("name", the_battle.name, size=20),
		battle_location_text	= common.text_box("location", new_location, 10),
		battle_start_text		= common.text_box("start", the_battle.start, 3),
		battle_duration_text	= common.text_box("duration", the_battle.duration, 3),
		city_menu				= common.option_box(
			name='city',
			elements=names,
			element_order=city_keys,
			custom_id="",
			selected=the_battle.city,
		),
		
		type = common.option_box("type", elements = battle.battle_types, element_order = [], selected=battle.battle_types[the_battle.type]),
		result = common.option_box("result", elements = battle.result_types, element_order = [], selected=battle.result_types[the_battle.result]),
	))
	
	output.append("</div>")
	
	return "".join(output)
コード例 #6
0
ファイル: list_armies.py プロジェクト: Teifion/Rob3
def main(cursor):
	# Get team Id
	team_id = int(common.get_val('team', 0))
	text_location = common.get_val('location', "")
	
	# Build team
	the_team = team_q.get_one_team(cursor, team_id)
	cities_dict = city_q.get_cities_from_team(cursor, team=team_id, include_dead=0)
	
	if team_id < 1:
		return "<div style='padding: 5px;'>%s</div>" %  common.select_team_form(cursor, 'list_armies')
		exit()
	
	armies_dict = army_q.get_armies_from_team(cursor, team=team_id, include_garrisons=1)
	
	output = []
	output.append("""
	<table border="0" cellspacing="0" cellpadding="5" style="width: 100%;">
		<tr class="row2">
			<th>Army</th>
			<th>Location</th>
			<th>Base</th>
			<th>Size</th>
			<th>&nbsp;</th>
			<th>&nbsp;</th>
		</tr>""")
	
	names = {}
	
	if len(armies_dict) > 0:
		count = -1
		
		# for team_id, team in team_dict.items():
		for army_id, the_army in armies_dict.items():
			count += 1
			
			city_location = the_army.garrison
			
			if the_army.garrison > 0:
				location = "Garrison"
			
			else:
				location = "%s, %s" % (the_army.x, the_army.y)
			
			if the_army.base in cities_dict:
				base_name = cities_dict[the_army.base].name
			else:
				base_name = "N/A"
			
			output.append("""
			<tr class="row%(row)d" id="%(army_id)d">
				<td><strong>%(name)s</strong></td>
				<td>%(location)s</td>
				<td>%(base)s</td>
				<td>%(size)s</td>
				
				<td style="padding: 0px;">
					<a class="block_link" id="show_squads_%(army_id)d" href="#" onclick="$('#div_%(army_id)d').load('web.py', {'mode':'list_squads', 'ajax':'True', 'army':'%(army_id)d'}, function () {$('#tr_%(army_id)d').fadeIn(0); $('#show_squads_%(army_id)d').fadeOut(0); $('#hide_squads_%(army_id)d').fadeIn(0);}); return false;">Show squads</a>
				<a id="hide_squads_%(army_id)d" style="display:none;" class="block_link" href="#" onclick="$('#tr_%(army_id)d').fadeOut(0); $('#show_squads_%(army_id)d').fadeIn(0); $('#hide_squads_%(army_id)d').fadeOut(0); return false;">Hide squads</a></td>
				
				<td style="padding: 0px;"><a class="block_link" href="web.py?mode=edit_army&amp;army=%(army_id)d">Edit army</a></td>
			</tr>
			<tr style="display: none;" id="tr_%(army_id)d">
				<td colspan="5" style="padding: 0 10px 10px 10px;">
					<div id="div_%(army_id)d">
						&nbsp;
					</div>
				</td>
			</tr>
			""" % {	'row': (count % 2),
					
					"army_id":		army_id,
					"name":			common.doubleclick_text("armies", "name", army_id, the_army.name, "font-weight:bold", size=18),
					"base":			base_name,
					"location":		location,
					"size":			the_army.get_size(cursor),
					})
	
	# Add new army thingie
	names = {}
	for c, the_city in cities_dict.items():
		names[c] = the_city.name
	
	count += 1
	output.append("""
	<tr class="row%(row)d">
		<form action="exec.py" id="add_army_form" method="post" accept-charset="utf-8">
		<input type="hidden" name="mode" value="add_army" />
		<input type="hidden" name="team" value="%(team_id)s" />
		<td style="padding: 1px;"><input type="text" id="new_name" name="name" value="" /></td>
		<td>&nbsp;</td>
		<td style="padding: 1px;">
			%(city_location)s
			&nbsp;&nbsp;&nbsp;
			%(text_location)s
		</td>
		<td style="padding: 0px;"><a href="web.py?mode=view_map&amp;new_mode=list_armies&amp;team=%(team_id)s" class="block_link">Pick location</a></td>
		<td colspan="2" style="padding: 0px;"><a class="block_link" href="#" onclick="$('#add_army_form').submit(); return false;">Add</a></td>
		</form>
		%(onload)s
	</tr>
	""" % {	'row': (count % 2),
			
			"team_id":			team_id,
			'city_location':	common.option_box(
				name='city_location',
				elements=names,
				element_order=cities_dict.keys(),
				custom_id="",
			),
			
			"text_location":	common.text_box("text_location", text_location, custom_id=""),
			"onload":			common.onload("$('#new_name').focus();")
			})	
	
	output.append("</table>")
	
	return "".join(output)
コード例 #7
0
ファイル: setup_campaign.py プロジェクト: Teifion/Rob3
def main(cursor, campaign_id=-1):
	output = ['<div style="padding: 5px;">']
	
	grab_coords = common.get_val('coords', '')
	radius = int(common.get_val('radius', 10))
	
	if grab_coords != '' and radius > 0:
		# 138, 1224
		grabbed_armies = grab_armies(cursor, grab_coords, radius)
	else:
		grabbed_armies = ""
	
	campaign_id = int(common.get_val('campaign', campaign_id))
	if campaign_id < 1:
		return "No city selected"
	
	# Get stuff from DB
	the_campaign = campaign_q.get_one_campaign(cursor, campaign_id)
	team_dict = team_q.get_all_teams(cursor)
	city_dict = city_q.get_cities_for_dropdown(cursor)
	battle_dict = battle_q.get_battles_from_campaign(cursor, campaign_id)
	
	if len(battle_dict) < 1:
		return common.redirect("web.py?mode=list_battles&campaign=%d" % campaign_id)
	
	# last_battle = battle_dict[list(battle_dict.keys())[-1]]
	last_battle = battle_q.get_last_battle_from_campaign(cursor, campaign_id)
	if not last_battle:
		return common.redirect("web.py?mode=list_battles&campaign=%d" % campaign_id)
	
	# coords_cities
	coords_cities = ['<select name="coords">']
	for city_id, the_city in city_dict.items():
		if city_id == last_battle.city:
			coords_cities.append("<option value='%s,%s' selected='selected'>%s</option>" % (the_city.x, the_city.y, the_city.name))
		else:
			coords_cities.append("<option value='%s,%s'>%s</option>" % (the_city.x, the_city.y, the_city.name))
	
	coords_cities.append("</select>")
	coords_cities = "".join(coords_cities)
	
	output.append("""
	<a href="web.py?mode=list_campaigns&amp;turn={turn}" class="block_link" style="display:inline; text-align:left;">Campaigns of this turn</a>
	<a href="web.py?mode=list_battles&amp;campaign={id}" class="block_link" style="display:inline;">List battles</a>
	<a href="web.py?mode=perform_battle&amp;battle={last_battle}" class="block_link" style="display:inline;">Last battle</a>
	<br /><br />
	<form action="exec.py" id="mass_add_army_form" method="post" accept-charset="utf-8" style="display:block; float:right; border: 0px solid #000; margin-right:20px;">
		<strong>Mass add units</strong><br />
		<input type="hidden" name="mode" value="mass_add_armies" />
		<input type="hidden" name="campaign" value="{id}" />
		{team_list}
		<br />
		<textarea name="army_names" rows="10" cols="40">{grabbed_armies}</textarea>
		<br />
		<input type="submit" value="Add armies" />
		<br /><br />
	</form>
	
	<form action="web.py" id="grab_armies_form_cities" method="get" accept-charset="utf-8" style="display:block; float:right; border: 0px solid #000; margin-right:20px;">
		<strong>Grab armies</strong><br />
		<input type="hidden" name="mode" value="setup_campaign" />
		<input type="hidden" name="campaign" value="{id}" />
		<label for="coords">Coords: </label>{coords_cities}<br />
		<label for="radius">Radius: </label><input type="text" name="radius" id="radius" value="10" /><br />
		<input type="submit" value="Grab armies" />
		<br /><br />
	</form>
	
	<form action="web.py" id="grab_armies_form" method="get" accept-charset="utf-8" style="display:block; float:right; border: 0px solid #000; margin-right:20px;">
		<strong>Grab armies</strong><br />
		<input type="hidden" name="mode" value="setup_campaign" />
		<input type="hidden" name="campaign" value="{id}" />
		<label for="coords">Coords: </label><input type="text" name="coords" id="coords" value="{default_coods}" /><br />
		<label for="radius">Radius: </label><input type="text" name="radius" id="radius" value="10" /><br />
		<input type="submit" value="Grab armies" />
		<br /><br />
	</form>
	
	<form action="exec.py" method="post" accept-charset="utf-8">
		<input type="hidden" name="mode" id="mode" value="setup_campaign_commit" />
		<input type="hidden" name="id" id="id" value="{id}" />
		
		Editing: {name_text}
		<br /><br />
		
		<table border="0" cellspacing="5" cellpadding="5">
			<tr>
				<td><label for="turn">Turn:</label></td>
				<td style="padding: 1px;">{turn_text}</td>
				
				<td width="5">&nbsp;</td>
				
				<td><label for="turn">Sides:</label></td>
				<td style="padding: 1px;">{sides_text}</td>
			</tr>
		</table>
		<br />
		<input type="submit" value="Perform edit" />
	</form>
	<br /><br />""".format(
		id =					campaign_id,
		name =					the_campaign.name,
		turn =					the_campaign.turn,
		name_text =				common.text_box("name", the_campaign.name, size=20),
		turn_text =				common.text_box("turn", the_campaign.turn, size=5),
		sides_text =			common.text_box("sides", the_campaign.sides, size=5),
		team_list				= team_f.structured_list(cursor, include_irs=True),
		grabbed_armies			= grabbed_armies,
		last_battle				= last_battle.id,
		coords_cities			= coords_cities,
		default_coods			= "%s, %s" % (last_battle.x, last_battle.y),
	))
	
	# Sides and teams
	side_form = ['<select id="side_menu">']
	
	for s in range(1, the_campaign.sides+1):
		side_form.append('<option value="{s}">{s}</option>'.format(s=s))
	
	side_form.append("</select>")
	side_form = "".join(side_form)
	
	# Form JS
	js = """
	var side = $("#side_menu").attr("value");
	var team_id = $("#new_team").attr("value");
	var team_name = $("#new_team :selected").text();
	
	team_list_content = $("#team_list_" + side).html();
	
	if (team_list_content != "")
	{
		$("#team_list_" + side).html(team_list_content + ", " + team_name);
	}
	else
	{
		$("#team_list_" + side).html(team_name);
	}
	
	$("#ajax_target").load("exec.py", {mode: "add_team_to_campaign", campaign: %s, side: side, team: team_id});
	$("#new_team").focus();
	return false;
	""" % campaign_id
	
	js = js.replace("\t", "").replace("\n", "")
	
	output.append('''
	<form action="" onsubmit='{js}' method="post" accept-charset="utf-8">
		{team_list}
		{side}
		
		<input type="submit" value="Add" />
	</form>
	
	<!-- PY -->
	<form action="exec.py" method="post" accept-charset="utf-8">
		<input type="hidden" name="mode" value="edit_campaign_armies" />
		<input type="hidden" name="campaign" value="{c}" />
		<input type="submit" value="Apply armies" />
		<!-- PYEND -->
		<table border="0" cellspacing="0" cellpadding="5" style="width:99%">
			<tr class="row2">
				<th width="15">#</th>
				<th>Teams</th>
			</tr>
	'''.format(
		c=campaign_id,
		team_list=team_f.structured_list(cursor, include_irs=True, field_id="new_team"),
		side=side_form,
		js=js,
	))
	
	army_ids = []
	
	the_campaign.get_sides_full(cursor)
	the_campaign.get_armies_full(cursor)
	campaign_armies = campaign_q.get_campaign_armies_from_turn(cursor, the_campaign.turn)
	teams_on_side_str = []
	for s in range(1, the_campaign.sides+1):
		teams_on_side = the_campaign.sides_full[s]
		
		if len(teams_on_side) > 0:
			teams_on_side_str = ['<table border="0" cellspacing="0" cellpadding="5" width="100%">']
			for t in teams_on_side:
				where = "campaign=%d and team=%d" % (campaign_id, t['team'])
				
				# Display "make secret" or "make public"
				public_display, secret_display = "", ""
				if t['secret']:	secret_display	= "display: none;"
				else:			public_display	= "display: none;"
				
				teams_on_side_str.append("""
				<tr id="team_row_{t}" class="row1">
					<td width="100">{name}</td>
					<td width="65">
						{started}
						-&gt;
						{finished}
					</td>
					<td>{remove}</td>
					<td>
					<a href="#" id="team_public_{t}"
						onclick="$('#ajax_target').load('web.py', {{mode:'campaign_team_public', team:{t}, campaign:{c}}}); {show_hide} return false;" class="mini_link" style="{public_display}">Make public</a>
					<a href="#" id="team_secret_{t}"
						onclick="$('#ajax_target').load('web.py', {{mode:'campaign_team_secret', team:{t}, campaign:{c}}}); {show_hide} return false;" class="mini_link" style="{secret_display}'">Make secret</a>
					</td>
				</tr>
				""".format(
					t = t['team'],
					c = campaign_id,
					name=team_dict[t['team']].name,
					started=common.doubleclick_text_full("campaign_teams", "started", where, t['started'], size=2),
					finished=common.doubleclick_text_full("campaign_teams", "finished", where, t['finished'], size=2),
					remove='''<a href="#" onclick='$("#ajax_target").load("exec.py", {mode: "remove_team_from_campaign", campaign: %d, team: %d, side: %d}); $("#team_row_%d").hide(); return false;'>Remove</a>''' % (campaign_id, t['team'], s, t['team']),
					
					show_hide = "$('#team_public_%d').toggle(); $('#team_secret_%d').toggle();" % (t['team'], t['team']),
					
					public_display = public_display,
					secret_display = secret_display,
				))
				
				# Now to put in the armies form
				army_form = []
				garrison_form = []
				
				team_armies = army_q.get_armies_from_team(cursor, t['team'], include_garrisons=True)
				# the_campaign.get_armies_full
				for army_id, the_army in team_armies.items():
					selected = False
					start_finish = ""
					
					if army_id in the_campaign.armies_full:
						selected = True
						where = "campaign=%d and army=%d" % (campaign_id, army_id)
						
						start_finish = "%s -&gt; %s" % (
							common.doubleclick_text_full("campaign_armies", "started", where, the_campaign.armies_full[army_id]['started'], size=2),
							common.doubleclick_text_full("campaign_armies", "finished", where, the_campaign.armies_full[army_id]['finished'], size=2))
					
					# Is it selected?
					if selected:
						checked = "checked='checked'"
						rclass = "selected_army"
					else:
						checked = ""
						rclass = ""
					
					# Is it being used elsewhere this turn?
					elsewhere = "<td>&nbsp;</td>"
					if army_id in campaign_armies:
						if campaign_id in campaign_armies[army_id]:
							elsewhere_count = len(campaign_armies[army_id]) - 1
						else:
							elsewhere_count = len(campaign_armies[army_id])
						
						if elsewhere_count == 1:
							elsewhere = "<td style='background-color:#700;'>&nbsp;</td>"
						elif elsewhere_count == 2:
							elsewhere = "<td style='background-color:#B00;'>&nbsp;</td>"
						elif elsewhere_count > 2:
							elsewhere = "<td style='background-color:#F00;'>&nbsp;</td>"
					
					army_s = '''<tr id="row_{a}" class="{rclass}">
					<td><label for="a_{a}" style="width:100%; display:block;">{name}</label></td>
					<td><input type="checkbox" name="a_{a}" id="a_{a}" value="True" onchange="if ($('#a_{a}').attr('checked')) {{$('#row_{a}').addClass('selected_army');}} else {{$('#row_{a}').removeClass('selected_army');}}" {checked}/></td>
					<td>{start_finish}&nbsp;&nbsp;</td>
					{elsewhere}
					</tr>'''.format(
						a = army_id,
						name = the_army.name,
						# cb = common.check_box("a_%d" % army_id, checked=selected),
						start_finish=start_finish,
						checked = checked,
						rclass = rclass,
						elsewhere = elsewhere,
					)
					
					if the_army.garrison:
						garrison_form.append(army_s)
					else:
						army_form.append(army_s)
					
					army_ids.append(army_id)
				
				
				teams_on_side_str.append("""
				<tr>
					<td colspan="4">
						<table border="0" cellspacing="0" cellpadding="0">
							<tr>
								<td width="300">
									<table border="0" cellspacing="0" cellpadding="3">
										{armies}
									</table>
								</td>
								<td>
									<table border="0" cellspacing="0" cellpadding="3">
										{garrisons}
									</table>
								</td>
								<td>
									&nbsp;
								</td>
							</tr>
						</table>
					</td>
				</tr>""".format(
					armies = "".join(army_form), 
					garrisons = "".join(garrison_form),
					
					c_id = campaign_id,
					team = t['team'],
				))
			
			teams_on_side_str.append("</table>")
		
		output.append("""
		<tr>
			<td colspan="2"><hr /></td>
		</tr>
		<tr>
			<td><strong>{s}</strong></td>
			<td>
				{teams}
				<br />
				<span id="team_list_{s}"></span>
			</td>
		</tr>
		""".format(
			s=s,
			teams="".join(teams_on_side_str),
			# teams=", ".join([team_dict[t].name for t in teams_on_side]),
		))
	
	# Field for the ids of the armies listed that we need to sort out
	output.append('<input type="hidden" name="army_ids" value="%s" />' % ",".join([str(a) for a in army_ids]))	
	output.append('<!-- PY --><tr><td colspan="2"><input type="submit" value="Apply armies" /></td></tr><!-- PYEND -->')
	output.append('''</table>
	<!-- PY --></form><!-- PYEND -->
	<br />''')
	
	# Delete button
	output.append("""
	<form id="delete_form" action="exec.py" method="post" accept-charset="utf-8">
		<input type="hidden" name="campaign" id="campaign" value="{id}" />
		<input type="hidden" name="mode" id="mode" value="remove_campaign" />
		<input style="float:right; margin-right:100px;" type="button" value="Delete campaign" onclick="var answer = confirm('Delete {esc_name}?')
		if (answer) $('#delete_form').submit();" />
	</form>""".format(
		id =					campaign_id,
		esc_name =				common.js_name(the_campaign.name),
	))
	
	output.append(common.onload("$('#new_team').focus();"))
	output.append('<a href="web.py?mode=list_battles&amp;campaign=%d" class="block_link">List battles</a>' % campaign_id)
	output.append("</div>")
	
	return "".join(output)
コード例 #8
0
ファイル: edit_army.py プロジェクト: Teifion/Rob3
def main(cursor):
	army_id = int(common.get_val('army', 0))
	garrison_id = int(common.get_val('garrison', 0))
	
	if army_id < 1 and garrison_id > 0:
		the_army = army_q.get_one_garrison(cursor, garrison_id)
	else:
		the_army = army_q.get_one_army(cursor, army_id)
	
	# If we're being sent the info from the view_map page then this is the new location we need
	new_location = common.get_val('location', "")
	
	if new_location == "":
		new_location = "%s,%s" % (the_army.x, the_army.y)# default value
		last_location = "%s,%s" % (the_army.old_x, the_army.old_y)
	
	if the_army.garrison > 0:
		new_location = """
		<td><label for="garrison">Garrison:</label></td>
		<td>%s</td>
		""" % (city_q.get_one_city(cursor, the_army.garrison).name)
	else:
		new_location = """
		<td style="padding: 0px;"><a href="web.py?mode=view_map&new_mode=edit_army&amp;army=%s" class="block_link">Location:</a></td>
		<td style="padding: 1px;">%s</td>""" % (the_army.id, common.text_box("location", new_location))
	
	output = []
	
	output.append("""<div style="float: right; width: 50%%;">
		<strong>Squads in army</strong>
		<div id="army_squads">
			
		</div>
	</div>""")
	
	output.append("<div style='padding: 5px;'>")
	
	if the_army.base > 0:
		base_name = "%s (%d)" % (city_q.get_one_city(cursor, the_army.base).name, the_army.base)
	else:
		base_name = "None"
	
	output.append("""
	<form action="exec.py" id="the_army_form" method="post" accept-charset="utf-8">
		<input type="hidden" name="mode" id="mode" value="edit_army_commit" />
		<input type="hidden" name="id" id="id" value="%(army_id)s" />
		
		Editing: %(name_text)s
		<br /><br />
		
		<table border="0" cellspacing="5" cellpadding="5">
			<tr>
				<td><label for="team">Team:</label></td>
				<td style="padding: 1px;">%(owner_select)s</td>
				
				<td width="5">&nbsp;</td>
				
				%(location)s
			</tr>
			<tr>
				<td>&nbsp;</td>
				<td>&nbsp;</td>
				
				<td width="5">&nbsp;</td>
				
				<td>Last location:</td>
				<td>%(last_location)s</td>
			</tr>
			<tr>
				<td>Base:</td>
				<td>%(base)s</td>
				
				<td width="5">&nbsp;</td>
				
				<td>Distance:</td>
				<td>%(distance)s</td>
			</tr>
			<tr>
				<td colspan="5" style="padding: 0;"><a class="block_link" href="#" onclick="$('#the_army_form').submit();">Apply changes</a></td>
			</tr>
		</table>
	</form>
	<form id="delete_form" action="exec.py" method="post" accept-charset="utf-8">
		<input type="hidden" name="army" id="army" value="%(army_id)s" />
		<input type="hidden" name="mode" id="mode" value="remove_army" />
		<input style="float:right; margin-right:100px;" type="button" value="Delete army" onclick="var answer = confirm('Delete %(name_safe)s?')
		if (answer) $('#delete_form').submit();" />
	</form>
	<br /><br />""" % {
		"name_safe":		common.js_name(the_army.name),
		"army_id":			the_army.id,
		"name":				the_army.name,
		"name_text":		common.text_box("name", the_army.name),
		"owner_select":		team_f.structured_list(cursor, default=the_army.team),
		"location":			new_location,
		"last_location":	last_location,
		"base":				base_name,
		"distance":			the_army.distance,
	})
	
	output.append(common.onload("$('#army_squads').load('web.py', {'mode':'list_squads','army':'%d', 'ajax':'True'});" % int(the_army.id)))
	
	output.append("</div>")
	
	page_data['Title'] = "Edit army %s" % the_army.name
	return "".join(output)
コード例 #9
0
ファイル: edit_player.py プロジェクト: Teifion/Rob3
def main(cursor):
	player_id	= int(common.get_val('player', 0))
	
	if player_id < 1:
		return "No player selected"
	
	the_player = player_q.get_one_player(cursor, player_id)
	
	output = ["<div style='padding: 5px;'>"]
	
	output.append("""
	<form action="exec.py" method="post" accept-charset="utf-8">
		<input type="hidden" name="mode" id="mode" value="edit_player_commit" />
		<input type="hidden" name="id" id="id" value="%(player_id)s" />
		
		<table border="0" cellspacing="5" cellpadding="5">
			<tr>
				<td><label for="name">Name:</label></td>
				<td>%(name_text)s</td>
				
				<td colspan="3">&nbsp;</td>
			</tr>
			<tr>
				<td><label for="team">Team:</label></td>
				<td>%(team)s</td>
				
				<td>&nbsp;</td>
				
				<td><label for="ir">IR:</label></td>
				<td>%(ir)s</td>
			</tr>
			<tr>
				<td>&nbsp;</td>
				<td>&nbsp;</td>
				
				<td colspan="3">&nbsp;</td>
			</tr>	
			<tr>
				<td><label for="last_posted">Last posted:</label></td>
				<td>%(last_posted_text)s</td>
				
				<td colspan="3">&nbsp;</td>
			</tr>
			<tr>
				<td><label for="daemon_type">Daemon type:</label></td>
				<td>%(daemon_type)s</td>
				
				<td colspan="3">&nbsp;</td>
			</tr>
			<tr>
				<td><label for="progression">Progression:</label></td>
				<td>%(progression)s</td>
				
				<td colspan="3">&nbsp;</td>
			</tr>
			<tr>
				<td><label for="not_a_player">Not a player:</label></td>
				<td>%(not_a_player)s</td>
				
				<td>&nbsp;</td>
				
				<td><label for="not_surplus">Not surplus:</label></td>
				<td>%(not_surplus)s</td>
			</tr>
		</table>
		<br />
		<input type="submit" value="Perform edit" />
	</form>
	<br /><br />""" % {
		"player_id":		player_id,
		"name":				the_player.name,
		"team":				team_f.structured_list(cursor, default=the_player.team, field_name="team"),
		"name_text":	common.text_box("name", the_player.name, size=20),
		"last_posted_text":	common.text_box("last_posted", the_player.last_posted),
		"not_a_player":		common.check_box("not_a_player", the_player.not_a_player),
	
		"daemon_type":		common.option_box("daemon_type", elements=player.daemon_types, selected=player.daemon_types[the_player.daemon_type]),
		"progression":		common.option_box("progression", elements=player.progressions, selected=player.progressions[the_player.progression]),
		
		"not_surplus":		common.check_box("not_surplus", the_player.not_surplus),
		"ir":				common.check_box("ir", the_player.ir),
		
		# option_box(name, elements = {}, element_order = [], tab_index = -1, onchange="", custom_id = "<>", selected=""):
	})
	
	# This get's ajax'd
	output.append("""
	<div style="clear: left;">
		<br /><br />
		<span class="stitle">Player powers</span>
		<div id="player_powers">
			
		</div>
		<br /><br />
		<span class="stitle">Player kills/deaths</span><br />
		<div id="player_kills" style="float:left; width:49%; border: 0px solid #000;">
			&nbsp;
		</div>
		<div id="player_deaths" style="float:right; width:49%; border: 0px solid #000;">
			&nbsp;
		</div>
		<br /><br />
	</div>""")
	
	# End of padding
	output.append("</div>")
	
	# Load in the player powers
	output.append(common.onload("""
		$('#player_powers').load('web.py', {'mode':'list_powers','player':'%d', 'ajax':'True'});
		$('#player_kills').load('web.py', {'mode':'player_kills','killer':'%d', 'player':'%d', 'ajax':'True'});
		$('#player_deaths').load('web.py', {'mode':'player_kills','victim':'%d', 'player':'%d', 'ajax':'True'});
	""" % (player_id, player_id, player_id, player_id, player_id)))
	
	return "".join(output)
コード例 #10
0
ファイル: edit_unit.py プロジェクト: Teifion/Rob3
def main(cursor):
	# Get team Id
	unit_id = int(common.get_val('unit', 0))
	
	if unit_id < 1:
		return "No unit selected"
	
	the_unit	= unit_q.get_one_unit(cursor, unit_id)
	army_dict	= army_q.get_all_armies(cursor)#get_armies_from_team(cursor, the_unit.team, include_garrisons=True)
	squad_dict	= squad_q.get_squads_from_team_of_type(cursor, the_unit.team, unit_id)
	equipment_dict = equipment_q.get_all_equipment(cursor)
	
	page_data['Title'] = "Edit unit: %s" % the_unit.name
	
	output = ["<div style='padding: 5px;'>"]
	
	# Unit cost breakdown
	unit_cost_breakdown = unit_rules.print_unit_cost(the_unit, cursor=cursor, breakdown_mode=True)
	
	w = world.World(cursor)
	real_cost = "Post override: %s/%s" % (
		unit_rules.unit_cost_override(w, the_unit, the_unit.costs['material_cost'], w.teams()[the_unit.team]),
		unit_rules.unit_cost_override(w, the_unit, the_unit.costs['iron_cost'], w.teams()[the_unit.team]),
	)
	real_upkeep = "Post override: %s/%s" % (
		unit_rules.unit_upkeep_override(w, the_unit, the_unit.costs['material_cost'], w.teams()[the_unit.team]),
		unit_rules.unit_upkeep_override(w, the_unit, the_unit.costs['iron_cost'], w.teams()[the_unit.team]),
	)
	# real_cost = 0
	# real_upkeep = 0
	
	output.append("""
	<div style="float: right; width: 50%;">
		<strong>Unit cost breakdown</strong><br />
		{cost_breakdown}<br />
		{real_cost}
		<br /><br />
	
		<strong>Unit upkeep breakdown</strong><br />
		{upkeep_breakdown}<br />
		{real_upkeep}
		<br /><br />
		
		<strong>Unit categories</strong><br />
		Type category: {type_cat}<br />
		Weapon category: {weapon_cat}<br />
		
		
		<br />
		<form id="delete_form" action="exec.py" method="post" accept-charset="utf-8">
			<input type="hidden" name="unit" id="unit" value="{unit_id}" />
			<input type="hidden" name="mode" id="mode" value="remove_unit" />
			<input style="float:right; margin-right:100px;" type="button" value="Delete unit" onclick="var answer = confirm('Delete {name}?')
			if (answer) $('#delete_form').submit();" />
		</form>
	</div>
	""".format(
		cost_breakdown		= "<br />".join(unit_cost_breakdown['cost']),
		upkeep_breakdown	= "<br />".join(unit_cost_breakdown['upkeep']),
		real_cost			= real_cost,
		real_upkeep			= real_upkeep,
		
		unit_id				= unit_id,
		name				= the_unit.name,
		
		type_cat			= unit.categories[the_unit.type_cat],
		weapon_cat			= unit.weapon_categories[the_unit.weapon_cat],
	))
	
	# Main unit stuff
	output.append("""
	<form action="exec.py" id="the_unit_form" method="post" accept-charset="utf-8">
		<input type="hidden" name="mode" value="edit_unit_commit" />
		<input type="hidden" name="id" value="%(unit_id)s" />
	
		<table border="0" cellspacing="5" cellpadding="5">
			<tr>
				<td><label for="name">Unit:</label></td>
				<td>%(name_text)s</td>
			
				<td>&nbsp;</td>
			
				<td><label for="team">Team:</label></td>
				<td>
					<select name="team" id="team">
						<option value="0">No team</option>
						%(team_option_box)s
					</select>
				</td>
			</tr>
			<tr>
				<td colspan="5" style="padding: 0px;"><a class="block_link" href="#" onclick="$('#the_unit_form').submit();">Apply changes</a></td>
			</tr>
		</table>
	</form>
	<br />

	""" % {
		"unit_id":			unit_id,
		"name_text":	common.text_box("name", the_unit.name),
		"team_option_box":	team_f.structured_list(cursor, default=the_unit.team),
	})
	
	# Unit equipment
	output.append("""
	<span class="stitle" id="equipment">Equipment</span>
	<table border="0" cellspacing="0" cellpadding="5">
		<tr class="row2">
			<th>Item</th>
			<th>&nbsp;</th>
		</tr>""")

	the_unit.get_equipment(cursor)

	counter = -1
	for e in the_unit.equipment:
		counter += 1
		output.append("""
		<tr class="row%(row)s">
			<td>%(item_name)s</td>
			<td style="padding: 0px;">
				<form action="exec.py" id="form_%(item_id)s" method="post" accept-charset="utf-8">
					<input type="hidden" name="mode" value="remove_equipment" />
					<input type="hidden" name="unit" value="%(unit_id)s" />
					<input type="hidden" name="item" value="%(item_id)s" />
					<a href="#" class="block_link" onclick="$('#form_%(item_id)s').submit();">Remove</a>
				</form>
			</td>
		</tr>""" % {
			"row":			counter%2,
			"item_name":	equipment_dict[e].name,
			"unit_id":		unit_id,
			"item_id":		e,
		})

	counter += 1
	output.append("""
	<tr class="row%(row)s">
		<form action="exec.py" id="new_equipment_form" method="post" accept-charset="utf-8">
			<input type="hidden" name="mode" value="add_equipment" />
			<input type="hidden" name="unit" value="%(unit_id)s" />
			<td>
				<select name="item">
					%(equipment_list)s
				</select>
			</td>
			<td>
				<input type="submit" value="Apply" />
			</td>
		</form>
	</tr>
	""" % {
		"row":				counter%2,
		"unit_id":			unit_id,
		"equipment_list":	equipment_f.equipment_option_list(cursor, remove_list=the_unit.equipment),
	})

	output.append("</table>")
	
	# What squads does the unit appear in?
	output.append("""
	<br /><br />
	<span class="stitle" id="squads">Squads</span>
	<table border="0" cellspacing="0" cellpadding="5">
		<tr class="row2">
			<th>Army</th>
			<th>Squad</th>
			<th>Size</th>
			<th>&nbsp;</th>
			<th>&nbsp;</th>
		</tr>""")

	the_unit.get_equipment(cursor)
	
	counter = -1
	for s, the_squad in squad_dict.items():
		counter += 1
		output.append("""
		<tr class="row%(row)s">
			<td>%(army_name)s</td>
			<td>%(name)s</td>
			<td>%(squad_size)s</td>
			<td style="padding: 0px;">
				<a href="web.py?mode=edit_army&amp;army=%(army_id)s" class="block_link">Edit army</a>
			</td>
			<td style="padding: 0px;">
				<a href="web.py?mode=edit_squad&amp;squad=%(squad_id)s" class="block_link">Edit squad</a>
			</td>
		</tr>""" % {
			"row":			counter%2,
			"army_name":	army_dict[the_squad.army].name,
			"army_id":		the_squad.army,
			"squad_id":		s,
			"name":			the_squad.name,
			"squad_size":	the_squad.amount,
		})
	
	output.append("</table>")
	output.append("</div>")
	
	return "".join(output)
コード例 #11
0
ファイル: edit_artefact.py プロジェクト: Teifion/Rob3
def main(cursor):
	artefact_id = int(common.get_val('artefact', 0))
	all_teams	= int(common.get_val('all_teams', 0))
	
	if artefact_id < 1:
		return "No artefact selected"
	
	the_artefact = artefact_q.get_one_artefact(cursor, artefact_id)
	
	names = {}
	if all_teams == 0 and the_artefact.team > 0:
		cities_dict = city_q.get_cities_from_team(cursor, team=the_artefact.team, include_dead=1)
		for c, the_c in cities_dict.items():
			names[c] = the_c.name
	else:
		cities_dict = city_q.get_live_cities(cursor)
		for c, the_c in cities_dict.items():
			names[c] = the_c.name
	
	output = ["<div style='padding: 5px;'>"]
	
	if all_teams != 1:
		output.append("""<a class="block_link" href="web.py?mode=edit_artefact&amp;artefact=%s&amp;all_teams=1">Show all team cities</a>""" % artefact_id)
	else:
		output.append("""<a class="block_link" href="web.py?mode=edit_artefact&amp;artefact=%s&amp;all_teams=0">Show only this team's cities</a>""" % artefact_id)
	
	output.append("""
	<form action="exec.py" method="post" accept-charset="utf-8">
		<input type="hidden" name="mode" id="mode" value="edit_artefact_commit" />
		<input type="hidden" name="id" id="id" value="%(artefact_id)s" />
	
		<table border="0" cellspacing="5" cellpadding="5">
			<tr>
				<td><label for="name">Name:</label></td>
				<td>%(name_text)s</td>
		
				<td width="5">&nbsp;</td>
			
				<td><label for="city">City:</label></td>
				<td>%(city_menu)s</td>
			</tr>
			<tr>
				<td><label for="description">Description:</label></td>
				<td colspan="5">%(artefact_description_text)s</td>
			</tr>
		</table>
		<br />
		<input type="submit" value="Perform edit" />
	</form>
	<!--
	<form id="delete_form" action="exec.py" method="post" accept-charset="utf-8">
		<input type="hidden" name="artefact" id="artefact" value="%(artefact_id)s" />
		<input type="hidden" name="mode" id="mode" value="remove_artefact" />
		<input style="float:right; margin-right:100px;" type="button" value="Delete artefact" onclick="var answer = confirm('Delete %(name)s?')
		if (answer) $('#delete_form').submit();" />
	</form>
	-->
	<br /><br />""" % {
		"artefact_id":					artefact_id,
		"name":				the_artefact.name,
		"city_menu":					common.option_box(
			name='city',
			elements=names,
			element_order=cities_dict.keys(),
			custom_id="",
			selected=the_artefact.city,
		),
		"name_text":			common.text_box("name", the_artefact.name, size=20),
		"artefact_description_text":	'<textarea name="description" id="description" rows="4" cols="40">%s</textarea>' % the_artefact.description,
	})
	
	output.append("</div>")
	
	return "".join(output)
コード例 #12
0
ファイル: edit_city.py プロジェクト: Teifion/Rob3
def main(cursor):
    # Get city Id
    city_id = int(common.get_val("city", 1))
    if city_id < 1:
        return "No city selected"

    # Build city item
    the_city = city_q.get_one_city(cursor, city_id)

    # Get buildings list
    building_dict = building_q.get_all_buildings(cursor)

    # If we're being sent the info from the view_map page then this is the new location we need
    new_location = common.get_val("location", "")

    if new_location == "":
        new_location = "%s,%s" % (the_city.x, the_city.y)  # default value

    output = []

    output.append(
        """<div style="float: right; width: 50%;">
		<strong>Happiness</strong>
		<div id="happiness">
			
		</div>
	</div>"""
    )

    output.append(
        """<div style='padding: 5px;'>
	<form action="exec.py" method="post" accept-charset="utf-8">
		<input type="hidden" name="mode" id="mode" value="edit_city_commit" />
		<input type="hidden" name="id" id="id" value="%(city_id)s" />
		
		Editing: %(name_text)s
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		<a href="web.py?mode=edit_army&amp;garrison=%(city_id)s">Edit garrison</a>
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		<a href="web.py?mode=list_operatives&amp;city=%(city_id)s">Operatives</a>
		<br /><br />
		
		<table border="0" cellspacing="5" cellpadding="5">
			<tr>
				<td><label for="team">Team:</label></td>
				<td colspan="4" style="padding: 1px;">%(owner_select)s</td>
				
				<td width="5">&nbsp;</td>
				
				<td>&nbsp;</td>
				<td colspan="6">&nbsp;</td>
			</tr>
			<tr>
				<td><label for="size">Size:</label></td>
				<td style="padding: 1px;">%(city_population_text)s</td>
				
				<td width="5">&nbsp;</td>
				
				<td><label for="slaves">Slaves:</label></td>
				<td style="padding: 1px;">%(city_slaves_text)s</td>
				
				<td width="5">&nbsp;</td>
				<td style="padding: 0px;">
					<a class="block_link" href="web.py?mode=view_map&amp;new_mode=edit_city&amp;city=%(city_id)s"">Location:</a>
				</td>
				<td style="padding: 1px;">%(city_location_text)s</td>
				
				<td>&nbsp;</td>
				<td>&nbsp;</td>
			</tr>
			<tr>
				<td><label for="port">Port:</label></td>
				<td>%(city_port_checkbox)s</td>
				
				<td><label for="nomadic">Nomadic:</label></td>
				<td>%(city_nomadic_checkbox)s</td>
				
				<td><label for="dead">Dead:</label></td>
				<td>%(city_dead)s</td>
				
				<td><label for="secret">Secret:</label></td>
				<td>%(city_secret_checkbox)s</td>
				
				<td><label for="founded">Founded:</label></td>
				<td>%(founded_text)s</td>
			</tr>
			<tr>
				<td colspan="10">&nbsp;&nbsp;&nbsp;Description:<br />
					%(city_description_textarea)s
				</td>
			</tr>
		</table>
		<br />
		<input type="submit" value="Perform edit" />
	</form>
	<form id="delete_form" action="exec.py" method="post" accept-charset="utf-8">
		<input type="hidden" name="city" id="city" value="%(city_id)s" />
		<input type="hidden" name="mode" id="mode" value="remove_city" />
		<input style="float:right; margin-right:100px;" type="button" value="Delete city" onclick="var answer = confirm('Delete %(name_safe)s?')
		if (answer) $('#delete_form').submit();" />
	</form>
	<br /><br />"""
        % {
            "city_id": city_id,
            "name": the_city.name,
            "name_text": common.text_box("name", the_city.name, size=20),
            "owner_select": team_f.structured_list(cursor, default=the_city.team, field_name="team"),
            # "city_location_text":			common.text_box("location", "%s,%s" % (the_city.x, the_city.y), 10),
            "city_location_text": common.text_box("location", new_location, 10),
            "city_population_text": common.text_box("population", the_city.population, 10),
            "city_slaves_text": common.text_box(
                "slaves", the_city.slaves, 10, warn_on=lambda x: (True if int(x) < 0 else False)
            ),
            "city_port_checkbox": common.check_box("port", the_city.port),
            "city_dead": common.text_box("dead", the_city.dead, 5),
            "city_nomadic_checkbox": common.check_box("nomadic", the_city.nomadic),
            "city_secret_checkbox": common.check_box("secret", the_city.secret),
            "city_description_textarea": '<textarea name="description" id="description" rows="4" cols="40">%s</textarea>'
            % the_city.description,
            "founded_text": the_city.founded,
            "name_safe": common.js_name(the_city.name),
        }
    )

    # 	Buildings
    # ----------------------
    the_city.get_buildings(cursor)

    output.append(
        """
	<table style="float:left; margin-right: 25px;" border="0" cellspacing="0" cellpadding="5">
	<tr class="row2">
		<th>Building</th>
		<th>Progress</th>
		<th>Amount</th>
		<th>&nbsp;</th>
		<th>&nbsp;</th>
	</tr>
	"""
    )

    counter = -1
    building_remove_list = []
    for building_id, completion in the_city.buildings.items():
        counter += 1

        building_remove_list.append(building_id)

        output.append(
            """
		<tr class="row%(row)d">
			<form id="b_%(building_id)s" action="exec.py" method="get" accept-charset="utf-8">
				<input type="hidden" name="mode" value="set_building" />
				<input type="hidden" name="city" value="%(city_id)s" />
				<input type="hidden" name="building" value="%(building_id)s" />
				<td><label for="%(building_name)s">%(building_name)s</label></td>
				<td style="padding: 1px;">
					%(building_completion_text)s/%(building_build_time)s
				</td>
				<td style="padding: 1px;">
					%(building_amount_text)s
				</td>
				<td style="padding: 0px;">
					<!--<a class="block_link" href="#" onclick="$('#b_%(building_id)s').submit();">Edit</a>-->
					<input type="submit" value="Edit" />
				</td>
				<td style="padding: 0px;">
					<a class="block_link" href="exec.py?mode=set_building&amp;building=%(building_id)d&amp;city=%(city_id)d&amp;completion=0&amp;amount=0">Remove</a>
				</td>
			</form>
		</tr>"""
            % {
                "row": (counter % 2),
                "building_name": building_dict[building_id].name,
                "building_id": building_id,
                "building_build_time": building_dict[building_id].build_time,
                "city_id": city_id,
                "building_completion_text": common.text_box("completion", the_city.buildings[building_id], size=4),
                "building_amount_text": common.text_box("amount", the_city.buildings_amount[building_id], size=3),
            }
        )

    output.append(
        """
		<tr class="row%(row)d">
		<form id="city_add_building_form" action="exec.py" method="post" accept-charset="utf-8">
			<input type="hidden" name="mode" value="set_building" />
			<input type="hidden" name="city" value="%(city_id)s" />
			<td style="padding:1px;">
				<select id="new_building" name="building" onchange="$('#building_completion_span').load('web.py', {mode: 'get_building_build_time', building: document.getElementById('new_building').value, ajax:'True'});">
					%(building_option_box)s
				</select>
			</td>
			<td style="padding:1px;">
				%(building_completion_text)s/<span id="building_completion_span">000</span>
			</td>
			<td style="padding:1px;">
				%(building_amount_text)s
			</td>
			<td style="padding: 0px;" colspan="2">
				<input type="submit" value="Add" />
				<!--<a href="#" onclick="$('#city_add_building_form').submit();" class="block_link">Add</a>-->
			</td>
		</tr>
		</form>
	</table>
	%(onload)s
	"""
        % {
            "row": ((counter + 1) % 2),
            "city_id": the_city.id,
            "building_option_box": building_f.building_option_list(cursor, building_remove_list),
            "building_completion_text": common.text_box("completion", 0, size=4),
            "building_amount_text": common.text_box("amount", 0, size=3),
            "onload": common.onload("$('#new_building').focus();"),
        }
    )

    output.append(
        common.onload(
            "$('#building_completion_span').load('web.py', {mode: 'get_building_build_time', building: document.getElementById('new_building').value, 'ajax':1});"
        )
    )

    output.append("<strong>Wonder construction speed</strong>")
    output.append("<ul>")

    # Work out city points
    cities_dict = city_q.get_cities_from_team(cursor, the_city.team)
    total_points = 0
    for city_id2, city2 in cities_dict.items():
        if city2.team != the_city.team:
            continue
        if city2.dead == True:
            continue

        points = city_rules.wonder_build_rate(city2, the_city)
        if points > 0:
            output.append("<li>%s: %s</li>" % (city2.name, points))
            total_points += points

    output.append("<li><em>Total: %s</em></li>" % total_points)
    output.append("</ul>")

    output.append(
        common.onload(
            "$('#happiness').load('web.py', {'mode':'happiness_breakdown','city':'%d', 'ajax':'True'});"
            % int(the_city.id)
        )
    )

    # output.append('''<img src="%simages/grid_25.png" width="0" height="0" onload="">''' % common.data['media_path'])
    output.append("</div>")

    page_data["Title"] = "Edit city (%s)" % the_city.name
    return "".join(output)
コード例 #13
0
ファイル: edit_wonder.py プロジェクト: Teifion/Rob3
def main(cursor):
	wonder_id = int(common.get_val('wonder', 0))
	
	if wonder_id < 1: return "No wonder selected"
	
	the_wonder = wonder_q.get_one_wonder(cursor, wonder_id)
	cities_dict = city_q.get_live_cities(cursor)
	teams_dict = team_q.get_real_teams(cursor)
	
	names = {}
	for c, the_city in cities_dict.items():
		names[c] = the_city.name
	
	# TODO Make this do it properly
	tnames = {}
	for t, the_team in teams_dict.items():
		tnames[t] = the_team.name
	
	output = ["<div style='padding: 5px;'>"]
	
	output.append("""
	<form action="exec.py" method="post" accept-charset="utf-8">
		<input type="hidden" name="mode" id="mode" value="edit_wonder_commit" />
		<input type="hidden" name="id" id="id" value="%(wonder_id)s" />
	
		Editing: %(name_text)s
		<br /><br />
	
		<table border="0" cellspacing="5" cellpadding="5">
			<tr>
				<td><label for="city">City:</label></td>
				<td>%(city_menu)s</td>
		
				<td width="5">&nbsp;</td>
			
				<td><label for="team">Team:</label></td>
				<td>%(team_menu)s</td>
			
				<td width="5">&nbsp;</td>
			
				<td><label for="completed">Completed:</label></td>
				<td style="padding: 1px;">%(completed)s</td>
			</tr>
			<tr>
				<td><label for="completion">Completion:</label></td>
				<td style="padding: 1px;">%(completion)s</td>
			
				<td width="5">&nbsp;</td>
			
				<td><label for="point_cost">Point cost:</label></td>
				<td style="padding: 1px;">%(point_cost)s</td>
			
				<td width="5">&nbsp;</td>
			
				<td><label for="material_cost">Material cost:</label></td>
				<td style="padding: 1px;">%(material_cost)s</td>
			</tr>
			<tr>
				<td colspan="10">&nbsp;&nbsp;&nbsp;Description:<br />
					%(description)s
				</td>
			</tr>
		</table>
		<br />
		<input type="submit" value="Perform edit" />
	</form>
	<form id="delete_form" action="exec.py" method="post" accept-charset="utf-8">
		<input type="hidden" name="wonder" id="wonder" value="%(wonder_id)s" />
		<input type="hidden" name="mode" id="mode" value="remove_wonder" />
		<input style="float:right; margin-right:100px;" type="button" value="Delete wonder" onclick="var answer = confirm('Delete %(name_safe)s?')
		if (answer) $('#delete_form').submit();" />
	</form>
	<br /><br />""" % {
		"wonder_id":					wonder_id,
		"name_text":				common.text_box("name", the_wonder.name),
		
		"city_menu":					common.option_box(
			name='city',
			elements=names,
			element_order=cities_dict.keys(),
			custom_id="",
			selected=the_wonder.city,
		),
		
		"team_menu":					common.option_box(
			name='team',
			elements=tnames,
			element_order=teams_dict.keys(),
			custom_id="",
			selected=the_wonder.team,
		),
		
		"completed":				common.check_box("completed", the_wonder.completed),
		"completion":				common.text_box("completion", the_wonder.completion, size=7),
		"point_cost":				common.text_box("point_cost", the_wonder.point_cost, size=7),
		"material_cost":			common.text_box("material_cost", the_wonder.material_cost, size=7),
		
		"description":	'<textarea name="description" id="description" rows="4" style="width:99%%;">%s</textarea>' % the_wonder.description,
		
		"name_safe":			common.js_name(the_wonder.name),
	})
	
	output.append("</div>")
	
	return "".join(output)
コード例 #14
0
ファイル: list_cities.py プロジェクト: Teifion/Rob3
def main(cursor):
	# Get team Id
	team_id = int(common.get_val('team', 0))
	
	text_location = common.get_val('location', "")
	
	if team_id < 1:
		return "<div style='padding: 5px;'>{0}</div>".format(common.select_team_form(cursor, 'list_cities'))
	
	cities_dict = city_q.get_cities_from_team(cursor, team = team_id, include_dead = True)
	
	# Work out city points
	total_points = 0
	for city_id, the_city in cities_dict.items():
		if the_city.dead == True: continue
		total_points += the_city.point_value()
	
	output = []
	
	output.append("""
	<table border="0" cellspacing="0" cellpadding="5" style="width: 100%;">
		<tr class="row2">
			<th>City name</th>
			<th colspan="3">Location</th>
			<th>Port</th>
			<th>Secret</th>
			<th>Dead</th>
			<th>Nomadic</th>
			
			<th>Overlap</th>
			
			<th>Wonder speed</th>
			<th>Population</th>
			<th>Slaves</th>
			<th>Happiness</th>
			
			<th colspan="2">&nbsp;</th>
		</tr>""")
	
	# Work out how fast it can build wonders
	city_wonder_speed = {}
	for c1, city1 in cities_dict.items():
		city_wonder_speed[c1] = math.floor((city1.population + city1.slaves)/1000)
		c1_loc = (cities_dict[c1].x, cities_dict[c1].y)
		
		for c2, city2 in cities_dict.items():
			if city2.dead: continue
			
			if c2 != c1:
				amount = city_rules.wonder_build_rate(city2, city1)
				city_wonder_speed[c1] += amount
		
		city_wonder_speed[c1] = common.number_format(int(city_wonder_speed[c1]))
	
	count = -1
	if len(cities_dict) > 0:
		for city_id, the_city in cities_dict.items():
			count += 1
			
			city_share = 0
			if not the_city.dead:
				if total_points > 0:
					city_share = round(the_city.point_value()/total_points*100,1)
			
			# Happiness
			happiness = city.happiness_str(the_city.happiness)
			
			if happiness == "Rebellious":
				happiness = '<span style="font-weight:bold;color:#A00;">Rebellious</span>'
			
			if happiness == "Utopian":
				happiness = '<span style="font-weight:bold;color:#0A0;">Utopian</span>'
			
			output.append("""
			<tr class="row%(row)d" id="%(city_id)d">
				<td>%(name)s</td>
		
				<td>%(x)s</td>
				<td>%(y)s</td>
				<td style="padding: 0px;"><a class="block_link" href="web.py?mode=view_map&amp;%(map_link)s">Map link</a></td>
				
				<td style="text-align: center;">%(port)s</td>
				<td style="text-align: center;">%(secret)s</td>
				<td style="text-align: center;">%(dead)s</td>
				<td style="text-align: center;">%(nomadic)s</td>
				
				<td>%(overlap)s</td>
				
				<td>%(wonder_speed)s</td>
				<td>%(population)s</td>
				<td>%(slaves)s</td>
				
				<td>%(happiness)s</td>
				
				<!--<td style="padding: 0px;"><a class="block_link" href="web.py?mode=view_city_trade&amp;city=%(city_id)d">City trade</a></td>-->
				<td style="padding: 0px;"><a class="block_link" href="web.py?mode=view_city_matrix&amp;city=%(city_id)d">City matrix</a></td>
				<td style="padding: 0px;"><a class="block_link" href="web.py?mode=edit_city&amp;city=%(city_id)d">Edit city</a></td>
			</tr>
			""" % {	'row': (count % 2),
			
					'city_id': the_city.id,
					'name': common.doubleclick_text("cities", "name", the_city.id, the_city.name, "font-weight:bold"),
					'x': common.doubleclick_text("cities", "x", the_city.id, the_city.x, ""),
					'y': common.doubleclick_text("cities", "y", the_city.id, the_city.y, ""),
					"map_link":	the_city.map_link_args(),
					
					'port': common.bstr(the_city.port),
					'secret': common.bstr(the_city.secret),
					'dead': "" if the_city.dead < 1 else common.doubleclick_text("cities", "dead", the_city.id, the_city.dead, "", size=3),
					'nomadic': common.bstr(the_city.nomadic),
				
					'overlap': the_city.overlap,
				
					'population': common.doubleclick_text("cities", "population", the_city.id, the_city.population, ""),
					'slaves': common.doubleclick_text("cities", "slaves", the_city.id, the_city.slaves, ""),
				
					"wonder_speed": city_wonder_speed[the_city.id],
					"happiness":	happiness,
				})


	# Add new city
	count += 1
	output.append("""
	<tr class="row%(row)d">
		<form action="exec.py" id="add_city_form" method="post" accept-charset="utf-8">
		<input type="hidden" name="mode" value="add_city" />
		<input type="hidden" name="team" value="%(team_id)s" />
		<td style="padding: 1px;"><input type="text" name="name" id="new_name" value="" /></td>
		<td style="padding: 0px;" colspan="2">
			<a href="web.py?mode=view_map&amp;new_mode=list_cities&amp;team=%(team_id)s" class="block_link">Location:</a>
		</td>
		<td colspan="1" style="padding:1px;">
			%(location)s
		</td>
		<td style="padding: 2px;"><input type="checkbox" name="port" value="True" /></td>
		<td style="padding: 2px;"><input type="checkbox" name="secret" value="True" /></td>
		<td style="padding: 2px;"><input type="text" name="dead" id="dead" value="0" size="3"/></td>
		<td style="padding: 2px;"><input type="checkbox" name="nomadic" value="True" /></td>
	
		<td>&nbsp;</td>
		
		<td>&nbsp;</td>
	
		<td style="padding: 1px;"><input type="text" name="population" value="" size="10"/></td>
		<td style="padding: 1px;"><input type="text" name="slaves" value="" size="10"/></td>
	
		<td style="padding: 2px;" colspan="3"><input type="submit" value="Add" /></td>
		<!--
		<td style="padding: 0px;" colspan="3"><a class="block_link" href="#" onclick="$('#add_city_form').submit();">Add</a></td>
		-->
		</form>
		%(onload)s
	</tr>
	""" % {	'row': (count % 2),

			"team_id":	team_id,
			"location": common.text_box("text_location", text_location, custom_id="", size="7"),
			"onload":	common.onload("$('#new_name').focus();"),
			})


	output.append("</table>")

	return "".join(output)
コード例 #15
0
ファイル: edit_power.py プロジェクト: Teifion/Rob3
def main(cursor):
	power_id	= int(common.get_val('power', 0))
	
	if power_id < 1:
		return "No power selected"
	
	the_power = power_q.get_one_power(cursor, power_id)
	
	output = ["<div style='padding: 5px;'>"]
	
	# Used for the player select menu
	player_dict = player_q.get_all_players(cursor)
	recent_dict = player_q.get_active_players(cursor)
	
	names = {}
	for p in recent_dict.keys():
		names[p] = player_dict[p].name
	
	if the_power.player not in names:
		# recent_dict[the_power.id] = the_power.player
		names[the_power.player] = player_dict[the_power.player].name
	
	
	output.append("""
	<form action="exec.py" method="post" accept-charset="utf-8">
		<input type="hidden" name="mode" id="mode" value="edit_power_commit" />
		<input type="hidden" name="id" id="id" value="%(power_id)s" />
	
		<table border="0" cellspacing="5" cellpadding="5">
			<tr>
				<td><label for="name">Name:</label></td>
				<td>%(name_text)s</td>
			
				<td width="5">&nbsp;</td>
			
				<td><label for="player">Player:</label></td>
				<td>%(player_select)s</td>
			</tr>
			<tr>
				<td><label for="type">Type:</label></td>
				<td>%(type)s</td>
			
				<td width="5">&nbsp;</td>
			
				<td>&nbsp;</td>
				<td>&nbsp;</td>
			</tr>
			<tr>
				<td colspan="5"><label for="description">Description:</label><br />
				<textarea name="description" rows="4" cols="60">%(description)s</textarea></td>
			</tr>
		</table>
		<br />
		<input type="submit" value="Perform edit" />
	</form>
	<br /><br />""" % {
		"power_id":			power_id,
		"name":		the_power.name,
		"description":		the_power.description,
		"name_text":	common.text_box("name", the_power.name, size=20),
		"player_select":	common.option_box(
			name='player',
			elements=names,
			element_order=recent_dict.keys(),
			selected=the_power.player,
			custom_id="",
		),
		"type":	common.option_box(
			name='type',
			elements=power.power_types,
			selected=power.power_types[the_power.type],
		),
	})


	# End of padding
	output.append("</div>")

	return "".join(output)
コード例 #16
0
ファイル: timestamps.py プロジェクト: Teifion/Rob3
def main(cursor):
	post_id 			= int(common.get_val('post', 0))
	turn				= int(common.get_val('turn', 0))
	timestamp			= int(common.get_val('timestamp', 0))
	
	delete_timestamp	= int(common.get_val('delete_timestamp', 0))
	
	output = ['<div style="padding: 5px;">']
	
	if post_id > 0 and turn > 0:
		getter_data = "p=%s&mode=postTime&post=%d" % (common.data['getterPass'], post_id)
		timestamp = int(urllib.request.urlopen(common.data['getter_url'], getter_data).read().strip())
		
		database.query(cursor,
			system_f.add_turn_timestamp(turn, timestamp))
		
		output.append('Post %d was posted at %s<br /><br />' % (post_id, timestamp))
	
	elif timestamp > 0 and turn > 0:
		database.query(cursor,
			system_f.add_turn_timestamp(turn, timestamp))
	
	# Deletion
	if delete_timestamp > 0:
		database.query(cursor,
			system_f.delete_turn_timestamp(delete_timestamp))
	
	current_turn = common.current_turn(force_requery=True)
	
	# Form to set timestamps
	output.append("""
	<form action="web.py" method="post" accept-charset="utf-8" style="width: 400px; float: left;">
		<input type="hidden" name="mode" value="timestamps" />
		<table border="0" cellspacing="5" cellpadding="5">
			<tr>
				<td><label for="turn">Turn:</label></td>
				<td>%(turn)s</td>
			</tr>
			<tr>
				<td><label for="post">Post:</label></td>
				<td><input type="text" name="post" id="post" value="" size="15"/></td>
			</tr>
		</table>
	
		<input type="submit" value="Set turn timestamp" />
	</form>

	<form action="web.py" method="post" accept-charset="utf-8">
		<input type="hidden" name="mode" value="timestamps" />
		<table border="0" cellspacing="5" cellpadding="5">
			<tr>
				<td><label for="turn_new">Turn:</label></td>
				<td><input type="text" name="turn" id="turn_new" value="%(last_turn)s" /></td>
			</tr>
			<tr>
				<td>Timestamp:</td>
				<td><input type="text" name="timestamp" id="timestamp" value="%(time_now)s" /></td>
			</tr>
		</table>
	
		<input type="submit" value="Set turn timestamp" />
	</form>
	<br /><br />
	""" % {
		"turn": common.text_box("turn", current_turn+2),
		"last_turn": current_turn+2,
		"time_now":	int(time.time()),
	})

	# Get turns
	output.append("""<table border="0" cellspacing="0" cellpadding="5">
		<tr class="row2">
			<th>Turn</th>
			<th colspan="2">Time</th>
			<th>&nbsp;</th>
		</tr>""")

	turn_dict = system_q.most_recent_turns(cursor, limit=30)
	
	count = 1
	for t, turn_time in turn_dict.items():
		count += 1
		output.append("""
		<tr class="row%(row)s">
			<td>%(turn)s</td>
			<td>%(string)s</td>
			<td>%(epoch)s</td>
			<td style="padding:0px;"><a href="timestamps&amp;delete_timestamp=%(turn)s" class="block_link">Delete</a></td>
		</tr>""" % {
			"row":		(count%2),
			"turn":		t,
			"string":	time.strftime("%A, %d %B %Y", time.localtime(turn_time)),
			"epoch":	turn_time,
		})
	
	output.append("</table>")
	output.append("</div>")
	
	return "".join(output)
コード例 #17
0
ファイル: edit_operative.py プロジェクト: Teifion/Rob3
def main(cursor):
	operative_id = int(common.get_val('operative'))
	
	the_operative = operative_q.get_one_operative(cursor, operative_id)
	
	city_dict = city_q.get_live_cities(cursor)
	
	names = {}
	for c, the_city in city_dict.items():
		names[c] = the_city.name
	
	output = []
	
	output.append("<div style='padding: 5px;'>")
	
	output.append("""
	<form action="exec.py" id="the_operative_form" method="post" accept-charset="utf-8">
		<input type="hidden" name="mode" id="mode" value="edit_operative_commit" />
		<input type="hidden" name="id" id="id" value="{operative_id}" />
		<input type="hidden" name="team" id="team" value="{team}" />
		
		<table border="0" cellspacing="5" cellpadding="5">
			<tr>
				<td><label for="name">Identifier:</label></td>
				<td style="padding: 1px;">{name}</td>
		
				<td width="5">&nbsp;</td>
				
				<td>&nbsp;</td>
				<td>&nbsp;</td>
				
				<td width="5">&nbsp;</td>
				
				<td>&nbsp;</td>
				<td>&nbsp;</td>
			</tr>
			<tr>
				<td><label for="location">Location:</label></td>
				<td style="padding: 1px;">{city_select}</td>
			
				<td width="5">&nbsp;</td>
			
				<td><label for="arrival">Arrival:</label></td>
				<td style="padding: 2px;">{arrival}</td>
				
				<td width="5">&nbsp;</td>
				
				<td><label for="size">Size:</label></td>
				<td style="padding: 2px;">{size}</td>
			</tr>
			<tr>
				<td><label for="stealth">Stealth:</label></td>
				<td style="padding: 2px;">{stealth}</td>
				
				<td>&nbsp;</td>
				
				<td><label for="observation">Observation:</label></td>
				<td style="padding: 2px;">{observation}</td>
				
				<td>&nbsp;</td>
				
				<td><label for="integration">Integration:</label></td>
				<td style="padding: 2px;">{integration}</td>
			</tr>
			<tr>
				<td><label for="sedition">Sedition:</label></td>
				<td style="padding: 2px;">{sedition}</td>
				
				<td>&nbsp;</td>
				
				<td><label for="sabotage">Sabotage:</label></td>
				<td style="padding: 2px;">{sabotage}</td>
				
				<td>&nbsp;</td>
				
				<td><label for="assassination">Assassination:</label></td>
				<td style="padding: 2px;">{assassination}</td>
			</tr>
			<tr>
				<td colspan="8" style="padding: 0;">
					<a class="block_link" href="#" onclick="$('#the_operative_form').submit();">Apply changes</a>
				</td>
			</tr>
		</table>
	</form>
	<form id="delete_form" action="exec.py" method="post" accept-charset="utf-8">
		<input type="hidden" name="operative" id="operative" value="{operative_id}" />
		<input type="hidden" name="mode" id="mode" value="remove_operative" />
		<input style="float:right; margin-right:100px;" type="button" value="Delete operative" onclick="var answer = confirm('Delete operative?')
		if (answer) $('#delete_form').submit();" />
	</form>
	<br /><br />""".format(
		operative_id	= operative_id,
		team			= the_operative.team,
		size			= common.text_box("size", the_operative.size),
		arrival			= common.text_box("arrival", the_operative.arrival, size=3),
		name		= common.text_box("name", the_operative.name),
		
		stealth			= common.text_box("stealth", the_operative.stealth, size=3),
		observation		= common.text_box("observation", the_operative.observation, size=3),
		integration		= common.text_box("integration", the_operative.integration, size=3),
		sedition		= common.text_box("sedition", the_operative.sedition, size=3),
		sabotage		= common.text_box("sabotage", the_operative.sabotage, size=3),
		assassination	= common.text_box("assassination", the_operative.assassination, size=3),
		
		city_select		= common.option_box(
			name='city',
			elements=names,
			element_order=city_dict.keys(),
			custom_id="",
			selected=the_operative.city
		),
	))
	
	output.append("</div>")
	
	return "".join(output)
コード例 #18
0
ファイル: latest_missions.py プロジェクト: Teifion/Rob3
	
	<td style="padding: 1px;">%(type)s</td>
	<td style="padding: 1px;">%(target)s</td>
	
	<!--
	<td>&nbsp;</td>
	-->
	
	<td style="padding: 0px;" colspan="2"><a class="block_link" href="#" onclick="$('#add_mission_form').submit();">Add</a></td>
	</form>
	%(onload)s
</tr>
""" % {	'row':			(count % 2),
		
		"team":			team_f.structured_list(field_name="team", field_id="new_mission_team"),
		"turn":			common.text_box('turn', text=common.current_turn(), size=5),
		"state":		common.option_box("state", mission.mission_states),
		
		"type":			common.option_box("type",
			elements=city_missions_dict,
			element_order=city_missions_list,
		),
		"target":		common.option_box(
			name='target',
			elements=names,
			element_order=cities_order,
		),
		
		"time_posted":	int(time.time()),
		"onload":		common.onload("$('#new_mission_team').focus();"),
		})
コード例 #19
0
ファイル: edit_mission.py プロジェクト: Teifion/Rob3
			<td>%(time_closed)s</td>
		</tr>
	</table>
	<input type="submit" value="Perform edit" />
</form>
<form id="delete_form" action="exec.py" method="post" accept-charset="utf-8">
	<input type="hidden" name="mission" id="mission" value="%(mission_id)s" />
	<input type="hidden" name="mode" id="mode" value="remove_mission" />
	<input style="float:right; margin-right:100px;" type="button" value="Delete mission" onclick="var answer = confirm('Delete this mission?')
	if (answer) $('#delete_form').submit();" />
</form>""" % {
	"mission_id":	mission_id,
	"team":			team_f.structured_list(default=the_mission.team, field_name="team"),
	"target":		target_string,
	
	"turn":			common.text_box("turn", the_mission.turn),
	"state":		mission.mission_states[the_mission.state],	
	# "state":		common.option_box("state", elements=mission.mission_states, selected=mission.mission_states[the_mission.state]),
	
	"time_posted":	time.strftime("%A, %d %B %Y", time.localtime(the_mission.time_posted)),
	"time_closed":	closed_string,
	
	
})

# # Fields
# self.add_field("type",				"int")
# self.add_field("target",			"int")
# 
# self.add_field("information",		"text")
#