/README

http://github.com/blackdog66/bdog-gtk · #! · 182 lines · 143 code · 39 blank · 0 comment · 0 complexity · 56c838f633cc2772b188d156ca369290 MD5 · raw file

  1. Below is my working example, it doesn't actually use the port specfied as I've altered the
  2. server to run gtk-server as a child process.
  3. -----------------------------------------------------------------------
  4. package test;
  5. import gtk.Model;
  6. import gtk.Gtk;
  7. import ui.Ui;
  8. import ui.MessageDialog;
  9. import ui.Window;
  10. import ui.Button;
  11. import ui.Text;
  12. import ui.Combo;
  13. import ui.Label;
  14. import ui.TextView;
  15. import ui.TextBuffer;
  16. import js.Node;
  17. import bdog.bingo.Common;
  18. import bdog.bingo.client.Controller;
  19. import bdog.extra.Locator;
  20. class BClient {
  21. public static function
  22. main() {
  23. Ui.init(50001,start);
  24. }
  25. static var entry1:Text;
  26. static var cmbRooms:Combo;
  27. static var lblState:Label;
  28. static var lblSecs:Label;
  29. static var lblNCards:Label;
  30. static var lblStatus:Label;
  31. static var window:Window;
  32. static var wndCards:Window;
  33. static var viewRaw:TextView;
  34. static var textBuffer:TextBuffer;
  35. public static function appWindow() {
  36. return window;
  37. }
  38. public static function
  39. start() {
  40. Ui.fromFile("bingo.glade",function(g:GladeXml) {
  41. Button.fromGlade(g,"btnCards",function(b) {
  42. b.onClick(function(w,e) {
  43. room().requestCards();
  44. });
  45. });
  46. Text.fromGlade(g,"entry1",function(t:Text) {
  47. entry1 = t;
  48. entry1.set("woot");
  49. });
  50. Button.fromGlade(g,"btnSLogin",function(b) {
  51. b.onClick(function(w,e) {
  52. sLogin();
  53. });
  54. });
  55. Label.fromGlade(g,"lblSecs",function(l) {
  56. lblSecs = l;
  57. });
  58. Label.fromGlade(g,"lblState",function(l) {
  59. lblState = l;
  60. });
  61. Label.fromGlade(g,"lblNCards",function(l) {
  62. lblNCards = l;
  63. });
  64. Label.fromGlade(g,"lblStatus",function(l) {
  65. lblStatus = l;
  66. });
  67. Combo.fromGlade(g,"cmbRooms",function(c:Combo) {
  68. cmbRooms = c;
  69. cmbRooms.onChange(function(w,e) {
  70. trace("room changed "+w+" with event "+e);
  71. });
  72. });
  73. TextView.fromGlade(g,"viewRaw",function(tv:TextView) {
  74. viewRaw = tv;
  75. tv.getBuffer(function(tb){
  76. textBuffer = tb;
  77. textBuffer.setText("woot");
  78. });
  79. });
  80. Window.fromGlade(g,"window1",function(w) {
  81. window = w;
  82. window.title("bingo");
  83. window.onDestroy(function(w,e) {
  84. Gtk.mainQuit();
  85. Node.process.exit(0);
  86. });
  87. Ui.poll(window);
  88. pLogin();
  89. });
  90. Window.fromGlade(g,"wndCards",function(w) {
  91. wndCards = w;
  92. wndCards.onDestroy(function(w,e) {
  93. wndCards.hide();
  94. });
  95. Button.fromGlade(g,"btnShowCards",function(b) {
  96. b.onClick(function(w,e) {
  97. wndCards.show();
  98. });
  99. });
  100. });
  101. });
  102. }
  103. static function
  104. pLogin() {
  105. var l:Location = {host:'localhost',port:8084};
  106. Controller.login(l,'t1@t1.com','pass','site',function(err,u) {
  107. entry1.set(u.sessID);
  108. });
  109. }
  110. public static function room() {
  111. return Controller.getRoom();
  112. }
  113. static function
  114. sLogin() {
  115. cmbRooms.selected(function(roomID) {
  116. trace("roomID = "+roomID);
  117. if (roomID == "") {
  118. MessageDialog.info("Select a room first",appWindow());
  119. return;
  120. }
  121. Controller.roomLogin(Controller.sessID,roomID,function(room) {
  122. room.event.onLogin.addHandler(function(login) {
  123. });
  124. room.event.onGame.addHandler(function(g) {
  125. });
  126. room.event.onCards.addHandler(function(c) {
  127. lblNCards.label(Std.string(c.cards.length));
  128. });
  129. room.event.onSync.addHandler(function(s:SyncPkt) {
  130. lblState.label(s.event);
  131. lblSecs.label(Std.string(s.curSec));
  132. });
  133. room.event.onDebug.addHandler(function(d:Dynamic) {
  134. trace("displaying raw ");
  135. textBuffer.setText(Std.string(d));
  136. });
  137. room.event.onCannotBuy.addHandler(function() {
  138. lblStatus.label("you cannot buy right now");
  139. });
  140. });
  141. });
  142. }
  143. }