Skip to content

Commit

Permalink
Added mod settings for MCM preview.
Browse files Browse the repository at this point in the history
  • Loading branch information
Scrivener07 committed Sep 5, 2018
1 parent e201ca6 commit 7305c4d
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 79 deletions.
5 changes: 2 additions & 3 deletions Data.Prototype/Interface/Source/ODST/ODST/MCM/Library.as
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@

public function Library()
{
Debug.WriteLine("Library", "(ctor)", "Constructor Code");
Debug.WriteLine("[MCM]", "[Library]", "(ctor)", "Constructor Code");
}

public function onLibLoaded(mcmCodeObject:*, f4seCodeObject:*):void
{
Debug.WriteLine("Library", "(onLibLoaded)", "MCM scaleform callback has been received.");
f4seCodeObject.SendExternalEvent("ODST_TestEvent");
Debug.WriteLine("[MCM]", "[Library]", "(onLibLoaded)", "MCM scaleform callback has been received.");
Debug.TraceObject(f4seCodeObject);
Debug.TraceObject(mcmCodeObject);
EmblemPreview.onLibLoaded(mcmCodeObject, f4seCodeObject);
Expand Down
Binary file modified Data.Prototype/Interface/Source/ODST/ODST/MCM/Library.fla
Binary file not shown.
93 changes: 82 additions & 11 deletions Data.Prototype/Interface/Source/ODST/ODST/MCM/Preview.as
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,23 @@
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.events.TimerEvent;
import flash.utils.*;
import AS3.*;
import MCM.*;

public class Preview extends MovieClip implements IMCMLibrary
{
private var mcm:*;

private var sEmblem_PreviewPrimary:String;
private var sEmblem_PreviewSecondary:String;
private var sEmblem_PreviewBackground:String;

private var iEmblem_PreviewPrimaryColor:int;
private var iEmblem_PreviewSecondaryColor:int;
private var iEmblem_PreviewBackgroundColor:int;

public static const MenuName:String = "PauseMenu"; // use root menu?

public var PrimaryTexture:TextureLoader;
Expand All @@ -22,24 +34,83 @@

public function Preview()
{
Debug.WriteLine("Preview", "ctor", "Constructor Code", "Hello");
Debug.WriteLine("[MCM]", "[Preview]", "(ctor)", "Constructor Code");
// var timer:Timer = new Timer(3000); // rip
// timer.addEventListener(TimerEvent.TIMER, OnTimer);
// timer.start();
}


// private function OnTimer(e:TimerEvent):void
// {
// Debug.WriteLine("[MCM]", "[Preview]", "OnTimer", e);
// GetModSettings();
// }


public function onLibLoaded(mcmCodeObject:*, f4seCodeObject:*):void
{
Debug.WriteLine("Preview", "(onLibLoaded)", "MCM scaleform callback has been received.");
Debug.WriteLine("[MCM]", "[Preview]", "(onLibLoaded)", "MCM scaleform callback has been received.");
mcm = mcmCodeObject;

PrimaryTexture.onF4SEObjCreated(f4seCodeObject);
PrimaryTexture.ImageMountID = PrimaryMountID;
PrimaryTexture.Load("ProjectHelljumper\\H3ODST\\1Decals\\Decals\\Primary\\Spartan1.dds");
try
{
PrimaryTexture.onF4SEObjCreated(f4seCodeObject);
PrimaryTexture.ImageMountID = PrimaryMountID;
// PrimaryTexture.Load("ProjectHelljumper\\H3ODST\\1Decals\\Decals\\Primary\\Spartan1.dds");

SecondaryTexture.onF4SEObjCreated(f4seCodeObject);
SecondaryTexture.ImageMountID = SecondaryMountID;
SecondaryTexture.Load("ProjectHelljumper\\H3ODST\\1Decals\\Decals\\Secondary\\Spartan2.dds");
SecondaryTexture.onF4SEObjCreated(f4seCodeObject);
SecondaryTexture.ImageMountID = SecondaryMountID;
// SecondaryTexture.Load("ProjectHelljumper\\H3ODST\\1Decals\\Decals\\Secondary\\Spartan2.dds");

BackgroundTexture.onF4SEObjCreated(f4seCodeObject);
BackgroundTexture.ImageMountID = BackgroundMountID;
BackgroundTexture.Load("ProjectHelljumper\\H3ODST\\1Decals\\Decals\\Background\\Shield.dds");
BackgroundTexture.onF4SEObjCreated(f4seCodeObject);
BackgroundTexture.ImageMountID = BackgroundMountID;
// BackgroundTexture.Load("ProjectHelljumper\\H3ODST\\1Decals\\Decals\\Background\\Shield.dds");

}
catch (error:Error)
{
Debug.WriteLine("[MCM]", "[Preview]", "(onLibLoaded)", "ERROR:", error.toString());
}

GetModSettings(mcmCodeObject);
}


private function GetModSettings(mcmCodeObject:*):void
{
if(mcm != null)
{
try
{
sEmblem_PreviewPrimary = mcm.GetModSettingString("ODST", "sEmblem_PreviewPrimary:Settings");
sEmblem_PreviewSecondary = mcm.GetModSettingString("ODST", "sEmblem_PreviewSecondary:Settings");
sEmblem_PreviewBackground = mcm.GetModSettingString("ODST", "sEmblem_PreviewBackground:Settings");
iEmblem_PreviewPrimaryColor = mcm.GetModSettingInt("ODST", "iEmblem_PreviewPrimaryColor:Settings");
iEmblem_PreviewSecondaryColor = mcm.GetModSettingInt("ODST", "iEmblem_PreviewSecondaryColor:Settings");
iEmblem_PreviewBackgroundColor = mcm.GetModSettingInt("ODST", "iEmblem_PreviewBackgroundColor:Settings");
Debug.WriteLine("[MCM]", "[Preview]", "(GetModSettings) Path", sEmblem_PreviewPrimary, sEmblem_PreviewSecondary, sEmblem_PreviewBackground);
Debug.WriteLine("[MCM]", "[Preview]", "(GetModSettings) Color", String(iEmblem_PreviewPrimaryColor), String(iEmblem_PreviewSecondaryColor), String(iEmblem_PreviewBackgroundColor));
}
catch (error:Error)
{
Debug.WriteLine("[MCM]", "[Preview]", "(GetModSettings::GetModSetting)", "ERROR:", error.toString());
}
try
{
PrimaryTexture.Load(sEmblem_PreviewPrimary);
PrimaryTexture.Load(sEmblem_PreviewSecondary);
PrimaryTexture.Load(sEmblem_PreviewBackground);
}
catch (error:Error)
{
Debug.WriteLine("[MCM]", "[Preview]", "(GetModSettings::Load)", "ERROR:", error.toString());
}
}
else
{
Debug.WriteLine("[MCM]", "[Preview]", "(GetModSettings)", "ERROR: The mcm object is null.");
}
}


Expand Down
26 changes: 14 additions & 12 deletions Data.Prototype/Interface/Source/ODST/ODST/MCM/TextureLoader.as
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ package

public dynamic class TextureLoader extends MovieClip implements IExtensions
{
public var ImageMountID:String; // must set from Preview.as
public var MenuName:String;
public var ImageMountID:String;
private var f4se:*;

// Files
Expand All @@ -39,7 +40,7 @@ package
ContentLoader = new Loader();
Info.addEventListener(Event.COMPLETE, this.OnLoadComplete);
Info.addEventListener(IOErrorEvent.IO_ERROR, this.OnLoadError);
Debug.WriteLine("[TextureLoader]", "(ctor)", "Constructor Code");
Debug.WriteLine("[MCM]", "[TextureLoader]", "(ctor)", "Constructor Code");
}


Expand All @@ -48,11 +49,11 @@ package
if(codeObject != null)
{
f4se = codeObject;
Debug.WriteLine(toString(), "(onF4SEObjCreated)", "Received F4SE code object.");
Debug.WriteLine("[MCM]", toString(), "(onF4SEObjCreated)", "Received F4SE code object.");
}
else
{
Debug.WriteLine(toString(), "(onF4SEObjCreated)", "The f4se object is null.");
Debug.WriteLine("[MCM]", toString(), "(onF4SEObjCreated)", "The f4se object is null.");
}
}

Expand All @@ -65,16 +66,16 @@ package
Unload();
if(GetTextureExists(filepath))
{
F4SE.Extensions.MountImage(f4se, Preview.MenuName, filepath, ImageMountID);
F4SE.Extensions.MountImage(f4se, MenuName, filepath, ImageMountID);
var urlRequest:URLRequest = new URLRequest("img://"+ImageMountID);
ContentLoader.load(urlRequest);
FilePath = filepath;
Debug.WriteLine(toString(), "(Load)", "'"+urlRequest.url+"' as '"+filepath+"' to "+Preview.MenuName+" with resource ID "+ImageMountID);
Debug.WriteLine("[MCM]", toString(), "(Load)", "'"+urlRequest.url+"' as '"+filepath+"' to "+MenuName+" with resource ID "+ImageMountID);
return true;
}
else
{
Debug.WriteLine(toString(), "(Load)", "'"+filepath+"' does not exist.");
Debug.WriteLine("[MCM]", toString(), "(Load)", "'"+filepath+"' does not exist.");
return false;
}
}
Expand All @@ -89,15 +90,16 @@ package

