###############################################################################
# File:        guGBView.py
# Appointment: Ground Battles list viewer
# Project:     GalaxyU
# Author:      AR
# History:
# 24.11.2013 Created
###############################################################################
import wxTools
import guObjects
import guApp
import guGroundBattle
import guListView

import wx


#===============================================================================
# Ship Types list control
#===============================================================================
class CGBViewCtrl(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(\
            "Invader", 
            lambda data: data.InvaderNationName)
        aBuilder.AddColumn(\
            "Owner", 
            lambda data: data.OwnerNationName)
        aBuilder.AddColumn(\
            "Invader Force",
            lambda data: "{0:.2f}".format(data.InvaderInitialCol), wx.LIST_FORMAT_RIGHT)
        aBuilder.AddColumn(\
            "Owner Force", 
            lambda data: "{0:.2f}".format(data.OwnerInitialCol), wx.LIST_FORMAT_RIGHT)
        aBuilder.AddColumn(\
            "Remaining Invader Force", 
            lambda data: "{0:.2f}".format(data.InvaderResultCol), wx.LIST_FORMAT_RIGHT)
        aBuilder.AddColumn(\
            "Remaining Owner Force", 
            lambda data: "{0:.2f}".format(data.OwnerResultCol), wx.LIST_FORMAT_RIGHT)
        aBuilder.AddColumn(\
            "Invader Loses", 
            lambda data: "{0:.2f}".format(data.InvaderInitialCol - data.InvaderResultCol), wx.LIST_FORMAT_RIGHT)
        aBuilder.AddColumn(\
            "Owner Loses", 
            lambda data: "{0:.2f}".format(data.OwnerInitialCol - data.OwnerResultCol), wx.LIST_FORMAT_RIGHT)


    #---------------------------------------------------------------------------
    # Redefined virtual
    def OnEdit(self, aPos):
        starMap = guApp.Application.GetStarMap()
        starId = self.GetItems()[self.GetSelectedDataItem()].StarId
        guGroundBattle.CGBViewer(self.GetItems()[self.GetSelectedDataItem()], 
                                 guApp.Application.GetReport().FindStar(starId),
                                 starMap.GetPlanetImage(starId), 
                                 starMap.GetStarImage(starId), 
                                 "GUI", "GBViewer").Go()

    #---------------------------------------------------------------------------
    # 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
#-------------------------------------------------------------------------------

#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# Shows a list of ground battles for star
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
def ShowGroundBattles(aStarId):
    return guApp.Application.WindowsCollection.RegisterAndShow(\
        lambda: guListView.CListViewFrame(\
            guApp.Application.GetMainWindow(),
            lambda: guApp.Application.GetReport().GetGroundBattleRecords(aStarId),
            lambda panel, aListCreator: CGBViewCtrl(panel, aListCreator),
            "CGBViewCtrl", 
            "All Ground Battles" if aStarId == 0 \
                else ("Ground Battles in the Star System " + \
                    guApp.Application.GetReport().GetStarName(aStarId))))
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
