###############################################################################
# File:        guReportMessagesListView.py
# Appointment: List of report messages
# Project:     GalaxyU
# Author:      AR
# History:
# 27.04.2019 added support for "SHIP DESTROYED" and "SHIP DAMAGED"
# 19.02.2019 added support for "ASSIGNMENT WAITING"
# 31.01.2019 added support for "ASSIGNMENT FAILED"
# 19.12.2018 added support for "FAILED TO CREATE A NEW COLONY"
# 18.01.2014 Created
###############################################################################
import wxTools
import guObjects
import guApp
import guListView
import guPlanetView

import wx


#===============================================================================
# List control
#===============================================================================
class CReportMessagesViewCtrl(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("Message Type", lambda data: data.Type)
        aBuilder.AddColumn("Message Text", lambda data: data.Text)


    #---------------------------------------------------------------------------
    # Returns true if item needs star id
    def NeedsStarId(self, item):
        return item.Type == "ADDED NEW COLONY" or \
               item.Type == "COLONY LOST" or \
               item.Type == "FAILED TO CREATE A NEW COLONY" or \
               item.Type == "ASSIGNMENT FAILED" or \
               item.Type == "ASSIGNMENT WAITING" or \
               item.Type == "SHIP DESTROYED" or \
               item.Type == "SHIP DAMAGED"


    #---------------------------------------------------------------------------
    # Redefined virtual
    def OnEdit(self, aPos):
        item = self.GetItems()[self.GetSelectedDataItem()]
        if self.NeedsStarId(item):
            starId = int(item.AdditionalData)
            guPlanetView.ShowPlanet(int(item.AdditionalData))


    #---------------------------------------------------------------------------
    # Redefined virtual
    def GetPopupMenu(self):
        item = self.GetItems()[self.GetSelectedDataItem()]

        menu = wx.Menu()
        if self.NeedsStarId(item):
            mi = wx.MenuItem(menu, wx.NewId(), 'Locate the star on the map')
            starId = int(item.AdditionalData)
            self.Bind(wx.EVT_MENU,
                lambda event: guApp.Application.GetStarMap().ShowSpaceObject(\
                    starId))
            menu.AppendItem(mi)

        return menu

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

#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# Shows a list of report messages
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
def ShowReportMessagesList():
    return guApp.Application.WindowsCollection.RegisterAndShow(\
        lambda: guListView.CListViewFrame(\
            guApp.Application.GetMainWindow(),
            lambda: guApp.Application.GetReport().ReportMessages,
            lambda panel, aListCreator: CReportMessagesViewCtrl(panel, aListCreator),
            "CReportMessagesViewCtrl", 
            "Report Messages"))
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
