]> git.sesse.net Git - ultimatescore/commitdiff
Add some code to display rosters.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 29 Oct 2017 23:09:50 +0000 (00:09 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 29 Oct 2017 23:09:50 +0000 (00:09 +0100)
client/mainwindow.cpp
client/mainwindow.h
client/mainwindow.ui
roster.js [new file with mode: 0644]
score.css
score.html

index 9787ecbea584caa21e519075765b5c38ae38e8c0..baf103d988a8e122018bdc6ea08774ff8a6313bb 100644 (file)
@@ -129,6 +129,9 @@ MainWindow::MainWindow(QWidget *parent) :
        connect(ui->show_schedule_btn, &QPushButton::clicked, this, &MainWindow::show_schedule_clicked);
        connect(ui->show_carousel_btn, &QPushButton::clicked, this, &MainWindow::show_carousel_clicked);
        connect(ui->show_nothing_btn, &QPushButton::clicked, this, &MainWindow::show_nothing_clicked);
+       connect(ui->show_roster_1_btn, &QPushButton::clicked, this, [this]() { show_roster_clicked(ui->initials_1_edit->text().toStdString()); });
+       connect(ui->show_roster_2_btn, &QPushButton::clicked, this, [this]() { show_roster_clicked(ui->initials_2_edit->text().toStdString()); });
+       connect(ui->show_roster_carousel_btn, &QPushButton::clicked, this, &MainWindow::show_roster_carousel_clicked);
 
        autocomment_update();
 
@@ -309,6 +312,15 @@ void MainWindow::show_group_clicked(const std::string &group_name)
        acmp->send_command("cg 1 invoke 1 showgroup_from_state");
 }
 
+void MainWindow::show_roster_clicked(const std::string &team_code)
+{
+       map<string, string> param;
+       param["team_code"] = team_code;
+       acmp->send_command("cg 1 invoke 1 stopcarousel");
+       acmp->send_command("cg 1 update 1 \"" + escape_quotes(serialize_as_json(param)) + "\"");
+       acmp->send_command("cg 1 invoke 1 showroster_from_state");
+}
+
 void MainWindow::show_schedule_clicked()
 {
        acmp->send_command("cg 1 invoke 1 stopcarousel");
@@ -321,6 +333,16 @@ void MainWindow::show_carousel_clicked()
        acmp->send_command("cg 1 invoke 1 showcarousel");
 }
 