private function OnLoadComplete(e:Event):void
{
Debug.WriteLine(toString(), "(OnLoadComplete)", e.toString()+"\n"+toString());
Debug.WriteLine("[MCM]", toString(), "(OnLoadComplete)", e.toString()+"\n"+toString());
addChild(Content);
Utility.ScaleToHeight(this, 75);
this.visible = true;
}


private function OnLoadError(e:IOErrorEvent):void
{
Debug.WriteLine(toString(), "(OnLoadError)", e.toString()+"\n"+toString());
Debug.WriteLine("[MCM]", toString(), "(OnLoadError)", e.toString()+"\n"+toString());
Unload();
}

Expand All @@ -111,16 +113,16 @@ package

if (FilePath != null)
{
F4SE.Extensions.UnmountImage(f4se, Preview.MenuName, FilePath);
Debug.WriteLine(toString(), "(Unload)", "Unmounted the image '"+FilePath+"' from "+Preview.MenuName+" with resource ID "+ImageMountID);
F4SE.Extensions.UnmountImage(f4se, MenuName, FilePath);
Debug.WriteLine("[MCM]", toString(), "(Unload)", "Unmounted the image '"+FilePath+"' from "+MenuName+" with resource ID "+ImageMountID);
}

if (Content)
{
this.visible = false;
removeChild(Content);
Content.loaderInfo.loader.unload();
Debug.WriteLine(toString(), "(Unload)", "Unloaded content from loader.");
Debug.WriteLine("[MCM]", toString(), "(Unload)", "Unloaded content from loader.");
}
}

