forked from SuperTux/flexlay
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimpleed.py
More file actions
executable file
·129 lines (98 loc) · 4.74 KB
/
simpleed.py
File metadata and controls
executable file
·129 lines (98 loc) · 4.74 KB
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
#!/usr/bin/env python3
# Flexlay - A Generic 2D Game Editor
# Copyright (C) 2014 Ingo Ruhnke <grumbel@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import random
from flexlay import (Flexlay, PixelBuffer, Sprite, Tile, Tileset, EditorMap,
TilemapLayer, ObjectLayer, ObjMapRectObject, Color, TileBrush, ObjectBrush,
ToolContext)
from flexlay.math import Size, Point, Rect
from flexlay.tools import WorkspaceMoveTool, ObjMapSelectTool, TilePaintTool
from flexlay.util import Config
def main():
flexlay = Flexlay("Simple Editor")
gui_manager = flexlay.create_gui_manager()
config = Config.create("simple-editor")
button_panel = gui_manager.create_button_panel(horizontal=True)
def on_object_tool():
workspace.set_tool(1, objtool)
workspace.set_tool(2, workspace_move_tool)
workspace.set_tool(3, TilePaintTool())
button_panel.add_text("ObjectTool", on_object_tool)
def on_tile_tool():
workspace.set_tool(1, tilemap_paint_tool)
workspace.set_tool(2, workspace_move_tool)
workspace.set_tool(3, tilemap_paint_tool)
button_panel.add_text("TileTool", on_tile_tool)
def on_generic_dialog():
dialog = gui_manager.create_generic_dialog("Generic Dialog")
dialog.add_bool("An Bool:", True)
dialog.add_int("An Int:", 5)
dialog.add_float("An Int:", 5.0)
dialog.add_string("An String:", "String")
dialog.add_enum("An Enum:", ["String", "Foo", "bar"], 0)
dialog.set_ok_callback(lambda: print(dialog.get_values()))
button_panel.add_text("Generic Dialog", on_generic_dialog)
menubar = gui_manager.create_menubar()
file_menu = menubar.add_menu("&File")
file_menu.add_item("Open...", lambda: print("Open"))
file_menu.add_item("Save...", lambda: print("Save"))
file_menu.add_item("Quit...", lambda: print("Quit"))
view_menu = menubar.add_menu("&View")
view_menu.add_item("Zoom In", lambda: print("Zoom In"))
view_menu.add_item("Zoom Out", lambda: print("Zoom Out"))
view_menu.add_item("Reset Zoom", lambda: print("Reset Zoom"))
editor_map_component = gui_manager.create_editor_map_component()
editormap = EditorMap()
tileset = Tileset(32)
tileset.add_tile(0, Tile(PixelBuffer.from_file("data/images/icons16/resize1.png"),
Sprite.from_file("data/images/icons16/resize1.png")))
tileset.add_tile(1, Tile(PixelBuffer.from_file("data/images/icons16/resize_vert.png"),
Sprite.from_file("data/images/icons16/resize_vert.png")))
tilemap = TilemapLayer(tileset, 20, 10)
TilemapLayer.current = tilemap
tilemap.set_draw_grid(True)
object_layer = ObjectLayer()
editormap.add_layer(tilemap)
editormap.add_layer(object_layer)
for i in range(20):
obj = ObjMapRectObject(Rect(Point(random.randint(0, 499), random.randint(0, 499)),
Size(32, 32)),
Color(0, 0, 255), None)
object_layer.add_object(obj)
workspace = editor_map_component.get_workspace()
workspace.set_map(editormap)
ToolContext()
ToolContext.current.tile_brush.put(0, 0, 1)
workspace_move_tool = WorkspaceMoveTool()
objtool = ObjMapSelectTool(gui_manager)
tilemap_paint_tool = TilePaintTool()
# tilemap_paint_tool.set_brush(ToolContext.current.tile_brush)
workspace.set_tool(1, objtool)
workspace.set_tool(2, workspace_move_tool)
# workspace.set_tool(1, tilemap_paint_tool)
# workspace.set_tool(3, tilemap_paint_tool)
object_selector = gui_manager.create_object_selector(40, 40)
object_selector.add_brush(ObjectBrush(Sprite.from_file("data/images/icons16/resize1.png"), None))
object_selector.add_brush(ObjectBrush(Sprite.from_file("data/images/icons16/resize2.png"), None))
tile_selector = gui_manager.create_tile_selector()
# tile_selector.set_tiles("All the tiles", tileset.get_tiles())
# tile_selector.set_tiles("All the tiles again", tileset.get_tiles())
# tile_selector.set_tiles("And again", tileset.get_tiles())
print("Successs!")
gui_manager.run()
if __name__ == "__main__":
main()
# EOF #