11using FSO . Client ;
22using FSO . Common . Utils ;
3+ using FSO . LotView ;
34using FSO . LotView . Components ;
5+ using FSO . LotView . Model ;
46using FSO . SimAntics ;
7+ using FSO . SimAntics . Engine . TSOTransaction ;
58using FSO . SimAntics . Entities ;
9+ using FSO . SimAntics . Model ;
10+ using FSO . SimAntics . NetPlay . Drivers ;
611using Microsoft . Xna . Framework ;
712using Microsoft . Xna . Framework . Graphics ;
8- using System ;
913
1014namespace FSO . UI . Utils
1115{
1216 public static class CatThumbGenerator
1317 {
18+ private static VM ThumbVM ;
19+
20+ private static VM GetThumbVM ( )
21+ {
22+ if ( ThumbVM == null )
23+ {
24+ var world = new ExternalWorld ( GameFacade . GraphicsDevice ) ;
25+ world . Initialize ( GameFacade . Scenes ) ;
26+ var context = new VMContext ( world ) ;
27+
28+ ThumbVM = new VM ( context , new VMServerDriver ( new VMTSOGlobalLinkStub ( ) ) , new VMNullHeadlineProvider ( ) ) ;
29+ ThumbVM . Init ( ) ;
30+
31+ var blueprint = new Blueprint ( 1 , 1 )
32+ {
33+ Light =
34+ [
35+ new RoomLighting ( ) { OutsideLight = 100 } ,
36+ new RoomLighting ( ) { OutsideLight = 100 } ,
37+ new RoomLighting ( ) { OutsideLight = 100 } ,
38+ ] ,
39+ OutsideColor = Color . White
40+ } ;
41+ blueprint . GenerateRoomLights ( ) ;
42+ blueprint . RoomColors [ 2 ] . A /= 2 ;
43+ world . State . AmbientLight . SetData ( blueprint . RoomColors ) ;
44+ world . State . OutsidePx . SetData ( [ Color . White ] ) ;
45+
46+ world . InitBlueprint ( blueprint ) ;
47+ context . Blueprint = blueprint ;
48+ context . Architecture = new VMArchitecture ( 1 , 1 , blueprint , ThumbVM . Context ) ;
49+ }
50+
51+ return ThumbVM ;
52+ }
53+
1454 public static Texture2D GenerateThumb ( VMMultitileGroup obj , VM vm )
1555 {
1656 var gd = GameFacade . GraphicsDevice ;
@@ -34,7 +74,15 @@ public static Texture2D GenerateThumb(VMMultitileGroup obj, VM vm)
3474 var oldRts = gd . GetRenderTargets ( ) ;
3575 gd . SetRenderTarget ( result ) ;
3676 gd . Clear ( Color . Black ) ;
37- sb . Begin ( blendState : BlendState . AlphaBlend ) ;
77+ var sampler = new SamplerState ( )
78+ {
79+ AddressU = TextureAddressMode . Clamp ,
80+ AddressV = TextureAddressMode . Clamp ,
81+ AddressW = TextureAddressMode . Clamp ,
82+ Filter = TextureFilter . Linear ,
83+ MipMapLevelOfDetailBias = - 0.5f ,
84+ } ;
85+ sb . Begin ( blendState : BlendState . NonPremultiplied , samplerState : sampler ) ;
3886 var minScale = Math . Min ( 37f / newAgain . Width , 37f / newAgain . Height ) ;
3987 if ( minScale > 1 ) minScale = 1 ;
4088 var rect = new Rectangle (
@@ -56,5 +104,23 @@ public static Texture2D GenerateThumb(VMMultitileGroup obj, VM vm)
56104 newAgain . Dispose ( ) ;
57105 return result ;
58106 }
107+
108+ public static Texture2D GenerateThumb ( uint guid )
109+ {
110+ var vm = GetThumbVM ( ) ;
111+
112+ var obj = vm . Context . CreateObjectInstance ( guid , LotTilePos . OUT_OF_WORLD , Direction . NORTH , true ) ;
113+
114+ if ( obj == null )
115+ {
116+ return null ;
117+ }
118+
119+ var icon = GenerateThumb ( obj , vm ) ;
120+
121+ obj . Delete ( vm . Context ) ;
122+
123+ return icon ;
124+ }
59125 }
60126}
0 commit comments