[Add] <resedit> You can modify planet commodities now.
This commit is contained in:
parent
2103fecfc4
commit
87514e63a7
22
utils/resedit/commodity.py
Normal file
22
utils/resedit/commodity.py
Normal file
@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import data
|
||||
|
||||
class Commodities:
|
||||
def __init__(self):
|
||||
self.commodities = {}
|
||||
self.commoditiesXML = "../../dat/commodity.xml"
|
||||
|
||||
def loadCommodities(self, xmlfile=None):
|
||||
if xmlfile == None:
|
||||
xmlFile = self.commoditiesXML
|
||||
self.commodities = data.load(xmlfile, "commodity", True)
|
||||
|
||||
def data(self):
|
||||
return self.commodities
|
||||
|
||||
def debug(self):
|
||||
print "---Commodities--------------------"
|
||||
print self.commodities
|
||||
print "----------------------------------"
|
||||
|
@ -9,20 +9,26 @@ except:
|
||||
print "http://pygtk.org/"
|
||||
raise SystemExit
|
||||
|
||||
import space, faction, fleet
|
||||
import space, faction, fleet, commodity
|
||||
|
||||
path = "../../dat/"
|
||||
|
||||
# Load the factions
|
||||
factions = faction.Factions()
|
||||
factions.loadFactions("../../dat/faction.xml")
|
||||
factions.loadFactions(path+"faction.xml")
|
||||
|
||||
# Load the fleets.
|
||||
fleets = fleet.Fleets()
|
||||
fleets.loadFleets("../../dat/fleet.xml")
|
||||
fleets.loadFleets(path+"fleet.xml")
|
||||
|
||||
# Load the commodities.
|
||||
commodities = commodity.Commodities()
|
||||
commodities.loadCommodities(path+"commodity.xml")
|
||||
|
||||
# Load the universe.
|
||||
universe = space.Space(factions.data(), fleets.data())
|
||||
universe.loadSystems("../../dat/ssys.xml")
|
||||
universe.loadPlanets("../../dat/planet.xml")
|
||||
universe = space.Space(factions.data(), fleets.data(), commodities.data())
|
||||
universe.loadSystems(path+"ssys.xml")
|
||||
universe.loadPlanets(path+"planet.xml")
|
||||
|
||||
# Load the editor interface.
|
||||
# Functions.
|
||||
|
@ -7,7 +7,7 @@ import data
|
||||
|
||||
class Space:
|
||||
|
||||
def __init__(self, factions=None, fleets=None):
|
||||
def __init__(self, factions=None, fleets=None, commodities=None):
|
||||
self.space_glade = "space.glade"
|
||||
self.planet_glade = "planets.glade"
|
||||
self.systemsXML = "../../dat/ssys.xml"
|
||||
@ -15,14 +15,9 @@ class Space:
|
||||
self.planet_gfx = "../../gfx/planet/"
|
||||
self.loadSystems(self.systemsXML)
|
||||
self.loadPlanets(self.planetsXML)
|
||||
if factions==None:
|
||||
self.factions = {}
|
||||
else:
|
||||
self.factions = factions
|
||||
if fleets==None:
|
||||
self.fleets = {}
|
||||
else:
|
||||
self.fleets = fleets
|
||||
self.factions = {} if factions is None else factions
|
||||
self.fleets = {} if fleets is None else fleets
|
||||
self.commodities = {} if commodities is None else commodities
|
||||
|
||||
self.swtree = None
|
||||
self.pwtree = None
|
||||
@ -136,7 +131,9 @@ class Space:
|
||||
"trePlanets":["button-release-event", self.__pupdate],
|
||||
"comSystem":["changed", self.__pnewSys],
|
||||
"comFaction":["changed", self.__pnewFact],
|
||||
"butSave":["clicked", self.savePlanets]
|
||||
"butSave":["clicked", self.savePlanets],
|
||||
"butComAdd":["clicked", self.__commodity_add],
|
||||
"butComRm":["clicked", self.__commodity_rm]
|
||||
}
|
||||
for key, val in hooks.items():
|
||||
self.__pwidget(key).connect(val[0], val[1])
|
||||
@ -169,6 +166,17 @@ class Space:
|
||||
wgt.set_model(combo)
|
||||
wgt.set_active(0)
|
||||
|
||||
# Commodities.
|
||||
wgt = self.__pwidget("comCommodities")
|
||||
combo.append(["None"])
|
||||
for c in self.commodities.keys():
|
||||
node = combo.append([c])
|
||||
cell = gtk.CellRendererText()
|
||||
wgt.pack_start(cell, True)
|
||||
wgt.add_attribute(cell, 'text', 0)
|
||||
wgt.set_model(combo)
|
||||
wgt.set_active(0)
|
||||
|
||||
def windowPlanetClose(self):
|
||||
wgt = self.__pwidget("winPlanets")
|
||||
if wgt != None:
|
||||
@ -206,6 +214,23 @@ class Space:
|
||||
col.add_attribute(cell, 'text', 0)
|
||||
wgt.set_model(self.tree_planets)
|
||||
|
||||
def __create_treCommodities(self):
|
||||
# Treeview.
|
||||
wgt = self.__pwdiget("treCommodities")
|
||||
self.tree_commodities = gtk.TreeStore(str)
|
||||
try:
|
||||
for commodity in self.planets[self.cur_planet]["general"]["commodities"]:
|
||||
treenode = self.tree_commodities.append(None, [commodity])
|
||||
except:
|
||||
commodity = None
|
||||
col = gtk.TreeViewColumn('Commodities')
|
||||
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_commodities)
|
||||
|
||||
def __swidget(self,wgtname):
|
||||
"""
|
||||
@ -360,6 +385,9 @@ class Space:
|
||||
wgt.set_active_iter(combo.get_iter(i))
|
||||
i = i + 1
|
||||
|
||||
# Commodities.
|
||||
self.__create_treCommodities()
|
||||
|
||||
def __sstore(self):
|
||||
sys_name = self.__swidget("inpName").get_text()
|
||||
if sys_name == "":
|
||||
@ -684,6 +712,35 @@ class Space:
|
||||
return
|
||||
i = i+1
|
||||
|
||||
"""
|
||||
Add or remove a commodity from a planet.
|
||||
"""
|
||||
def __comodity_sel(self):
|
||||
tree = self.__pwidget("treCommodities")
|
||||
model = tree.get_model()
|
||||
try:
|
||||
iter = tree.get_selection().get_selected()[1]
|
||||
except:
|
||||
return ""
|
||||
return model.get_value(iter, 0)
|
||||
|
||||
def __commodity_add(self, wgt=None, event=None):
|
||||
commodity = self.__pwidget("comCommodities").get_active_text()
|
||||
if commodity != "None" and self.cur_planet != "":
|
||||
planet = self.planets[self.cur_planet]
|
||||
try:
|
||||
planet["general"]["commodities"].append(commodity)
|
||||
data.uniq(planet["general"]["commodities"])
|
||||
except:
|
||||
planet["general"]["commodities"] = [commodity]
|
||||
self.__pupdate()
|
||||
|
||||
def __commodity_rm(self, wgt=None, event=None):
|
||||
commodity = self.__commodity_sel()
|
||||
if commodity != "":
|
||||
self.planets[self.cur_planet]["general"]["commodities"].remove(commodity)
|
||||
self.__pupdate()
|
||||
|
||||
"""
|
||||
Create a new star system.
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user