[Add] resedit: Faction editor and support for planet factions.

This commit is contained in:
Allanis 2013-04-19 19:56:45 +01:00
parent 86dd13174b
commit 8fd0e73e66
6 changed files with 252 additions and 17 deletions

84
utils/resedit/faction.py Normal file
View File

@ -0,0 +1,84 @@
#!/usr/bin/env python
import gtk, gtk.glade
import gobject
import data
class Factions:
def __init__(self):
self.faction = {}
self.factionsXML = "../../dat/faction.xml"
self.glade = "space.glade"
self.cur_faction = ""
def loadFactions(self, xmlfile=None):
if xmlfile == None:
xmlFile = self.factionsXML
self.factions = data.load(xmlfile, "faction", True)
def saveFactions(self, xmlfile=None):
"""
Needs to take into account alliances to be implemented properly.
"""
print "TODO"
def data(self):
return self.factions
def window(self):
self.wtree = gtk.glade.XML(self.glade, "winFactions")
hooks = {
"treFactions":["button-release-event", self.__update]
}
for key, val in hooks.items():
self.__widget(key).connect(val[0], val[1])
# List the factions.
self.__createTree()
self.__widget("winFactions").show_all()
def __widget(self, name):
return self.wtree.get_widget(name)
def __createTree(self):
wgt = self.__widget("treFactions")
tree = gtk.TreeStore(str)
for faction in self.factions: # Load the factions.
treenode = tree.append(None, [faction])
col = gtk.TreeViewColumn('Factions')
cell = gtk.CellRendererText()
if wgt.get_column(0):
wgt.remove_column(wgt.get_column(0))
wgt.append_column(col)
col.pack_start(cell, True)
col.add_attribute(cell, 'text', 0)
wgt.set_model(tree)
def __update(self, wgt=None, event=None):
self.cur_faction = self.__curFaction()
if self.cur_faction == "":
return
dic = {
"entName":self.cur_faction
}
for key, value in dic.items():
self.__widget(key).set_text(str(value))
def __curFaction(self):
tree = self.__widget("treFactions")
model = tree.get_model()
try:
iter = tree.get_selection().get_selected()[1]
except:
return ""
return model.get_value(iter, 0)
def debug(self):
print "---FACTIONS--------------------"
print self.factions
print "-------------------------------"

BIN
utils/resedit/faction.pyc Normal file

Binary file not shown.

View File

@ -1,10 +1,26 @@
#!/usr/bin/env python
import space
try:
import gtk, gtk.glade
import gobject
except:
print "You do not have python gtk bindings, or you're missin glade libs"
print "To use Lephisto's resedit you must install them"
print "http://pygtk.org/"
raise SystemExit
import space, faction
# Load the factions
factions = faction.Factions()
factions.loadFactions("../../dat/faction.xml")
factions.window()
# Load the universe.
universe = space.Space()
universe = space.Space(factions.data())
universe.loadSystems("../../dat/ssys.xml")
universe.loadPlanets("../../dat/planet.xml")
universe.window()
gtk.main()

View File

@ -957,4 +957,97 @@
</widget>
</child>
</widget>
<widget class="GtkWindow" id="winFactions">
<property name="width_request">400</property>
<property name="height_request">150</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<child>
<widget class="GtkHPaned" id="hpaned3">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<child>
<widget class="GtkTreeView" id="treFactions">
<property name="width_request">150</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="headers_clickable">True</property>
</widget>
<packing>
<property name="resize">False</property>
<property name="shrink">True</property>
</packing>
</child>
<child>
<widget class="GtkLayout" id="layout3">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<child>
<widget class="GtkLabel" id="label15">
<property name="width_request">72</property>
<property name="height_request">20</property>
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">Name</property>
</widget>
<packing>
<property name="x">34</property>
<property name="y">17</property>
</packing>
</child>
<child>
<widget class="GtkEntry" id="entName">
<property name="width_request">100</property>
<property name="height_request">20</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
</widget>
<packing>
<property name="x">108</property>
<property name="y">17</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="butSave">
<property name="width_request">62</property>
<property name="height_request">37</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">Save</property>
<property name="response_id">0</property>
</widget>
<packing>
<property name="x">105</property>
<property name="y">46</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="butNew">
<property name="width_request">68</property>
<property name="height_request">37</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">New</property>
<property name="response_id">0</property>
</widget>
<packing>
<property name="x">13</property>
<property name="y">45</property>
</packing>
</child>
</widget>
<packing>
<property name="resize">True</property>
<property name="shrink">True</property>
</packing>
</child>
</widget>
</child>
</widget>
</glade-interface>

