def render_cost(self, screen, structure_id, left, bottom):
		
			resources = structure.get_structure_resources(structure_id)
			counts = []
			for key in resources.keys():
				counts.append((key, resources[key]))
			counts.sort(key=lambda z:z[1])
			counts = counts[::-1]
			
			x = left + 5
			y = bottom - 5 - 12
			for count in counts:
				key = count[0]
				amount = count[1]
				if amount == 0:
					break
				img = get_resource_icon(key)
				screen.blit(img, (x, y))
				x += 3 + img.get_width()
				img = get_text(str(amount), (255, 255, 255), 14)
				screen.blit(img, (x, y))
				x += 8 + img.get_width()
			limit = structure.get_structure_limit(structure_id)
			if limit != 0:
				img = get_text("Limit: " + str(limit), (255, 255, 255), 14)
				screen.blit(img, (x, y))
	def render(self, screen):
		self.playscene.render(screen)
		left = 140
		top = 100
		
		screen.blit(self.bg, (left, top))
		left += 5
		top += 5
		y = top
		
		img = get_text(self.title, (255, 255, 255), 18)
		
		screen.blit(img, (left, y))
		
		y += img.get_height() + 5
		
		if len(self.pages) > 0:
			for line in self.pages[0]:
				img = get_tiny_text(line)
				screen.blit(img, (left, y))
				y += img.get_height() + 3
		
		self.counter += 1
		
		if (self.counter // 5) % 2 == 0:
			img = get_text("<Press SPACE>", (0, 128, 255), 14)
			screen.blit(img, (left, top + self.bg.get_height() - img.get_height() - 8))
    def render(self, screen):
        screen.fill((0, 0, 0))
        y = int(screen.get_height() - (self.counter - 1) * 1.5)
        sw = screen.get_width()
        for credit in self.credits:
            line1 = get_text(credit[0], (160, 160, 160), 16)
            line2 = get_text(credit[1], (255, 255, 255), 24)
            left1 = sw // 2 - line1.get_width() // 2
            left2 = sw // 2 - line2.get_width() // 2
            mleft = left1 if left1 < left2 else left2
            right1 = sw // 2 + line1.get_width() // 2
            right2 = sw // 2 + line2.get_width() // 2
            mright = right1 if right1 > right2 else right2
            screen.blit(line1, (left1, y))
            screen.blit(line2, (left2, y + line1.get_height() + 3))

            lperson = credit[2]
            rperson = credit[3]
            if lperson != None:
                screen.blit(lperson, (mleft - lperson.get_width() - 8, y - 8))
            if rperson != None:
                screen.blit(rperson, (mright + 8, y - 8))
            y += 220

        if y < 0:
            self.next = scenefactory.build_scene('title', [])
	def render(self, screen):
		screen.fill((0, 0, 0))
		y = int(screen.get_height() - (self.counter - 1) * 1.5)
		sw = screen.get_width()
		for credit in self.credits:
			line1 = get_text(credit[0], (160, 160, 160), 16)
			line2 = get_text(credit[1], (255, 255, 255), 24)
			left1 = sw // 2 - line1.get_width() // 2
			left2 = sw // 2 - line2.get_width() // 2
			mleft = left1 if left1 < left2 else left2
			right1 = sw // 2 + line1.get_width() // 2
			right2 = sw // 2 + line2.get_width() // 2
			mright = right1 if right1 > right2 else right2
			screen.blit(line1, (left1, y))
			screen.blit(line2, (left2, y + line1.get_height() + 3))
			
			lperson = credit[2]
			rperson = credit[3]
			if lperson != None:
				screen.blit(lperson, (mleft - lperson.get_width() - 8, y - 8))
			if rperson != None:
				screen.blit(rperson, (mright + 8, y - 8))
			y += 220
		
		if y < 0:
			self.next = scenefactory.build_scene('title', [])
	def render(self, screen):
		cursortile = terrain.nearesttile(self.you.x, self.you.y)
		worldmap.drawscene(screen, self.structures + self.sprites, (self.you.x, self.you.y))
		if settings.showminimap:
			worldmap.drawminimap(screen, [self.you])
		ax, ay = terrain.toModel(*cursortile)
		screen.blit(get_text("Position: %s %s" % (int(ax//1), int(ay//1)), (255, 0, 0), 18), (4, settings.sy-22))
	def draw_button(self, id, index, screen, caption, hotkey=None):
		y = 5
		hide_border = False
		if index == 0:
			x = 2
			hide_border = True
		elif index == 100:
			x = screen.get_width() - 50
		else:
			x = 40 + 60 * (index - 1)
		
		screen.blit(self.buttons[id], (x, y))
		if not hide_border:
			pygame.draw.rect(
				screen,
				(255, 255, 255) if self.hovering == index else (128, 128, 128),
				pygame.Rect(x, y, 40, 24),
				1)
		
		if hotkey != None or id == 'main_exit':
			if hotkey != None:
				screen.blit(get_text(hotkey.upper(), (255, 255, 255), 12), (x + 40, y + 15))
			tc = self.tiny_captions.get(id, None)
			if tc != None:
				screen.blit(get_tiny_text(tc), (x, y + 23))
	def render(self, screen, is_focused):
		box = pygame.Rect(self.x, self.y, self.width, self.height)
		color = (255, 255, 255) if self.enabled else (128, 128, 128)
		pygame.draw.rect(screen, (40, 40, 40), box)
		pygame.draw.rect(screen, color, box, 1)
		img = get_text(self.text, color, 18)
		screen.blit(img, (self.x + 2, self.y + 2))
Beispiel #8
0
 def render(self, screen, is_focused):
     box = pygame.Rect(self.x, self.y, self.width, self.height)
     color = (255, 255, 255) if self.enabled else (128, 128, 128)
     pygame.draw.rect(screen, (40, 40, 40), box)
     pygame.draw.rect(screen, color, box, 1)
     img = get_text(self.text, color, 18)
     screen.blit(img, (self.x + 2, self.y + 2))
	def render(self, screen):
		screen.blit(self.pages[self.current], (0, 0))
		y = 20
		x = 10
		for line in self.text[self.current]:
			img = get_text(util.trim(line), (0, 0, 0), 18)
			screen.blit(img, (x, y))
			y += img.get_height() + 4
 def render(self, screen):
     screen.blit(self.pages[self.current], (0, 0))
     y = 20
     x = 10
     for line in self.text[self.current]:
         img = get_text(util.trim(line), (0, 0, 0), 18)
         screen.blit(img, (x, y))
         y += img.get_height() + 4
 def render(self, screen):
     cursortile = terrain.nearesttile(self.you.x, self.you.y)
     worldmap.drawscene(screen, self.structures + self.sprites,
                        (self.you.x, self.you.y))
     if settings.showminimap:
         worldmap.drawminimap(screen, [self.you])
     ax, ay = terrain.toModel(*cursortile)
     screen.blit(
         get_text("Position: %s %s" % (int(ax // 1), int(ay // 1)),
                  (255, 0, 0), 18), (4, settings.sy - 22))
	def __init__(self, x, y, label, handler, enabled):
		Element.__init__(self, "Button", x, y)
		self.text = label
		self.handler = handler
		self.width = get_text(label, (255, 255, 255), 18).get_width() + 4
		self.height = 18
		if enabled:
			self.enable()
		else:
			self.disable(None)
Beispiel #13
0
 def __init__(self, x, y, label, handler, enabled):
     Element.__init__(self, "Button", x, y)
     self.text = label
     self.handler = handler
     self.width = get_text(label, (255, 255, 255), 18).get_width() + 4
     self.height = 18
     if enabled:
         self.enable()
     else:
         self.disable(None)
	def render_action_menu(self, screen, caption, button_id):
		text = get_text(caption, (255, 255, 255), 24)
		
		screen.blit(text, (40, 12))
		button = self.buttons[button_id]
		r = screen.blit(button, (screen.get_width() - button.get_width() - 8, 5))
		pygame.draw.rect(screen, (0, 128, 255), r, 1)
		
		if button_id.startswith('build_'):
			id = button_id.split('_')[1]
			self.render_cost(screen, id, 100, 18)
 def render(self, screen):
     bg = self.images[self.page]
     if bg == None:
         screen.fill((0, 0, 0))
     else:
         screen.blit(bg, (0, 0))
     text = pages[self.page]
     y = self.pos[self.page][1]
     for line in text:
         t = get_text(line, (255, 255, 255), 18, (0, 0, 0))
         screen.blit(t, (self.pos[self.page][0], y))
         y += t.get_height() + 6
	def render(self, screen):
		bg = self.images[self.page]
		if bg == None:
			screen.fill((0, 0, 0))
		else:
			screen.blit(bg, (0, 0))
		text = pages[self.page]
		y = self.pos[self.page][1]
		for line in text:
			t = get_text(line, (255, 255, 255), 18, (0, 0, 0))
			screen.blit(t, (self.pos[self.page][0], y))
			y += t.get_height() + 6
	def render(self, screen, is_focused):
		self.counter += 1
		pygame.draw.rect(screen, (0,0, 0), self.box)
		pygame.draw.rect(screen, (0, 128, 255), self.box, 1)
		
		text = self.text
		color = (255, 255, 255)
		farleft = False
		if len(self.text) == 0:
			text = self.watermark
			color = (80, 80, 80)
			farleft = True
		
		t = get_text(text, color, 16)
		screen.blit(t, (self.x + 2, self.y + 4))
		if is_focused and (self.counter // 10) % 2 == 0:
			x = self.x + 2
			if not farleft:
				x += t.get_width()
			pygame.draw.rect(screen, (255, 255, 255), pygame.Rect(x, self.y + 3, 1, 12))
Beispiel #18
0
    def render(self, screen, is_focused):
        self.counter += 1
        pygame.draw.rect(screen, (0, 0, 0), self.box)
        pygame.draw.rect(screen, (0, 128, 255), self.box, 1)

        text = self.text
        color = (255, 255, 255)
        farleft = False
        if len(self.text) == 0:
            text = self.watermark
            color = (80, 80, 80)
            farleft = True

        t = get_text(text, color, 16)
        screen.blit(t, (self.x + 2, self.y + 4))
        if is_focused and (self.counter // 10) % 2 == 0:
            x = self.x + 2
            if not farleft:
                x += t.get_width()
            pygame.draw.rect(screen, (255, 255, 255),
                             pygame.Rect(x, self.y + 3, 1, 12))
	def __init__(self, user_id, password, sector, loc, new, research, buildings, unlock, bots, tutorial):
		self.next = self
		self.tutorial = tutorial
		
		network.toggle_tutorial(tutorial)
		if tutorial:
			from src import fakenetwork
			fakenetwork.set_active_tutorial(fakenetwork.Tutorial())
		
		self.user_id = user_id
		self.password = password
		self.counter = 0
		self.new = new
		self.sector = sector
		self.loc = loc
		self.poll = network.send_poll(user_id, password, sector, {})
		self.potato = data.MagicPotato()
		self.loading_x = 200 - get_text("Loading..", (255, 255, 255), 22).get_width() // 2
		self.potato.bytes_stolen = research
		self.potato.starting_buildings(buildings)
		self.potato.unlock = unlock
		self.potato.apply_bot_snapshot(bots[0], bots[1], bots[2])
	def render(self, screen):
		self.playscene.render(screen)
		left = screen.get_width() // 2 - self.bg.get_width() // 2
		top = screen.get_height() // 2 - self.bg.get_height() // 2
		y = top
		
		screen.blit(self.bg, (left, top))
		
		left += 5
		y += 5
		title = get_text("OH NOES!", (255, 0, 0), (24))
		lines = [
			get_tiny_text("Detecting the lowering of the sheilds"),
			get_tiny_text("a swarm of natives decide to use the"),
			get_tiny_text("opportunity to attack!")
		]
		
		screen.blit(title, (left, y))
		y += title.get_height() + 5
		for line in lines:
			screen.blit(line, (left, y))
			y += 3 + line.get_height()
	def renderstatus(self, screen):
		data = self.bytes_stolen()
		
		if self.is_computer_attacking():
			text = "Bytes lost: " + str(data)
			color = (255, 0, 0)
		else:
			text = "Bytes learned: " + str(data)
			color = (0, 100, 255)
		if data == 0:
			text = "Attack in progress"

		if self.is_computer_attacking():
			text = "Attack in progress"
		else:
			text = "Bots available:  [1]: %s/%s   [2]: %s/%s   [3]: %s/%s" % (self.nbots[0], self.nbots0[0], self.nbots[1], self.nbots0[1], self.nbots[2], self.nbots0[2])

		
		text = get_text(text, color, 22)
		x = ((screen.get_width() - text.get_width()) // 2)
		y = screen.get_height() * 4 // 5
		screen.blit(text, (x, y))
Beispiel #22
0
    def renderstatus(self, screen):
        data = self.bytes_stolen()

        if self.is_computer_attacking():
            text = "Bytes lost: " + str(data)
            color = (255, 0, 0)
        else:
            text = "Bytes learned: " + str(data)
            color = (0, 100, 255)
        if data == 0:
            text = "Attack in progress"

        if self.is_computer_attacking():
            text = "Attack in progress"
        else:
            text = "Bots available:  [1]: %s/%s   [2]: %s/%s   [3]: %s/%s" % (
                self.nbots[0], self.nbots0[0], self.nbots[1], self.nbots0[1],
                self.nbots[2], self.nbots0[2])

        text = get_text(text, color, 22)
        x = ((screen.get_width() - text.get_width()) // 2)
        y = screen.get_height() * 4 // 5
        screen.blit(text, (x, y))
	def render_details_menu(self, item, screen):
		target = item[2]
		width = 150
		top = 40
		height = 100
		bottom = top + height
		left = 5
		right = 395 - width
		dx = (right - left) // 5
		left = left + dx * (item[0] - 1)
		
		if target.startswith('build_'):

			structure_id = target.split('_')[1]
			s = structure.get_structure_by_id(structure_id)
			
			if self.details_bg == None:
				self.details_bg = pygame.Surface((width, height), pygame.SRCALPHA)
				self.details_bg.fill((0, 0, 0, 150))
			
			screen.blit(self.details_bg, (left, top))
			title = get_text(structure.get_structure_name(structure_id), (255, 255, 255), 18)
			screen.blit(title, (left + 5, top + 5))
			
			y = top + 5 + title.get_height() + 5
			description = []
			for line in structure.get_structure_description(structure_id).split('|'):
				img = get_text(line, (255, 255, 255), 14)
				screen.blit(img, (left + 5, y))
				y += img.get_height() + 4
			
			self.render_cost(screen, structure_id, left, bottom)
		else:
			caption = None
			if target.startswith('era_'):
				if target == 'era_landing':
					caption = "Resource Generating"
				elif target == 'era_lowtech':
					caption = "Defensive Structures"
				elif target == 'era_medtech':
					caption = "Offensive Structures"
				elif target == 'era_hightech':
					caption = "Miscellaneous"
				else:
					caption = "Space Travel"
			elif target == 'main_demolish':
				caption = "Demolish Building"
			elif target == 'main_build':
				caption = "Build Structure"
			elif target == 'main_bots':
				caption = "Deploy Bots"
			elif target == 'main_fight':
				caption = "Fire Lazor"
			elif target == 'main_exit':
				caption = "Main Menu"
			elif target == 'locked':
				caption = "Research to Unlock"
			
			if caption != None:
				text = get_text(caption, (255, 255, 255), 18)
				height = text.get_height() + 10
				if self.caption_bg == None:
					self.caption_bg = pygame.Surface((width + 12, height), pygame.SRCALPHA)
					self.caption_bg.fill((0, 0, 0, 150))
				
				screen.blit(self.caption_bg, (left, top))
				screen.blit(text, (left + 5, top + 5))
	def render(self, screen):
		width = screen.get_width()
		height = screen.get_height()
		
		self.playscene.render(screen)
		
		line_height = 10
		margin = 10
		left = margin + line_height
		bg = get_dark_bg(width - margin * 2, height - 35 - margin * 2)
		y = 35 + margin
		screen.blit(bg, (margin, y))
		y += line_height
		title = get_text("Deploy Seeker Bots", (255, 255, 255), 24)
		
		screen.blit(title, (left, y))
		y += title.get_height() + line_height
		
		show_ok = False
		
		deploy_status = None #self.playscene.potato.deploy_success(False)
		if deploy_status == 'deploying':
			img = get_text("Deploying...", (255, 255, 255), 24)
			screen.blit(img, (screen.get_width() // 2 - img.get_width() // 2, screen.get_height() // 2 - img.get_height() // 2))
		elif deploy_status == None:
			if self.target_user == 0:
				text = get_text("You must be in another user's base to do this.", (255, 0, 0), 14)
				screen.blit(text, (left, y))
			elif self.target_user == self.playscene.user_id:
				text = [
					get_text("You can't deploy your own bots against yourself.", (255, 255, 255), 14),
					get_text("That's just silly.", (255, 0, 255), 14)]
				for t in text:
					screen.blit(t, (left, y))
					y += t.get_height() + line_height
			else:
				show_ok = True
				text = get_text("Send bots to attack: " + self.playscene.potato.get_user_name(self.target_user), (255, 255, 255), 14)
				screen.blit(text, (left, y))
				y += line_height + text.get_height()
				
				self.num_bytes = self.playscene.potato.get_value_of_attack(self.playscene.user_id, self.target_user)
				x = left
				text = [
					get_text("If successful, you will gain ", (255, 255, 255), 14),
					get_text(str(self.num_bytes), (0, 128, 255), 16),
					get_text(" bytes of data.", (255, 255, 255), 14)]
				for t in text:
					screen.blit(t, (x, y))
					x += t.get_width()
				
				y += line_height + text[0].get_height()
				
				text = get_text("Shall we proceed?", (255, 255, 255), 18)
				screen.blit(text, (left, y))
		
		right = margin + bg.get_width()
		bottom = 35 + margin + bg.get_height()
		caption = get_text("Nevermind", (255, 255, 255), 24)
		
		bwidth = caption.get_width() + 10
		bheight = caption.get_height() + 6
		
		bleft = right - line_height - bwidth
		btop = bottom - line_height - bheight
		brect = pygame.Rect(bleft, btop, bwidth, bheight)
		hovering = self.mx >= bleft and self.mx <= bleft + bwidth and self.my >= btop and self.my < btop + bheight
		color = (0, 0, 255) if hovering else (0, 0, 0)
		
		pygame.draw.rect(screen, color, brect)
		pygame.draw.rect(screen, (255, 255, 255), brect, 1)
		screen.blit(caption, (bleft + 5, btop + 3))
		self.cancel_button = (bleft, btop, bleft + bwidth, btop + bheight)
		
		if show_ok:
			bleft = margin + line_height
			caption = get_text("FLY, MY PRETTIES!", (255, 255, 255), 24)
			
			bwidth = caption.get_width() + 10
			bheight = caption.get_height() + 6
			
			#bleft = right - line_height - bwidth
			btop = bottom - line_height - bheight
			brect = pygame.Rect(bleft, btop, bwidth, bheight)
			hovering = self.mx >= bleft and self.mx <= bleft + bwidth and self.my >= btop and self.my < btop + bheight
			color = (0, 180, 0) if hovering else (0, 0, 0)
			
			pygame.draw.rect(screen, color, brect)
			pygame.draw.rect(screen, (255, 255, 255), brect, 1)
			screen.blit(caption, (bleft + 5, btop + 3))
			
			self.ok_button = (bleft, btop, bleft + bwidth, btop + bheight)
	def render(self, screen):
		self.counter += 1
		z = (self.counter // 15) % 4
		loading = get_text("Loading" + ("." * z), (255, 255, 255), 22)
		screen.fill((0, 0, 0))
		screen.blit(loading, (self.loading_x, 100))
	def render(self, screen):
		self.last_width = screen.get_width()
		cx = self.player.x
		cy = self.player.y
		cz = self.player.z
		camera.track(cx, cy, cz)
		structures = self.potato.get_structures_for_screen(cx, cy)
		labels = []
		
		if self.curiosity != None:
			cur = self.curiosity
			for s in structures:
				if s.btype == 'hq' and s.user_id == self.user_id:
					cur.hq.x = s.x
					cur.hq.y = s.y
			entities = [cur.hq]
			height = cur.get_hq_height()
			if height != None:
				cur.hq.setheight(height)
			else:
				entities = []
		else:
			for s in structures:
				if s.btype == 'hq':
					owner_id = s.user_id
					name = self.potato.get_user_name(owner_id)
					img = get_text(name, (255, 255, 255), 18)
					px, py = camera.screenpos(s.x, s.y, s.z - 20)
					labels.append([img, px-img.get_width()//2, py])
			# Don't show destroyed buildings outside battle
			if self.battle is None:
				structures = [s for s in structures if not s.destroyed]
			entities = structures + self.shots
			# HACK
			entities += [s for s in self.sprites if (s.x - self.player.x) ** 2 + (s.y - self.player.y) ** 2 < 40 ** 2]
#			entities = structures + [self.player] + self.shots
			if self.battle != None:
				entities += self.battle.get_sprites()
		
		px, py = self.player.getModelXY()
		sx = int(px // 60)
		sy = int(py // 60)
		
		borders = self.potato.get_borders_near_sector(sx, sy)
		if self.potato.borders_by_user[self.user_id].iswithin(self.player.x, self.player.y):
			if self.build_mode:
				# HAAAAACK!
				s = structure.btypedict[self.build_mode].size if self.build_mode in structure.btypedict else 1
				cursor = (cx, cy, s)
			else:
				cursor = (cx, cy, 0)
		else:
			cursor = None
		worldmap.drawscene(screen, entities + effects.effects, cursor, borders)
		
		if self.curiosity != None:
			self.curiosity.render_skycrane(screen)
		
		for label in labels:
			screen.blit(label[0], (label[1], label[2]))
		if settings.showminimap:
		    worldmap.drawminimap(screen, entities)
		mx, my = self.player.getModelXY()
		lx, ly = int(mx // 1), int(my // 1)
#		coords = get_text("R: (%0.1f, %0.1f) M: (%0.1f, %0.1f) L: (%i, %i)" % (cx, cy, mx, my, lx, ly), (255, 255, 0), 16)
		coords = get_text("location: (%.0f, %.0f)" % (cx, cy), (255, 255, 0), 16)
		screen.blit(coords, (5, screen.get_height() - 25 - coords.get_height()))
		self.toolbar.render(screen)
		self.player.drawhealth(screen)

		if self.battle != None:
			self.battle.renderstatus(screen)
				
		left = 330
		top = 40
		y = top
		x = left
		for res in ('food', 'water', 'aluminum', 'copper', 'silicon', 'oil', 'research'):
			screen.blit(get_resource_icon(res), (left, y))
			
			color = (255, 255, 255)
			
			if res == 'research':
				amount = int(self.potato.bytes_stolen)
				color = (0, 255, 255)
			else:
				amount = int(self.potato.get_resource(res))
			
			if amount < 0:
				amount = 0
			
			famount = []
			while amount > 0:
				z = str(amount % 1000)
				while len(z) < 3:
					z = '0' + z
				famount.append(z)
				amount = amount // 1000
			
			
			
			amount = ','.join(famount[::-1])
			while len(amount) > 1 and amount[0] == '0':
				amount = amount[1:]
			
			screen.blit(get_text(str(amount), color, 14), (left + 14, y))
			
			mx, my = self.mousex, self.mousey
			
			if mx > left and my > y and my < y + 20:
				newname = {
					'food': settings.RESOURCE_FOOD,
					'water': settings.RESOURCE_WATER,
					'oil': settings.RESOURCE_OIL,
					'aluminum': settings.RESOURCE_ALUMINUM,
					'copper': settings.RESOURCE_COPPER,
					'silicon': settings.RESOURCE_SILICON,
					'research': "Bytes of Research"
				}
				img = get_text(newname[res], color, 14)
				screen.blit(img, (left - 5 - img.get_width(), y + 1))
			
			y += 20

		if self.blinkt:
			h = screen.get_height()
			w = screen.get_width()
			sh = min(h * self.blinkt // 10, h // 2 + 1)
			pygame.draw.rect(screen, (0,0,0), (0,0,w,sh), 0)
			pygame.draw.rect(screen, (0,0,0), (0,h-sh,w,sh), 0)
		
		jukebox.ensure_playing('general')