###############################################################################
# File:        guBombingView.py
# Appointment: Bombings list viewer
# Project:     GalaxyU
# Author:      AR
# History:
# 15.10.2013 (York) created
###############################################################################
import wxTools
import guObjects
import guApp
import guPlanetView
import guListView

import wx


#===============================================================================
# Ship Types list control
#===============================================================================
class CBombViewCtrl(guListView.CListViewCtrlWithBuilder):
    #---------------------------------------------------------------------------
    def __init__(self, parent, aListCreator):
        guListView.CListViewCtrlWithBuilder.__init__(self, parent, aListCreator)

    #---------------------------------------------------------------------------
    # Redefined virtual
    def PrepareBuilder(self, aBuilder):        
        # Add columns
        aBuilder.AddColumn("Star", lambda data: guApp.Application.GetReport().GetStarName(data.StarId))
        aBuilder.AddColumn("Damage Info", lambda data: self.__GetStarDamageInfo(data.StarId))
        aBuilder.AddColumn("Attacker", lambda data: data.Attacker)
        aBuilder.AddColumn("Owner", lambda data: data.Owner)
        aBuilder.AddColumn(\
            "Destroyed COL",
            lambda data: "{0:.2f}".format(data.Col/guApp.Application.API.guColFactor()), wx.LIST_FORMAT_RIGHT)
        aBuilder.AddColumn("Destroyed Population", lambda data: "{0:.2f}".format(data.Pop), wx.LIST_FORMAT_RIGHT)
        aBuilder.AddColumn("Destroyed Industry", lambda data: "{0:.2f}".format(data.Ind), wx.LIST_FORMAT_RIGHT)
                       
    #---------------------------------------------------------------------------
    def __GetStarDamageInfo(self, aStarId):
        star = guApp.Application.GetReport().FindStar(aStarId)
        return 'Wiped' if star is not None and star.Population == 0 and star.Industry == 0 else 'Damaged'

    #---------------------------------------------------------------------------
    # Redefined virtual
    def OnEdit(self, aPos): 
        guPlanetView.ShowPlanet(self.GetItems()[self.GetSelectedDataItem()].StarId)
        
        
    #---------------------------------------------------------------------------
    # Redefined virtual
    def GetPopupMenu(self):
        menu = wx.Menu()
        mi = wx.MenuItem(menu, wx.NewId(), 'Locate the star on the map')
        self.Bind(wx.EVT_MENU,
            lambda event: guApp.Application.GetStarMap().ShowSpaceObject(\
                self.GetItems()[self.GetSelectedDataItem()].StarId))
        menu.AppendItem(mi)
        return menu
#-------------------------------------------------------------------------------

