code_uilayout.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. // UILayout application source code
  2. using System;
  3. using AtomicEngine;
  4. public class code_uilayout : CSComponent {
  5. private static string layoutomaticstr; // LAYOUT-O-MATIC string
  6. private static void ReplaceChar( int index, char newChar)
  7. {
  8. char[] array = layoutomaticstr.ToCharArray();
  9. array[index] = newChar;
  10. layoutomaticstr = new string(array);
  11. }
  12. public void Setup( UIWidget layout )
  13. {
  14. layoutomaticstr = "XGCPC";
  15. var dest = new AtomicEngine.Vector<AtomicEngine.UIWidget>();
  16. layout.SearchWidgetClass( "TBButton", dest );
  17. for (var ii = 0; ii < dest.Size; ii++) {
  18. dest[ii].SubscribeToEvent<WidgetEvent> (dest [ii], HandleUilayoutEvent );
  19. }
  20. UILayout myc = (UILayout)layout.GetWidget("uilayoutcontainer"); // get the container layout
  21. UIButton tf0 = new UIButton(); // the layout-o-matic spawner
  22. tf0.SetText( "LAYOUT-O-MATIC");
  23. tf0.SetId( "go_layout_config");
  24. UILayout lo0 = new UILayout();
  25. lo0.SetId( "target_layout");
  26. lo0.SetLayoutConfig ( "-----" );
  27. lo0.Load("Scenes/simp_button.ui.txt");
  28. lo0.AddChildBefore(tf0, lo0.GetFirstChild() );
  29. myc.AddChild(lo0); // drop it in
  30. tf0.SubscribeToEvent<WidgetEvent> (tf0, HandleUilayoutEvent );
  31. UITextField tf1 = new UITextField();
  32. tf1.SetText( "layout config XACAC");
  33. UILayout lo1 = new UILayout();
  34. lo1.SetLayoutConfig ( "XACAC" );
  35. lo1.Load("Scenes/simp_button.ui.txt");
  36. lo1.AddChildBefore(tf1, lo1.GetFirstChild() );
  37. myc.AddChild(lo1);
  38. UITextField tf2 = new UITextField();
  39. tf2.SetText( "layout config XGCAC");
  40. UILayout lo2 = new UILayout();
  41. lo2.SetLayoutConfig ( "XGCAC" );
  42. lo2.Load("Scenes/simp_button.ui.txt");
  43. lo2.AddChildBefore(tf2, lo2.GetFirstChild() );
  44. myc.AddChild(lo2);
  45. UITextField tf3 = new UITextField();
  46. tf3.SetText( "layout config XPCAC");
  47. UILayout lo3 = new UILayout();
  48. lo3.SetLayoutConfig ( "XPCAC" );
  49. lo3.Load("Scenes/simp_button.ui.txt");
  50. lo3.AddChildBefore(tf3, lo3.GetFirstChild() );
  51. myc.AddChild(lo3);
  52. UITextField tf4 = new UITextField();
  53. tf4.SetText( "layout config XACGC");
  54. UILayout lo4 = new UILayout();
  55. lo4.SetLayoutConfig ( "XACGC" );
  56. lo4.Load("Scenes/simp_button.ui.txt");
  57. lo4.AddChildBefore(tf4, lo4.GetFirstChild() );
  58. myc.AddChild(lo4);
  59. UITextField tf5 = new UITextField();
  60. tf5.SetText( "layout config XGRGC");
  61. UILayout lo5 = new UILayout();
  62. lo5.SetLayoutConfig ( "XGRGC" );
  63. lo5.Load("Scenes/simp_button.ui.txt");
  64. lo5.AddChildBefore(tf5, lo5.GetFirstChild() );
  65. myc.AddChild(lo5);
  66. UITextField tf6 = new UITextField();
  67. tf6.SetText( "layout config XPLGC");
  68. UILayout lo6 = new UILayout();
  69. lo6.SetLayoutConfig ( "XPLGC" );
  70. lo6.Load("Scenes/simp_button.ui.txt");
  71. lo6.AddChildBefore(tf6, lo6.GetFirstChild() );
  72. myc.AddChild(lo6);
  73. UITextField tf7 = new UITextField();
  74. tf7.SetText( "layout config XACPC");
  75. UILayout lo7 = new UILayout();
  76. lo7.SetLayoutConfig ( "XACPC" );
  77. lo7.Load("Scenes/simp_button.ui.txt");
  78. lo7.AddChildBefore(tf7, lo7.GetFirstChild() );
  79. myc.AddChild(lo7);
  80. UITextField tf8 = new UITextField();
  81. tf8.SetText( "layout config XGLPL");
  82. UILayout lo8 = new UILayout();
  83. lo8.SetLayoutConfig ( "XGLPL" );
  84. lo8.Load("Scenes/simp_button.ui.txt");
  85. lo8.AddChildBefore(tf8, lo8.GetFirstChild() );
  86. myc.AddChild(lo8);
  87. UITextField tf9 = new UITextField();
  88. tf9.SetText( "layout config XPCPR");
  89. UILayout lo9 = new UILayout();
  90. lo9.SetLayoutConfig ( "XPCPR" );
  91. lo9.Load("Scenes/simp_button.ui.txt");
  92. lo9.AddChildBefore(tf9, lo9.GetFirstChild() );
  93. myc.AddChild(lo9);
  94. }
  95. private static void HandleUilayoutEvent ( WidgetEvent ev )
  96. {
  97. UIWidget widget = (UIWidget)ev.Target;
  98. if ( widget.Equals(null)) return;
  99. if ( ev.Type == UI_EVENT_TYPE.UI_EVENT_TYPE_CLICK) {
  100. if (widget.GetId() == "go_layout_config" ) { // its LAYOUT-O-MATIC time.
  101. AtomicMain.AppLog( "UILayout action : " + widget.GetId() + " was pressed, its LAYOUT-O-MATIC time");
  102. UIView someview = widget.GetView();
  103. UIWindow window = new UIWindow();
  104. window.SetSettings ( UI_WINDOW_SETTINGS.UI_WINDOW_SETTINGS_DEFAULT );
  105. window.SetText( "LAYOUT-O-MATIC(tm)");
  106. window.Load("Scenes/view_layout.ui.txt");
  107. window.ResizeToFitContent();
  108. someview.AddChild(window);
  109. UIWidget okbutt = window.GetWidget("ok");
  110. okbutt.SubscribeToEvent<WidgetEvent> (okbutt, HandleUilayoutEvent );
  111. var lox = new AtomicEngine.Vector<AtomicEngine.UIWidget>();
  112. window.SearchWidgetClass( "TBRadioButton", lox );
  113. for (var ii = 0; ii < lox.Size; ii++) {
  114. lox[ii].SubscribeToEvent<WidgetEvent> (lox [ii],HandleUilayoutEvent );
  115. }
  116. }
  117. if (widget.GetId() == "ok" ) {
  118. UIWindow mywindow = (UIWindow)AtomicMain.FindTheWindowParent(widget);
  119. if (!mywindow.Equals(null))
  120. mywindow.Close();
  121. }
  122. if (widget.GetId() == "set_ax" ) {
  123. UILayout targetl = (UILayout)widget.FindWidget("target_layout"); // who to operate on.
  124. UIRadioButton setla = (UIRadioButton)widget; // who we are
  125. if (!targetl.Equals(null) && !setla.Equals(null)) {
  126. if ( setla.GetValue() == 1 ) {
  127. ReplaceChar(0, 'X');
  128. targetl.SetLayoutConfig(layoutomaticstr);
  129. }
  130. }
  131. }
  132. if (widget.GetId() == "set_ay" ) {
  133. UILayout targetl = (UILayout)widget.FindWidget("target_layout"); // who to operate on.
  134. UIRadioButton setla = (UIRadioButton)widget; // who we are
  135. if (!targetl.Equals(null) && !setla.Equals(null)) {
  136. if ( setla.GetValue() == 1) {
  137. ReplaceChar(0, 'Y');
  138. targetl.SetLayoutConfig(layoutomaticstr);
  139. }
  140. }
  141. }
  142. if (widget.GetId() == "set_sza" ) {
  143. UILayout targetl = (UILayout)widget.FindWidget("target_layout"); // who to operate on.
  144. UIRadioButton setla = (UIRadioButton)widget; // who we are
  145. if (!targetl.Equals(null) && !setla.Equals(null)) {
  146. if ( setla.GetValue() == 1) {
  147. ReplaceChar( 1, 'A');
  148. targetl.SetLayoutConfig(layoutomaticstr);
  149. }
  150. }
  151. }
  152. if (widget.GetId() == "set_szg" ) {
  153. UILayout targetl = (UILayout)widget.FindWidget("target_layout"); // who to operate on.
  154. UIRadioButton setla = (UIRadioButton)widget; // who we are
  155. if (!targetl.Equals(null) && !setla.Equals(null)) {
  156. if ( setla.GetValue() == 1) {
  157. ReplaceChar( 1, 'G');
  158. targetl.SetLayoutConfig(layoutomaticstr);
  159. }
  160. }
  161. }
  162. if (widget.GetId() == "set_szp" ) {
  163. UILayout targetl = (UILayout)widget.FindWidget("target_layout"); // who to operate on.
  164. UIRadioButton setla = (UIRadioButton)widget; // who we are
  165. if (!targetl.Equals(null) && !setla.Equals(null)) {
  166. if ( setla.GetValue() == 1) {
  167. ReplaceChar( 1, 'P');
  168. targetl.SetLayoutConfig(layoutomaticstr);
  169. }
  170. }
  171. }
  172. if (widget.GetId() == "set_posc" ) {
  173. UILayout targetl = (UILayout)widget.FindWidget("target_layout"); // who to operate on.
  174. UIRadioButton setla = (UIRadioButton)widget; // who we are
  175. if (!targetl.Equals(null) && !setla.Equals(null)) {
  176. if ( setla.GetValue() == 1) {
  177. ReplaceChar( 2, 'C');
  178. targetl.SetLayoutConfig(layoutomaticstr);
  179. }
  180. }
  181. }
  182. if (widget.GetId() == "set_posg" ) {
  183. UILayout targetl = (UILayout)widget.FindWidget("target_layout"); // who to operate on.
  184. UIRadioButton setla = (UIRadioButton)widget; // who we are
  185. if (!targetl.Equals(null) && !setla.Equals(null)) {
  186. if ( setla.GetValue() == 1) {
  187. ReplaceChar( 2, 'G');
  188. targetl.SetLayoutConfig(layoutomaticstr);
  189. }
  190. }
  191. }
  192. if (widget.GetId() == "set_posl" ) {
  193. UILayout targetl = (UILayout)widget.FindWidget("target_layout"); // who to operate on.
  194. UIRadioButton setla = (UIRadioButton)widget; // who we are
  195. if (!targetl.Equals(null) && !setla.Equals(null)) {
  196. if ( setla.GetValue() == 1) {
  197. ReplaceChar( 2, 'L');
  198. targetl.SetLayoutConfig(layoutomaticstr);
  199. }
  200. }
  201. }
  202. if (widget.GetId() == "set_posr" ) {
  203. UILayout targetl = (UILayout)widget.FindWidget("target_layout"); // who to operate on.
  204. UIRadioButton setla = (UIRadioButton)widget; // who we are
  205. if (!targetl.Equals(null) && !setla.Equals(null)) {
  206. if ( setla.GetValue() == 1) {
  207. ReplaceChar( 2, 'R');
  208. targetl.SetLayoutConfig(layoutomaticstr);
  209. }
  210. }
  211. }
  212. if (widget.GetId() == "set_dista" ) {
  213. UILayout targetl = (UILayout)widget.FindWidget("target_layout"); // who to operate on.
  214. UIRadioButton setla = (UIRadioButton)widget; // who we are
  215. if (!targetl.Equals(null) && !setla.Equals(null)) {
  216. if ( setla.GetValue() == 1) {
  217. ReplaceChar(3, 'A');
  218. targetl.SetLayoutConfig(layoutomaticstr);
  219. }
  220. }
  221. }
  222. if (widget.GetId() == "set_distg" ) {
  223. UILayout targetl = (UILayout)widget.FindWidget("target_layout"); // who to operate on.
  224. UIRadioButton setla = (UIRadioButton)widget; // who we are
  225. if (!targetl.Equals(null) && !setla.Equals(null)) {
  226. if ( setla.GetValue() == 1) {
  227. ReplaceChar(3, 'G');
  228. targetl.SetLayoutConfig(layoutomaticstr);
  229. }
  230. }
  231. }
  232. if (widget.GetId() == "set_distp" ) {
  233. UILayout targetl = (UILayout)widget.FindWidget("target_layout"); // who to operate on.
  234. UIRadioButton setla = (UIRadioButton)widget; // who we are
  235. if (!targetl.Equals(null) && !setla.Equals(null)) {
  236. if ( setla.GetValue() == 1) {
  237. ReplaceChar(3, 'P');
  238. targetl.SetLayoutConfig(layoutomaticstr);
  239. }
  240. }
  241. }
  242. if (widget.GetId() == "set_dpc" ) {
  243. UILayout targetl = (UILayout)widget.FindWidget("target_layout"); // who to operate on.
  244. UIRadioButton setla = (UIRadioButton)widget; // who we are
  245. if (!targetl.Equals(null) && !setla.Equals(null)) {
  246. if ( setla.GetValue() == 1) {
  247. ReplaceChar( 4, 'C');
  248. targetl.SetLayoutConfig(layoutomaticstr);
  249. }
  250. }
  251. }
  252. if (widget.GetId() == "set_dpl" ) {
  253. UILayout targetl = (UILayout)widget.FindWidget("target_layout"); // who to operate on.
  254. UIRadioButton setla = (UIRadioButton)widget; // who we are
  255. if (!targetl.Equals(null) && !setla.Equals(null)) {
  256. if ( setla.GetValue() == 1) {
  257. ReplaceChar( 4, 'L');
  258. targetl.SetLayoutConfig(layoutomaticstr);
  259. }
  260. }
  261. }
  262. if (widget.GetId() == "set_dpr" ) {
  263. UILayout targetl = (UILayout)widget.FindWidget("target_layout"); // who to operate on.
  264. UIRadioButton setla = (UIRadioButton)widget; // who we are
  265. if (!targetl.Equals(null) && !setla.Equals(null)) {
  266. if ( setla.GetValue() == 1) {
  267. ReplaceChar( 4, 'R');
  268. targetl.SetLayoutConfig(layoutomaticstr);
  269. }
  270. }
  271. }
  272. }
  273. }
  274. }