More indentation conversion

This commit is contained in:
Vortrex
2022-03-16 17:06:57 -05:00
parent efc72dffe1
commit d0e0cc7c2c
51 changed files with 625 additions and 632 deletions

View File

@@ -0,0 +1,8 @@
// ===========================================================================
// Vortrex's Roleplay Resource
// https://github.com/VortrexFTW/gtac_roleplay
// ===========================================================================
// FILE: vehicle.js
// DESC: Provides vehicle functions and arrays with data
// TYPE: Client (JavaScript)
// ===========================================================================

View File

@@ -10,27 +10,27 @@
// ===========================================================================
function isPlayerHandCuffed(client) {
return (getPlayerData(client).pedState == VRR_PEDSTATE_BINDED);
return (getPlayerData(client).pedState == VRR_PEDSTATE_BINDED);
}
// ===========================================================================
function handCuffPlayer(client) {
getPlayerData(client).pedState = VRR_PEDSTATE_BINDED;
setPlayerControlState(client, false);
getPlayerData(client).pedState = VRR_PEDSTATE_BINDED;
setPlayerControlState(client, false);
}
// ===========================================================================
function unHandCuffPlayer(client) {
getPlayerData(client).pedState = VRR_PEDSTATE_READY;
setPlayerControlState(client, true);
getPlayerData(client).pedState = VRR_PEDSTATE_READY;
setPlayerControlState(client, true);
}
// ===========================================================================
function isPlayerSurrendered(client) {
return true; //(getPlayerData(client).pedState == VRR_PEDSTATE_TAZED || getPlayerData(client).pedState == VRR_PEDSTATE_HANDSUP);
return true; //(getPlayerData(client).pedState == VRR_PEDSTATE_TAZED || getPlayerData(client).pedState == VRR_PEDSTATE_HANDSUP);
}
// ===========================================================================

View File

@@ -8,48 +8,48 @@
// ===========================================================================
function getItemWithPhoneNumber(phoneNumber) {
for(let i in getServerData().items) {
if(getItemTypeData(getItemData(i).itemTypeIndex).useType == VRR_ITEM_USETYPE_PHONE) {
if(getItemData(i).value == phoneNumber) {
return i;
}
}
}
return -1;
for(let i in getServerData().items) {
if(getItemTypeData(getItemData(i).itemTypeIndex).useType == VRR_ITEM_USETYPE_PHONE) {
if(getItemData(i).value == phoneNumber) {
return i;
}
}
}
return -1;
}
// ===========================================================================
function isPhoneItemEnabled(itemIndex) {
return getItemData(itemIndex).enabled;
return getItemData(itemIndex).enabled;
}
// ===========================================================================
function ringPhoneForNearbyPlayers(itemIndex) {
/*
if(isPhoneItemEnabled(itemIndex)) {
switch(getItemData(itemIndex).ownerType) {
case VRR_ITEM_OWNER_GROUND:
playRingtoneForPlayersInRange(getItemData(itemIndex).position, getItemData(i).extra);
break;
/*
if(isPhoneItemEnabled(itemIndex)) {
switch(getItemData(itemIndex).ownerType) {
case VRR_ITEM_OWNER_GROUND:
playRingtoneForPlayersInRange(getItemData(itemIndex).position, getItemData(i).extra);
break;
case VRR_ITEM_OWNER_VEHTRUNK:
playRingtoneForPlayersInRange(getVehiclePosition(getItemData(itemIndex).ownerId), getItemData(i).extra);
break;
case VRR_ITEM_OWNER_VEHTRUNK:
playRingtoneForPlayersInRange(getVehiclePosition(getItemData(itemIndex).ownerId), getItemData(i).extra);
break;
case VRR_ITEM_OWNER_VEHDASH:
playRingtoneForPlayersInRange(getVehiclePosition(getItemData(itemIndex).ownerId), getItemData(i).extra);
break;
}
}
*/
case VRR_ITEM_OWNER_VEHDASH:
playRingtoneForPlayersInRange(getVehiclePosition(getItemData(itemIndex).ownerId), getItemData(i).extra);
break;
}
}
*/
}
// ===========================================================================
function phoneTransmit(radioFrequency, messageText, transmittingPlayer) {
phoneOutgoingToNearbyPlayers(transmittingPlayer, messageText);
phoneOutgoingToNearbyPlayers(transmittingPlayer, messageText);
}
// ===========================================================================

View File

@@ -10,21 +10,21 @@
// ===========================================================================
function isPlayerTied(client) {
return (getPlayerData(client).pedState == VRR_PEDSTATE_BINDED);
return (getPlayerData(client).pedState == VRR_PEDSTATE_BINDED);
}
// ===========================================================================
function ropeTiePlayer(client) {
getPlayerData(client).pedState = VRR_PEDSTATE_BINDED;
setPlayerControlState(client, false);
getPlayerData(client).pedState = VRR_PEDSTATE_BINDED;
setPlayerControlState(client, false);
}
// ===========================================================================
function ropeUnTiePlayer(client) {
getPlayerData(client).pedState = VRR_PEDSTATE_READY;
setPlayerControlState(client, true);
getPlayerData(client).pedState = VRR_PEDSTATE_READY;
setPlayerControlState(client, true);
}
// ===========================================================================

View File

@@ -10,34 +10,34 @@
// ===========================================================================
function isPlayerTazed(client) {
return (getPlayerData(client).pedState == VRR_PEDSTATE_TAZED);
return (getPlayerData(client).pedState == VRR_PEDSTATE_TAZED);
}
// ===========================================================================
function tazePlayer(client) {
getPlayerData(client).pedState = VRR_PEDSTATE_TAZED;
setPlayerControlState(client, false);
getPlayerData(client).pedState = VRR_PEDSTATE_TAZED;
setPlayerControlState(client, false);
let animationId = getAnimationFromParams("tazed");
if(animationId != false) {
forcePlayerPlayAnimation(client, animationId);
}
let animationId = getAnimationFromParams("tazed");
if(animationId != false) {
forcePlayerPlayAnimation(client, animationId);
}
setTimeout(function() {
unTazePlayer(client);
doActionToNearbyPlayers(client, `The tazer effect wears off`);
}, getGlobalConfig().tazerEffectDuration);
setTimeout(function() {
unTazePlayer(client);
doActionToNearbyPlayers(client, `The tazer effect wears off`);
}, getGlobalConfig().tazerEffectDuration);
}
// ===========================================================================
function unTazePlayer(client) {
getPlayerData(client).pedState = VRR_PEDSTATE_READY;
getPlayerData(client).pedState = VRR_PEDSTATE_READY;
setPlayerControlState(client, true);
setPlayerPosition(client, getPlayerData(client).currentAnimationPositionReturnTo);
makePedStopAnimation(getPlayerData(client).ped);
setPlayerControlState(client, true);
setPlayerPosition(client, getPlayerData(client).currentAnimationPositionReturnTo);
makePedStopAnimation(getPlayerData(client).ped);
}

View File

