#"""Add bridge preview to QB Pane as suggested on the forums"""
###############################################################################
# Filename: 000-Foundation-Bridge-Preview-2020929.py
#
# by Mario, aka USS Sovereign
#
# A quick battle bridge preview
#
# Created: 2020/09/29 - USS Sovereign, modified by HaxxOR1337
###############################################################################
import App
import Foundation
import QuickBattle.QuickBattle
menuScrollers = None
try:
import Custom.Sneaker.MenuScrollers
menuScrollers = Custom.Sneaker.MenuScrollers
except:
pass
QB = QuickBattle.QuickBattle
originalBuildDialog = QB.BuildDialog
#####################################
# edit for precise position
#####################################
REGION_MENU_HEIGHT = 0.5
BRIDGE_MENU_X_POS = 0.508
BRIDGE_MENU_Y_POS = 0.518
BRIDGE_MENU_WIDTH = 0.464
BRIDGE_MENU_ICON_X_POS = 0.23
iconRegistry = {}
qbIcons = "QBIcons"
#####################################
# for low resolution /128/
# 800x600, 1024x1024, 1280x1024
# for higher resolution /256/
#####################################
iconPath = "data/Icons/Bridge/256/%s.tga"
icons = None
iconsPane = None
if int(Foundation.version[0:8]) >= 20030222:
print("Adding bridge preview pane...")
def RegisterQBIcons(group=None):
global iconRegistry
if not group:
group = App.g_kIconManager.CreateIconGroup(qbIcons)
App.g_kIconManager.AddIconGroup(group)
if len(iconRegistry) == 0:
position = 1
for bridge in Foundation.bridgeList:
path = iconPath % bridge.name
try:
textureHandle = group.LoadIconTexture(path)
if textureHandle > -1:
group.SetIconLocation(position, textureHandle, 0, 0, 256, 256) # 225 = /128/ | 256 = /256/
iconRegistry[bridge.name] = {'path': path, 'exists': 1, 'position': position}
position = position + 1
else:
iconRegistry[bridge.name] = {'path': path, 'exists': 0, 'position': 0}
except:
iconRegistry[bridge.name] = {'path': path, 'exists': 0, 'position': 0}
pass
else:
for k, v in iconRegistry:
textureHandle = group.LoadIconTexture(v['path'])
group.SetIconLocation(v['position'], textureHandle, 0, 0, 256, 256) # 225 = /128/ | 256 = /256/
def GetQBIcon(bridgeName):
global iconRegistry
if not bridgeName:
return None
if iconRegistry[bridgeName]['exists']:
return iconRegistry[bridgeName]['position']
return None
def GeneratePlayerBridgeMenu(iShipsUnlocked1):
global icons, iconsPane
# Create menus for the player's ship
# making the bridge menu the slightest bit longer
pShipMenu = App.STSubPane_Create(QB.BRIDGE_MENU_WIDTH,
QB.BRIDGE_MENU_HEIGHT, 1)
iconsPane = App.STSubPane_Create(QB.BRIDGE_MENU_WIDTH,
QB.BRIDGE_MENU_HEIGHT, 1)
icons = App.TGIcon_Create(qbIcons, App.SPECIES_UNKNOWN)
icons.Resize(QB.BRIDGE_MENU_WIDTH, QB.BRIDGE_MENU_HEIGHT)
RegisterQBIcons()
App.g_kIconManager.RegisterIconGroup(qbIcons, __name__, "RegisterQBIcons")
LoadIcon()
iconsPane.AddChild(icons)
pStylizedWindow = App.STStylizedWindow_CreateW("StylizedWindow", "NoMinimize",
QB.g_pMissionDatabase.GetString("Select Player Bridge"))
pStylizedWindow.SetUseScrolling(1)
# making the bridge menu the slightest bit longer
pStylizedWindow.SetFixedSize(BRIDGE_MENU_WIDTH,
QB.BRIDGE_MENU_HEIGHT)
pStylizedWindow.SetTitleBarThickness(QB.BAR_HEIGHT)
pStylizedWindow.AddChild(iconsPane, BRIDGE_MENU_ICON_X_POS)
pStylizedWindow.AddChild(pShipMenu)
QB.g_pPlayerPane.AddChild(pStylizedWindow, QB.BRIDGE_MENU_X_POS, QB.BRIDGE_MENU_Y_POS)
###############################################################################
# Dasher42's additions
QB.bridgeMenuBuilder(QB.qbGameMode.bridgeList, pShipMenu, QB.ET_SELECT_BRIDGE_TYPE, QB.g_pXO)
pShipMenu.Resize(pShipMenu.GetWidth() - (BRIDGE_MENU_WIDTH - QB.BRIDGE_MENU_WIDTH),
pShipMenu.GetTotalHeightOfChildren())
iconsPane.Resize(iconsPane.GetWidth() - (BRIDGE_MENU_WIDTH - QB.BRIDGE_MENU_WIDTH),
iconsPane.GetTotalHeightOfChildren())
pStylizedWindow.Layout()
pStylizedWindow.InteriorChangedSize()
return pStylizedWindow
def BuildDialog(bPreservePane=0):
addHandler = QB.g_bAddedUIHandlers
originalBuildDialog(bPreservePane)
if not addHandler:
QB.g_pXO.AddPythonFuncHandlerForInstance(QB.ET_SELECT_BRIDGE_TYPE, __name__ + ".HandleBridgeIcon")
def HandleBridgeIcon(pObject, pEvent):
LoadIcon(Foundation.bridgeList[pEvent.GetInt()].name)
pObject.CallNextHandler(pEvent)
def LoadIcon(bridgeName=None):
global iconRegistry
if not bridgeName:
for bridge in Foundation.bridgeList:
if bridge.bridgeString == QB.g_sBridgeType:
bridgeName = bridge.name
break
icon = GetQBIcon(bridgeName)
if icon:
icons.SetVisible()
icons.SetIconNum(icon)
icons.SizeToArtwork()
else:
icons.SetNotVisible()
class FoundationPreviewPane:
def __init__(self):
self.__funcoverride__()
def __funcoverride__(self):
QB.REGION_MENU_HEIGHT = REGION_MENU_HEIGHT
QB.GeneratePlayerBridgeMenu = GeneratePlayerBridgeMenu
QB.BuildDialog = BuildDialog
if menuScrollers:
menuScrollers.GeneratePlayerBridgeMenu = GeneratePlayerBridgeMenu
Foundation.FoundationPreviewPane = FoundationPreviewPane()