Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_ImageSetGenerator.c
Go to the documentation of this file.
1[WorkbenchPluginAttribute(name: "Image Set Generator", wbModules: { "ResourceManager" }, awesomeFontCode: 0xF302)]
2class SCR_ImageSetGenerator : WorkbenchPlugin
3{
4 const string TAB = " ";
5
6 //[Attribute("{717ED53394FC3C27}UI/Textures/Editor/Concept/editor_mockup_sheet.edds", UIWidgets.ResourceNamePicker, "Path to the source image", "edds")]
7 //protected ResourceName m_sImage;
8
9 [Attribute("generatedImageSet", desc: "File name of the image set")]
10 protected string m_sFileName;
11
12 [Attribute("$ArmaReforger:UI/imagesets/", desc: "Directory at which the image set will be saved")]
13 protected string m_sDirectory;
14
15 [Attribute("512", desc: "Width of the image set")]
16 protected int m_iImageWidth;
17
18 [Attribute("512", desc: "Height of the image set")]
19 protected int m_iImageHeight;
20
21 [Attribute("", UIWidgets.Auto, "Independent tile areas. There can be multiple within one image set, e.g., left half containing 32x32 tiles and the right one 64x64 tiles")]
22 protected ref array<ref ImageSetGeneratorArea> m_aAreas;
23
24 protected string m_sTabs;
25 protected int m_iTabsCount;
26 protected ref FileHandle m_File;
27
28 //------------------------------------------------------------------------------------------------
29 protected void AddTabs(int tabsCountDelta)
30 {
31 m_iTabsCount += tabsCountDelta;
32 m_sTabs = "";
33 for (int i = 0; i < m_iTabsCount; i++)
34 {
35 m_sTabs += TAB;
36 }
37 }
38
39 //------------------------------------------------------------------------------------------------
40 protected void AddLine(string text)
41 {
42 m_File.WriteLine(m_sTabs + text);
43 }
44
45 //------------------------------------------------------------------------------------------------
46 protected void Generate()
47 {
48
49 if (!m_sDirectory.EndsWith("/"))
50 m_sDirectory += "/";
51
52 string fullPath = m_sDirectory + m_sFileName + ".imageset";
53 m_File = FileIO.OpenFile(fullPath, FileMode.WRITE);
54 Print(m_File, LogLevel.NORMAL);
55 if (!m_File)
56 return;
57
58 //--- Header
59 AddLine("ImageSetClass {");
60 AddTabs(1);
61
62 AddLine(string.Format("RefSize %1 %2", m_iImageWidth, m_iImageHeight));
63
64 /*
65 AddLine("Textures {");
66 AddTabs(1);
67
68 AddLine("ImageSetTextureClass {");
69 AddTabs(1);
70
71 AddLine("mpix 1");
72 AddLine(string.Format("directory \"%1\"", m_sImage.GetPath()));
73
74 AddTabs(-1);
75 AddLine("}");
76
77 AddTabs(-1);
78 AddLine("}");
79 */
80
81 //--- Groups
82 AddLine("Groups {");
83 AddTabs(1);
84
85 foreach (ImageSetGeneratorArea area : m_aAreas)
86 {
87 string groupName = string.Format("%1x%2", area.tileWidth, area.tileHeight);
88
89 AddLine(string.Format("ImageSetGroupClass \"%1\" {", groupName));
90 AddTabs(1);
91 AddLine(string.Format("Name \"%1\"", groupName));
92 AddLine("Images {");
93 AddTabs(1);
94
95 //--- Images
96 int widthFull = area.tileWidth + area.marginWidth;
97 int heightFull = area.tileHeight + area.marginHeight;
98 int columns = area.areaWidth / widthFull;
99 int rows = area.areaHeight / heightFull;
100 for (int r = 0; r < rows; r++)
101 {
102 for (int c = 0; c < columns; c++)
103 {
104 string tileName = string.Format("%1-%2", c, r);
105 AddLine(string.Format("ImageSetDefClass %1 {", groupName));
106 AddTabs(1);
107
108 //--- Image
109 AddLine(string.Format("Name \"%1\"", tileName));
110 AddLine(string.Format("Pos %1 %2", area.areaX + c * widthFull, area.areaY + r * heightFull));
111 AddLine(string.Format("Size %1 %2", area.tileWidth, area.tileHeight));
112 AddLine("Flags 0");
113
114 AddTabs(-1);
115 AddLine("}");
116 }
117 }
118
119 AddTabs(-1);
120 AddLine("}");
121
122 AddTabs(-1);
123 AddLine("}");
124 }
125
126 AddTabs(-1);
127 AddLine("}");
128
129 AddTabs(-1);
130 AddLine("}");
131
132 m_File.Close();
133
134 Print(string.Format("Image set generated at %1", fullPath), LogLevel.DEBUG);
135 }
136
137 //------------------------------------------------------------------------------------------------
138 override void Run()
139 {
140 if (!Workbench.ScriptDialog("Image Set Generator", "Generate an image set template with pre-define grids.\nOnce generated, you can simply map the texture and rename existing tiles,\ninstead of having to configure them manually one by one.", this))
141 return;
142
143 Generate();
144 }
145
146 //------------------------------------------------------------------------------------------------
147 [ButtonAttribute("OK")]
148 protected bool ButtonOK()
149 {
150 return true;
151 }
152
153 //------------------------------------------------------------------------------------------------
154 [ButtonAttribute("Cancel")]
155 protected bool ButtonCancel()
156 {
157 return false;
158 }
159}
160
161// TODO: SCR_, m_
163class ImageSetGeneratorArea
164{
165 [Attribute("0", UIWidgets.Auto, "Position of left edge")]
166 int areaX;
167
168 [Attribute("0", UIWidgets.Auto, "Position of top edge")]
169 int areaY;
170
171 [Attribute("512", UIWidgets.Auto, "Area width")]
172 int areaWidth;
173
174 [Attribute("512", UIWidgets.Auto, "Area height")]
175 int areaHeight;
176
177 [Attribute("32", UIWidgets.Auto, "Width of individual tile")]
178 int tileWidth;
179
180 [Attribute("32", UIWidgets.Auto, "Height of individual tile")]
181 int tileHeight;
182
183 [Attribute("0", UIWidgets.Auto, "Width of a margin between tiles")]
184 int marginWidth;
186 [Attribute("0", UIWidgets.Auto, "Height of a margin between tiles")]
187 int marginHeight;
GenerateFlowMaps WorkbenchPlugin WorkbenchPluginAttribute("Regenerate river flow-maps", "Generate and save/overwrite river flow-maps", "", "", {"WorldEditor"}, "", 0xf773)
Definition FlowmapTool.c:59
SCR_ImageSetGenerator WorkbenchPlugin BaseContainerProps()] class ImageSetGeneratorArea
void AddLine(string text)
void Generate()
void AddTabs(int tabsCountDelta)
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
class WorkbenchDialog_AbortRetryIgnore ButtonAttribute("OK", true)
void AddTabs(int tabsCountDelta)
ref array< ref ImageSetGeneratorArea > m_aAreas
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
SCR_FieldOfViewSettings Attribute
FileMode
Mode for opening file. See FileSystem::Open.
Definition FileMode.c:14