Expand Down
6 changes: 6 additions & 0 deletions Data.Prototype/MCM/Config/ODST/settings.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
[Settings]
iEmblem_Selected=0
sEmblem_PreviewPrimary=""
iEmblem_PreviewPrimaryColor=0
sEmblem_PreviewSecondary=""
iEmblem_PreviewSecondaryColor=0
sEmblem_PreviewBackground=""
iEmblem_PreviewBackgroundColor=0

[Emblem001]
iEmblem_Foreground=0
Expand Down
66 changes: 26 additions & 40 deletions Data.Prototype/Scripts/Source/ODST/ODST/Emblems/Editor.psc
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ EndEvent

Event OnGameReload()
WriteLine(self, "OnGameReload")
Deserialize()
Update()

If (Deserialize() > Invalid)
Update()
UseMaterial(self, Game.GetPlayer())
EndIf
EndEvent


Expand All @@ -48,16 +51,10 @@ Event ODST:MCM:Menu.OnMenuState(MCM:Menu sender, var[] arguments)
If (arguments)
MCM:Menu:MenuStateEventArgs e = sender.GetMenuStateEventArgs(arguments)
WriteLine(self, "ODST:MCM:Menu.OnMenuState", e)

If (e.MenuState == sender.MenuOpened)
Deserialize()
sender.RefreshMenu()
EndIf

; If (e.MenuState == sender.MenuClosed)
; ; TODO: Call `Update` here for material change?
; EndIf

