Jump to content
Korean Random
AntonVK

[1.5.x] Вызов окна в ангаре при нажатии кнопки

Recommended Posts

Добрый день!

 

Прошу помочь в следующем вопросе.

 

До патча 1.5.х  использовал в своем моде следующую конструкцию

 

 

Python (для кнопки вызова)

#
import os
#
from gui.app_loader.loader import g_appLoader
from gui.Scaleform import SCALEFORM_SWF_PATH
from gui.Scaleform.Flash import Flash
from gui.Scaleform.framework import g_entitiesFactories, ViewSettings, ViewTypes, ScopeTemplates
from gui.Scaleform.framework.entities.abstract.AbstractViewMeta import AbstractViewMeta
from gui.Scaleform.framework.entities.View import View
from gui.Scaleform.framework.managers.loaders import SFViewLoadParams
from gui.shared import events
from gui.app_loader.settings import APP_NAME_SPACE
from gui.shared import g_eventBus, EVENT_BUS_SCOPE

class hangarCalculatorButton(View, AbstractViewMeta):

	def __init__(self):
		View.__init__(self)

	def _populate(self):
		View._populate(self)

	def _dispose(self):
		View._dispose(self)

	def py_log(self, text):
		print('[hangarCalculatorButton]: %s' % text)

	def py_getWoTPath(self):
		__WoT__ = os.path.dirname(os.path.abspath(__file__))
		__WoT__ = __WoT__[0:__WoT__.rfind('scripts')]
		return __WoT__

_windowAlias = 'hangarCalculatorButton'
_url = 'hangarCalculatorButton.swf'
_type = ViewTypes.WINDOW
_event = None
_scope = ScopeTemplates.GLOBAL_SCOPE

_settings = ViewSettings(_windowAlias, hangarCalculatorButton, _url, _type, _event, _scope)
g_entitiesFactories.addSettings(_settings)

def new_afterCreate(self):
    old_afterCreate(self)
    self.addExternalCallback('hangarCalculatorButton.showCalculator', lambda name, alias: g_appLoader.getApp().loadView(SFViewLoadParams('hangarCalculator', 'hangarCalculator')))

old_afterCreate = Flash.afterCreate
Flash.afterCreate = new_afterCreate

def onAppInitialized(event):
    if event.ns == APP_NAME_SPACE.SF_LOBBY:
        app = g_appLoader.getApp(event.ns)
        if app:
            app.loadView(SFViewLoadParams(_windowAlias, _windowAlias))


g_eventBus.addListener(events.AppLifeCycleEvent.INITIALIZED, onAppInitialized, scope=EVENT_BUS_SCOPE.GLOBAL)

 

AS3 (для кнопки вызова)

package  {

	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.external.ExternalInterface;
	import net.wg.gui.lobby.LobbyPage;
	import net.wg.infrastructure.base.AbstractView;
	import net.wg.infrastructure.events.LoaderEvent;
	import net.wg.infrastructure.interfaces.IView;
	import scaleform.clik.events.ButtonEvent;

	public class hangarCalculatorButton extends AbstractView implements IhangarCalculatorButton {

		public function hangarCalculatorButton() {
			super();
			this.init();
		}

		public var py_log:Function;
		public var py_getWoTPath:Function;

		private var lobby:LobbyPage = null;
		private var current_alias:String = "";

		private var zCalculatorButton:hCalculatorButton;

		private function init(param1:Event = null):void {
			if(!stage) {
				addEventListener(Event.ADDED_TO_STAGE,this.init);
				return;
			}
			removeEventListener(Event.ADDED_TO_STAGE,this.init);
			App.containerMgr.loader.addEventListener(LoaderEvent.VIEW_LOADED,this.onViewLoaded);
		}

		private function onViewLoaded(param1:LoaderEvent):void {
			this.processView(param1.view,false);
		}

		private function processView(param1:IView, param2:Boolean):void {
			var view:IView = param1;
			var populated:Boolean = param2;
			var _WoT_:String = py_getWoTPath();
			try {
				this.zCalculatorButton = new hCalculatorButton(_WoT_);
				this.current_alias = view.as_config.alias;
				this.zCalculatorButton.addEventListener(ButtonEvent.CLICK,this.onCalcBtnClick);
				if(this.current_alias == "lobby") {
					this.lobby = view as LobbyPage;
					this.lobby.header.addChild(this.zCalculatorButton);
					//py_log("is loaded");
				}
			}
			catch(error:Error) {
				py_log("processView" + error.getStackTrace());
			}
		}

		override protected function nextFrameAfterPopulateHandler():void {
			if(this.parent != App.instance) {
				(App.instance as MovieClip).addChild(this);
			}
			visible = false;
		}

		override protected function onDispose():void {
			this.zCalculatorButton.removeEventListener(MouseEvent.CLICK,this.onCalcBtnClick);
		}

		private function onCalcBtnClick(param1:ButtonEvent):void {
			var external:Array = new Array();
			external.push(this.current_alias);
			external.unshift("hangarCalculatorButton.showCalculator","hangarCalculatorButton");
			ExternalInterface.call.apply(null,external);
		}

	}

}

 

Эти две вещи между собой взаимодействовали и далее там уже вызывался собственный код.

 

В результате, в ангаре кнопка, нажимаешь кнопку открывается окошко и всё как надо.

 

В текущей версии игрового клиента мои попытки что-то исправить ни к чему не привели.

 

Python исправил следующим образом:

 