View File

@ -1,25 +1,23 @@
#!/usr/bin/env python
try:
import gtk,gtk.glade
import gobject
except:
print "You do not have python gtk bindings, or you're missing glade libs"
print "To use Lephisto's resedit you must install them"
print "http://pygtk.org/ "
raise SystemExit
import data
class Space:
def __init__(self):
def __init__(self, factions=None):
self.glade = "space.glade"
self.systemsXML = "../../dat/ssys.xml"
self.planetsXML = "../../dat/planet.xml"
self.planet_gfx = "../../gfx/planet/"
self.loadSystems(self.systemsXML)
self.loadPlanets(self.planetsXML)
if factions==None:
self.factions = {}
else:
self.factions = factions
def loadSystems(self, xmlfile):
self.systems = data.load(xmlfile, "ssys", True,
@ -105,6 +103,7 @@ class Space:
"butNew":["clicked", self.__pnew],
"trePlanets":["button-release-event", self.__pupdate],
"comSystem":["changed", self.__pnewSys],
"comFaction":["changed", self.__pnewFact],
"butSave":["clicked", self.savePlanets]
}
for key, val in hooks.items():
@ -118,15 +117,25 @@ class Space:
"M", "O", "P", "Q", "R", "S", "T", "X", "Y", "Z", "0", "1"]
wgt = self.__pwidget("comClass")
combo = gtk.ListStore(str)
for a in classes:
node = combo.append(a)
for c in classes:
node = combo.append(c)
cell = gtk.CellRendererText()
wgt.pack_start(cell, True)
wgt.add_attribute(cell, 'text', 0)
wgt.set_model(combo)
# Factions.
wgt = self.__pwidget("comFaction")
combo = gtk.ListStore(str)
combo.append(["None"])
for f in self.factions.keys():
node = combo.append([f])
cell = gtk.CellRendererText()
wgt.pack_start(cell, True)
wgt.add_attribute(cell, "text", 0)
wgt.set_model(combo)
# ---------------------------------------------
gtk.main()
def __create_treSystems(self):
# Populate the tree.
@ -239,6 +248,19 @@ class Space:
wgt.set_active_iter(model.get_iter(i))
i = i + 1
# Faction.
wgt = self.__pwidget("comFaction")
try:
fact = planet["general"]["faction"]
i = 0
model = wgt.get_model()
for row in model:
if row[0] == fact:
wgt.set_active(i)
i = i + 1
except:
wgt.set_active(0) # None.
# Tech.
try:
self.__pwidget("spiTech0").set_text(str(planet["general"]["tech"]["main"]))
@ -641,14 +663,34 @@ class Space:
self.__supdate()
self.__pupdate()
def __pnewFact(self, wgt=None, event=None):
combo = self.__pwidget("comFaction")
fact = combo.get_active_text()
planet = self.planets[self.cur_planet]
if planet == "":
return
if fact == "None":
try:
del planet["general"]["faction"]
except:
return
else:
planet["general"]["faction"] = fact
def debug(self):
print "SYSTEMS LOADED:"
print "---SYSTEMS------------------"
print
for name, sys in self.systems.items():
print "SYSTEM: %s" % name
print " ---SYSTEM: %s-----------" % name
print sys
print " ------------------------"
print
print "----------------------------"
print
print "PLANETS LOADED:"
print "---PLANETS------------------"
print self.planets
print "----------------------------"
print

Binary file not shown.