Cosmetic changes to the webclient options
- Renamed the used attribute - Changed to use only one inputfunc
This commit is contained in:
parent
221aa362ab
commit
8dcd242d3b
3 changed files with 68 additions and 61 deletions
|
|
@ -421,58 +421,62 @@ def unmonitor(session, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
kwargs["stop"] = True
|
kwargs["stop"] = True
|
||||||
monitor(session, *args, **kwargs)
|
monitor(session, *args, **kwargs)
|
||||||
|
|
||||||
def _on_webclient_setting_change(**kwargs):
|
|
||||||
|
def _on_webclient_options_change(**kwargs):
|
||||||
"""
|
"""
|
||||||
Called when the settings stored on the player changes.
|
Called when the webclient options stored on the player changes.
|
||||||
Inform the interested clients of this change.
|
Inform the interested clients of this change.
|
||||||
"""
|
"""
|
||||||
session = kwargs["session"]
|
session = kwargs["session"]
|
||||||
obj = kwargs["obj"]
|
obj = kwargs["obj"]
|
||||||
fieldname = kwargs["fieldname"]
|
fieldname = kwargs["fieldname"]
|
||||||
clientsettings = _GA(obj, fieldname)
|
clientoptions = _GA(obj, fieldname)
|
||||||
|
|
||||||
session.msg(webclient_settings=clientsettings)
|
|
||||||
|
|
||||||
def webclient_settings(session, *args, **kwargs):
|
session.msg(webclient_options=clientoptions)
|
||||||
|
|
||||||
|
|
||||||
|
def webclient_options(session, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
Handles returning and monitoring stored settings relatede to the webclient.
|
Handles retrieving and changing of options related to the webclient.
|
||||||
|
|
||||||
|
If kwargs is empty (or contains just a "cmdid"), the saved options will be
|
||||||
|
sent back to the session.
|
||||||
|
A monitor handler will be created to inform the client of any future options
|
||||||
|
that changes.
|
||||||
|
|
||||||
|
If kwargs is not empty, the key/values stored in there will be persisted
|
||||||
|
to the player object.
|
||||||
|
|
||||||
Kwargs:
|
Kwargs:
|
||||||
monitor (bool): If this is true, starts monitoring the settings for
|
<option name>: an option to save
|
||||||
changes too
|
|
||||||
"""
|
"""
|
||||||
player = session.player
|
player = session.player
|
||||||
|
|
||||||
clientsettings = settings.WEBCLIENT_SETTINGS.copy()
|
|
||||||
storedsettings = player.db.webclient_settings or {}
|
|
||||||
clientsettings.update(storedsettings)
|
|
||||||
|
|
||||||
session.msg(webclient_settings=clientsettings)
|
|
||||||
|
|
||||||
if kwargs.get("monitor", False):
|
clientoptions = settings.WEBCLIENT_OPTIONS.copy()
|
||||||
|
storedoptions = player.db._saved_webclient_options or {}
|
||||||
|
clientoptions.update(storedoptions)
|
||||||
|
|
||||||
|
# The webclient adds a cmdid to every kwargs, but we don't need it.
|
||||||
|
try:
|
||||||
|
del kwargs["cmdid"]
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if not kwargs:
|
||||||
|
# No kwargs: we are getting the stored options
|
||||||
|
session.msg(webclient_options=clientoptions)
|
||||||
|
|
||||||
|
# Create a monitor. If a monitor already exists then it will replace
|
||||||
|
# the previous one since it would use the same idstring
|
||||||
from evennia.scripts.monitorhandler import MONITOR_HANDLER
|
from evennia.scripts.monitorhandler import MONITOR_HANDLER
|
||||||
MONITOR_HANDLER.add(player, "webclient_settings",
|
MONITOR_HANDLER.add(player, "webclient_options",
|
||||||
_on_webclient_setting_change,
|
_on_webclient_options_change,
|
||||||
idstring=session.sessid, persistent=False,
|
idstring=session.sessid, persistent=False,
|
||||||
session=session)
|
session=session)
|
||||||
|
else:
|
||||||
def set_webclient_settings(session, *args, **kwargs):
|
# kwargs provided: persist them to the player object
|
||||||
"""
|
for key, value in kwargs.iteritems():
|
||||||
Handles changing of a setting related to the webclient: the setting will
|
clientoptions[key] = value
|
||||||
get saved to the player object.
|
|
||||||
|
|
||||||
Kwargs:
|
|
||||||
<setting>: A setting to save.
|
|
||||||
"""
|
|
||||||
|
|
||||||
player = session.player
|
|
||||||
|
|
||||||
clientsettings = settings.WEBCLIENT_SETTINGS.copy()
|
|
||||||
storedsettings = player.db.webclient_settings or {}
|
|
||||||
clientsettings.update(storedsettings)
|
|
||||||
|
|
||||||
for key, value in kwargs.iteritems():
|
|
||||||
clientsettings[key] = value
|
|
||||||
|
|
||||||
player.db.webclient_settings = clientsettings
|
player.db._saved_webclient_options = clientoptions
|
||||||
|
|
|
||||||
|
|
@ -623,8 +623,8 @@ STATICFILES_IGNORE_PATTERNS = ('README.md',)
|
||||||
# directory names shown in the templates directory.
|
# directory names shown in the templates directory.
|
||||||
WEBSITE_TEMPLATE = 'website'
|
WEBSITE_TEMPLATE = 'website'
|
||||||
WEBCLIENT_TEMPLATE = 'webclient'
|
WEBCLIENT_TEMPLATE = 'webclient'
|
||||||
# The default settings used by the webclient
|
# The default options used by the webclient
|
||||||
WEBCLIENT_SETTINGS = {
|
WEBCLIENT_OPTIONS = {
|
||||||
"gagprompt": True, # Gags prompt from the output window and keep them
|
"gagprompt": True, # Gags prompt from the output window and keep them
|
||||||
# together with the input bar
|
# together with the input bar
|
||||||
"helppopup": True, # Shows help files in a new popup window
|
"helppopup": True, # Shows help files in a new popup window
|
||||||
|
|
@ -633,7 +633,7 @@ WEBCLIENT_SETTINGS = {
|
||||||
"notification_sound": False # Plays a sound for notifications of new
|
"notification_sound": False # Plays a sound for notifications of new
|
||||||
# messages
|
# messages
|
||||||
}
|
}
|
||||||
|
|
||||||
# We setup the location of the website template as well as the admin site.
|
# We setup the location of the website template as well as the admin site.
|
||||||
TEMPLATES = [{
|
TEMPLATES = [{
|
||||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||||
|
|
|
||||||
|
|
@ -107,8 +107,8 @@ function doSendText() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Opens the settings dialog
|
// Opens the options dialog
|
||||||
function doOpenSettings() {
|
function doOpenOptions() {
|
||||||
if (!Evennia.isConnected()) {
|
if (!Evennia.isConnected()) {
|
||||||
alert("You need to be connected.");
|
alert("You need to be connected.");
|
||||||
return;
|
return;
|
||||||
|
|
@ -239,11 +239,11 @@ function onPrompt(args, kwargs) {
|
||||||
|
|
||||||
// Called when the user logged in
|
// Called when the user logged in
|
||||||
function onLoggedIn() {
|
function onLoggedIn() {
|
||||||
Evennia.msg("webclient_settings", [], {"monitor": true});
|
Evennia.msg("webclient_options", [], {});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called when a setting changed
|
// Called when a setting changed
|
||||||
function onGotSetting(args, kwargs) {
|
function onGotOptions(args, kwargs) {
|
||||||
$.each(kwargs, function(key, value) {
|
$.each(kwargs, function(key, value) {
|
||||||
var elem = $("[data-setting='" + key + "']");
|
var elem = $("[data-setting='" + key + "']");
|
||||||
if (elem.length === 0) {
|
if (elem.length === 0) {
|
||||||
|
|
@ -255,10 +255,13 @@ function onGotSetting(args, kwargs) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called when the user changed a setting from the interface
|
// Called when the user changed a setting from the interface
|
||||||
function onSettingCheckboxChanged() {
|
function onOptionCheckboxChanged() {
|
||||||
var name = $(this).data("setting");
|
var name = $(this).data("setting");
|
||||||
var value = this.checked;
|
var value = this.checked;
|
||||||
Evennia.msg("set_webclient_settings", [], {name: value});
|
var options = {};
|
||||||
|
options[name] = value;
|
||||||
|
|
||||||
|
Evennia.msg("webclient_options", [], options);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Silences events we don't do anything with.
|
// Silences events we don't do anything with.
|
||||||
|
|
@ -341,23 +344,23 @@ function onNewLine(text, originator) {
|
||||||
function doStartDragDialog(event) {
|
function doStartDragDialog(event) {
|
||||||
var dialog = $(event.target).closest(".dialog");
|
var dialog = $(event.target).closest(".dialog");
|
||||||
dialog.css('cursor', 'move');
|
dialog.css('cursor', 'move');
|
||||||
|
|
||||||
var position = dialog.offset();
|
var position = dialog.offset();
|
||||||
var diffx = event.pageX;
|
var diffx = event.pageX;
|
||||||
var diffy = event.pageY;
|
var diffy = event.pageY;
|
||||||
|
|
||||||
var drag = function(event) {
|
var drag = function(event) {
|
||||||
var y = position.top + event.pageY - diffy;
|
var y = position.top + event.pageY - diffy;
|
||||||
var x = position.left + event.pageX - diffx;
|
var x = position.left + event.pageX - diffx;
|
||||||
dialog.offset({top: y, left: x});
|
dialog.offset({top: y, left: x});
|
||||||
};
|
};
|
||||||
|
|
||||||
var undrag = function() {
|
var undrag = function() {
|
||||||
$(document).unbind("mousemove", drag);
|
$(document).unbind("mousemove", drag);
|
||||||
$(document).unbind("mouseup", undrag);
|
$(document).unbind("mouseup", undrag);
|
||||||
dialog.css('cursor', '');
|
dialog.css('cursor', '');
|
||||||
}
|
}
|
||||||
|
|
||||||
$(document).bind("mousemove", drag);
|
$(document).bind("mousemove", drag);
|
||||||
$(document).bind("mouseup", undrag);
|
$(document).bind("mouseup", undrag);
|
||||||
}
|
}
|
||||||
|
|
@ -394,19 +397,19 @@ $(document).ready(function() {
|
||||||
|
|
||||||
// Pressing the send button
|
// Pressing the send button
|
||||||
$("#inputsend").bind("click", doSendText);
|
$("#inputsend").bind("click", doSendText);
|
||||||
|
|
||||||
// Pressing the settings button
|
// Pressing the settings button
|
||||||
$("#optionsbutton").bind("click", doOpenSettings);
|
$("#optionsbutton").bind("click", doOpenOptions);
|
||||||
|
|
||||||
// Checking a checkbox in the settings dialog
|
// Checking a checkbox in the settings dialog
|
||||||
$("[data-setting]").bind("change", onSettingCheckboxChanged);
|
$("[data-setting]").bind("change", onOptionCheckboxChanged);
|
||||||
|
|
||||||
// Pressing the close button on a dialog
|
// Pressing the close button on a dialog
|
||||||
$(".dialogclose").bind("click", doCloseDialog);
|
$(".dialogclose").bind("click", doCloseDialog);
|
||||||
|
|
||||||
// Makes dialogs draggable
|
// Makes dialogs draggable
|
||||||
$(".dialogtitle").bind("mousedown", doStartDragDialog);
|
$(".dialogtitle").bind("mousedown", doStartDragDialog);
|
||||||
|
|
||||||
// This is safe to call, it will always only
|
// This is safe to call, it will always only
|
||||||
// initialize once.
|
// initialize once.
|
||||||
Evennia.init();
|
Evennia.init();
|
||||||
|
|
@ -416,7 +419,7 @@ $(document).ready(function() {
|
||||||
Evennia.emitter.on("default", onDefault);
|
Evennia.emitter.on("default", onDefault);
|
||||||
Evennia.emitter.on("connection_close", onConnectionClose);
|
Evennia.emitter.on("connection_close", onConnectionClose);
|
||||||
Evennia.emitter.on("logged_in", onLoggedIn);
|
Evennia.emitter.on("logged_in", onLoggedIn);
|
||||||
Evennia.emitter.on("webclient_settings", onGotSetting);
|
Evennia.emitter.on("webclient_options", onGotOptions);
|
||||||
// silence currently unused events
|
// silence currently unused events
|
||||||
Evennia.emitter.on("connection_open", onSilence);
|
Evennia.emitter.on("connection_open", onSilence);
|
||||||
Evennia.emitter.on("connection_error", onSilence);
|
Evennia.emitter.on("connection_error", onSilence);
|
||||||
|
|
@ -436,8 +439,8 @@ $(document).ready(function() {
|
||||||
},
|
},
|
||||||
60000*3
|
60000*3
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue