###############################################################################
# File:        guKnownNationsListView.py
# Appointment: List of known nations
# Project:     GalaxyU
# Author:      AR
# History:
# 18.01.2014 Created
###############################################################################
import wxTools
import guObjects
import guApp
import guListView

import wx


#===============================================================================
# List control
#===============================================================================
class CKnownNationsViewCtrl(guListView.CListViewCtrlWithBuilder):
    #---------------------------------------------------------------------------
    def __init__(self, parent, aListCreator):
        guListView.CListViewCtrlWithBuilder.__init__(self, parent, aListCreator)
        
    #---------------------------------------------------------------------------
    # Redefined virtual
    def PrepareBuilder(self, aBuilder):
        # Add columns
        aBuilder.AddColumn("Nation", lambda data: data.NationName)
        aBuilder.AddColumn("Known Nation", lambda data: data.KnownNationName)
        aBuilder.AddColumn("Diplomatic State", 
            lambda data: guApp.Application.GetReport().GetDiplomaticState(data.KnownNationName))
        aBuilder.AddColumn("Last Contact (years ago)", 
            lambda data: str(guApp.Application.GetReport().Turn - data.LastTimeContact), wx.LIST_FORMAT_RIGHT, True)
        aBuilder.AddColumn("Tech Drive", 
            lambda data: "{0:.2f}".format(data.TechDrive), wx.LIST_FORMAT_RIGHT, True)
        aBuilder.AddColumn("Tech Weapon", 
            lambda data: "{0:.2f}".format(data.TechWeapon), wx.LIST_FORMAT_RIGHT, True)
        aBuilder.AddColumn("Tech Shield",
            lambda data: "{0:.2f}".format(data.TechShield), wx.LIST_FORMAT_RIGHT, True)
        aBuilder.AddColumn("Tech Cargo", 
            lambda data: "{0:.2f}".format(data.TechCargo), wx.LIST_FORMAT_RIGHT, True)
        aBuilder.AddColumn("Last techs updated", 
            lambda data: str(guApp.Application.GetReport().Turn - data.LastTechUpdated) if data.LastTechUpdated > 0 else guObjects.NA, wx.LIST_FORMAT_RIGHT, True)
        aBuilder.AddColumn("Population", 
            lambda data: "{0:.2f}".format(data.Population) if data.Population != guObjects.CRatingData.RATING_NA else guObjects.NA, wx.LIST_FORMAT_RIGHT, True)
        aBuilder.AddColumn("Industry", 
            lambda data: "{0:.2f}".format(data.Industry) if data.Industry != guObjects.CRatingData.RATING_NA else guObjects.NA, wx.LIST_FORMAT_RIGHT, True)
        aBuilder.AddColumn("Last pop/ind updated", 
            lambda data: str(guApp.Application.GetReport().Turn - data.LastPopulationUpdated) if data.LastPopulationUpdated > 0 else guObjects.NA, wx.LIST_FORMAT_RIGHT, True)


    #---------------------------------------------------------------------------
    def OnGetItemAttr(self, item):
        return guApp.Application.GetReport().GetDiplomaticStateColourAttr(\
            self.GetItems()[self.RowToItem(item)].KnownNationName)

#-------------------------------------------------------------------------------

#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# Shows a list of known nations
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
def ShowKnownNationsList():
    return guApp.Application.WindowsCollection.RegisterAndShow(\
        lambda: guListView.CListViewFrame(\
            guApp.Application.GetMainWindow(),
            lambda: guApp.Application.GetReport().KnownNations,
            lambda panel, aListCreator: CKnownNationsViewCtrl(panel, aListCreator),
            "CKnownNationsViewCtrl", 
            "Known Nations"))
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
