PageRenderTime 19ms CodeModel.GetById 7ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/README

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