Skip to content
This repository has been archived by the owner on Mar 26, 2020. It is now read-only.

Commit

Permalink
Add single selection input window, with object editor unit fields ope…
Browse files Browse the repository at this point in the history
…ning some of the new enums

See #24
  • Loading branch information
ChiefOfGxBxL committed Jun 7, 2017
1 parent 03438b8 commit 081a3ad
Show file tree
Hide file tree
Showing 12 changed files with 179 additions and 1 deletion.
2 changes: 1 addition & 1 deletion classes/Window.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ var Window = {
}

function loadDefaultInputWindows() {
var inputTypes = ['int', 'unknown'];
var inputTypes = ['int', 'singleChoice', 'unknown'];

inputTypes.forEach((type) => {
var inputName = 'input' + (type[0].toUpperCase()) + type.substr(1);
Expand Down
7 changes: 7 additions & 0 deletions enum/AIBuffer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
None: '_',
Factory: 'factory',
General: 'buffer',
Hall: 'townhall',
Resource: 'resource'
}
8 changes: 8 additions & 0 deletions enum/ArmorType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// NOTE: oddly, the raw values here are still capitalized
module.exports = {
Ethereal: 'Ethereal',
Flesh: 'Flesh',
Metal: 'Metal',
Stone: 'Stone',
Wood: 'Wood'
}
10 changes: 10 additions & 0 deletions enum/AttackType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
None: 'unknown',
Normal: 'normal',
Pierce: 'pierce',
Siege: 'siege',
Spells: 'spells',
Chaos: 'chaos',
Magic: 'magic',
Hero: 'hero',
}
5 changes: 5 additions & 0 deletions enum/AttributeType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
Strength: 'STR',
Agility: 'AGI',
Intelligence: 'INT'
}
10 changes: 10 additions & 0 deletions enum/DefenseType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
Normal: 'normal',
Small: 'small',
Medium: 'medium',
Large: 'large',
Fortified: 'fort',
Hero: 'hero',
Divine: 'divine',
Unarmored: 'none'
}
9 changes: 9 additions & 0 deletions enum/MovementType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
None: '',
Foot: 'foot',
Horse: 'horse',
Fly: 'fly',
Hover: 'hover',
Float: 'float',
Amphibious: 'amph'
}
16 changes: 16 additions & 0 deletions enum/TeamColor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
OwningPlayer: -1,
Player1: 0,
Player2: 1,
Player3: 2,
Player4: 3,
Player5: 4,
Player6: 5,
Player7: 6,
Player8: 7,
Player9: 8,
Player10: 9,
Player11: 10,
Player12: 11,
NeutralHostile: 12
}
13 changes: 13 additions & 0 deletions enum/UnitRace.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
None: 'unknown',
Commoner: 'commoner',
Creep: 'creeps',
Critter: 'critters',
Demon: 'demon',
Human: 'human',
Naga: 'naga',
NightElf: 'nightelf',
Orc: 'orc',
Other: 'other',
Undead: 'undead'
}
11 changes: 11 additions & 0 deletions enum/WeaponType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
None: '',
Normal: 'normal',
Instant: 'instant',
Artillery: 'artillery',
ArtilleryLine: 'aline',
Missile: 'missile',
MissileSplash: 'msplash',
MissileBounce: 'mbounce',
MissileLine: 'mline'
}
51 changes: 51 additions & 0 deletions views/input/singleChoice.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Ice Sickle - {{type}}</title>

<link rel="stylesheet" href="../../assets/css/font-awesome.min.css">
<link rel="stylesheet" href="../../assets/css/mini-default.min.css">
<link rel="stylesheet" href="../../assets/css/user-input-page.css">

<script>
function submitUserDataForm() {
var {ipcRenderer} = require('electron');

ipcRenderer.send('response-user-input', {
id: '{{id}}',
entryId: '{{entryId}}',
type: 'singleChoice',
value: document.getElementById('choice').selectedOptions[0].value
});

window.close();
}
</script>
</head>
<body>
<form>
<fieldset>
<legend>Edit Value{{#if fieldName}} - {{fieldName}}{{/if}}</legend>

<label>
Value:
<select id='choice'>
{{#each choices}}
<option value='{{value}}' {{#if selected}}selected{{/if}}>{{key}}</option>
{{/each}}
</select>
</label>

<div class='buttons-right'>
<a class='button' onclick='window.close()'>Cancel</a>
<a class='button primary' onclick='submitUserDataForm()'>OK</a>
</div>

{{#if tooltip}}
<p class='comment'>{{tooltip}}</p>
{{/if}}
</fieldset>
</form>
</body>
</html>
38 changes: 38 additions & 0 deletions views/object-editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,47 @@
})

var userInputListener = false;

// Stores field whose selection mode is a simple dropdown menu
// where only one option may be selected; value is the enum file
var userInputSingleChoices = {
// fieldType: enumeration file name
'armorType': 'ArmorType',
'attackType': 'AttackType',
'weaponType': 'WeaponType',
'moveType': 'MovementType',
'teamColor': 'TeamColor',
'defenseType': 'DefenseType',
'attributeType': 'AttributeType',
'unitRace': 'UnitRace',
'aiBuffer': 'AIBuffer'
};
function requestUserInput(type, context, entryId, cb) {
context.entryId = entryId;

// Is the input a single dropdown menu?
var singleChoice = userInputSingleChoices[type];
if(singleChoice) {
type = 'singleChoice';

var dataChoices = require('../enum/' + singleChoice),
choices = Object.keys(dataChoices).map((key) => {
return {
key: key,
value: dataChoices[key],
selected:
// Sometimes the enums have integer values, so we must check if they are integers
// to avoid an error when trying to call toLowerCase() on them
((typeof dataChoices[key] == 'string') ? dataChoices[key].toLowerCase() : dataChoices[key])
==
((typeof context.currentValue == 'string') ? context.currentValue.toLowerCase() : context.currentValue)
}
});

context['choices'] = choices;
}


ipcRenderer.send('request-user-input', {
type: type,
context: context
Expand Down

0 comments on commit 081a3ad

Please sign in to comment.