public void AddForm(string stateTxn, Stage.Types.Schema schema, List <UTXO> utxos, Stage stage) { Assert.IsTrue(!string.IsNullOrEmpty(stateTxn)); payeeAddr = stage.Payee; funds = stage.Funds; Assert.IsTrue(!string.IsNullOrEmpty(payeeAddr)); stateId = stateTxn; foreach (var utxo in utxos) { if (utxo.Satoshis >= 100000) // Dont use an utxo meant for an image to submit this { continue; } submitUTXO = utxo; utxos.Remove(utxo); break; } SchemaController.BuildForm(schema, utxos.ToArray()); SchemaController.OnSubmit.AddListener(SubmitForm); }
public void BuildForm(Stage.Types.Schema schema, UTXO[] utxos) { var utxoIndex = 0; var schemaName = Instantiate(SchemaNameTextPrefab, Parent); schemaName.GetComponent <Text>().text = schema.Name.ToUpper(); foreach (var field in schema.Fields) { switch (field.Type) { case Field.Types.Type.Text: var text = Instantiate(TextInputFieldPrefab, Parent); text.GetComponentInChildren <Text>().text = field.Label; FieldGetterMap.Add(field.Key, text.GetComponent <ISchemaFieldGetter>()); break; case Field.Types.Type.Number: var number = Instantiate(NumberInputFieldPrefab, Parent); number.GetComponentInChildren <Text>().text = field.Label; FieldGetterMap.Add(field.Key, number.GetComponent <ISchemaFieldGetter>()); break; case Field.Types.Type.Image: var image = Instantiate(ImageUploadWidgetPrefab, Parent); image.GetComponentsInChildren <Text>()[5].text = field.Label; image.GetComponentInChildren <TakePicture>().UTXO = utxos[utxoIndex]; utxoIndex++; FieldGetterMap.Add(field.Key, image.GetComponent <ISchemaFieldGetter>()); break; case Field.Types.Type.File: var file = Instantiate(FileUploadWidgetPrefab, Parent); file.GetComponentsInChildren <Text>()[5].text = field.Label; file.GetComponentInChildren <UploadFile>().UTXO = utxos[utxoIndex]; utxoIndex++; FieldGetterMap.Add(field.Key, file.GetComponent <ISchemaFieldGetter>()); break; case Field.Types.Type.Boolean: var boolean = Instantiate(BoolInputPrefab, Parent); boolean.GetComponentInChildren <Text>().text = field.Label; FieldGetterMap.Add(field.Key, boolean.GetComponent <ISchemaFieldGetter>()); break; } } var button = Instantiate(ButtonPrefab, Parent); button.GetComponentInChildren <Text>().text = "Submit"; var b = button.GetComponent <Button>(); b.onClick.AddListener(Submit); }