Else
WriteUnexpectedValue(self, "ODST:MCM:Menu.OnMenuState", "arguments", "The arguments are none or empty.")
EndIf
Expand All @@ -76,7 +73,7 @@ Event ODST:MCM:Menu.OnOption(MCM:Menu sender, var[] arguments)
sender.RefreshMenu()
Else
Emblems:Preset preset = GetPreset(Selected)
preset.OnChangeValue(ConfigurationMenu, e)
preset.SetValue(ConfigurationMenu, e)
Preview.Update(self, preset)
Update()
sender.RefreshMenu()
Expand Down Expand Up @@ -116,7 +113,7 @@ Function Update()
While (index < Presets.Length)
Emblems:Preset preset = Presets[index]
preset.Condition = (Selected == preset.Option)
preset.Update(self)
preset.Remap(self)
index += 1
EndWhile
WriteLine(self, "Update:"+ToString())
Expand Down Expand Up @@ -193,7 +190,7 @@ EndFunction

bool Function UseMaterial(Emblems:Editor editor, Actor user) Global
If (user)
int BipedBody = 3 ; const
int BipedBody = 3 ;const
ObjectMod[] omods = user.GetWornItemMods(BipedBody)
If (omods)
int index = 0
Expand All @@ -202,36 +199,47 @@ bool Function UseMaterial(Emblems:Editor editor, Actor user) Global
If (omod.GetLooseMod() == editor.miscmod_mod_ODST_Emblems)
If (omod)
MatSwap material = GetMaterial(omod)
return ApplyMaterial(user, material)
If (material)
user.SetMaterialSwap(Material)
If (user.ApplyMaterialSwap(material))
WriteLine("[ODST:Emblems:Editor]", "UseMaterial", "Material remapping was successful. "+material.GetRemapData())
return true
Else
WriteUnexpected("[ODST:Emblems:Editor]", "UseMaterial", "No source/target pairs succeeded in swapping. "+material.GetRemapData())
return false
EndIf
Else
WriteUnexpectedValue("[ODST:Emblems:Editor]", "UseMaterial", "material", "The value cannot be none.")
return false
EndIf
Else
WriteUnexpectedValue("ODST:Emblems:Editor", "UseMaterial", "omod", "The value cannot be none.")
WriteUnexpectedValue("[ODST:Emblems:Editor]", "UseMaterial", "omod", "The value cannot be none.")
return false
EndIf
EndIf

index += 1
EndWhile
WriteUnexpected("ODST:Emblems:Editor", "UseMaterial", "No valid object mod was found.")
return false
Else
WriteUnexpectedValue("ODST:Emblems:Editor", "UseMaterial", "omods", "The array cannot be none or empty.")
WriteUnexpectedValue("[ODST:Emblems:Editor]", "UseMaterial", "omods", "The array cannot be none or empty.")
return false
EndIf
Else
WriteUnexpectedValue("ODST:Emblems:Editor", "UseMaterial", "user", "The argument Actor cannot be none.")
WriteUnexpectedValue("[ODST:Emblems:Editor]", "UseMaterial", "user", "The argument Actor cannot be none.")
return false
EndIf
EndFunction


MatSwap Function GetMaterial(ObjectMod omod) Global
{Gets the material that is applied by an object mod.}
ObjectMod:PropertyModifier[] modifiers = omod.GetPropertyModifiers()
If (modifiers)
int index = 0
While (index < modifiers.Length)
MatSwap material = modifiers[index].Object as MatSwap
If (material)
WriteLine("ODST:Emblems:Editor", "GetMaterial", "omod:"+omod+", material:"+material)
WriteLine("[ODST:Emblems:Editor]", "GetMaterial", "omod:"+omod+", material:"+material)
return material
EndIf
index += 1
Expand All @@ -241,28 +249,6 @@ MatSwap Function GetMaterial(ObjectMod omod) Global
EndFunction


bool Function ApplyMaterial(Actor user, MatSwap material) Global
If (user)
If (material)
user.SetMaterialSwap(Material)
If (user.ApplyMaterialSwap(material))
WriteLine("ODST:Emblems:Editor", "ApplyMaterial", "Material remapping was successful. "+material.GetRemapData())
return true
Else
WriteUnexpected("ODST:Emblems:Editor", "ApplyMaterial", "No source/target pairs succeeded in swapping. "+material.GetRemapData())
return false
EndIf
Else
WriteUnexpectedValue("ODST:Emblems:Editor", "ApplyMaterial", "material", "The value cannot be none.")
return false
EndIf
Else
WriteUnexpectedValue("ODST:Emblems:Editor", "ApplyMaterial", "user", "The value cannot be none.")
return false
EndIf
EndFunction


; Properties
;---------------------------------------------

Expand Down
Loading

0 comments on commit 7305c4d

Please sign in to comment.