+void MainWindow::show_roster_carousel_clicked()
+{
+       map<string, string> param;
+       param["team1"] = escape_html(ui->initials_1_edit->text().toStdString());
+       param["team2"] = escape_html(ui->initials_2_edit->text().toStdString());
+       acmp->send_command("cg 1 invoke 1 stopcarousel");
+       acmp->send_command("cg 1 update 1 \"" + escape_quotes(serialize_as_json(param)) + "\"");
+       acmp->send_command("cg 1 invoke 1 showrostercarousel_from_state");
+}
+
 void MainWindow::show_nothing_clicked()
 {
        acmp->send_command("cg 1 invoke 1 hidescorebug");
index b9e90217a77d6eb9b15b82d76252bc6b8c1147d8..99b8a34196dd1d2804c690fae7462a738626e496 100644 (file)
@@ -42,8 +42,10 @@ private:
        void autocomment_update();
        void show_scorebug_clicked();
        void show_group_clicked(const std::string &group_name);
+       void show_roster_clicked(const std::string &team_code);
        void show_schedule_clicked();
        void show_carousel_clicked();
+       void show_roster_carousel_clicked();
        void show_nothing_clicked();
 
        Ui::MainWindow *ui;
index 37d38bf5dc93fedc10c3e56b762466a02f5a36fb..fe5886d475d506220789ca6d90f030b6e8a619e2 100644 (file)
@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>720</width>
-    <height>552</height>
+    <width>803</width>
+    <height>597</height>
    </rect>
   </property>
   <property name="windowTitle">
         <item>
          <widget class="QPushButton" name="show_scorebug_btn">
           <property name="text">
-           <string>Show scorebug</string>
+           <string>Show score</string>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <widget class="QPushButton" name="show_roster_1_btn">
+          <property name="text">
+           <string>Roster 1</string>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <widget class="QPushButton" name="show_roster_2_btn">
+          <property name="text">
+           <string>Roster 2</string>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <widget class="QPushButton" name="show_roster_carousel_btn">
+          <property name="text">
+           <string>Roster 1+2</string>
           </property>
          </widget>
         </item>
         <item>
          <widget class="QPushButton" name="show_group_a_btn">
           <property name="text">
-           <string>Show group A</string>
+           <string>Group A</string>
           </property>
          </widget>
         </item>
         <item>
          <widget class="QPushButton" name="show_group_b_btn">
           <property name="text">
-           <string>Show group B</string>
+           <string>Group B</string>
           </property>
          </widget>
         </item>
         <item>
          <widget class="QPushButton" name="show_schedule_btn">
           <property name="text">
-           <string>Show schedule</string>
+           <string>Schedule</string>
           </property>
          </widget>
         </item>
diff --git a/roster.js b/roster.js
new file mode 100644 (file)
index 0000000..b9230fd
--- /dev/null
+++ b/roster.js
@@ -0,0 +1,106 @@
+function load_roster(sheet, cb)
+{
+       var req = new XMLHttpRequest();
+       req.onload = function(e) {
+               var response = JSON.parse(req.responseText);
+
+               var team_name = '';
+               if (response.values[0].length >= 1 &&
+                   response.values[0][0] !== undefined &&
+                   response.values[0][0] !== null) {
+                       team_name = response.values[0][0];
+               }
+
+               var roster = [];
+               var i;
+               for (i = 0; i < response.values.length; ++i) {
+                       if (response.values[i][0] === 'Number') {
+                               ++i;
+                               break;
+                       }
+               }
+
+               for ( ; response.values[i] !== undefined && response.values[i].length >= 3; ++i) {
+                       var display_number = response.values[i][1];
+                       var name = response.values[i][2];
+                       roster.push({
+                               "number": display_number,
+                               "name": name
+                       });
+               }
+               cb(team_name, roster);
+       };
+       req.open('GET', 'https://sheets.googleapis.com/v4/spreadsheets/1RciMlauWxqM9LYKdsY6lPjJbIAcHJpCXTqyZSEHxH3U/values/\'' + sheet + '\'!A1:J50?key=AIzaSyAuP9yQn8g0bSay6r_RpGtpFeIbwprH1TU');
+       req.send();
+};
+
+function display_roster(team_name, roster)
+{
+       document.getElementById('entire-bug').style.display = 'none';
+
+       var carousel = document.getElementById('carousel');
+       clear_carousel(carousel);
+
+       if (team_name === '') {
+               addheading(carousel, 4, 'Team lineup');
+       } else {
+               addheading(carousel, 4, 'Team lineup<br />' + team_name);
+       }
+
+       for (var i = 0; i < roster.length; i += 2) {
+               var tr = document.createElement("tr");
+
+               addth(tr, "playernum", roster[i].number);
+               addtd(tr, "playername", roster[i].name);
+
+               if (i + 1 < roster.length) {
+                       addth(tr, "playernum", roster[i + 1].number);
+                       addtd(tr, "playername", roster[i + 1].name);
+               } else {
+                       addth(tr, "playernum", "");
+                       addtd(tr, "playername", "");
+               }
+               carousel.appendChild(tr);
+       }
+       fade_in_rows(carousel);
+
+       carousel.style.display = 'table';
+}
+
+function showroster(sheet)
+{
+       load_roster(sheet, display_roster);
+}
+
+function showroster_from_state()
+{
+       showroster(state['team_code']);
+}
+
+function showrostercarousel(sheet1, sheet2)
+{
+       var team_names = [null, null];
+       var rosters = [null, null];
+       var num_left = 2;
+
+       var cb = function(id, team_name, roster) {
+               team_names[id] = team_name;
+               rosters[id] = roster;
+               if (--num_left == 0) {
+                       do_series([
+                               [ 13000, function() { display_roster(team_names[0], rosters[0]); } ],
+                               [ 2000, function() { hidetable(); } ],
+                               [ 13000, function() { display_roster(team_names[1], rosters[1]); } ],
+                               [ 2000, function() { hidetable(); } ]
+                       ]);
+               }
+       };
+
+       load_roster(sheet1, function(team_name, roster) { cb(0, team_name, roster); });
+       load_roster(sheet2, function(team_name, roster) { cb(1, team_name, roster); });
+}
+
+function showrostercarousel_from_state()
+{
+       showrostercarousel(state['team1'], state['team2']);
+}
index 01dcbd1b6faf167ba398f1f5a4a687ec0406468b..e2d5edc97a1c47b5090693cd10bedc21422fb831 100644 (file)
--- a/score.css
+++ b/score.css
@@ -323,6 +323,25 @@ body {
   text-transform: none;
 }
 
+/* roster */
+#carousel .playerpadding {
+  font-size: 25px;
+  background: rgba(0,0,0,0);
+}
+#carousel th.playernum, #carousel .playername {
+  font-size: 35px;
+}
+#carousel th.playernum {
+  text-align: center;
+  padding-right: 8px;
+  padding-left: 0px; margin-left: 0px;
+  width: 80px;
+}
+#carousel .playername {
+  text-transform: none;
+  width: auto;
+}
+
 .nplayed, .gd, .pts {
   text-align: center;
 }
index c6f385b53559d245fca28c85d6230be243988093..4d7921daf037cc2af067101e8a660c56bd62fa03 100644 (file)
@@ -66,6 +66,9 @@
       </p>
       <p>
         <a href="javascript:stopcarousel();hidetable();showscorebug()">show scorebug</a>
+        <a href="javascript:stopcarousel();showroster('TFK')">show roster 1</a>
+        <a href="javascript:stopcarousel();showroster('ESK')">show roster 2</a>
+        <a href="javascript:stopcarousel();showrostercarousel('TFK', 'ESK')">show roster 1+2</a>
         <a href="javascript:stopcarousel();showgroup('Group A')">show group A</a>
         <a href="javascript:stopcarousel();showgroup('Group B')">show group B</a>
         <a href="javascript:stopcarousel();showschedule()">show schedule</a>
@@ -77,5 +80,6 @@
 <script src="carousel.js" type="text/javascript"></script>
 <script src="score.js" type="text/javascript"></script>
 <script src="quickl3.js" type="text/javascript"></script>
+<script src="roster.js" type="text/javascript"></script>
   </body>
 </html>