source: trunk/tools/writing_editor/scripts/dialogMap.py @ 280

Revision 280, 2.9 KB checked in by bretzel_parpg, 10 years ago (diff)

Patch by Bretzel.

  • Wrote a parser for the new syntax I developed (I will post about this at the forums in the Dialog System Implementation thread)
  • Started to add a dialogue map, which will show you the flow of the dialogue
  • Overrode the resize event in the application so that it will also resize the editor and dialog map
Line 
1#!/usr/bin/python
2
3#   This file is part of PARPG.
4
5#   PARPG is free software: you can redistribute it and/or modify
6#   it under the terms of the GNU General Public License as published by
7#   the Free Software Foundation, either version 3 of the License, or
8#   (at your option) any later version.
9
10#   PARPG is distributed in the hope that it will be useful,
11#   but WITHOUT ANY WARRANTY; without even the implied warranty of
12#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13#   GNU General Public License for more details.
14
15#   You should have received a copy of the GNU General Public License
16#   along with PARPG.  If not, see <http://www.gnu.org/licenses/>.
17
18from PyQt4 import QtGui, QtCore
19from scripts.parser import parse
20
21class DialogScene(object):
22    """
23    The scene that contains the dialog map
24    """
25    def __init__(self, widget):
26        """
27        Initialize the scene
28        @type widget: QtGui.QTextEdit
29        @param widget: the widget that contians the text to add objects from
30        @return: None
31        """
32        self.widget = widget
33        self.refreshMap()
34
35    def refreshMap(self):
36        """
37        Refresh the map to reflect all the new data
38        @return: None
39        """
40        self.scene = QtGui.QGraphicsScene()
41        objects = self.findObjects(self.widget.toPlainText())
42        self.addObjectsFromList(objects)
43
44    def findObjects(self, text):
45        """
46        Parse text and then return the objects
47        @return: a list of all the objects
48        """
49        objects = []
50
51        ptext = parse(text)
52        objects.append(ptext)
53        for obj in ptext.options:
54            objects.append(obj)
55
56        return objects
57
58    def addObjectsFromList(self, obj_list):
59        """
60        Add all of the objects in a list to the dialog map
61        @type obj_list: list
62        @param obj_list: the list of objects
63        @return: None
64        """
65        pos = 50
66        for obj in obj_list:
67 #           print obj
68            item = QtGui.QGraphicsEllipseItem(pos,pos,50,50)
69            self.scene.addItem(item)
70            pos += 10
71#        print "Scene list: " + str(self.scene.items())
72   
73
74class DialogMap(QtGui.QGraphicsView):
75    """
76    The dialog map final widget
77    """
78    def __init__(self, settings, main_edit, parent):
79        """
80        @type settings: settings.Settings
81        @param settings: the settings for the editor
82        @type main_edit: QtGui.QTextEdit
83        @param main_edit: The main text editor
84        @type parent: Any Qt widget
85        @param parent: The widgets' parent
86        @return: None
87        """
88        QtGui.QWidget.__init__(self, parent)
89        self.map = DialogScene(main_edit)
90        self.setScene(self.map.scene)
91        self.setSceneRect(0,0,int(settings.res_width),int(settings.res_height))
92        self.setGeometry(QtCore.QRect(0,0,int(settings.res_width),int(settings.res_height)))
Note: See TracBrowser for help on using the repository browser.