Python (для кнопки вызова)

#
import os
#
from gui.shared.personality import ServicesLocator
from gui.Scaleform import SCALEFORM_SWF_PATH
from gui.Scaleform.flash_wrapper import Flash
from gui.Scaleform.framework import g_entitiesFactories, ViewSettings, ViewTypes, ScopeTemplates
from gui.Scaleform.framework.entities.abstract.AbstractViewMeta import AbstractViewMeta
from gui.Scaleform.framework.entities.View import View
from gui.Scaleform.framework.managers.loaders import SFViewLoadParams
from gui.shared import events
from gui.app_loader.settings import APP_NAME_SPACE
from gui.shared import g_eventBus, EVENT_BUS_SCOPE

class hangarCalculatorButton(View, AbstractViewMeta):

	def __init__(self):
		View.__init__(self)

	def _populate(self):
		View._populate(self)

	def _dispose(self):
		View._dispose(self)

	def py_log(self, text):
		print('[hangarCalculatorButton]: %s' % text)

	def py_getWoTPath(self):
		__WoT__ = os.path.dirname(os.path.abspath(__file__))
		__WoT__ = __WoT__[0:__WoT__.rfind('scripts')]
		return __WoT__

_windowAlias = 'hangarCalculatorButton'
_url = 'hangarCalculatorButton.swf'
_type = ViewTypes.WINDOW
_event = None
_scope = ScopeTemplates.GLOBAL_SCOPE

_settings = ViewSettings(_windowAlias, hangarCalculatorButton, _url, _type, _event, _scope)
g_entitiesFactories.addSettings(_settings)

def new_afterCreate(self):
    old_afterCreate(self)
    self.addExternalCallback('hangarCalculatorButton.showCalculator', lambda name, alias: ServicesLocator.appLoader.getApp().loadView(SFViewLoadParams('hangarCalculator', 'hangarCalculator')))

old_afterCreate = Flash.afterCreate
Flash.afterCreate = new_afterCreate

def onAppInitialized(event):
    if event.ns == APP_NAME_SPACE.SF_LOBBY:
        app = ServicesLocator.appLoader.getApp(event.ns)
        if app:
            app.loadView(SFViewLoadParams(_windowAlias, _windowAlias))


g_eventBus.addListener(events.AppLifeCycleEvent.INITIALIZED, onAppInitialized, scope=EVENT_BUS_SCOPE.GLOBAL)

Python (для самого окна)

#
from gui.Scaleform import SCALEFORM_SWF_PATH
from gui.Scaleform.daapi import LobbySubView
from gui.Scaleform.daapi.view.meta.WindowViewMeta import *
from gui.Scaleform.flash_wrapper import Flash
from gui.Scaleform.framework import g_entitiesFactories, ViewSettings, ViewTypes, ScopeTemplates
from gui.Scaleform.framework.entities.View import View

from gui.shared import events

LobbySubView.__background_alpha__ = 0

class hangarCalculator(LobbySubView, WindowViewMeta):

	def __init__(self):
		View.__init__(self)

	def _populate(self):
		View._populate(self)

	def _dispose(self):
		View._dispose(self)

	def onTryClosing(self):
		return True

	def onWindowClose(self):
		self.destroy()

	def py_log(self, text):
		print('[hangarCalculator]: %s' % text)

_windowAlias = 'hangarCalculator'
_url = 'hangarCalculator.swf'
_type = ViewTypes.WINDOW
_event = None
_scope = ScopeTemplates.DEFAULT_SCOPE

_settings = ViewSettings(_windowAlias, hangarCalculator, _url, _type, _event, _scope)
g_entitiesFactories.addSettings(_settings)

 

Ожидаемо, заменить только g_appLoader на ServicesLocator.appLoader.getApp() ничем не помогло в данном случае.

 

Для AS3 код части, которая взаимодействует с Python, ничего не менял. Для кнопки код выше для окна вот (на всякий случай)

package  {

	import flash.display.MovieClip;
	import net.wg.infrastructure.base.AbstractWindowView;

	public class hangarCalculator extends AbstractWindowView {

		public function hangarCalculator() {
			super();
			isCentered = true;
		}

		public var py_log: Function;

		private var zCalculator:hCalculator;

		override protected function onPopulate():void {
			super.onPopulate();
		}

		override protected function onDispose():void {
			super.onDispose();
		}

		override protected function configUI():void {
			try {
				super.configUI();
			}
			catch(error:Error) {
				py_log("configUI " + error.getStackTrace());
			}
		}

	}

}

 

Что в итоге, кнопка на месте, окно не вызывается.

 

Буду признателен за помощь в решении проблемы.

 

Спасибо!

 

Share this post


Link to post

Short link
Share on other sites

в прошлом патче флешь класс изменили, поэтому теперь делай так

 

from gui.Scaleform.framework.application import AppEntry

def new_afterCreate(self):
    old_afterCreate(self)
    self.addExternalCallback('hangarCalculatorButton.showCalculator', lambda name, alias: ServicesLocator.appLoader.getApp().loadView(SFViewLoadParams('hangarCalculator', 'hangarCalculator')))

old_afterCreate = AppEntry.afterCreate
AppEntry.afterCreate = new_afterCreate

 

Edited by Ekspoint
  • Upvote 2

Share this post


Link to post

Short link
Share on other sites

@Ekspoint 

 

Большое спасибо!

 

Сегодня добрался проверить, теперь вызов работает нормально.

Share this post


Link to post

Short link
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×