[Add] resedit: More progress on the planet editor.

This commit is contained in:
Allanis 2013-04-16 21:35:08 +01:00
parent a1c18084fd
commit 24969cf807
3 changed files with 253 additions and 50 deletions

View File

@ -5,7 +5,7 @@
<property name="width_request">750</property>
<property name="height_request">450</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="title" translatable="yes">Systems</property>
<property name="title" translatable="yes">System Editor</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
<child>
<widget class="GtkVBox" id="vbox1">
@ -422,8 +422,9 @@
</widget>
<widget class="GtkWindow" id="winPlanets">
<property name="width_request">600</property>
<property name="height_request">450</property>
<property name="height_request">500</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="title" translatable="yes">Planet Editor</property>
<child>
<widget class="GtkHPaned" id="hpaned2">
<property name="visible">True</property>
@ -490,8 +491,8 @@
</child>
<child>
<widget class="GtkComboBox" id="comFaction">
<property name="width_request">129</property>
<property name="height_request">29</property>
<property name="width_request">182</property>
<property name="height_request">24</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>
</widget>
@ -520,22 +521,22 @@
<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">11</property>
<property name="y">94</property>
<property name="x">12</property>
<property name="y">173</property>
</packing>
</child>
<child>
<widget class="GtkTreeView" id="treCommodities">
<property name="width_request">188</property>
<property name="height_request">166</property>
<property name="height_request">149</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="x">16</property>
<property name="y">116</property>
<property name="x">17</property>
<property name="y">196</property>
</packing>
</child>
<child>
@ -547,7 +548,7 @@
</widget>
<packing>
<property name="x">15</property>
<property name="y">287</property>
<property name="y">350</property>
</packing>
</child>
<child>
@ -562,8 +563,8 @@
<property name="response_id">0</property>
</widget>
<packing>
<property name="x">15</property>
<property name="y">318</property>
<property name="x">16</property>
<property name="y">380</property>
</packing>
</child>
<child>
@ -579,19 +580,19 @@
</widget>
<packing>
<property name="x">115</property>
<property name="y">316</property>
<property name="y">380</property>
</packing>
</child>
<child>
<widget class="GtkVSeparator" id="vseparator2">
<property name="width_request">20</property>
<property name="height_request">255</property>
<property name="height_request">171</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>
</widget>
<packing>
<property name="x">209</property>
<property name="y">110</property>
<property name="y">194</property>
</packing>
</child>
<child>
@ -602,8 +603,8 @@
<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">7</property>
<property name="y">360</property>
<property name="x">6</property>
<property name="y">419</property>
</packing>
</child>
<child>
@ -615,8 +616,8 @@
<property name="label" translatable="yes">Services</property>
</widget>
<packing>
<property name="x">232</property>
<property name="y">115</property>
<property name="x">254</property>
<property name="y">194</property>
</packing>
</child>
<child>
@ -632,7 +633,7 @@
</widget>
<packing>
<property name="x">240</property>
<property name="y">145</property>
<property name="y">215</property>
</packing>
</child>
<child>
@ -648,7 +649,7 @@
</widget>
<packing>
<property name="x">320</property>
<property name="y">145</property>
<property name="y">215</property>
</packing>
</child>
<child>
@ -664,7 +665,7 @@
</widget>
<packing>
<property name="x">240</property>
<property name="y">170</property>
<property name="y">235</property>
</packing>
</child>
<child>
@ -680,7 +681,7 @@
</widget>
<packing>
<property name="x">240</property>
<property name="y">195</property>
<property name="y">255</property>
</packing>
</child>
<child>
@ -696,7 +697,7 @@
</widget>
<packing>
<property name="x">320</property>
<property name="y">195</property>
<property name="y">255</property>
</packing>
</child>
<child>
@ -707,8 +708,8 @@
<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">221</property>
<property name="y">217</property>
<property name="x">219</property>
<property name="y">274</property>
</packing>
</child>
<child>
@ -720,8 +721,8 @@
<property name="label" translatable="yes">Tech</property>
</widget>
<packing>
<property name="x">246</property>
<property name="y">238</property>
<property name="x">260</property>
<property name="y">293</property>
</packing>
</child>
<child>
@ -734,12 +735,12 @@
</widget>
<packing>
<property name="x">222</property>
<property name="y">260</property>
<property name="y">320</property>
</packing>
</child>
<child>
<widget class="GtkSpinButton" id="spinbutton1">
<property name="width_request">72</property>
<widget class="GtkSpinButton" id="spiTech0">
<property name="width_request">58</property>
<property name="height_request">20</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
@ -747,8 +748,8 @@
<property name="adjustment">0 0 100000 1 10 10</property>
</widget>
<packing>
<property name="x">272</property>
<property name="y">260</property>
<property name="x">300</property>
<property name="y">320</property>
</packing>
</child>
<child>
@ -760,8 +761,8 @@
<property name="label" translatable="yes">Special</property>
</widget>
<packing>
<property name="x">225</property>
<property name="y">290</property>
<property name="x">224</property>
<property name="y">345</property>
</packing>
</child>
<child>
@ -775,7 +776,7 @@
</widget>
<packing>
<property name="x">235</property>
<property name="y">315</property>
<property name="y">365</property>
</packing>
</child>
<child>
@ -789,7 +790,7 @@
</widget>
<packing>
<property name="x">300</property>
<property name="y">315</property>
<property name="y">365</property>
</packing>
</child>
<child>
@ -803,7 +804,7 @@
</widget>
<packing>
<property name="x">235</property>
<property name="y">340</property>
<property name="y">390</property>
</packing>
</child>
<child>
@ -817,19 +818,19 @@
</widget>
<packing>
<property name="x">300</property>
<property name="y">340</property>
<property name="y">390</property>
</packing>
</child>
<child>
<widget class="GtkComboBox" id="comSystem">
<property name="width_request">160</property>
<property name="height_request">25</property>
<property name="height_request">23</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>
</widget>
<packing>
<property name="x">12</property>
<property name="y">400</property>
<property name="y">465</property>
</packing>
</child>
<child>
@ -841,7 +842,7 @@
<property name="label" translatable="yes">System</property>
</widget>
<packing>
<property name="y">378</property>
<property name="y">440</property>
</packing>
</child>
<child>
@ -856,8 +857,8 @@
<property name="response_id">0</property>
</widget>
<packing>
<property name="x">190</property>
<property name="y">377</property>
<property name="x">189</property>
<property name="y">438</property>
</packing>
</child>
<child>
@ -869,8 +870,82 @@
<property name="label" translatable="yes">Class</property>
</widget>
<packing>
<property name="x">227</property>
<property name="y">60</property>
<property name="x">289</property>
<property name="y">20</property>
</packing>
</child>
<child>
<widget class="GtkImage" id="imaPlanet">
<property name="width_request">152</property>
<property name="height_request">122</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="stock">gtk-missing-image</property>
</widget>
<packing>
<property name="x">260</property>
<property name="y">48</property>
</packing>
</child>
<child>
<widget class="GtkComboBox" id="comClass">
<property name="width_request">79</property>
<property name="height_request">33</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>
</widget>
<packing>
<property name="x">341</property>
<property name="y">9</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label13">
<property name="width_request">101</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">GFX Space</property>
</widget>
<packing>
<property name="y">92</property>
</packing>
</child>
<child>
<widget class="GtkComboBox" id="comSpace">
<property name="width_request">163</property>
<property name="height_request">24</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>
</widget>
<packing>
<property name="x">96</property>
<property name="y">89</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label14">
<property name="width_request">98</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">GFX Exterior</property>
</widget>
<packing>
<property name="x">10</property>
<property name="y">123</property>
</packing>
</child>
<child>
<widget class="GtkComboBox" id="comExterior">
<property name="width_request">154</property>
<property name="height_request">22</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>
</widget>
<packing>
<property name="x">106</property>
<property name="y">120</property>
</packing>
</child>
</widget>
@ -883,4 +958,3 @@
</child>
</widget>
</glade-interface>

