+class DebugUI {
+
+ final ChannelMapping[] channelList;
+ final int debugX = 5;
+ final int debugY = 5;
+ final int debugXSpacing = 28;
+ final int debugYSpacing = 21;
+ final int[][] debugState;
+ final int[] indexState;
+
+ final int ERROR_STATE_USED = 0;
+ final int ERROR_STATE_DUPLICATED = 1;
+
+ final int CUBE_STATE_UNUSED = 0;
+ final int CUBE_STATE_USED = 1;
+
+ final int DEBUG_STATE_ANIM = 0;
+ final int DEBUG_STATE_WHITE = 1;
+ final int DEBUG_STATE_OFF = 2;
+
+ DebugUI(PandaMapping[] pandaMappings) {
+ int totalChannels = pandaMappings.length * PandaMapping.CHANNELS_PER_BOARD;
+ debugState = new int[totalChannels+1][ChannelMapping.CUBES_PER_CHANNEL+1];
+ indexState = new int[glucose.model.cubes.size()+1];
+
+ channelList = new ChannelMapping[totalChannels];
+ int channelIndex = 0;
+ for (PandaMapping pm : pandaMappings) {
+ for (ChannelMapping channel : pm.channelList) {
+ channelList[channelIndex++] = channel;
+ }
+ }
+ for (int i = 0; i < debugState.length; ++i) {
+ for (int j = 0; j < debugState[i].length; ++j) {
+ debugState[i][j] = DEBUG_STATE_ANIM;
+ }
+ }
+
+ for (int rawIndex = 0; rawIndex < glucose.model.cubes.size()+1; rawIndex++) {
+ indexState[rawIndex] = CUBE_STATE_UNUSED;
+ }
+ for (ChannelMapping channel : channelList) {
+ for (int rawCubeIndex : channel.objectIndices) {
+ if (rawCubeIndex > 0)
+ indexState[rawCubeIndex]++;
+ }
+ }
+ }
+
+ void draw() {
+ noStroke();
+ int xBase = debugX;
+ int yPos = debugY;
+
+ fill(#000000);
+ rect(0, 0, debugX + 5*debugXSpacing, height);
+
+ int channelNum = 0;
+ for (ChannelMapping channel : channelList) {
+ int xPos = xBase;
+ drawNumBox(xPos, yPos, channelNum+1, debugState[channelNum][0]);
+ xPos += debugXSpacing;
+
+ switch (channel.mode) {
+ case ChannelMapping.MODE_CUBES:
+ int stateIndex = 0;
+ boolean first = true;
+ for (int rawCubeIndex : channel.objectIndices) {
+ if (rawCubeIndex < 0) {
+ break;
+ }
+ if (first) {
+ first = false;
+ } else {
+ stroke(#999999);
+ line(xPos - 12, yPos + 8, xPos, yPos + 8);
+ }
+ drawNumBox(xPos, yPos, rawCubeIndex, debugState[channelNum][stateIndex+1], indexState[rawCubeIndex]);
+ ++stateIndex;
+ xPos += debugXSpacing;
+ }
+ break;
+ case ChannelMapping.MODE_BASS:
+ drawNumBox(xPos, yPos, "B", debugState[channelNum][1]);
+ break;
+ case ChannelMapping.MODE_SPEAKER:
+ drawNumBox(xPos, yPos, "S" + channel.objectIndices[0], debugState[channelNum][1]);
+ break;
+ case ChannelMapping.MODE_STRUTS_AND_FLOOR:
+ drawNumBox(xPos, yPos, "F", debugState[channelNum][1]);
+ break;
+ case ChannelMapping.MODE_NULL:
+ break;
+ default:
+ throw new RuntimeException("Unhandled channel mapping mode: " + channel.mode);
+ }
+
+ yPos += debugYSpacing;
+ ++channelNum;
+ }
+ drawNumBox(xBase, yPos, "A", debugState[channelNum][0]);
+ yPos += debugYSpacing * 2;
+
+ noFill();
+ stroke(#CCCCCC);
+ rect(xBase, yPos, 100, 16);
+ fill(#CCCCCC);
+ text("Unused Cubes", xBase + 5, yPos + 12);
+ yPos += debugYSpacing;
+
+ int x_index = 0;
+ for (int rawIndex = 1; rawIndex < glucose.model.cubes.size()+1; rawIndex++) {
+ if (indexState[rawIndex] == 0) {
+ drawNumBox(xBase + (x_index * debugXSpacing), yPos, rawIndex, 0, 2);
+ x_index++;
+ if (x_index > 4) {
+ x_index = 0;
+ yPos += debugYSpacing + 2;
+ }
+ }
+ }