summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/ui/editor/EditorToolbar.js
blob: a5ad2dd024d883cb435ac8dc1b1db5e465d61c9a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
var EditorToolbar = View.extend({
	el: "#editorToolbar",

	events: {
	  "mousedown": 'stopPropagation',
	  "mouseenter": 'mouseenter',
	  "mouseleave": 'mouseleave',
		"click [data-role='undo']": 'undo',
		"click [data-role='toggle-map-view']": 'toggleMap',
		"click [data-role='toggle-project-settings']": 'toggleSettings',
		"click [data-role='open-media-viewer']": 'openMediaViewer',
    "click [data-role='toggle-presets']": 'togglePresets',
		"click [data-role='toggle-wallpaper-panel']": 'toggleWallpaper',
		"click [data-role='toggle-color-control']": 'toggleColorControl',
		"click [data-role='toggle-text-editor']": 'toggleTextEditor',
	},
	
	initialize: function(opt){
		this.parent = opt.parent
	},

	undo: function(e){
		if (e.shiftKey) {
			var canRedo = UndoStack.redo()
			console.log("can redo", canRedo)
		}
		else {
			var canUndo = UndoStack.undo()
			console.log("can undo", canUndo)
		}
	},
	
	toggleMap: function(state){
// 		if (typeof state != "boolean") {
// 		  state = ! $("[data-role='toggle-map-view']").hasClass("inuse")
//       this.resetControls()
// 		}
//     $("[data-role='toggle-map-view']").toggleClass("inuse", state)
		var state = map.toggle(state)
		if (state) { map.ui.blur() }
		$("#minimap").toggleClass("hide", state)
		this.parent.info.toggle(state)
	},
	
	toggleSettings: function(){
// 	  this.resetMode()
    this.toggleMap(false)
    this.parent.textEditor.hide()
		this.parent.presets.hide()
		this.parent.colorControl.hide()
		this.parent.wallpaperPicker.hide()
		this.parent.mediaEditor.hide()
		this.parent.settings.toggle()
	},
	
	openMediaViewer: function(){
		this.resetMode()
		this.resetControls()
		this.toggleMap(false)
		this.parent.mediaViewer.show()
	},

	resetMode: function(){
 	  $(".inuse").removeClass("inuse")
    $("body").removeClass("addText")
		this.parent.hideExtras()
		this.resetPermissions()
	},
	
	resetControls: function(){
	  $(".inuse").removeClass("inuse")
    this.toggleMap(false)
    this.parent.textEditor.hide()
		this.parent.wallpaperPicker.hide()
		this.parent.presets.hide()
		this.parent.colorControl.hide()
		this.parent.settings.hide()
	},
	
	resetPermissions: function(){
    editor.permissions.add("pick")
    editor.permissions.add("move")
    editor.permissions.add("resize")
    editor.permissions.remove("destroy")
	},
	
	toggleWallpaper: function(){
		var state = ! $("[data-role='toggle-wallpaper-panel']").hasClass("inuse")
		this.resetMode()
		$("[data-role='toggle-wallpaper-panel']").toggleClass("inuse", state)
		this.parent.mediaEditor.hide()
		this.parent.colorControl.hide()
    this.parent.textEditor.hide()
		this.parent.settings.hide()
		this.parent.presets.hide()
		this.toggleMap(false)
		this.parent.wallpaperPicker.toggle(state)
	},
	
	toggleColorControl: function(){
		var state = ! $("[data-role='toggle-color-control']").hasClass("inuse")
		this.resetMode()
		$("[data-role='toggle-color-control']").toggleClass("inuse", state)
		this.parent.mediaEditor.hide()
		this.parent.wallpaperPicker.hide()
    this.parent.textEditor.hide()
		this.parent.settings.hide()
		this.parent.presets.hide()
		this.toggleMap(false)
		this.parent.colorControl.toggle(state)
	},
	
	toggleTextEditor: function(){
		var state = ! $("[data-role='toggle-text-editor']").hasClass("inuse")
		this.resetMode()
		$("[data-role='toggle-text-editor']").toggleClass("inuse", state)
		this.parent.mediaEditor.hide()
		this.parent.wallpaperPicker.hide()
		this.parent.colorControl.hide()
		this.parent.settings.hide()
		this.parent.presets.hide()
		this.toggleMap(false)
		this.parent.textEditor.toggle(state)
  },

	togglePresets: function(){
		var state = ! $("[data-role='toggle-presets']").hasClass("inuse")
		this.resetMode()
		$("[data-role='toggle-presets']").toggleClass("inuse", state)
		this.parent.mediaEditor.hide()
		this.parent.wallpaperPicker.hide()
    this.parent.textEditor.hide()
		this.parent.settings.hide()
		this.parent.colorControl.hide()
		this.toggleMap(false)
		this.parent.presets.toggle(state)
	},
	
	mouseenter: function(){
	  this.parent.cursor.hide()
	},
	
	mouseleave: function(){
	  this.parent.cursor.show()
	},
})

var editor = new function(){
	this.permissions = new Permissions({
	  'pick': true,
		'move': true,
		'resize': true,
		'destroy': false,
	})
}