View File

@ -17,6 +17,7 @@ class Space:
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)
@ -66,7 +67,7 @@ class Space:
"butReset":["clicked", self.__space_reset],
"butAddJump":["clicked", self.__jump_add],
"butRmJump":["clicked", self.__jump_rm],
"butNew":["clicked", self.__new]
"butNew":["clicked", self.__snew]
}
for key, val in hooks.items():
self.__swidget(key).connect(val[0], val[1])
@ -99,6 +100,29 @@ class Space:
self.__pwidget("winPlanets").show_all()
self.cur_planet = ""
# Hooks.
hooks = {
"butNew":["clicked", self.__pnew],
"trePlanets":["button-release-event", self.__pupdate]
}
for key, val in hooks.items():
self.__pwidget(key).connect(val[0], val[1])
# Planet tree.
self.__create_trePlanets()
# Classes.
classes = [ "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L",
"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)
cell = gtk.CellRendererText()
wgt.pack_start(cell, True)
wgt.add_attribute(cell, "text", 0)
wgt.set_model(combo)
# ---------------------------------------------
gtk.main()
@ -119,6 +143,22 @@ class Space:
col.add_attribute(cell, 'text', 0)
wgt.set_model(self.tree_systems)
def __create_trePlanets(self):
# Population.
wgt = self.__pwidget("trePlanets")
self.tree_planets = gtk.TreeStore(str)
for planet in self.planets:
treenode = self.tree_planets.append(None, [planet])
col = gtk.TreeViewColumn('Planets')
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(self.tree_planets)
def __swidget(self,wgtname):
"""
get a widget from the winSystems
@ -180,6 +220,48 @@ class Space:
return
planet = self.planets[self.cur_planet]
dic = {
"inpName":self.cur_planet
}
for key, value in dic.items():
self.__pwidget(key).set_text(str(value))
# Class.
cls = planet["general"]["class"]
i = 0
wgt = self.__pwidget("comClass")
model = wgt.get_model()
for row in model:
if row[0] == cls:
wgt.set_active_iter(model.get_iter(i))
i = i + 1
# Tech.
try:
self.__pwidget("spiTech0").set_text(str(planet["general"]["tech"]["main"]))
except:
self.__pwidget("spiTech0").set_text(str(0))
# Services.
services = int(planet["general"]["services"])
serv = {
"cheLand":2**0,
"cheBasic":2**1,
"cheCommodity":2**2,
"cheOutfits":2**3,
"cheShipyard":2**4,
}
for s, m in serv.items():
if services & m > 0:
self.__pwidget(s).set_active(True)
else:
self.__pwidget(s).set_active(False)
self.__pwidget("imaPlanet").set_from_file(self.planet_gfx + "space/" +
planet["GFX"]["space"])
def __sstore(self):
sys_name = self.__swidget("inpName").get_text()
if sys_name == "":
@ -220,6 +302,43 @@ class Space:
self.__sinpStore(system, "spiInterference", "general", "interference")
self.__sinpStore(system, "spiAsteroids", "general", "asteroids")
def __pstore(self):
planet_name = self.__swidget("inpName").get_text()
if planet_name == "":
return
if planet_name != self.cur_planet:
self.planets[planet_name] = self.planets[self.cur_planet]
model = self.__pwidget("trePlanets").get_model()
for i in model:
if i[0] == self.cur_planet:
i[0] = planet_name
break
del self.planets[self.cur_planet]
self.cur_planet = planet_name
try:
planet = self.planets[self.cur_planet]
except:
return
# Get the service.
services = 0
serv = {
"cheLand":2**0,
"cheBasic":2**1,
"cheCommodity":2**2,
"cheOutfits":2**3,
"cheShipyard":2**4
}
for s, m in serv.items():
if self.__pwidget(s).get_active():
services = services + m
planet["general"]["services"] = services
def __sinpStore(self, system, wgt, tag, minortag=None):
text = self.__swidget(wgt).get_text()
if minortag==None:
@ -427,8 +546,8 @@ class Space:
self.__supdate()
self.__space_draw()
def __new(self, wgt=None, event=None):
name = "untitled"
def __snew(self, wgt=None, event=None):
name = "new system"
gen = { "asteroids":0, "interference":0, "stars":100 }
pos = { "x":0, "y":0 }
new_ssys = { "general":gen, "pos":pos, "jumps":[], "fleets":{}, "planets":[] }
@ -436,6 +555,16 @@ class Space:
self.__create_treSystems()
self.__selSys(name)
def __pnew(self, wgt=None, event=None):
name = "new planet"
gfx = { "space":"none.png" }
gen = { "class":"A", "services":0, "GFX":gfx }
pos = { "x":0, "y":0 }
new_planet = { "general":gen, "pos":pos }
self.planets[name] = new_planet
self.__create_trePlanets()
self.__selPlanet(name)
def __selSys(self, system):
i = 0
tree = self.__swidget("treSystems")

Binary file not shown.