@@ -16,15 +16,15 @@ function getPlayerActiveWalkieTalkieFrequency(client) {
return getItemData(getPlayerData(client).hotBarItems[walkieTalkieSlot]).value;
}
}
}
}
return false;
return false;
}
// ===========================================================================
function walkieTalkieTransmit(radioFrequency, messageText, transmittingPlayer) {
walkieTalkieOutgoingToNearbyPlayers(transmittingPlayer, messageText);
walkieTalkieOutgoingToNearbyPlayers(transmittingPlayer, messageText);
//let clients = getServerData().items;
//for(let i in clients) {

View File

@@ -8,157 +8,157 @@
// ===========================================================================
function policeTazerCommand(command, params, client) {
if(!canPlayerUseJobs(client)) {
messagePlayerError(client, "You are not allowed to use jobs.");
return false;
}
if(!canPlayerUseJobs(client)) {
messagePlayerError(client, "You are not allowed to use jobs.");
return false;
}
if(!canPlayerUsePoliceJob(client)) {
messagePlayerError(client, "You are not allowed to use the police job.");
return false;
}
if(!canPlayerUsePoliceJob(client)) {
messagePlayerError(client, "You are not allowed to use the police job.");
return false;
}
if(!isPlayerWorking(client)) {
messagePlayerError(client, "You are not working! Use /startwork first.");
return false;
}
if(!isPlayerWorking(client)) {
messagePlayerError(client, "You are not working! Use /startwork first.");
return false;
}
if(!doesPlayerHaveJobType(client, VRR_JOB_POLICE)) {
messagePlayerError(client, "You don't have a police job.");
return false;
}
if(!doesPlayerHaveJobType(client, VRR_JOB_POLICE)) {
messagePlayerError(client, "You don't have a police job.");
return false;
}
return true;
return true;
}
// ===========================================================================
function policeCuffCommand(command, params, client) {
if(!canPlayerUseJobs(client)) {
messagePlayerError(client, "You are not allowed to use jobs.");
return false;
}
if(!canPlayerUseJobs(client)) {
messagePlayerError(client, "You are not allowed to use jobs.");
return false;
}
if(!canPlayerUsePoliceJob(client)) {
messagePlayerError(client, "You are not allowed to use the police job.");
return false;
}
if(!canPlayerUsePoliceJob(client)) {
messagePlayerError(client, "You are not allowed to use the police job.");
return false;
}
if(!isPlayerWorking(client)) {
messagePlayerError(client, "You are not working! Use /startwork first.");
return false;
}
if(!isPlayerWorking(client)) {
messagePlayerError(client, "You are not working! Use /startwork first.");
return false;
}
if(!doesPlayerHaveJobType(client, VRR_JOB_POLICE)) {
messagePlayerError(client, "You don't have a police job.");
return false;
}
if(!doesPlayerHaveJobType(client, VRR_JOB_POLICE)) {
messagePlayerError(client, "You don't have a police job.");
return false;
}
return true;
return true;
}
// ===========================================================================
function policeArrestCommand(command, params, client) {
if(!canPlayerUseJobs(client)) {
messagePlayerError(client, "You are not allowed to use jobs.");
return false;
}
if(!canPlayerUseJobs(client)) {
messagePlayerError(client, "You are not allowed to use jobs.");
return false;
}
if(!canPlayerUsePoliceJob(client)) {
messagePlayerError(client, "You are not allowed to use the police job.");
return false;
}
if(!canPlayerUsePoliceJob(client)) {
messagePlayerError(client, "You are not allowed to use the police job.");
return false;
}
if(!isPlayerWorking(client)) {
messagePlayerError(client, "You are not working! Use /startwork first.");
return false;
}
if(!isPlayerWorking(client)) {
messagePlayerError(client, "You are not working! Use /startwork first.");
return false;
}
if(!doesPlayerHaveJobType(client, VRR_JOB_POLICE)) {
messagePlayerError(client, "You don't have a police job.");
return false;
}
if(!doesPlayerHaveJobType(client, VRR_JOB_POLICE)) {
messagePlayerError(client, "You don't have a police job.");
return false;
}
return true;
return true;
}
// ===========================================================================
function policeSearchCommand(command, params, client) {
if(!canPlayerUseJobs(client)) {
messagePlayerError(client, "You are not allowed to use jobs.");
return false;
}
if(!canPlayerUseJobs(client)) {
messagePlayerError(client, "You are not allowed to use jobs.");
return false;
}
if(!canPlayerUsePoliceJob(client)) {
messagePlayerError(client, "You are not allowed to use the police job.");
return false;
}
if(!canPlayerUsePoliceJob(client)) {
messagePlayerError(client, "You are not allowed to use the police job.");
return false;
}
if(!isPlayerWorking(client)) {
messagePlayerError(client, "You are not working! Use /startwork first.");
return false;
}
if(!isPlayerWorking(client)) {
messagePlayerError(client, "You are not working! Use /startwork first.");
return false;
}
if(!doesPlayerHaveJobType(client, VRR_JOB_POLICE)) {
messagePlayerError(client, "You don't have a police job.");
return false;
}
if(!doesPlayerHaveJobType(client, VRR_JOB_POLICE)) {
messagePlayerError(client, "You don't have a police job.");
return false;
}
return true;
return true;
}
// ===========================================================================
function policeDragCommand(command, params, client) {
if(!canPlayerUseJobs(client)) {
messagePlayerError(client, "You are not allowed to use jobs.");
return false;
}
if(!canPlayerUseJobs(client)) {
messagePlayerError(client, "You are not allowed to use jobs.");
return false;
}
if(!canPlayerUsePoliceJob(client)) {
messagePlayerError(client, "You are not allowed to use the police job.");
return false;
}
if(!canPlayerUsePoliceJob(client)) {
messagePlayerError(client, "You are not allowed to use the police job.");
return false;
}
if(!isPlayerWorking(client)) {
messagePlayerError(client, "You are not working! Use /startwork first.");
return false;
}
if(!isPlayerWorking(client)) {
messagePlayerError(client, "You are not working! Use /startwork first.");
return false;
}
if(!doesPlayerHaveJobType(client, VRR_JOB_POLICE)) {
messagePlayerError(client, "You don't have a police job.");
return false;
}
if(!doesPlayerHaveJobType(client, VRR_JOB_POLICE)) {
messagePlayerError(client, "You don't have a police job.");
return false;
}
return true;
return true;
}
// ===========================================================================
function policeDetainCommand(command, params, client) {
if(!canPlayerUseJobs(client)) {
messagePlayerError(client, "You are not allowed to use jobs.");
return false;
}
if(!canPlayerUseJobs(client)) {
messagePlayerError(client, "You are not allowed to use jobs.");
return false;
}
if(!canPlayerUsePoliceJob(client)) {
messagePlayerError(client, "You are not allowed to use the police job.");
return false;
}
if(!canPlayerUsePoliceJob(client)) {
messagePlayerError(client, "You are not allowed to use the police job.");
return false;
}
if(!isPlayerWorking(client)) {
messagePlayerError(client, "You are not working! Use /startwork first.");
return false;
}
if(!isPlayerWorking(client)) {
messagePlayerError(client, "You are not working! Use /startwork first.");
return false;
}
if(!doesPlayerHaveJobType(client, VRR_JOB_POLICE)) {
messagePlayerError(client, "You don't have a police job.");
return false;
}
if(!doesPlayerHaveJobType(client, VRR_JOB_POLICE)) {
messagePlayerError(client, "You don't have a police job.");
return false;
}
return true;
return true;
}
// ===========================================================================

View File

@@ -8,25 +8,25 @@
// ===========================================================================
function taxiSetFareCommand(command, params, client) {
if(!canPlayerUseJobs(client)) {
messagePlayerError(client, "You are not allowed to use jobs.");
return false;
}
if(!canPlayerUseJobs(client)) {
messagePlayerError(client, "You are not allowed to use jobs.");
return false;
}
if(!canPlayerUseTaxiJob(client)) {
messagePlayerError(client, "You are not allowed to use the taxi job.");
return false;
}
if(!canPlayerUseTaxiJob(client)) {
messagePlayerError(client, "You are not allowed to use the taxi job.");
return false;
}
if(!isPlayerWorking(client)) {
messagePlayerError(client, "You are not working! Use /startwork first.");
return false;
}
if(!isPlayerWorking(client)) {
messagePlayerError(client, "You are not working! Use /startwork first.");
return false;
}
if(!doesPlayerHaveJobType(client, VRR_JOB_TAXI)) {
messagePlayerError(client, "You don't have a taxi job.");
return false;
}
if(!doesPlayerHaveJobType(client, VRR_JOB_TAXI)) {
messagePlayerError(client, "You don't have a taxi job.");
return false;
}
return true;
}

View File

@@ -10,90 +10,90 @@
// ===========================================================================
function getPlayerPosition(client) {
if(!areServerElementsSupported()) {
return getPlayerData(client).syncPosition;
} else {
if(client.player != null) {
return client.player.position;
}
}
if(!areServerElementsSupported()) {
return getPlayerData(client).syncPosition;
} else {
if(client.player != null) {
return client.player.position;
}
}
}
// ===========================================================================
function setPlayerPosition(client, position) {
logToConsole(LOG_DEBUG, `Setting ${getPlayerDisplayForConsole(client)}'s position to ${position.x}, ${position.y}, ${position.z}`);
sendPlayerSetPosition(client, position);
logToConsole(LOG_DEBUG, `Setting ${getPlayerDisplayForConsole(client)}'s position to ${position.x}, ${position.y}, ${position.z}`);
sendPlayerSetPosition(client, position);
}
// ===========================================================================
function getPlayerHeading(client) {
if(!areServerElementsSupported()) {
return getPlayerData(client).syncHeading;
} else {
if(client.player != null) {
return client.player.heading;
}
}
if(!areServerElementsSupported()) {
return getPlayerData(client).syncHeading;
} else {
if(client.player != null) {
return client.player.heading;
}
}
}
// ===========================================================================
function setPlayerHeading(client, heading) {
logToConsole(LOG_DEBUG, `Setting ${getPlayerDisplayForConsole(client)}'s heading to ${heading}`);
sendPlayerSetHeading(client, heading);
logToConsole(LOG_DEBUG, `Setting ${getPlayerDisplayForConsole(client)}'s heading to ${heading}`);
sendPlayerSetHeading(client, heading);
}
// ===========================================================================
function getPlayerVehicle(client) {
if(!areServerElementsSupported()) {
return getPlayerData().syncVehicle;
} else {
if(client.player.vehicle) {
return client.player.vehicle;
}
}
return false;
if(!areServerElementsSupported()) {
return getPlayerData().syncVehicle;
} else {
if(client.player.vehicle) {
return client.player.vehicle;
}
}
return false;
}
// ===========================================================================
function getPlayerDimension(client) {
if(!areServerElementsSupported()) {
return getPlayerData(client).syncDimension;
} else {
if(client.player != null) {
return client.player.dimension;
}
}
if(!areServerElementsSupported()) {
return getPlayerData(client).syncDimension;
} else {
if(client.player != null) {
return client.player.dimension;
}
}
}
// ===========================================================================
function getPlayerInterior(client) {
return getPlayerCurrentSubAccount(client).interior || 0;
return getPlayerCurrentSubAccount(client).interior || 0;
}
// ===========================================================================
function setPlayerDimension(client, dimension) {
logToConsole(LOG_DEBUG, `Setting ${getPlayerDisplayForConsole(client)}'s dimension to ${dimension}`);
if(!areServerElementsSupported()) {
getPlayerData(client).syncDimension = dimension;
} else {
if(client.player != null) {
client.player.dimension = dimension;
}
}
logToConsole(LOG_DEBUG, `Setting ${getPlayerDisplayForConsole(client)}'s dimension to ${dimension}`);
if(!areServerElementsSupported()) {
getPlayerData(client).syncDimension = dimension;
} else {
if(client.player != null) {
client.player.dimension = dimension;
}
}
}
// ===========================================================================
function setPlayerInterior(client, interior) {
logToConsole(LOG_DEBUG, `Setting ${getPlayerDisplayForConsole(client)}'s interior to ${interior}`);
sendPlayerSetInterior(client, interior);
logToConsole(LOG_DEBUG, `Setting ${getPlayerDisplayForConsole(client)}'s interior to ${interior}`);
sendPlayerSetInterior(client, interior);
if(isPlayerLoggedIn(client) && isPlayerSpawned(client)) {
getPlayerCurrentSubAccount(client).interior = interior;
}
@@ -102,19 +102,19 @@ function setPlayerInterior(client, interior) {
// ===========================================================================
function isPlayerInAnyVehicle(client) {
if(!areServerElementsSupported()) {
return (getPlayerData().syncVehicle != null);
} else {
return (client.player.vehicle != null);
}
if(!areServerElementsSupported()) {
return (getPlayerData().syncVehicle != null);
} else {
return (client.player.vehicle != null);
}
}
// ===========================================================================
function getPlayerVehicleSeat(client) {
if(!isPlayerInAnyVehicle(client)) {
return false;
}
if(!isPlayerInAnyVehicle(client)) {
return false;
}
if(!areServerElementsSupported()) {
return getPlayerData().syncVehicleSeat;
@@ -126,25 +126,25 @@ function getPlayerVehicleSeat(client) {
}
}
return false;
return false;
}
// ===========================================================================
function isPlayerSpawned(client) {
return getPlayerData(client).spawned;
return getPlayerData(client).spawned;
}
// ===========================================================================
function getVehiclePosition(vehicle) {
return vehicle.position;
return vehicle.position;
}
// ===========================================================================
function getVehicleHeading(vehicle) {
return vehicle.heading;
return vehicle.heading;
}
// ===========================================================================
@@ -153,13 +153,13 @@ function setVehicleHeading(vehicle, heading) {
if(getGame() == VRR_GAME_GTA_IV) {
return sendNetworkEventToPlayer("vrr.vehPosition", null, getVehicleForNetworkEvent(vehicle), heading);
}
return vehicle.heading = heading;
return vehicle.heading = heading;
}
// ===========================================================================
function getVehicleSyncer(vehicle) {
return getElementSyncer(vehicle);
return getElementSyncer(vehicle);
}
// ===========================================================================
@@ -171,40 +171,40 @@ function getVehicleForNetworkEvent(vehicle) {
}
return -1;
}
return vehicle.id;
return vehicle.id;
}
// ===========================================================================
function deleteGameElement(element) {
try {
if(element != null) {
destroyElement(element);
return true;
}
} catch(error) {
return false;
}
try {
if(element != null) {
destroyElement(element);
return true;
}
} catch(error) {
return false;
}
}
// ===========================================================================
function isPlayerInFrontVehicleSeat(client) {
return (getPlayerVehicleSeat(client) == 0 || getPlayerVehicleSeat(client) == 1);
return (getPlayerVehicleSeat(client) == 0 || getPlayerVehicleSeat(client) == 1);
}
// ===========================================================================
function removePlayerFromVehicle(client) {
logToConsole(LOG_DEBUG, `Removing ${getPlayerDisplayForConsole(client)} from their vehicle`);
sendPlayerRemoveFromVehicle(client);
return true;
logToConsole(LOG_DEBUG, `Removing ${getPlayerDisplayForConsole(client)} from their vehicle`);
sendPlayerRemoveFromVehicle(client);
return true;
}
// ===========================================================================
function setPlayerSkin(client, skinIndex) {
logToConsole(LOG_DEBUG, `Setting ${getPlayerDisplayForConsole(client)}'s skin to ${getGameConfig().skins[getGame()][skinIndex][0]} (Index: ${skinIndex}, Name: ${getGameConfig().skins[getGame()][skinIndex][1]})`);
logToConsole(LOG_DEBUG, `Setting ${getPlayerDisplayForConsole(client)}'s skin to ${getGameConfig().skins[getGame()][skinIndex][0]} (Index: ${skinIndex}, Name: ${getGameConfig().skins[getGame()][skinIndex][1]})`);
if(getGame() == VRR_GAME_GTA_IV) {
triggerNetworkEvent("vrr.localPlayerSkin", client, getGameConfig().skins[getGame()][skinIndex][0]);
} else {
@@ -215,35 +215,35 @@ function setPlayerSkin(client, skinIndex) {
// ===========================================================================
function getPlayerSkin(client) {
return getSkinIndexFromModel(client.player.modelIndex);
return getSkinIndexFromModel(client.player.modelIndex);
}
// ===========================================================================
function setPlayerHealth(client, health) {
logToConsole(LOG_DEBUG, `Setting ${getPlayerDisplayForConsole(client)}'s health to ${health}`);
sendPlayerSetHealth(client, health);
logToConsole(LOG_DEBUG, `Setting ${getPlayerDisplayForConsole(client)}'s health to ${health}`);
sendPlayerSetHealth(client, health);
getServerData(client).health = health;
}
// ===========================================================================
function getPlayerHealth(client) {
return getServerData(client).health;
return getServerData(client).health;
}
// ===========================================================================
function setPlayerArmour(client, armour) {
logToConsole(LOG_DEBUG, `Setting ${getPlayerDisplayForConsole(client)}'s armour to ${armour}`);
sendPlayerSetArmour(client, armour);
//client.player.armour = armour;
logToConsole(LOG_DEBUG, `Setting ${getPlayerDisplayForConsole(client)}'s armour to ${armour}`);
sendPlayerSetArmour(client, armour);
//client.player.armour = armour;
}
// ===========================================================================
function getPlayerArmour(client) {
return client.player.armour;
return client.player.armour;
}
// ===========================================================================
@@ -253,9 +253,9 @@ function setPlayerCash(client, amount) {
return false;
}
if(isNaN(amount)) {
return false;
}
if(isNaN(amount)) {
return false;
}
getPlayerCurrentSubAccount(client).cash = toInteger(amount);
updatePlayerCash(client);
@@ -268,9 +268,9 @@ function givePlayerCash(client, amount) {
return false;
}
if(isNaN(amount)) {
return false;
}
if(isNaN(amount)) {
return false;
}
getPlayerCurrentSubAccount(client).cash = getPlayerCurrentSubAccount(client).cash + toInteger(amount);
updatePlayerCash(client);
@@ -283,9 +283,9 @@ function takePlayerCash(client, amount) {
return false;
}
if(isNaN(amount)) {
return false;
}
if(isNaN(amount)) {
return false;
}
getPlayerCurrentSubAccount(client).cash = getPlayerCurrentSubAccount(client).cash - toInteger(amount);
updatePlayerCash(client);
@@ -294,173 +294,173 @@ function takePlayerCash(client, amount) {
// ===========================================================================
function disconnectPlayer(client) {
logToConsole(LOG_DEBUG, `Disconnecting (kicking) ${getPlayerDisplayForConsole(client)}`);
client.disconnect();
return false;
logToConsole(LOG_DEBUG, `Disconnecting (kicking) ${getPlayerDisplayForConsole(client)}`);
client.disconnect();
return false;
}
// ===========================================================================
function getElementSyncer(element) {
return getClients()[element.syncer];
return getClients()[element.syncer];
}
// ===========================================================================
function getPlayerWeaponAmmo(client) {
return client.player.weaponAmmunition;
return client.player.weaponAmmunition;
}
// ===========================================================================
function setPlayerVelocity(client, velocity) {
logToConsole(LOG_DEBUG, `Setting ${getPlayerDisplayForConsole(client)}'s velocity to ${velocity.x}, ${velocity.y}, ${velocity.z}`);
if(typeof client.player.velocity != "undefined") {
client.player.velocity = velocity;
}
logToConsole(LOG_DEBUG, `Setting ${getPlayerDisplayForConsole(client)}'s velocity to ${velocity.x}, ${velocity.y}, ${velocity.z}`);
if(typeof client.player.velocity != "undefined") {
client.player.velocity = velocity;
}
}
// ===========================================================================
function getPlayerVelocity(client, velocity) {
if(typeof client.player.velocity != "undefined") {
return client.player.velocity;
}
return toVector3(0.0, 0.0, 0.0);
if(typeof client.player.velocity != "undefined") {
return client.player.velocity;
}
return toVector3(0.0, 0.0, 0.0);
}
// ===========================================================================
function getElementDimension(element) {
if(typeof element.dimension != "undefined") {
return element.dimension;
}
return 0;
if(typeof element.dimension != "undefined") {
return element.dimension;
}
return 0;
}
// ===========================================================================
function setElementDimension(element, dimension) {
if(typeof element.dimension != "undefined") {
element.dimension = dimension;
return true;
}
return false;
if(typeof element.dimension != "undefined") {
element.dimension = dimension;
return true;
}
return false;
}
// ===========================================================================
function setElementRotation(element, rotation) {
return element.setRotation(rotation);
return element.setRotation(rotation);
}
// ===========================================================================
function givePlayerHealth(client, amount) {
if(getPlayerHealth(client)+amount > 100) {
logToConsole(LOG_DEBUG, `Setting ${getPlayerDisplayForConsole(client)}'s health to 100`);
setPlayerHealth(client, 100);
} else {
logToConsole(LOG_DEBUG, `Setting ${getPlayerDisplayForConsole(client)}'s health to ${getPlayerHealth(client)+amount}`);
setPlayerHealth(client, getPlayerHealth(client)+amount);
}
if(getPlayerHealth(client)+amount > 100) {
logToConsole(LOG_DEBUG, `Setting ${getPlayerDisplayForConsole(client)}'s health to 100`);
setPlayerHealth(client, 100);
} else {
logToConsole(LOG_DEBUG, `Setting ${getPlayerDisplayForConsole(client)}'s health to ${getPlayerHealth(client)+amount}`);
setPlayerHealth(client, getPlayerHealth(client)+amount);
}
}
// ===========================================================================
function givePlayerArmour(client, amount) {
if(getPlayerArmour(client)+amount > 100) {
logToConsole(LOG_DEBUG, `Setting ${getPlayerDisplayForConsole(client)}'s armour to 100`);
setPlayerArmour(client, 100);
} else {
logToConsole(LOG_DEBUG, `Setting ${getPlayerDisplayForConsole(client)}'s armour to ${getPlayerArmour(client)+amount}`);
setPlayerArmour(client, getPlayerArmour(client)+amount);
}
if(getPlayerArmour(client)+amount > 100) {
logToConsole(LOG_DEBUG, `Setting ${getPlayerDisplayForConsole(client)}'s armour to 100`);
setPlayerArmour(client, 100);
} else {
logToConsole(LOG_DEBUG, `Setting ${getPlayerDisplayForConsole(client)}'s armour to ${getPlayerArmour(client)+amount}`);
setPlayerArmour(client, getPlayerArmour(client)+amount);
}
}
// ===========================================================================
function getServerGame() {
return getGame();
return getGame();
}
// ===========================================================================
function consolePrint(text) {
console.log(text);
console.log(text);
}
// ===========================================================================
function getPlayerName(client) {
return client.name;
return client.name;
}
// ===========================================================================
function getServerName() {
return server.name;
return server.name;
}
// ===========================================================================
function createGamePickup(modelIndex, position, type) {
if(!isGameFeatureSupported("pickups")) {
return false;
}
return game.createPickup(modelIndex, position, type);
if(!isGameFeatureSupported("pickups")) {
return false;
}
return game.createPickup(modelIndex, position, type);
}
// ===========================================================================
function createGameBlip(position, type = 0, colour = toColour(255, 255, 255, 255)) {
if(!isGameFeatureSupported("blips")) {
return false;
}
return game.createBlip(type, position, 1, colour);
if(!isGameFeatureSupported("blips")) {
return false;
}
return game.createBlip(type, position, 1, colour);
}
// ===========================================================================
function createGameObject(modelIndex, position) {
if(!isGameFeatureSupported("objects")) {
return false;
}
return game.createObject(getGameConfig().objects[getGame()][modelIndex][0], position);
if(!isGameFeatureSupported("objects")) {
return false;
}
return game.createObject(getGameConfig().objects[getGame()][modelIndex][0], position);
}
// ===========================================================================
function setElementOnAllDimensions(element, state) {
if(!isNull(element) && element != false) {
element.onAllDimensions = state;
}
if(!isNull(element) && element != false) {
element.onAllDimensions = state;
}
}
// ===========================================================================
function destroyGameElement(element) {
if(!isNull(element) && element != false) {
destroyElement(element);
}
if(!isNull(element) && element != false) {
destroyElement(element);
}
}
// ===========================================================================
function isMeleeWeapon(weaponId, gameId = getServerGame()) {
return (getGameConfig().meleeWeapons[gameId].indexOf(weaponId) != -1);
return (getGameConfig().meleeWeapons[gameId].indexOf(weaponId) != -1);
}
// ===========================================================================
function getPlayerLastVehicle(client) {
return getPlayerData(client).lastVehicle;
return getPlayerData(client).lastVehicle;
}
// ===========================================================================
function isVehicleObject(vehicle) {
return (vehicle.type == ELEMENT_VEHICLE);
return (vehicle.type == ELEMENT_VEHICLE);
}
// ===========================================================================
@@ -479,7 +479,7 @@ function setVehicleLights(vehicle, lights) {
function setVehicleEngine(vehicle, engine) {
vehicle.engine = engine;
setEntityData(vehicle, "vrr.engine", engine, true);
setEntityData(vehicle, "vrr.engine", engine, true);
}
// ===========================================================================
@@ -524,13 +524,13 @@ function setVehicleColours(vehicle, colour1, colour2, colour3 = -1, colour4 = -1
vehicle.colour1 = colour1;
vehicle.colour2 = colour2;
if(colour3 != -1) {
vehicle.colour3 = colour3;
}
if(colour3 != -1) {
vehicle.colour3 = colour3;
}
if(colour4 != -1) {
vehicle.colour4 = colour4;
}
if(colour4 != -1) {
vehicle.colour4 = colour4;
}
}
// ===========================================================================
@@ -544,7 +544,7 @@ function createGameVehicle(modelIndex, position, heading, toClient = null) {
// ===========================================================================
function getIsland(position) {
if(getServerGame() == VRR_GAME_GTA_III) {
if(getServerGame() == VRR_GAME_GTA_III) {
if(position.x > 616) {
return VRR_ISLAND_PORTLAND;
} else if(position.x < -283) {
@@ -561,11 +561,11 @@ function getIsland(position) {
// ===========================================================================
function isValidVehicleModel(model) {
if(getVehicleModelIndexFromModel(model) != false) {
return true;
}
if(getVehicleModelIndexFromModel(model) != false) {
return true;
}
return false;
return false;
}
// ===========================================================================
@@ -589,8 +589,8 @@ function setPlayerFightStyle(client, fightStyleId) {
return false;
}
setEntityData(getPlayerElement(client), "vrr.fightStyle", [getGameConfig().fightStyles[getServerGame()][fightStyleId][1][0], getGameConfig().fightStyles[getServerGame()][fightStyleId][1][1]]);
forcePlayerToSyncElementProperties(null, getPlayerElement(client));
setEntityData(getPlayerElement(client), "vrr.fightStyle", [getGameConfig().fightStyles[getServerGame()][fightStyleId][1][0], getGameConfig().fightStyles[getServerGame()][fightStyleId][1][1]]);
forcePlayerToSyncElementProperties(null, getPlayerElement(client));
}
// ===========================================================================
@@ -649,32 +649,32 @@ function isTaxiVehicle(vehicle) {
// ===========================================================================
function getVehicleName(vehicle) {
let model = getElementModel(vehicle);
let model = getElementModel(vehicle);
return getVehicleNameFromModel(model) || "Unknown";
}
// ===========================================================================
function getElementModel(element) {
if(typeof element.modelIndex != "undefined") {
return element.modelIndex;
}
if(typeof element.modelIndex != "undefined") {
return element.modelIndex;
}
if(typeof element.model != "undefined") {
return element.model;
}
if(typeof element.model != "undefined") {
return element.model;
}
}
// ===========================================================================
function givePlayerWeaponAmmo(client, ammo) {
givePlayerWeapon(client, getPlayerWeapon(client), getPlayerWeaponAmmo(client) + ammo);
givePlayerWeapon(client, getPlayerWeapon(client), getPlayerWeaponAmmo(client) + ammo);
}
// ===========================================================================
function getPlayerWeapon(client) {
return client.player.weapon;
return client.player.weapon;
}
// ===========================================================================
@@ -914,7 +914,7 @@ function sendNetworkEventToPlayer(eventName, client, ...args) {
// ===========================================================================
function addNetworkEventHandler(eventName, handlerFunction) {
addNetworkHandler(eventName, handlerFunction);
addNetworkHandler(eventName, handlerFunction);
}
// ===========================================================================
@@ -1027,8 +1027,8 @@ function setVehicleHealth(vehicle, health) {
// ===========================================================================
function givePlayerWeapon(client, weaponId, ammo, active = true) {
logToConsole(LOG_DEBUG, `[VRR.Client] Sending signal to ${getPlayerDisplayForConsole(client)} to give weapon (Weapon: ${weaponId}, Ammo: ${ammo})`);
sendNetworkEventToPlayer("vrr.giveWeapon", client, weaponId, ammo, active);
logToConsole(LOG_DEBUG, `[VRR.Client] Sending signal to ${getPlayerDisplayForConsole(client)} to give weapon (Weapon: ${weaponId}, Ammo: ${ammo})`);
sendNetworkEventToPlayer("vrr.giveWeapon", client, weaponId, ammo, active);
}
// ===========================================================================

View File

@@ -2,12 +2,12 @@ mexui.Component.Control = function(window, x, y, w, h, styles, callback)
{
mexui.Entity.Component.call(this, false);
mexui.Entity.StyleableEntity.call(this, this.linkComponentStyles('Control', styles));
this.window = window;
this.position = new Vec2(x, y);
this.size = new Vec2(w, h);
this.callback = callback;
this.boundTo = null;
};
mexui.util.extend(mexui.Component.Control, mexui.Entity.Component);
@@ -131,4 +131,3 @@ mexui.Component.Control.prototype.unbind = function()
{
this.boundTo = null;
};

View File

@@ -2,7 +2,7 @@ mexui.Component.Entry = function(control, axisIndex, text, styles)
{
mexui.Entity.Component.call(this, false);
mexui.Entity.StyleableEntity.call(this, this.linkComponentStyles('Entry', styles));
this.control = control;
this.axisIndex = axisIndex;
this.text = text;
@@ -29,4 +29,3 @@ mexui.Component.Entry.prototype.remove = function()
this.control.axis[this.getAxisKey()].entries.splice(this.getEntryIndex(), 1);
this.control.checkToShowScrollBars();
};

View File

@@ -3,4 +3,3 @@ mexui.Component.Event = function()
this.used = false;
this.clickedAControl = false;
};

View File

@@ -2,11 +2,11 @@ mexui.Component.Window = function(x, y, w, h, title, styles)
{
mexui.Entity.Component.call(this, true);
mexui.Entity.StyleableEntity.call(this, this.linkComponentStyles('Window', styles));
this.position = new Vec2(x, y);
this.size = new Vec2(w, h);
this.title = title || '';
this.controls = [];
this.titleBarShown = true;
this.titleBarHeight = 30;
@@ -21,7 +21,7 @@ mexui.Component.Window.defaultStyles = mexui.util.linkStyles(mexui.Entity.Stylea
{
backgroundColour: toColour(0, 0, 0, 190),
textColour: toColour(255, 255, 255, 255),
hover:
{
backgroundColour: toColour(0, 0, 0, 170)
@@ -52,12 +52,12 @@ mexui.Component.Window.prototype.onMouseDown = function(e)
e.used = true;
return;
}
if(this.isCursorOverWindow())
{
this.setTop();
}
this.triggerEvent('onMouseDown', e);
};
@@ -70,15 +70,15 @@ mexui.Component.Window.prototype.onMouseMove = function(e, offset)
{
//var wasHovered = this.isHovered();
//e.wasHovered = wasHovered;
if(mexui.hoveredComponent && !mexui.hoveredComponent.isCursorOverItem())
{
mexui.hoveredComponent.onMouseExit();
mexui.clearHoveredComponent();
}
this.triggerEvent('onMouseMove', e, offset);
if(e.used)
{
/*
@@ -90,7 +90,7 @@ mexui.Component.Window.prototype.onMouseMove = function(e, offset)
*/
return;
}
if(this.isCursorOverWindow())
{
if(!this.isHovered())
@@ -129,13 +129,13 @@ mexui.Component.Window.prototype.render = function()
{
// window background
mexui.native.drawRectangleBackground(this.position, this.size, this.getStyles('main'));
if(this.titleBarShown)
{
// window title bar
mexui.native.drawRectangle(this.position, new Vec2(this.size.x, this.titleBarHeight), this.getStyles('title'));
mexui.native.drawText(this.position, new Vec2(this.size.x, this.titleBarHeight), this.title, this.getStyles('title'));
if(this.titleBarIconShown)
{
// window title bar icons
@@ -144,17 +144,17 @@ mexui.Component.Window.prototype.render = function()
mexui.native.drawText(iconPos, this.titleBarIconSize, 'X', this.getStyles('icon'));
}
}
// window border
mexui.native.drawRectangleBorder(this.position, this.size, this.getStyles('main'));
// window controls
var show, control;
for(var i in this.controls)
{
control = this.controls[i];
show = false;
if(control.shown)
{
show = true;
@@ -164,7 +164,7 @@ mexui.Component.Window.prototype.render = function()
show = false;
}
}
if(show)
control.render.call(control);
}
@@ -177,7 +177,7 @@ mexui.Component.Window.prototype.renderAfter = function()
if(this.controls[i].shown)
{
this.controls[i].renderAfter.call(this.controls[i]);
for(var i2 in this.controls[i].scrollBars)
{
if(this.controls[i].scrollBars[i2].shown)
@@ -219,10 +219,10 @@ mexui.Component.Window.prototype.triggerEvent = function(eventName, e, data, cal
for(var i in this.controls)
{
var control = this.controls[i];
if(!control.shown)
continue;
if(callBaseMethodFirst)
{
if(mexui.Entity.Component.prototype[eventName])
@@ -231,7 +231,7 @@ mexui.Component.Window.prototype.triggerEvent = function(eventName, e, data, cal
if(e.used)
break;
}
this.controls[i][eventName].call(control, e, data);
if(e.used)
break;
@@ -248,7 +248,7 @@ mexui.Component.Window.prototype.triggerEvent = function(eventName, e, data, cal
}
break;
}
if(mexui.Entity.Component.prototype[eventName])
{
mexui.Entity.Component.prototype[eventName].call(control, e, data);
@@ -268,9 +268,9 @@ mexui.Component.Window.prototype.addControl = function(control)
mexui.Component.Window.prototype.setShown = function(shown)
{
//var anyWindowShownBefore = mexui.isAnyWindowShown();
this.shown = shown;
if(mexui.focusedControl && this.isControlInWindow(mexui.focusedControl))
{
if(!shown)
@@ -278,7 +278,7 @@ mexui.Component.Window.prototype.setShown = function(shown)
mexui.focusedControl = null;
}
}
/*
if(shown)
{
@@ -336,7 +336,7 @@ mexui.Component.Window.prototype.getFirstShownControl = function()
mexui.Component.Window.prototype.getNextShownControl = function(afterControl)
{
var controlIndex = this.controls.indexOf(afterControl);
if(this.controls[controlIndex + 1])
return this.controls[controlIndex + 1];
else
@@ -386,4 +386,3 @@ mexui.Component.Window.prototype.tree = function(x, y, w, h, styles, callback)
mexui.Component.Window.prototype.week = function(x, y, w, h, text, styles, callback) { return this.addControl(new mexui.Control.Week(this, x, y, w, h, text, styles, callback)); };
mexui.Component.Window.prototype.weekDay = function(x, y, w, h, text, styles, callback) { return this.addControl(new mexui.Control.WeekDay(this, x, y, w, h, text, styles, callback)); };
mexui.Component.Window.prototype.year = function(x, y, w, h, text, styles, callback) { return this.addControl(new mexui.Control.Year(this, x, y, w, h, text, styles, callback)); };

View File

@@ -1,7 +1,7 @@
mexui.util.createControlConstructor('Button', false, function(window, x, y, w, h, text, styles, callback)
{
mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('Button', styles), callback);
this.text = text;
});
@@ -31,10 +31,10 @@ mexui.Control.Button.prototype.onKeyDown = function(e, key, mods)
mexui.Control.Button.prototype.render = function()
{
var pos = this.getScreenPosition();
mexui.native.drawRectangle(pos, this.size, this.getStyles('main'));
mexui.native.drawText(pos, this.size, this.text, this.getStyles('main'));
if(this.isFocused())
mexui.native.drawRectangleBorder(mexui.util.subtractVec2(pos,new Vec2(2,2)), mexui.util.addVec2(this.size,new Vec2(3,3)), this.getStyles('focused'));
};

View File

@@ -1,15 +1,15 @@
mexui.util.createControlConstructor('Date', false, function(window, x, y, w, h, text, styles, callback)
{
mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('Date', styles), callback, false, false);
this.day = 1;
this.month = 1;
this.year = 2019;
this.inputShown = false;
this.valueBoxSize = new Vec2(50, 30);
this.arrowBoxSize = new Vec2(25, 22);
this.maxYearOffset = 10;
this.minYearCallback = ()=>{ return 1900; };
this.maxYearCallback = ()=>{ return new Date().getFullYear() + this.maxYearOffset; }
@@ -40,42 +40,42 @@ mexui.Control.Date.prototype.onMouseDown = function(e)
var propIndex = (Math.ceil((arrowIndex + 1) / 2)) - 1;
var propName = mexui.Control.Date.units[propIndex];
var isIncrease = (arrowIndex % 2) == 1;
if(isIncrease)
this[propName]++;
else
this[propName]--;
if(this.day == 0)
this.day = 31;
else if(this.day == 32)
this.day = 1;
if(this.month == 0)
this.month = 12;
else if(this.month == 13)
this.month = 1;
var minYear = this.minYearCallback();
var maxYear = this.maxYearCallback();
if(this.year < minYear)
this.year = minYear;
else if(this.year > maxYear)
this.year = maxYear;
this.generateText();
return;
}
}
if(this.isCursorOverControl())
{
this.inputShown = !this.inputShown;
e.used = true;
return;
}
if(this.inputShown)
{
this.inputShown = false;
@@ -89,18 +89,18 @@ mexui.Control.Date.prototype.renderAfter = function()
{
if(!this.inputShown)
return;
var screenPos = this.getScreenPosition();
var pos = new Vec2(screenPos.x, screenPos.y);
for(var i=0; i<3; i++)
{
mexui.native.drawRectangle(pos, this.valueBoxSize, this.getStyles('main'));
mexui.native.drawText(pos, this.valueBoxSize, this[mexui.Control.Date.units[i]], this.getStyles('main'));
pos.x += this.valueBoxSize.x;
}
pos = new Vec2(screenPos.x, screenPos.y);
pos.y += this.valueBoxSize.y;
for(var i=0; i<3; i++)
@@ -108,10 +108,10 @@ mexui.Control.Date.prototype.renderAfter = function()
for(var i2=0; i2<2; i2++)
{
var text = (i2 % 2) == 0 ? '<' : '>';
mexui.native.drawRectangle(pos, this.arrowBoxSize, this.getStyles('main'));
mexui.native.drawText(pos, this.arrowBoxSize, text, this.getStyles('main'));
pos.x += this.arrowBoxSize.x;
}
}
@@ -133,16 +133,16 @@ mexui.Control.Date.prototype.validateInputCallback = function(e, character)
mexui.Control.Date.prototype.validateValueCallback = function(e)
{
var parts = this.getText().split('/');
if(parts.length != 3)
return false;
for(var i in parts)
{
var partAsStr = parts[i];
if(partAsStr === '')
return false;
if(i == 0)
{
if(!mexui.util.isDayIdWithOptionalSuffix(partAsStr))
@@ -159,18 +159,18 @@ mexui.Control.Date.prototype.validateValueCallback = function(e)
return false;
}
}
return true;
};
mexui.Control.Date.prototype.getArrowIndexByCursor = function()
{
var cursorPos = gui.cursorPosition;
var screenPos = this.getScreenPosition();
var firstArrowStartPos = new Vec2(screenPos.x, screenPos.y + this.valueBoxSize.y);
var lastArrowEndPos = new Vec2(screenPos.x + (this.arrowBoxSize.x * 6), screenPos.y + this.valueBoxSize.y + this.arrowBoxSize.y);
if(cursorPos.x >= firstArrowStartPos.x && cursorPos.y >= firstArrowStartPos.y && cursorPos.x <= lastArrowEndPos.x && cursorPos.y <= lastArrowEndPos.y)
{
return Math.floor((cursorPos.x - firstArrowStartPos.x) / this.arrowBoxSize.x);

View File

@@ -2,11 +2,11 @@ mexui.util.createControlConstructor('DropDown', true, function(window, x, y, w,
{
mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('DropDown', styles), callback);
mexui.Entity.ControlWithEntries.call(this, true, true, new Vec2(0, h), new Vec2(w + 120, 25));
this.axis.y.entriesShown = false;
this.text = text;
this.arrowShown = true;
this.selectedEntryIndex = -1;
this.hoveredEntryIndex = -1;
@@ -18,7 +18,7 @@ mexui.util.linkBaseControlStyles('DropDown', {
{
backgroundColour: toColour(255, 255, 255, 255),
textColour: toColour(0, 0, 0, 255),
hover:
{
backgroundColour: toColour(80, 80, 80, 255),
@@ -34,7 +34,7 @@ mexui.Control.DropDown.prototype.onMouseDown = function(e)
{
if(this.axis.y.entries.length == 0)
return;
var hitButton = this.isCursorOverControl();
if(hitButton)
{
@@ -51,7 +51,7 @@ mexui.Control.DropDown.prototype.onMouseDown = function(e)
}
}
}
if(!e.used)
mexui.Entity.ControlWithEntries.prototype.onMouseDown.call(this, e);
};
@@ -81,20 +81,20 @@ mexui.Control.DropDown.prototype.onKeyDown = function(e, key, mods)
mexui.Control.DropDown.prototype.render = function()
{
var pos = this.getScreenPosition();
mexui.native.drawRectangle(pos, this.size, this.getStyles('main'));
var text = this.selectedEntryIndex == -1 ? this.text : this.axis.y.entries[this.selectedEntryIndex].text;
mexui.native.drawText(pos, this.size, text, this.getStyles('main'));
if(this.arrowShown)
{
var pos2 = new Vec2(pos.x + this.size.x - (25 + 3), pos.y + 0);
mexui.native.drawImage(pos2, new Vec2(25, 25), mexui.images.downArrow, this.getStyles('main'));
}
mexui.Entity.ControlWithEntries.prototype.render.call(this);
if(this.isFocused())
mexui.native.drawRectangleBorder(mexui.util.subtractVec2(pos,new Vec2(2,2)), mexui.util.addVec2(this.size,new Vec2(3,3)), this.getStyles('focused'));
};
@@ -105,31 +105,31 @@ mexui.Control.DropDown.prototype.renderAfter = function()
{
var pos = this.getScreenPosition();
var pos2 = new Vec2(pos.x, pos.y);
pos.x += this.entriesPositionOffset.x;
pos.y += this.entriesPositionOffset.y;
pos2.x += this.entriesPositionOffset.x;
pos2.y += this.entriesPositionOffset.y;
for(var i=this.axis.y.getEntryStartIndex(),j=this.axis.y.getEntryEndIndex(); i<j; i++)
{
var item = this.axis.y.entries[i];
if(!item)
break;
//this.hovered = i == this.axis.y.hoveredEntryIndex;
mexui.native.drawRectangle(pos, this.entrySize, this.getStyles('item'));
mexui.native.drawText(pos, this.entrySize, item.text, this.getStyles('item'));
pos.y += this.entrySize.y;
}
if(this.isFocused())
mexui.native.drawRectangleBorder(mexui.util.subtractVec2(pos2,new Vec2(2,2)), mexui.util.addVec2(new Vec2(this.entrySize.x,this.axis.y.getDisplayedEntriesLength()),new Vec2(3,3)), this.getStyles('focused'));
}
mexui.Entity.ControlWithEntries.prototype.renderAfter.call(this);
};

View File

@@ -30,54 +30,54 @@ mexui.util.linkBaseControlStyles('Grid', {
mexui.Control.Grid.prototype.render = function()
{
var pos = this.getScreenPosition();
mexui.native.drawRectangle(pos, this.size, this.getStyles('main'));
var startX = pos.x;
var maxColumnHeight = 0;
for(var i in this.axis.x.entries)
{
var column = this.axis.x.entries[i];
mexui.native.drawText(new Vec2(startX, pos.y), new Vec2(column.width, column.height), column.text, this.getStyles('header'));
startX += column.width;
mexui.native.drawAALine(new Vec2(startX, pos.y), new Vec2(startX, pos.y + this.size.y), this.getStyles('column'));
if(column.height > maxColumnHeight)
{
maxColumnHeight = column.height;
}
}
var startY = pos.y + maxColumnHeight;
mexui.native.drawAALine(new Vec2(pos.x, startY), new Vec2(pos.x + this.size.x, startY), this.getStyles('row'));
for(var i=this.axis.y.getEntryStartIndex(),j=this.axis.y.getEntryEndIndex(); i<j; i++)
{
var row = this.axis.y.entries[i];
if(!row)
break;
startX = pos.x;
for(var i2 in row.cells)
{
var column = this.axis.x.entries[i2];
var cell = row.cells[i2];
var cellText = cell.text;
var styles = this.getEntryStyles([[cell,'main'], [row,'main'], [this,'row'], [this,'cell']]);
mexui.native.drawRectangle(new Vec2(startX, startY), new Vec2(column.width, column.height), styles);
mexui.native.drawText(new Vec2(startX, startY), new Vec2(column.width, column.height), cellText, styles);
startX += column.width;
}
startY += row.rowHeight;
mexui.native.drawAALine(new Vec2(pos.x, startY), new Vec2(pos.x + this.size.x, startY), this.getStyles('row'));
}
if(this.isFocused())
mexui.native.drawRectangleBorder(mexui.util.subtractVec2(pos,new Vec2(2,2)), mexui.util.addVec2(this.size,new Vec2(3,3)), this.getStyles('focused'));
};
@@ -104,7 +104,7 @@ mexui.Control.Grid.prototype.row = function(cellsData, styles)
cells[i] = new mexui.Component.Entry(this, 1, cellsData[i] + '');
}
}
var entry = new mexui.Entry.GridRow(this, cells, styles);
this.axis.y.addEntry(entry);
return entry;
@@ -127,4 +127,3 @@ mexui.Control.Grid.prototype.getAllEntriesLength = function(axisIndex)
return this.axis.y.getAllEntriesLength2();
}
};

View File

@@ -13,9 +13,9 @@ mexui.Control.Hour.prototype.validateInputCallback = function(e, character)
mexui.Control.Hour.prototype.validateValueCallback = function(e)
{
var _int = parseInt(this.getText());
if(_int < 1 || _int > 23)
return false;
return true;
};

View File

@@ -1,7 +1,7 @@
mexui.util.createControlConstructor('Image', false, function(window, x, y, w, h, filePath, styles)
{
mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('Image', styles));
this.image = mexui.native.loadImage(filePath);
});
@@ -12,9 +12,9 @@ mexui.util.linkBaseControlStyles('Image', {});
mexui.Control.Image.prototype.render = function()
{
var pos = this.getScreenPosition();
mexui.native.drawImage(pos, this.size, this.image, this.getStyles('main'));
if(this.isFocused())
mexui.native.drawRectangleBorder(mexui.util.subtractVec2(pos,new Vec2(2,2)), mexui.util.addVec2(this.size,new Vec2(3,3)), this.getStyles('focused'));
};

View File

@@ -2,7 +2,7 @@ mexui.util.createControlConstructor('List', true, function(window, x, y, w, h, s
{
mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('List', styles), callback);
mexui.Entity.ControlWithEntries.call(this, false, false);
this.activeRow = null;
this.rowHeight = 25;
});
@@ -35,19 +35,19 @@ mexui.Control.List.prototype.render = function()
{
var pos = this.getScreenPosition();
var pos2 = new Vec2(pos.x, pos.y);
for(var i in this.axis.y.entries)
{
var row = this.axis.y.entries[i];
var rowText = row.text;
mexui.native.drawRectangle(pos, new Vec2(this.size.x, this.rowHeight), this.getStyles('row'));
mexui.native.drawText(pos, new Vec2(this.size.x, this.rowHeight), rowText, this.getStyles('row'));
pos.y += this.rowHeight;
mexui.native.drawAALine(pos, new Vec2(pos.x + this.size.x, pos.y), this.getStyles('rowLine'));
}
if(this.isFocused())
mexui.native.drawRectangleBorder(mexui.util.subtractVec2(pos2,new Vec2(2,2)), mexui.util.addVec2(this.size,new Vec2(3,3)), this.getStyles('focused'));
};
@@ -59,4 +59,3 @@ mexui.Control.List.prototype.row = function(text)
this.axis.y.addEntry(entry);
return entry;
};

View File

@@ -13,9 +13,9 @@ mexui.Control.Minute.prototype.validateInputCallback = function(e, character)
mexui.Control.Minute.prototype.validateValueCallback = function(e)
{
var _int = parseInt(this.getText());
if(_int < 1 || _int > 59)
return false;
return true;
};

View File

@@ -1,7 +1,7 @@
mexui.util.createControlConstructor('Password', false, function(window, x, y, w, h, text, styles, callback)
{
mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('Password', styles), callback, false, true);
this.masked = true;
});
mexui.util.extend(mexui.Control.Password, mexui.Control.TextInput);

View File

@@ -1,9 +1,9 @@
mexui.util.createControlConstructor('ProgressBar', false, function(window, x, y, w, h, text, styles)
{
mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('ProgressBar', styles));
this.text = text;
this.progress = 0.0;
});
@@ -12,7 +12,7 @@ mexui.util.linkBaseControlStyles('ProgressBar', {
innerBar:
{
backgroundColour: toColour(0, 255, 0, 255),
hover:
{
backgroundColour: toColour(80, 255, 0, 255)
@@ -24,12 +24,12 @@ mexui.util.linkBaseControlStyles('ProgressBar', {
mexui.Control.ProgressBar.prototype.render = function()
{
var pos = this.getScreenPosition();
mexui.native.drawRectangle(pos, this.size, this.getStyles('main'));
var innerBarSize = new Vec2(this.size.x * this.progress, this.size.y);
mexui.native.drawRectangle(pos, innerBarSize, this.getStyles('innerBar'));
if(this.text != '')
mexui.native.drawText(pos, this.size, this.text, this.getStyles('main'));
};

View File

@@ -1,10 +1,10 @@
mexui.util.createControlConstructor('RadioButton', false, function(window, x, y, w, h, groupId, text, styles, callback)
{
mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('RadioButton', styles), callback);
this.groupId = groupId;
this.text = text;
this.checked = this.isFirstRadioInGroup();
this.textMarginLeft = 5;
});
@@ -42,14 +42,14 @@ mexui.Control.RadioButton.prototype.onKeyDown = function(e, key, mods)
mexui.Control.RadioButton.prototype.render = function()
{
var pos = this.getScreenPosition();
mexui.native.drawRectangle(pos, this.size, this.getStyles('main'));
if(this.checked)
mexui.native.drawRectangle(mexui.util.addVec2(pos, new Vec2(2, 2)), new Vec2(this.size.x - 4, this.size.y - 4), this.getStyles('innerBox'));
mexui.native.drawText(mexui.util.addVec2(pos, new Vec2(this.size.x + this.textMarginLeft, 2)), this.size, this.text, this.getStyles('main'));
if(this.isFocused())
mexui.native.drawRectangleBorder(mexui.util.subtractVec2(pos,new Vec2(2,2)), mexui.util.addVec2(this.size,new Vec2(3,3)), this.getStyles('focused'));
};
@@ -68,11 +68,11 @@ mexui.Control.RadioButton.prototype.getGroupRadios = function()
for(var i in windows)
{
var window = mexui.windows[i];
for(var i2 in window.controls)
{
var control = window.controls[i2];
if((control instanceof mexui.Control.RadioButton) && this.groupId == control.groupId)
{
radios.push(control);
@@ -103,7 +103,7 @@ mexui.Control.RadioButton.prototype.setChecked = function()
var checkedRadio = this.getCheckedRadio();
if(checkedRadio != this.checked)
checkedRadio.checked = false;
this.checked = !this.checked;
this.checkToCallCallback();
};

View File

@@ -1,7 +1,7 @@
mexui.util.createControlConstructor('RangedInteger', false, function(window, x, y, w, h, min, max, text, styles, callback)
{
mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('RangedInteger', styles), callback, false, false);
this.min = min === undefined ? 0 : min;
this.max = max === undefined ? 100 : max;
});
@@ -18,7 +18,7 @@ mexui.Control.RangedInteger.prototype.validateValueCallback = function(e)
var text = this.getText();
if(!mexui.util.isInt(text))
return false;
var _int = parseInt(text);
return _int >= this.min && _int <= this.max;
};

View File

@@ -1,7 +1,7 @@
mexui.util.createControlConstructor('RangedNumber', false, function(window, x, y, w, h, min, max, text, styles, callback)
{
mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('RangedNumber', styles), callback, false, false);
this.min = min === undefined ? 0.0 : min;
this.max = max === undefined ? 100.0 : max;
});
@@ -18,7 +18,7 @@ mexui.Control.RangedNumber.prototype.validateValueCallback = function(e)
var text = this.getText();
if(!mexui.util.isFloat(text))
return false;
var number = parseFloat(text);
return number >= this.min && number <= this.max;
};

View File

@@ -1,11 +1,11 @@
mexui.util.createControlConstructor('ScrollBar', false, function(window, x, y, w, h, isVertical, styles, callback)
{
mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('ScrollBar', styles), callback);
this.isVertical = isVertical;
this.axisIndex = isVertical ? 1 : 0;
this.otherAxisIndex = isVertical ? 0 : 1;
this.barHigherLength = 50;
this.scrolledRatio = 0.0;
this.isScrolling = false;
@@ -16,7 +16,7 @@ mexui.util.linkBaseControlStyles('ScrollBar', {
main:
{
backgroundColour: toColour(0, 0, 0, 190),
hover:
{
backgroundColour: toColour(0, 0, 0, 150)
@@ -25,7 +25,7 @@ mexui.util.linkBaseControlStyles('ScrollBar', {
innerBar:
{
backgroundColour: toColour(79, 161, 246, 190),
hover:
{
backgroundColour: toColour(79, 161, 246, 150)
@@ -69,7 +69,7 @@ mexui.Control.ScrollBar.prototype.onMouseMove = function(e, offset)
this.clampScrolledRatio();
e.used = true;
}
if(!e.used)
mexui.Component.Control.prototype.onMouseMove.call(this, e, offset);
};
@@ -100,7 +100,7 @@ mexui.Control.ScrollBar.prototype.getInnerBarPosition = function()
{
var screenPos = this.getScreenPosition();
var pos = new Vec2(screenPos.x, screenPos.y);
var minPos = pos[this.axisIndex] + 1;
var maxPos = pos[this.axisIndex] + this.size[this.axisIndex] - 2;
pos[this.axisIndex] = minPos + (this.scrolledRatio * (maxPos - minPos - this.barHigherLength));

View File

@@ -13,9 +13,9 @@ mexui.Control.Second.prototype.validateInputCallback = function(e, character)
mexui.Control.Second.prototype.validateValueCallback = function(e)
{
var _int = parseInt(this.getText());
if(_int < 1 || _int > 59)
return false;
return true;
};

View File

@@ -4,14 +4,14 @@ mexui.util.createControlConstructor('Slider', false, function(window, x, y, w, h
text = text === undefined ? '' : text;
minText = minText === undefined ? '' : minText;
maxText = maxText === undefined ? '' : maxText;
mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('Slider', styles), callback);
this.isVertical = isVertical;
this.text = text;
this.minText = minText;
this.maxText = maxText;
this.progress = 0.0;
this.axisIndex = isVertical ? 1 : 0;
this.innerBarSize = new Vec2(30, 25);
@@ -57,7 +57,7 @@ mexui.Control.Slider.prototype.onMouseMove = function(e, offset)
{
if(!this.sliding)
return false;
this.progress += this.getProgressIncreaseByPixels(offset);
this.clampProgress();
e.used = true;
@@ -68,21 +68,21 @@ mexui.Control.Slider.prototype.render = function()
{
var pos = this.getScreenPosition();
var pos2 = new Vec2(pos.x, pos.y);
mexui.native.drawRectangle(pos, this.size, this.getStyles('main'));
mexui.native.drawRectangle(this.getInnerBarPosition(), this.innerBarSize, this.getStyles('innerBar'));
pos.y += this.size.y;
mexui.native.drawText(pos, this.size, this.minText, this.getStyles('minText'));
var offset = (this.size.x - mexui.native.getTextWidth(this.text, this.getStyles('main'))) / 2;
pos.x += offset;
mexui.native.drawText(pos, this.size, this.text, this.getStyles('main'));
pos.x -= offset;
pos.x += this.size.x - mexui.native.getTextWidth(this.maxText, this.getStyles('maxText'));
mexui.native.drawText(pos, this.size, this.maxText, this.getStyles('maxText'));
if(this.isFocused())
mexui.native.drawRectangleBorder(mexui.util.subtractVec2(pos2,new Vec2(2,2)), mexui.util.addVec2(this.size,new Vec2(3,3)), this.getStyles('focused'));
};
@@ -113,4 +113,3 @@ mexui.Control.Slider.prototype.clampProgress = function()
else if(this.progress > 1.0)
this.progress = 1.0;
};

View File

@@ -2,7 +2,7 @@ mexui.util.createControlConstructor('TabPanel', true, function(window, x, y, w,
{
mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('TabPanel', styles));
mexui.Entity.ControlWithEntries.call(this, false, false);
this.activeTabIndex = 0;
});
@@ -13,7 +13,7 @@ mexui.util.linkBaseControlStyles('TabPanel', {
backgroundColour: toColour(240, 20, 20, 200),
borderColour: toColour(120, 20, 20, 225),
textColour: toColour(0, 0, 0, 255),
hover:
{
backgroundColour: toColour(240, 20, 20, 150),
@@ -29,24 +29,24 @@ mexui.Control.TabPanel.prototype.onMouseDown = function(e)
if(e.button == 0)
{
var pos = this.getScreenPosition();
var tabX = pos.x;
for(var i in this.axis.x.entries)
{
var tab = this.axis.x.entries[i];
var tabPos = new Vec2(tabX, pos.y);
var tabSize = new Vec2(mexui.native.getTextWidth(tab.text, this.getStyles('tab')) + 10, 25);
if(mexui.util.isCursorInRectangle(tabPos, tabSize))
{
tab.setActive();
break;
}
tabX += tabSize.x;
}
/*
var tab = this.axis.x.getEntryByCursor();
if(tab)
@@ -59,22 +59,22 @@ mexui.Control.TabPanel.prototype.onMouseDown = function(e)
mexui.Control.TabPanel.prototype.render = function()
{
var pos = this.getScreenPosition();
mexui.native.drawRectangle(pos, this.size, this.getStyles('main'));
var tabX = pos.x;
for(var i in this.axis.x.entries)
{
var tab = this.axis.x.entries[i];
var tabPos = new Vec2(tabX, pos.y);
var tabSize = new Vec2(mexui.native.getTextWidth(tab.text, this.getStyles('tab')) + 10, 25);
mexui.native.drawRectangle(tabPos, tabSize, this.getStyles('tab'));
mexui.native.drawText(tabPos, tabSize, tab.text, this.getStyles('tab'));
tabX += tabSize.x;
}
if(this.isFocused())
mexui.native.drawRectangleBorder(mexui.util.subtractVec2(pos,new Vec2(2,2)), mexui.util.addVec2(this.size,new Vec2(3,3)), this.getStyles('focused'));
};

View File

@@ -1,7 +1,7 @@
mexui.util.createControlConstructor('Text', false, function(window, x, y, w, h, text, styles)
{
mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('Text', styles));
this.text = text;
});
@@ -12,9 +12,9 @@ mexui.util.linkBaseControlStyles('Text', {});
mexui.Control.Text.prototype.render = function()
{
var pos = this.getScreenPosition();
mexui.native.drawText(pos, this.size, this.text, this.getStyles('main'));
if(this.isFocused())
mexui.native.drawRectangleBorder(mexui.util.subtractVec2(pos,new Vec2(2,2)), mexui.util.addVec2(this.size,new Vec2(3,3)), this.getStyles('focused'));
};

View File

@@ -1,7 +1,7 @@
mexui.util.createControlConstructor('TextArea', false, function(window, x, y, w, h, text, styles, callback)
{
mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('TextArea', styles), callback, false, true);
this.multiLine = true;
});
mexui.util.extend(mexui.Control.TextArea, mexui.Control.TextInput);

View File

@@ -3,11 +3,11 @@ mexui.util.createControlConstructor('TextInput', false, function(window, x, y, w
text = text || '';
if(singleCharacter)
multiLineSupported = false;
mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('TextInput', styles), callback);
this.lines = text ? mexui.util.splitLines(text) : [''];
this.caretPosition = new Vec2(0, 0);
this.multiLineSupported = multiLineSupported === undefined ? true : multiLineSupported;
this.multiLine = this.multiLineSupported ? mexui.util.doesContainEOLChar(text) : false;
@@ -17,7 +17,7 @@ mexui.util.createControlConstructor('TextInput', false, function(window, x, y, w
this.caretShownForBlink = true;
this.lineHeight = 25;
this.maxLength = this.singleCharacter ? 1 : false;
this.validValue = true;
});
@@ -44,7 +44,7 @@ mexui.Control.TextInput.prototype.onMouseDown = function(e)
this.caretPosition = this.getCaretPositionByCursor();
}
}
mexui.Component.Control.prototype.onMouseDown.call(this, e);
};
@@ -57,11 +57,11 @@ mexui.Control.TextInput.prototype.onCharacter = function(e, character)
if(!isValid1 && isValid1 !== undefined)
return;
*/
var isValid2 = this.validateInputCallback ? this.validateInputCallback(e, character) : true;
if(!isValid2)
return;
if(this.singleCharacter)
{
this.resetText();
@@ -73,7 +73,7 @@ mexui.Control.TextInput.prototype.onCharacter = function(e, character)
this.lines[this.caretPosition.y] = this.getTextWithNewCharacter(character);
this.caretPosition.x++;
}
this.checkToCallCallback();
this.validateValue(e);
}
@@ -83,9 +83,9 @@ mexui.Control.TextInput.prototype.onKeyDown = function(e, key, mods)
{
if(mexui.focusedControl != this)
return;
var controlIsDown = (mods & KMOD_CTRL) == KMOD_CTRL;
switch(key)
{
case SDLK_LEFT:
@@ -156,7 +156,7 @@ mexui.Control.TextInput.prototype.onKeyDown = function(e, key, mods)
}
break;
}
if(this.multiLine)
{
switch(key)
@@ -199,7 +199,7 @@ mexui.Control.TextInput.prototype.onKeyDown = function(e, key, mods)
break;
}
}
this.validateValue(e);
};
@@ -208,9 +208,9 @@ mexui.Control.TextInput.prototype.render = function()
{
var pos = this.getScreenPosition();
var pos2 = new Vec2(pos.x, pos.y);
mexui.native.drawRectangle(pos, this.size, this.getStyles('main'));
if(this.isEmpty())
{
mexui.native.drawText(pos, this.size, this.placeholder, this.getStyles('placeholder'));
@@ -222,18 +222,18 @@ mexui.Control.TextInput.prototype.render = function()
{
var displayedText = this.masked ? '*'.repeat(this.lines[i].length) : this.lines[i];
mexui.native.drawText(pos, lineSize, displayedText, this.getStyles('main'));
pos.y += this.lineHeight;
}
}
var valueIsInvalid = !this.isEmpty() && !this.validValue;
if(this.isFocused())
{
if(!valueIsInvalid)
mexui.native.drawRectangleBorder(mexui.util.subtractVec2(pos2,new Vec2(2,2)), mexui.util.addVec2(this.size,new Vec2(3,3)), this.getStyles('focused'));
if(this.caretShownForBlink)
{
var pos = this.getScreenPosition();
@@ -246,7 +246,7 @@ mexui.Control.TextInput.prototype.render = function()
mexui.native.drawAALine(caretPoint1, caretPoint2, this.getStyles('caret'));
}
}
if(valueIsInvalid)
mexui.native.drawRectangleBorder(mexui.util.subtractVec2(pos2,new Vec2(2,2)), mexui.util.addVec2(this.size,new Vec2(3,3)), this.getStyles('invalidValue'));
};
@@ -269,7 +269,7 @@ mexui.Control.TextInput.prototype.clampCaretPosition = function()
this.caretPosition.y = 0;
else if(this.caretPosition.y > (this.lines.length - 1))
this.caretPosition.y = this.lines.length - 1;
if(this.caretPosition.x < 0)
this.caretPosition.x = 0;
else if(this.caretPosition.x > this.lines[this.caretPosition.y].length)
@@ -287,7 +287,7 @@ mexui.Control.TextInput.prototype.getCaretLineIndexByCursor = function()
{
var yPos = gui.cursorPosition.y - this.getScreenPosition().y;
var lineIndex = Math.floor(yPos / this.lineHeight);
if(lineIndex < 0)
return 0;
else if(lineIndex > (this.lines.length - 1))
@@ -301,12 +301,12 @@ mexui.Control.TextInput.prototype.getCharIndexByCursor = function(lineIndex)
var xPos = gui.cursorPosition.x - this.getScreenPosition().x;
var line = this.lines[lineIndex];
var lineStyles = this.getStyles('caret');
for(var i=0,j=line.length; i<j; i++)
{
var text = line.substr(0, i + 1);
var textWidth = mexui.native.getTextWidth(text, lineStyles);
if(xPos < textWidth)
return i;
}

View File

@@ -1,11 +1,11 @@
mexui.util.createControlConstructor('Time', false, function(window, x, y, w, h, text, styles, callback)
{
mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('Time', styles), callback, false, false);
this.hour = 0;
this.minute = 0;
this.second = 0;
this.inputShown = false;
this.valueBoxSize = new Vec2(50, 30);
this.arrowBoxSize = new Vec2(25, 22);
@@ -35,29 +35,29 @@ mexui.Control.Time.prototype.onMouseDown = function(e)
var propIndex = (Math.ceil((arrowIndex + 1) / 2)) - 1;
var propName = mexui.Control.Time.units[propIndex];
var isIncrease = (arrowIndex % 2) == 1;
if(isIncrease)
this[propName]++;
else
this[propName]--;
this[propName] %= propIndex == 0 ? 24 : 60;
if(this[propName] == -1)
this[propName] = propIndex == 0 ? 23 : 59;
this.generateText();
return;
}
}
if(this.isCursorOverControl())
{
this.inputShown = !this.inputShown;
e.used = true;
return;
}
if(this.inputShown)
{
this.inputShown = false;
@@ -71,18 +71,18 @@ mexui.Control.Time.prototype.renderAfter = function()
{
if(!this.inputShown)
return;
var screenPos = this.getScreenPosition();
var pos = new Vec2(screenPos.x, screenPos.y);
for(var i=0; i<3; i++)
{
mexui.native.drawRectangle(pos, this.valueBoxSize, this.getStyles('main'));
mexui.native.drawText(pos, this.valueBoxSize, this[mexui.Control.Time.units[i]], this.getStyles('main'));
pos.x += this.valueBoxSize.x;
}
pos = new Vec2(screenPos.x, screenPos.y);
pos.y += this.valueBoxSize.y;
for(var i=0; i<3; i++)
@@ -90,10 +90,10 @@ mexui.Control.Time.prototype.renderAfter = function()
for(var i2=0; i2<2; i2++)
{
var text = (i2 % 2) == 0 ? '<' : '>';
mexui.native.drawRectangle(pos, this.arrowBoxSize, this.getStyles('main'));
mexui.native.drawText(pos, this.arrowBoxSize, text, this.getStyles('main'));
pos.x += this.arrowBoxSize.x;
}
}
@@ -115,42 +115,42 @@ mexui.Control.Time.prototype.validateInputCallback = function(e, character)
mexui.Control.Time.prototype.validateValueCallback = function(e)
{
var parts = this.getText().split(':');
if(parts.length != 3)
return false;
for(var i in parts)
{
var partAsStr = parts[i];
if(partAsStr === '')
return false;
var part = parseInt(partAsStr);
if(partAsStr.length == 2 && partAsStr.substr(0, 1) == '0')
partAsStr = partAsStr.substr(1);
if(!mexui.util.isPositiveInt(partAsStr))
return false;
if(part < 0)
return false;
if(part > (i == 0 ? 23 : 59))
return false;
}
return true;
};
mexui.Control.Time.prototype.getArrowIndexByCursor = function()
{
var cursorPos = gui.cursorPosition;
var screenPos = this.getScreenPosition();
var firstArrowStartPos = new Vec2(screenPos.x, screenPos.y + this.valueBoxSize.y);
var lastArrowEndPos = new Vec2(screenPos.x + (this.arrowBoxSize.x * 6), screenPos.y + this.valueBoxSize.y + this.arrowBoxSize.y);
if(cursorPos.x >= firstArrowStartPos.x && cursorPos.y >= firstArrowStartPos.y && cursorPos.x <= lastArrowEndPos.x && cursorPos.y <= lastArrowEndPos.y)
{
return Math.floor((cursorPos.x - firstArrowStartPos.x) / this.arrowBoxSize.x);

View File

@@ -2,7 +2,7 @@ mexui.util.createControlConstructor('Tree', true, function(window, x, y, w, h, s
{
mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('Tree', styles));
mexui.Entity.ControlWithEntries.call(this, false, false);
this.rowHeight = 25;
this.rowLevelIndentation = 10;
this.scrollMultiplier = 10.0;
@@ -32,10 +32,10 @@ mexui.Control.Tree.prototype.onMouseDown = function(e)
{
var pos = this.getScreenPosition();
pos.y -= this.axis.y.getScrolledOffset();
this.testRowClick(e, this.axis.y.entries, pos);
}
if(!e.used)
mexui.Entity.ControlWithEntries.prototype.onMouseDown.call(this, e);
};
@@ -45,9 +45,9 @@ mexui.Control.Tree.prototype.render = function()
{
var pos = this.getScreenPosition();
pos.y -= this.axis.y.getScrolledOffset();
this.renderRows(this.axis.y.entries, 0, pos);
if(this.isFocused())
mexui.native.drawRectangleBorder(mexui.util.subtractVec2(pos,new Vec2(2,2)), mexui.util.addVec2(this.size,new Vec2(3,3)), this.getStyles('focused'));
};
@@ -58,23 +58,23 @@ mexui.Control.Tree.prototype.renderRows = function(rows, level, pos)
{
var row = rows[i];
var shouldDraw = pos.y >= this.getScreenPosition().y && pos.y <= (this.getScreenPosition().y + this.size.y);
if(shouldDraw)
{
if(row.rows.length > 0)
mexui.native.drawText(new Vec2(pos.x - (this.rowLevelIndentation * 2), pos.y), new Vec2(this.size.x, this.rowHeight), row.open ? '-' : '+', this.getStyles('rowIcon'));
mexui.native.drawRectangle(pos, new Vec2(this.size.x - (this.rowLevelIndentation * level), this.rowHeight), this.getStyles('row'));
mexui.native.drawText(pos, new Vec2(this.size.x, this.rowHeight), row.text, this.getStyles('row'));
}
pos.y += this.rowHeight;
if(shouldDraw)
{
mexui.native.drawAALine(pos, new Vec2(pos.x + this.size.x, pos.y), this.getStyles('rowLine'));
}
if(row.rows.length > 0 && row.open)
{
pos.x += this.rowLevelIndentation;
@@ -106,7 +106,7 @@ mexui.Control.Tree.prototype.testRowClick = function(e, rows, pos)
for(var i in rows)
{
var row = rows[i];
var rowPos = new Vec2(pos.x - (this.rowLevelIndentation * 2), pos.y);
var rowSize = new Vec2(this.size.x + (this.rowLevelIndentation * 2), this.rowHeight);
if(mexui.util.isCursorInRectangle(rowPos, rowSize))
@@ -115,9 +115,9 @@ mexui.Control.Tree.prototype.testRowClick = function(e, rows, pos)
e.used = true;
return;
}
pos.y += this.rowHeight;
if(row.rows.length > 0 && row.open)
{
this.testRowClick(e, row.rows, pos);
@@ -132,10 +132,10 @@ mexui.Control.Tree.prototype.onClickRow = function(row)
if(row.rows.length > 0)
{
//var scrollableLengthBefore = this.axis.y.getScrollableLength();
row.open = !row.open;
this.checkToShowScrollBars();
/*
if(this.scrollBars[1].shown)
{
@@ -153,4 +153,3 @@ mexui.Control.Tree.prototype.row = function(text)
this.axis.y.addEntry(entry);
return entry;
};

View File

@@ -13,9 +13,9 @@ mexui.Control.Week.prototype.validateInputCallback = function(e, character)
mexui.Control.Week.prototype.validateValueCallback = function(e)
{
var _int = parseInt(this.getText());
if(_int < 1 || _int > 52)
return false;
return true;
};

View File

@@ -1,7 +1,7 @@
mexui.util.createControlConstructor('Year', false, function(window, x, y, w, h, text, styles, callback)
{
mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('Year', styles), callback, false, false);
this.maxYearOffset = 10;
this.minYearCallback = ()=>{ return 1900; };
this.maxYearCallback = ()=>{ return new Date().getFullYear() + this.maxYearOffset; }

View File

@@ -1,7 +1,7 @@
mexui.Entity.Component = function(moveable)
{
this.moveable = moveable;
this.moving = false;
};
mexui.util.extend(mexui.Entity.Component, mexui.Entity.StyleableEntity);

View File

@@ -3,7 +3,7 @@ mexui.Entity.ControlAxis = function(control, isVertical, manualScrollBar, entrie
this.control = control;
this.isVertical = isVertical;
this.manualScrollBar = manualScrollBar;
this.axisIndex = isVertical ? 1 : 0;
this.entriesShown = true;
this.entryCountShown = 15;
@@ -27,7 +27,7 @@ mexui.Entity.ControlAxis.prototype.initScrollBar = function()
var pos = mexui.util.addVec2(this.control.position, new Vec2(this.control.entriesPositionOffset.x, this.control.size.y));
this.scrollBar = new mexui.Control.ScrollBar(this.control.window, pos.x, pos.y, this.getDisplayedEntriesLength(), 25, false, this.control.styles.scrollBar);
}
if(this.manualScrollBar)
this.scrollBar.shown = false;
};
@@ -73,19 +73,19 @@ mexui.Entity.ControlAxis.prototype.getEntryIndexByPoint = function(point)
{
return null;
}
var pos = new Vec2(screenPos.x + this.control.entriesPositionOffset.x, screenPos.y + this.control.entriesPositionOffset.y);
var index = Math.floor((point.y - pos.y) / this.control.entrySize[this.axisIndex]);
index += this.getEntryStartIndex();
if(index < 0 || index >= this.entries.length)
return null;
return index;
}
else
{
}
};
@@ -121,7 +121,7 @@ mexui.Entity.ControlAxis.prototype.getDisplayedEntriesLength = function()
mexui.Entity.ControlAxis.prototype.setScrollBarManual = function(manual)
{
this.manualScrollBar = manual;
if(manual)
{
this.setScrollBarShown(false);
@@ -150,7 +150,7 @@ mexui.Entity.ControlAxis.prototype.checkToShowScrollBar = function()
{
if(this.manualScrollBar)
return;
this.setScrollBarShown(this.shouldDisplayScrollBar(), true);
};
@@ -160,7 +160,7 @@ mexui.Entity.ControlAxis.prototype.getScrolledOffset = function()
{
if(!this.scrollBar.shown)
return 0;
return this.scrollBar.scrolledRatio * this.getScrollableLength();
}
else
@@ -197,4 +197,3 @@ mexui.Entity.ControlAxis.prototype.getDisplayedEntryCount = function()
var displayedEntryCount = Math.floor(displayedEntriesLength / this.control.entrySize[this.axisIndex]);
return this.entries.length < displayedEntryCount ? this.entries.length : displayedEntryCount;
};

View File

@@ -4,14 +4,14 @@ mexui.Entity.ControlWithEntries = function(entriesOutsideControl, manualScrollBa
this.entriesPositionOffset = entriesPositionOffset || new Vec2(0, 0);
this.entrySize = entrySize || new Vec2(this.size.x, 25);
this.entriesSizeOffset = entriesSizeOffset || new Vec2(0, 0);
this.axis = {};
this.axis.x = new mexui.Entity.ControlAxis(this, false, manualScrollBar, entriesPositionOffset);
this.axis.y = new mexui.Entity.ControlAxis(this, true, manualScrollBar, entriesPositionOffset);
this.axis.x.initScrollBar();
this.axis.y.initScrollBar();
this.checkToShowScrollBars();
};
mexui.util.extend(mexui.Entity.ControlWithEntries, mexui.Component.Control);
@@ -46,7 +46,7 @@ mexui.Entity.ControlWithEntries.prototype.onMouseMove = function(e, offset)
}
}
}
if(!e.used)
this.triggerEvent('onMouseMove', e, offset);
};
@@ -74,7 +74,7 @@ mexui.Entity.ControlWithEntries.prototype.triggerEvent = function(eventName, e,
return;
}
}
mexui.Component.Control.prototype[eventName].call(this, e, data);
};
@@ -95,4 +95,3 @@ mexui.Entity.ControlWithEntries.prototype.removeAllEntries = function()
this.axis.x.removeAllEntries();
this.axis.y.removeAllEntries();
};

View File

@@ -1,12 +1,12 @@
mexui.Entity.StyleableEntity = function(styles)
{
this.styles = styles;
this.shown = true;
//this.hovered = false;
this.transitions = {}; // string controlPartName => Transition transition
/*
this.transitionDelayTimer = null;
this.transitionStartTime = 0;
@@ -26,9 +26,9 @@ mexui.Entity.StyleableEntity.globalDefaultStyles = {
textAlign: 0.0,
textIndent: 5,
textColour: toColour(0, 0, 0, 255),
backgroundColour: toColour(255, 255, 255, 255),
lineWeight: 1
}
};
@@ -39,14 +39,14 @@ mexui.Entity.StyleableEntity.defaultStyles = mexui.util.linkGlobalStyles(mexui.E
backgroundColour: toColour(255, 255, 255, 255),
borderColour: 'none',
textColour: toColour(0, 0, 0, 255),
hover:
{
backgroundColour: toColour(220, 220, 220, 255),
borderColour: 'none',
textColour: toColour(0, 0, 0, 255)
}/*,
focus:
{
borderColour: toColour(255, 128, 0, 230),
@@ -96,30 +96,30 @@ mexui.Entity.StyleableEntity.prototype.getStyles = function(controlPartName)
var isFocused = this.isFocused();
var isHovered = this.isHovered();
var styles = this.styles[controlPartName];
var transition = this.getTransition(controlPartName);
if(transition.isProcessing())
{
return mexui.util.getTransitionStyles(styles, ['hover'], transition.getMainToPseudoProgress());
}
if(isHovered)
{
return mexui.util.mergeStyles(styles, ['hover']);
}
return styles;
};
mexui.Entity.StyleableEntity.prototype.getEntryStyles = function(data)
{
var styles = {};
for(var i in data)
{
var baseStyles = data[i][0].getStyles(data[i][1]);
for(var k in baseStyles)
{
if(baseStyles.hasOwnProperty(k) && styles[k] === undefined)
@@ -128,11 +128,11 @@ mexui.Entity.StyleableEntity.prototype.getEntryStyles = function(data)
}
}
}
for(var i in data)
{
var baseStyles = data[i][0].getStyles(data[i][1]);
for(var k in baseStyles)
{
if(styles[k] === undefined)
@@ -141,7 +141,7 @@ mexui.Entity.StyleableEntity.prototype.getEntryStyles = function(data)
}
}
}
return styles;
};
@@ -152,10 +152,10 @@ mexui.Entity.StyleableEntity.prototype.onMouseEnter = function()
for(var i in controlParts)
{
var transition = this.getTransition(controlParts[i]);
var delay = this.getTransitionDelayStyle(controlParts[i]);
var time = this.getTransitionTimeStyle(controlParts[i]);
transition.onMouseEnter(delay, time);
}
};
@@ -166,7 +166,7 @@ mexui.Entity.StyleableEntity.prototype.onMouseExit = function()
for(var i in controlParts)
{
var transition = this.getTransition(controlParts[i]);
transition.onMouseExit();
}
};
@@ -207,4 +207,3 @@ mexui.Entity.StyleableEntity.prototype.getTransitionTimeStyle = function(control
else
return mexui.Entity.Transition.defaultTransitionTime;
};

View File

@@ -21,10 +21,10 @@ mexui.Entity.Transition.prototype.onMouseEnter = function(transitionDelay, trans
if(this.isMouseEntered())
return;
this.setMouseEntered(true);
this.transitionDelay = transitionDelay;
this.transitionTime = transitionTime;
if(transitionDelay > 0)
{
this.startDelay();
@@ -44,7 +44,7 @@ mexui.Entity.Transition.prototype.onMouseExit = function()
if(!this.isMouseEntered())
return;
this.setMouseEntered(false);
if(this.isDelayActive())
{
this.clearDelayTimer();
@@ -82,7 +82,7 @@ mexui.Entity.Transition.prototype.stopProcessing = function()
{
this.stopInterpolation();
}
this.delayTimer = null;
this.processing = false;
};
@@ -129,12 +129,12 @@ mexui.Entity.Transition.prototype.increaseMainToPseudoProgress = function()
var timeDiff = mexui.util.time() - this.lastUpdateTime;
this.lastUpdateTime = mexui.util.time();
var progressDiff = timeDiff / this.transitionTime;
if(this.direction)
this.mainToPseudoProgress += progressDiff;
else
this.mainToPseudoProgress -= progressDiff;
if(this.mainToPseudoProgress < 0.0)
{
this.mainToPseudoProgress = 0.0;
@@ -149,7 +149,7 @@ mexui.Entity.Transition.prototype.increaseMainToPseudoProgress = function()
mexui.Entity.Transition.prototype.getMainToPseudoProgress = function()
{
this.increaseMainToPseudoProgress();
return this.mainToPseudoProgress;
};
@@ -181,4 +181,3 @@ mexui.Entity.Transition.prototype.clearDelayTimer = function()
clearTimeout(this.delayTimer);
this.delayTimer = null;
};

View File

@@ -1,7 +1,7 @@
mexui.Entry.DropDownItem = function(dropDown, text)
{
mexui.Component.Entry.call(this, dropDown, 1);
this.text = text;
};
mexui.util.extend(mexui.Entry.DropDownItem, mexui.Component.Entry);

View File

@@ -1,7 +1,7 @@
mexui.Entry.GridColumn = function(grid, text, width, height)
{
mexui.Component.Entry.call(this, grid, 0);
this.text = text || 'Column';
this.width = width || 100;
this.height = height || 25;

View File

@@ -2,7 +2,7 @@ mexui.Entry.GridRow = function(grid, cells, styles)
{
mexui.Component.Entry.call(this, grid, 1);
mexui.Entity.StyleableEntity.call(this, this.linkEntryStyles('GridRow', styles));
this.cells = cells;
this.rowHeight = 25;
};
@@ -10,4 +10,3 @@ mexui.util.extend(mexui.Entry.GridRow, mexui.Component.Entry);
// default styles
mexui.Entry.GridRow.defaultStyles = mexui.util.linkStyles(mexui.Entity.StyleableEntity.defaultStyles, {});

View File

@@ -1,7 +1,7 @@
mexui.Entry.ListRow = function(list, text)
{
mexui.Component.Entry.call(this, list, 1);
this.text = text;
};
mexui.util.extend(mexui.Entry.ListRow, mexui.Component.Entry);

View File

@@ -1,7 +1,7 @@
mexui.Entry.Tab = function(tabPanel, text)
{
mexui.Component.Entry.call(this, tabPanel, 0);
this.text = text;
this.controls = [];
};
@@ -18,9 +18,9 @@ mexui.Entry.Tab.prototype.setActive = function()
{
for(var i in this.control.entries[this.control.activeTabIndex].controls)
this.control.entries[this.control.activeTabIndex].controls[i].shown = false;
this.control.activeTabIndex = this.getEntryIndex();
for(var i in this.control.entries[this.control.activeTabIndex].controls)
this.control.entries[this.control.activeTabIndex].controls[i].shown = true;
};

View File

@@ -1,7 +1,7 @@
mexui.Entry.TreeRow = function(tree, text)
{
mexui.Component.Entry.call(this, tree, 1);
this.open = true;
this.text = text;
this.rows = [];

View File

@@ -151,4 +151,3 @@ mexui.native.drawImage = function(position, size, image, styles)
{
drawing.drawRectangle(image, position, size);
};

View File

@@ -242,9 +242,9 @@ mexui.util.getWindowSize = function()
mexui.util.isRectangleInsideRectangle = function(pos1, size1, pos2, size2)
{
return !(pos2.x > (pos1.x + size1.x) ||
(pos2.x + size2.x) < pos1.x ||
pos2.y > (pos1.y + size1.y) ||
(pos2.y + size2.y) < pos1.y);
(pos2.x + size2.x) < pos1.x ||
pos2.y > (pos1.y + size1.y) ||
(pos2.y + size2.y) < pos1.y);
};
mexui.util.mergeStyles = function(styles, pseudoPartNames)

View File

@@ -297,4 +297,3 @@ mexui.setInput = function(showInput)
// }
//}
};